comparison python/makeinitrd.py @ 217:8b2e5f3cd579

Removed some stale python source files
author Windel Bouwman
date Fri, 05 Jul 2013 14:13:59 +0200
parents cos/utils/makeinitrd.py@35cc54e078dd
children
comparison
equal deleted inserted replaced
216:57c032c5e753 217:8b2e5f3cd579
1 #!/usr/bin/python
2
3 # Script for generation of an initial ramdisk that contains
4 # the first programs to run.
5
6 import struct
7 import sys
8
9 if len(sys.argv) < 3:
10 print('Usage: {0} output file1 [file2] ...'.format(sys.argv[0]))
11 sys.exit(1)
12
13 outputfilename = sys.argv[1]
14 inputFileNames = sys.argv[2:]
15
16 with open(outputfilename, 'wb') as outputFile:
17 # Amount of files:
18 outputFile.write(struct.pack('<I', 0x1337babe))
19 outputFile.write(struct.pack('<I', len(inputFileNames)))
20 for inputFileName in inputFileNames:
21 # Magic:
22 outputFile.write(struct.pack('<I', 0xcafebabe))
23
24 # Filename:
25 fn = inputFileName.encode('ascii')
26 outputFile.write(struct.pack('<I', len(fn)))
27 outputFile.write(fn)
28
29 # Data:
30 with open(inputFileName, 'rb') as inputFile:
31 data = inputFile.read()
32 outputFile.write(struct.pack('<I', len(data)))
33 outputFile.write(data)
34