Skip to content

Instantly share code, notes, and snippets.

@jarkkojs
Created May 18, 2023 17:28
Show Gist options
  • Save jarkkojs/8529b5e06f71c1b80549820075f12a13 to your computer and use it in GitHub Desktop.
Save jarkkojs/8529b5e06f71c1b80549820075f12a13 to your computer and use it in GitHub Desktop.
macro(bin2elf Path Name)
set(objcopy_flags -I binary -O elf64-littleriscv -B riscv --rename-section .data=.rodata,alloc,load,readonly,data,contents)
string(MAKE_C_IDENTIFIER ${Path} unstripped)
add_custom_command(
OUTPUT ${Path}.o
COMMAND ${CMAKE_OBJCOPY} ${objcopy_flags} ${Path} ${Path}.o
COMMAND ${CMAKE_OBJCOPY} --redefine-sym _binary_${unstripped}_start=${Name}_start ${Path}.o
COMMAND ${CMAKE_OBJCOPY} --redefine-sym _binary_${unstripped}_end=${Name}_end ${Path}.o
COMMAND ${CMAKE_OBJCOPY} --redefine-sym _binary_${unstripped}_size=${Name}_size ${Path}.o
)
message(${unstripped})
endmacro()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment