408
|
1 """
|
|
2 Custom task to create boot image.
|
|
3 """
|
|
4 from ppci import tasks
|
|
5 import struct
|
|
6
|
|
7
|
|
8 @tasks.register_task('mkimage')
|
|
9 class MkImageTask(tasks.Task):
|
|
10 """ Concatenate kernel and boot data in cunning manner """
|
|
11 def run(self):
|
|
12 self.logger.info('Constructing boot image')
|
|
13 data = bytearray()
|
|
14 # TODO: parameterize:
|
|
15
|
|
16 # Read kernel:
|
|
17 with open(self.relpath('kernel/obj/kernel.bin'), 'rb') as f:
|
|
18 data += f.read()
|
|
19
|
|
20 # Read images:
|
|
21 with open(self.relpath('user/obj/init.bin'), 'rb') as f:
|
|
22 init = f.read()
|
|
23
|
|
24 # Construct table:
|
|
25 table = struct.pack('<II', 0x1337, 1)
|
|
26 data += table
|
|
27 data += struct.pack('<I', len(init))
|
|
28 data += init
|
|
29
|
|
30
|
|
31 # Produce output:
|
|
32 with open(self.relpath('image.img'), 'wb') as f:
|
|
33 f.write(data)
|