44 "debug/elf"
55 "io/ioutil"
66 "os"
7- "path/filepath"
87 "sort"
98
109 "github.com/marcinbor85/gohex"
@@ -93,7 +92,7 @@ func extractROM(path string) (uint64, []byte, error) {
9392
9493// objcopy converts an ELF file to a different (simpler) output file format:
9594// .bin or .hex. It extracts only the .text section.
96- func objcopy (infile , outfile string ) error {
95+ func objcopy (infile , outfile , binaryFormat string ) error {
9796 f , err := os .OpenFile (outfile , os .O_RDWR | os .O_CREATE | os .O_TRUNC , 0666 )
9897 if err != nil {
9998 return err
@@ -107,23 +106,20 @@ func objcopy(infile, outfile string) error {
107106 }
108107
109108 // Write to the file, in the correct format.
110- switch filepath .Ext (outfile ) {
111- case ".gba" :
112- // The address is not stored in a .gba file.
113- _ , err := f .Write (data )
114- return err
115- case ".bin" :
116- // The address is not stored in a .bin file (therefore you
117- // should use .hex files in most cases).
118- _ , err := f .Write (data )
119- return err
120- case ".hex" :
109+ switch binaryFormat {
110+ case "hex" :
111+ // Intel hex file, includes the firmware start address.
121112 mem := gohex .NewMemory ()
122113 err := mem .AddBinary (uint32 (addr ), data )
123114 if err != nil {
124115 return objcopyError {"failed to create .hex file" , err }
125116 }
126117 return mem .DumpIntelHex (f , 16 )
118+ case "bin" :
119+ // The start address is not stored in raw firmware files (therefore you
120+ // should use .hex files in most cases).
121+ _ , err := f .Write (data )
122+ return err
127123 default :
128124 panic ("unreachable" )
129125 }
0 commit comments