view customtasks.py @ 410:6aa9743ed362 tip

Reflect change in c3 public modifier
author Windel Bouwman
date Mon, 23 Feb 2015 21:06:04 +0100
parents ad6be5454067
children
line wrap: on
line source

"""
    Custom task to create boot image.
"""
from ppci import tasks
import struct


@tasks.register_task('mkimage')
class MkImageTask(tasks.Task):
    """ Concatenate kernel and boot data in cunning manner """
    def run(self):
        self.logger.info('Constructing boot image')
        data = bytearray()
        # TODO: parameterize:

        # Read kernel:
        with open(self.relpath('kernel/obj/kernel.bin'), 'rb') as f:
            data += f.read()

        # Read images:
        with open(self.relpath('user/obj/init.bin'), 'rb') as f:
            init = f.read()

        # Construct table:
        table = struct.pack('<II', 0x1337, 1)
        data += table
        data += struct.pack('<I', len(init))
        data += init


        # Produce output:
        with open(self.relpath('image.img'), 'wb') as f:
            f.write(data)