annotate customtasks.py @ 408:ad6be5454067

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