elfconvert_command.cmake 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # For MWDT the elfconvert command is made into a script.
  2. # Reason for that is because not a single command covers all use cases,
  3. # and it must therefore be possible to call individual commands, depending
  4. # on the arguments used.
  5. # Handle stripping
  6. if (STRIP_DEBUG OR STRIP_ALL)
  7. if(STRIP_ALL)
  8. set(obj_copy_strip "-qs")
  9. elseif(STRIP_DEBUG)
  10. set(obj_copy_strip "-ql")
  11. endif()
  12. execute_process(
  13. COMMAND ${STRIP} ${obj_copy_strip}
  14. ${INFILE} ${FILEOUT})
  15. endif()
  16. # no support of --srec-len in mwdt
  17. # Handle Input and Output target types
  18. if(DEFINED OUTTARGET)
  19. set(obj_copy_target_output "")
  20. set(obj_copy_gap_fill "")
  21. if(GAP_FILL)
  22. set(obj_copy_gap_fill "-f;${GAP_FILL}")
  23. endif()
  24. # only mwdt's elf2hex supports gap fill
  25. if(${OUTTARGET} STREQUAL "srec")
  26. set(obj_copy_target_output "-m")
  27. elseif(${OUTTARGET} STREQUAL "ihex")
  28. set(obj_copy_target_output "-I")
  29. elseif(${OUTTARGET} STREQUAL "binary")
  30. set(obj_copy_target_output "-B")
  31. endif()
  32. execute_process(
  33. COMMAND ${ELF2HEX} ${obj_copy_gap_fill} ${obj_copy_target_output}
  34. -o ${OUTFILE} ${INFILE}
  35. )
  36. endif()
  37. # Handle sections, if any
  38. # 1. Section only selection(s)
  39. set(obj_copy_sections_only "")
  40. if(DEFINED ONLY_SECTION)
  41. # There could be more than one, so need to check all args.
  42. foreach(n RANGE ${CMAKE_ARGC})
  43. foreach(argument ${CMAKE_ARGV${n}})
  44. if(${argument} MATCHES "-DONLY_SECTION=(.*)")
  45. list(APPEND obj_copy_sections_only "-sn;${CMAKE_MATCH_1}")
  46. endif()
  47. endforeach()
  48. endforeach()
  49. execute_process(
  50. COMMAND ${ELF2BIN} -q ${obj_copy_sections_only}
  51. ${INFILE} ${OUTFILE}
  52. )
  53. endif()
  54. # no support of rename sections in mwdt, here just use arc-elf32-objcopy temporarily
  55. set(obj_copy_sections_rename "")
  56. if(DEFINED RENAME_SECTION)
  57. foreach(n RANGE ${CMAKE_ARGC})
  58. foreach(argument ${CMAKE_ARGV${n}})
  59. if(${argument} MATCHES "-DRENAME_SECTION=(.*)")
  60. list(APPEND obj_copy_sections_rename "--rename-section;${CMAKE_MATCH_1}")
  61. endif()
  62. endforeach()
  63. endforeach()
  64. execute_process(
  65. COMMAND ${OBJCOPY} ${obj_copy_sections_rename}
  66. ${INFILE} ${OUTFILE}
  67. )
  68. endif()
  69. # no support of remove sections