Skip to main content
Topic: "Lower case hexfile" breaks pirate-loader (Read 2576 times) previous topic - next topic

"Lower case hexfile" breaks pirate-loader

I received this via email:
Code: [Select]
Hello, ... "Lower case hexfile" breaks pirate-loader!
--- cut here ---

unsigned char hexdec(const char* pc)
        char    c0, c1;
        c0 = (pc[0] < 'a')?pc[0]:(pc[0]-'a'+'A');
        c1 = (pc[1] < 'a')?pc[1]:(pc[1]-'a'+'A');
        return (((c0 >= 'A') ? ( c0 - 'A' + 10 ) : ( c0 - '0' ) ) << 4 |
                        ((c1 >= 'A') ? ( c1 - 'A' + 10 ) : ( c1 - '0' ) )) & 0x0FF;
}
Got a question? Please ask in the forum for the fastest answers.

Re: "Lower case hexfile" breaks pirate-loader

Reply #1
Does the intel hex fileformat supports even uppercase? I've never seen a .hex with lowercase.

The specs does say it should be (more or less) uppercase: http://microsym.com/editor/assets/intelhex.pdf

Re: "Lower case hexfile" breaks pirate-loader

Reply #2
why doesn't it use "strtol" function to do the conversion ?

The following call has the same functionality, and is case insensitive (and has much better maintainability :) )

Code: [Select]
strtol(pc, NULL, 16);

Re: "Lower case hexfile" breaks pirate-loader

Reply #3
>Does the intel hex fileformat supports even uppercase? I've never seen a .hex with lowercase.

At least one binary: pic30-coff-bin2hex.exe (MPLAB 8.02) do produce lowercase hex.
And You will find (in "11836 Aug 26  2008 ./acme/binutils/bin2hex.c") current bin2hex(without -u option) will do it as well.
                                                nm

Re: "Lower case hexfile" breaks pirate-loader

Reply #4
>why doesn't it use "strtol" function to do the conversion ?

Well, may be because we *love* C-ish_ascii_based_coding style?
(I believe strtol() is ok, even on the EBCDIC based systems, though :-)
                                                                                              nm

Re: "Lower case hexfile" breaks pirate-loader

Reply #5
Sorry to bump an old topic, but during coding I came across this:

Code: [Select]

  C:Program FilesMicrochipMPLAB C30binbin/pic30-coff-bin2hex.exe -- convert
 an object file to Intel hex format
  Microchip %s Build date: Dec-08-2009
  usage: C:Program FilesMicrochipMPLAB C30binbin/pic30-coff-bin2hex.exe fil
e [options]

  options:
    -a        sort sections by address
    -u        use upper-case hex digits
    -v        print verbose messages



-u had it all solved... I can't find it it as a setting in MPLAB somewhere, but when you generate a makefile it can be added.