Mercurial > lcfOS
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/makeinitrd.py Fri Jul 05 14:13:59 2013 +0200 @@ -0,0 +1,34 @@ +#!/usr/bin/python + +# Script for generation of an initial ramdisk that contains +# the first programs to run. + +import struct +import sys + +if len(sys.argv) < 3: + print('Usage: {0} output file1 [file2] ...'.format(sys.argv[0])) + sys.exit(1) + +outputfilename = sys.argv[1] +inputFileNames = sys.argv[2:] + +with open(outputfilename, 'wb') as outputFile: + # Amount of files: + outputFile.write(struct.pack('<I', 0x1337babe)) + outputFile.write(struct.pack('<I', len(inputFileNames))) + for inputFileName in inputFileNames: + # Magic: + outputFile.write(struct.pack('<I', 0xcafebabe)) + + # Filename: + fn = inputFileName.encode('ascii') + outputFile.write(struct.pack('<I', len(fn))) + outputFile.write(fn) + + # Data: + with open(inputFileName, 'rb') as inputFile: + data = inputFile.read() + outputFile.write(struct.pack('<I', len(data))) + outputFile.write(data) +