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 6# Handle stripping 7if (STRIP_DEBUG OR STRIP_ALL) 8 if(STRIP_ALL) 9 set(obj_copy_strip "-qs") 10 elseif(STRIP_DEBUG) 11 set(obj_copy_strip "-ql") 12 endif() 13 14 execute_process( 15 COMMAND ${STRIP} ${obj_copy_strip} 16 ${INFILE} ${FILEOUT}) 17endif() 18 19# no support of --srec-len in mwdt 20 21# Handle Input and Output target types 22if(DEFINED OUTTARGET) 23 set(obj_copy_target_output "") 24 set(obj_copy_gap_fill "") 25 if(GAP_FILL) 26 set(obj_copy_gap_fill "-f;${GAP_FILL}") 27 endif() 28 # only mwdt's elf2hex supports gap fill 29 if(${OUTTARGET} STREQUAL "srec") 30 set(obj_copy_target_output "-m") 31 elseif(${OUTTARGET} STREQUAL "ihex") 32 set(obj_copy_target_output "-I") 33 elseif(${OUTTARGET} STREQUAL "binary") 34 set(obj_copy_target_output "-B") 35 endif() 36 execute_process( 37 COMMAND ${ELF2HEX} ${obj_copy_gap_fill} ${obj_copy_target_output} 38 -o ${OUTFILE} ${INFILE} 39 ) 40endif() 41 42# Handle sections, if any 43# 1. Section only selection(s) 44set(obj_copy_sections_only "") 45if(DEFINED ONLY_SECTION) 46# There could be more than one, so need to check all args. 47 foreach(n RANGE ${CMAKE_ARGC}) 48 foreach(argument ${CMAKE_ARGV${n}}) 49 if(${argument} MATCHES "-DONLY_SECTION=(.*)") 50 list(APPEND obj_copy_sections_only "-sn;${CMAKE_MATCH_1}") 51 endif() 52 endforeach() 53 endforeach() 54 55 execute_process( 56 COMMAND ${ELF2BIN} -q ${obj_copy_sections_only} 57 ${INFILE} ${OUTFILE} 58 ) 59endif() 60 61# no support of rename sections in mwdt, here just use arc-elf32-objcopy temporarily 62set(obj_copy_sections_rename "") 63if(DEFINED RENAME_SECTION) 64 foreach(n RANGE ${CMAKE_ARGC}) 65 foreach(argument ${CMAKE_ARGV${n}}) 66 if(${argument} MATCHES "-DRENAME_SECTION=(.*)") 67 list(APPEND obj_copy_sections_rename "--rename-section;${CMAKE_MATCH_1}") 68 endif() 69 endforeach() 70 endforeach() 71 72 execute_process( 73 COMMAND ${OBJCOPY} ${obj_copy_sections_rename} 74 ${INFILE} ${OUTFILE} 75 ) 76endif() 77 78# no support of remove sections 79