Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FindKocherga.cmake for convenience #16

Open
pavel-kirienko opened this issue Jun 30, 2022 · 0 comments
Open

Add FindKocherga.cmake for convenience #16

pavel-kirienko opened this issue Jun 30, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@pavel-kirienko
Copy link
Member

# Given an .elf file produced by the linker, generate an .app.bin with the correct signature
# that is accepted by the Kocherga bootloader.
# The source ELF file will be also side-patched for convenience.
function(
        generate_kocherga_image
        ARG_ELF_FILE_NAME
        ARG_OUTPUT_BASENAME
)
    set(elf ${ARG_ELF_FILE_NAME})
    set(bin ${ARG_OUTPUT_BASENAME}.bin)
    set(app ${ARG_OUTPUT_BASENAME}.app.bin)
    add_custom_target(
            ${app} ALL
            COMMAND rm -f *.bin  # Remove all previous build outputs
            COMMAND ${CMAKE_OBJCOPY} -O binary ${elf} ${bin}
            COMMAND ${KOCHERGA_IMAGE_TOOL} --lazy --verbose ${bin} --side-patch ${elf}
            COMMAND rm -f ${bin}
            DEPENDS ${elf}
            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
            COMMENT "Generating application image compatible with the Kocherga bootloader: ${app}"
    )
endfunction()

find_program(
        KOCHERGA_IMAGE_TOOL NAMES kocherga_image kocherga_image.py
        PATHS
        ${CMAKE_CURRENT_SOURCE_DIR}
        ${CMAKE_CURRENT_SOURCE_DIR}/..
        ${CMAKE_CURRENT_SOURCE_DIR}/../..
        ${CMAKE_SOURCE_DIR}
        ${CMAKE_SOURCE_DIR}/lib
        PATH_SUFFIXES
        tools
        kocherga/tools
        REQUIRED
)
message(STATUS "Found kocherga_image tool: ${KOCHERGA_IMAGE_TOOL}")
@pavel-kirienko pavel-kirienko added the enhancement New feature or request label Jun 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant