Exemplo n.º 1
0
def prepare(address, ldname, fwname):
    def encrypt(source, target, env):
        marlin.encrypt_mks(source, target, env, fwname)

    marlin.relocate_firmware(address)
    marlin.custom_ld_script(ldname)
    marlin.add_post_action(encrypt)
Exemplo n.º 2
0
def prepare(address, ldname, fwname):
    import pioutil
    if pioutil.is_pio_build():
        import marlin

        def encrypt(source, target, env):
            marlin.encrypt_mks(source, target, env, fwname)

        marlin.relocate_firmware(address)
        marlin.custom_ld_script(ldname)
        marlin.add_post_action(encrypt)
Exemplo n.º 3
0
#
# For build.offset define LD_FLASH_OFFSET, used by ldscript.ld
#
if 'offset' in board.get("build").keys():
    LD_FLASH_OFFSET = board.get("build.offset")
    marlin.relocate_vtab(LD_FLASH_OFFSET)

    # Flash size
    maximum_flash_size = int(board.get("upload.maximum_size") / 1024)
    marlin.replace_define('STM32_FLASH_SIZE', maximum_flash_size)

    # Get upload.maximum_ram_size (defined by /buildroot/share/PlatformIO/boards/VARIOUS.json)
    maximum_ram_size = board.get("upload.maximum_ram_size")

    for i, flag in enumerate(env["LINKFLAGS"]):
        if "-Wl,--defsym=LD_FLASH_OFFSET" in flag:
            env["LINKFLAGS"][
                i] = "-Wl,--defsym=LD_FLASH_OFFSET=" + LD_FLASH_OFFSET
        if "-Wl,--defsym=LD_MAX_DATA_SIZE" in flag:
            env["LINKFLAGS"][i] = "-Wl,--defsym=LD_MAX_DATA_SIZE=" + str(
                maximum_ram_size - 40)

#
# Only copy the file if there's no encrypt
#
board_keys = board.get("build").keys()
if 'firmware' in board_keys and ('encrypt' not in board_keys
                                 or board.get("build.encrypt") == 'No'):
    import marlin
    marlin.add_post_action(noencrypt)
Exemplo n.º 4
0
            if "-Wl,--defsym=LD_FLASH_OFFSET" in flag:
                env["LINKFLAGS"][
                    i] = "-Wl,--defsym=LD_FLASH_OFFSET=" + LD_FLASH_OFFSET
            if "-Wl,--defsym=LD_MAX_DATA_SIZE" in flag:
                env["LINKFLAGS"][i] = "-Wl,--defsym=LD_MAX_DATA_SIZE=" + str(
                    maximum_ram_size - 40)

    #
    # For build.encrypt rename and encode the firmware file.
    #
    if 'encrypt' in board_keys:

        # Encrypt ${PROGNAME}.bin and save it with the name given in build.encrypt
        def encrypt(source, target, env):
            marlin.encrypt_mks(source, target, env, board.get("build.encrypt"))

        if board.get("build.encrypt") != "":
            marlin.add_post_action(encrypt)

    #
    # For build.rename simply rename the firmware file.
    #
    if 'rename' in board_keys:

        def rename_target(source, target, env):
            firmware = os.path.join(target[0].dir.path,
                                    board.get("build.rename"))
            os.rename(target[0].path, firmware)

        marlin.add_post_action(rename_target)
        bootloader = open(bootloader_bin, "rb")
        lengthbootloader = os.path.getsize(bootloader_bin)

        firmware_with_boothloader_bin = target[
            0].dir.path + '/firmware_with_bootloader.bin'
        if os.path.exists(firmware_with_boothloader_bin):
            os.remove(firmware_with_boothloader_bin)
        firmwareimage = open(firmware_with_boothloader_bin, "wb")
        position = 0
        while position < lengthbootloader:
            byte = bootloader.read(1)
            firmwareimage.write(byte)
            position += 1
        position = 0
        while position < lengthfirmware:
            byte = firmware.read(1)
            firmwareimage.write(byte)
            position += 1
        bootloader.close()
        firmware.close()
        firmwareimage.close()

        firmware_without_bootloader_bin = target[
            0].dir.path + '/firmware_for_sd_upload.bin'
        if os.path.exists(firmware_without_bootloader_bin):
            os.remove(firmware_without_bootloader_bin)
        os.rename(target[0].path, firmware_without_bootloader_bin)
        #os.rename(target[0].dir.path+'/firmware_with_bootloader.bin', target[0].dir.path+'/firmware.bin')

    marlin.add_post_action(addboot)
Exemplo n.º 6
0
    for block_number in range(0, block_count):
        block_offset = (block_number * block_size)
        block_end = block_offset + block_size
        block_array = bytearray(input_file[block_offset: block_end])
        xor_block(block_array, block_array, block_number, block_size, file_key)
        for n in range (0, block_size):
            input_file[block_offset + n] = block_array[n]

        # update the expected CRC value.
        xor_crc = calculate_crc(block_array, xor_crc)

    # write CRC
    output_file.write(struct.pack("<I", xor_crc))

    # finally, append the encrypted results.
    output_file.write(input_file)
    return

# Encrypt ${PROGNAME}.bin and save it as 'update.cbd'
def encrypt(source, target, env):
    firmware = open(target[0].path, "rb")
    update = open(target[0].dir.path + '/update.cbd', "wb")
    length = os.path.getsize(target[0].path)

    encrypt_file(firmware, update, length)

    firmware.close()
    update.close()

marlin.add_post_action(encrypt);