Mercurial > lcfOS
annotate python/makeinitrd.py @ 237:81752b0f85a5
Added burn led test program
author | Windel Bouwman |
---|---|
date | Wed, 17 Jul 2013 22:31:54 +0200 |
parents | 8b2e5f3cd579 |
children |
rev | line source |
---|---|
32
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
1 #!/usr/bin/python |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
2 |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
3 # Script for generation of an initial ramdisk that contains |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
4 # the first programs to run. |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
5 |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
6 import struct |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
7 import sys |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
8 |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
9 if len(sys.argv) < 3: |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
10 print('Usage: {0} output file1 [file2] ...'.format(sys.argv[0])) |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
11 sys.exit(1) |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
12 |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
13 outputfilename = sys.argv[1] |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
14 inputFileNames = sys.argv[2:] |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
15 |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
16 with open(outputfilename, 'wb') as outputFile: |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
17 # Amount of files: |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
18 outputFile.write(struct.pack('<I', 0x1337babe)) |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
19 outputFile.write(struct.pack('<I', len(inputFileNames))) |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
20 for inputFileName in inputFileNames: |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
21 # Magic: |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
22 outputFile.write(struct.pack('<I', 0xcafebabe)) |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
23 |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
24 # Filename: |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
25 fn = inputFileName.encode('ascii') |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
26 outputFile.write(struct.pack('<I', len(fn))) |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
27 outputFile.write(fn) |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
28 |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
29 # Data: |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
30 with open(inputFileName, 'rb') as inputFile: |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
31 data = inputFile.read() |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
32 outputFile.write(struct.pack('<I', len(data))) |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
33 outputFile.write(data) |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
34 |