• AVR Freaks

Hot!Using Values From the Source Code in a Post Build Command

Author
chrisgr99@gmail.com
New Member
  • Total Posts : 7
  • Reward points : 0
  • Joined: 2019/01/12 07:57:34
  • Location: 0
  • Status: offline
2019/08/20 07:22:57 (permalink)
0

Using Values From the Source Code in a Post Build Command

Using MPLabX I need to use the post processer to insert in the hex file some values #defined in the XC32 source code.
 
Is there a way for the post processor to access information from the source code?
#1

5 Replies Related Threads

    aschen0866
    Super Member
    • Total Posts : 4496
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    Re: Using Values From the Source Code in a Post Build Command 2019/08/20 08:20:43 (permalink)
    +2 (2)
    You'll need to give us a bit more details. If a #define is already in the source code, why don't you just store the value in program memory? The space and address attributes should do the job.
    #2
    chrisgr99@gmail.com
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2019/01/12 07:57:34
    • Location: 0
    • Status: offline
    Re: Using Values From the Source Code in a Post Build Command 2019/08/20 08:48:13 (permalink)
    0
    The hex file is to be used in an installer and I need to insert a text header at the start of the hex file with things like version information so my custom bootloader can look in the hex file and verify compatibility before uploading it.
     
    The information is defined in the source code so I need to access that in the post processor to insert it to the hex file.
     
     
    #3
    Jim Nickerson
    User 452
    • Total Posts : 6187
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: Using Values From the Source Code in a Post Build Command 2019/08/20 09:55:13 (permalink)
    0
    If it were me ( as you have control of the bootloader ) I would use an external program to preface the hex file with custom record types containing the data you want ( it need not be in intel hex format for that matter )
    I would pass the information to the external file to execute after the build.
    FYI all your defines are store in the .xml file which your external file could process.
    #4
    aschen0866
    Super Member
    • Total Posts : 4496
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    Re: Using Values From the Source Code in a Post Build Command 2019/08/20 11:41:30 (permalink)
    +3 (3)
    chrisgr99@gmail.com
    ... I need to insert a text header at the start of the hex file with things like version information ...

    Without using an external tool, this might be hard to do. However, you could try these steps:
    1. Store version info in the program memory with a fixed address, for example,

    #define VERSION_NUMBER 0x11223344
    const uint32_t __attribute__((space(prog), address(0x9D001000), keep)) version = VERSION_NUMBER;

    2. Extract 1D00_1000 - 1D00_1003 from the application hex file and append the hex content to the beginning of the application hex file itself.
    - Post-build command

    add_version.bat ${ImagePath}

    - add_version.bat

    hexmate r1D001000-1D001003,%1 -Oversion.hex
    copy version.hex + %1 app_with_version.hex

    - app_with_version.hex

    :020000041D00DD  <-- 1D00_1000: 0x11223344
    :041000004433221142 <--
    :00000001FF   <---- EOF
    :020000040000fa
    :020000041fc01b
    :100000000200f00f0000000000601a40c0045a7f98
    ...
    :080308000800e0030000000002
    :00000001FF  <--- EOF

    The problem is that this hex file contains two type 1 EOF records. Would that confuse your installer or bootloader?
     
     
    #5
    cvm
    Super Member
    • Total Posts : 293
    • Reward points : 0
    • Joined: 2011/09/16 05:16:15
    • Location: 0
    • Status: offline
    Re: Using Values From the Source Code in a Post Build Command 2019/09/02 15:14:49 (permalink)
    0
    A little late, but..
     
    >I need to insert a text header at the start of the hex file
     
    Although not necessary, just to make it a little easier to parse, maybe put the version info in its own header file-
    //version.h
    //add whatever is needed
    #define MAJOR_VERSION 12
    #define MINOR_VERSION 3456
     
    //normal c files-
    #include "version.h"
     
    //post build step (all one line)-
    sed "s:#define ::g" myversion.h > ${ImageDir}/${PROJECTNAME}.${IMAGE_TYPE}.version.hex;
    cat ${ImageDir}/${PROJECTNAME}.${IMAGE_TYPE}.hex >> ${ImageDir}/${PROJECTNAME}.${IMAGE_TYPE}.version.hex
     
    (simply creates a new hex file with header info, then appends original hex file)
     
    MAJOR_VERSION 12
    MINOR_VERSION 3456
    :1000000044C0DDC6DCC6DBC6DAC6D9C6D8C6D7C68C
    :10001000D6C6D5C6D4C6D3C6D2C6D1C6D0C6CFC61C
     
    I doubt this is exactly what is wanted, but you get the idea. The gnu tools included should be able to do whatever you want to process the version header (or any other header for that matter). Although text outside a hex record in a hex file should be ignored, you don't even have to worry about that as you control the decoding. (I'm assuming a 'text header' means exactly that).
    #6
    Jump to:
    © 2019 APG vNext Commercial Version 4.5