Merging S19 Files

If using a bootloader with an application, one thing is to to merge the bootloader with the application into a single file. I do this with the ‘SRecord’ tool like this:

srec_cat bootloader.s19 application.s19 -o merged.s19
Combining S19 Files

Combining S19 Files

The SRecord utility is available on SourceForge: http://srecord.sourceforge.net/

The SRecord utility can do much more than concatenating files, and S19 files are just one format it supports. See CRC Checksum Generation with ‘SRecord’ Tools for GNU and Eclipse.

There are multiple ways how you can create S19 files from your tool chain, one explained in Binary (and S19) Files for the mbed Bootloader with Eclipse and GNU ARM Eclipse Plugins.

To automate the merging, you could write a make file, or use the post-build step in Eclipse, see Executing Multiple Commands as Post-Build Steps in Eclipse.

Happy merging 🙂

Links

32 thoughts on “Merging S19 Files

  1. Just what I needed!!!
    Tried to do it manually, by:
    1. Adding the booatloader code excluding vector-table into the application code
    2. Merging the booatloader’s vector-table into the application’s vector-table
    3. Setting the entry-point address to that of the booatloader
    It didn’t quite work.
    Thank you!

    Like

  2. Calling ‘srec_cat’ as shown above, I am receiving message ‘539: multiple 0x0000FFC0 values (previous = 0xFB, this one = 0x2A).

    This makes sense, as the interrupt-vector tables of both images are located around that same address.

    The Bootloader:
    ———————
    S1 04 FFBD FD42
    S1 23 FFBF 82FBFDFBFAFBF7FBF4FBF1FBEEFBEBFBE8FBE5FBE2FBDFFBDCFBD9FBD6FBD3FB54
    S1 23 FFDF D0FBCDFBCAFBC7FBC4FBC1FBBEFBBBFBB8FBB5FBB2FBAFFBACFBA9FBA6FBA3FCB5
    S1 04 FFFF 24D9
    S9 03 0000 FC

    The Application:
    ———————
    S1 23 FFC0 2A072A072A072A072A072A0729692A072A0729772A0A248124B125102422238097
    S1 23 FFE0 238023662366234C234C233223322A0726B62683257D25F82A072A072A0734F68E
    S9 03 34F6 D2

    For the same reason, I couldn’t find a way to do it manually (but I thought that the srec_cat tool would be able to work-around it).

    Any ideas?

    Like

      • OK, using ‘-multiple’ resolves the problem of the ‘srec_cat’ utility exiting with an error.

        But it doesn’t merge the files correctly – the application is running, but the bootloader is not responding when needed.

        I tried replacing ‘-multiple’ with ‘-exclude 0xFFC0 0x10000’ (which is the only conflicting address-range), but it did not resolve the problem.

        To clarify this a little bit, we are using Freescale’s AN2295 Serial Bootloader for HCS08.

        In order to investigate this, I have exported the memory image of each scenario:
        – The bad one (after programming the ‘merged.s19’ file through debugger)
        – The good one (after programming the ‘application.s19’ file through AN2295)

        I also tried comparing the three ‘s19’ files at hand (‘booatloader’, ‘application’ and ‘merged’).
        And in addition, I tried to figure out how each one of them was eventually “integrated into physical memory”.

        I’m pretty sure that I do not understand every bit here, but there seem to be two different interrupt-tables, one located at 0xFBA0 and the other located at 0xFFC0, which are not merged properly by the ‘srec_cat’ utility.

        Any idea what am I missing here?

        Thanks

        Like

        • I’m affraid that you need to understand the structure of the bootloader with its own vector table at 0xFFFE, and your application vector table located at 0xFBA0. You need to make sure that these two tables are at the correct location, and do not overlap.

          Like

      • OK, so I take it that the ‘srec_cat’ utility does not provide any flags which allow the user to specify the location of the vector table?

        Like

        • The srec_cat deals with the file content, and has no knowledge about the internal meanings like vector table. So yes, you will not be able to let the tool to do something like this: the developer has that knowledge and needs to tell this to the srec_cat tool e.g. with excluding/moving some memory ranges. The tool cannot do this. I hope this makes sense.

          Like

      • OK, so I’ve managed to figure out how to do it, through reverse engineering Freescale’s AN2295 code (client side communicating with the boot-loader).

        It also “aligns” pretty well with the comparison that I had conducted between the boot-loader image and the application image.

        For anyone reading this, the function name is ‘setup_vect_tbl’.
        This function masquerades the vector table, and contains a different implementation for each boot-loader version.

        We are using the BL_HCS08_LARGE boot-loader, so I will describe the steps required for this specific version (the code for each one of the other versions looks pretty similar):

        1. Copy the 32 2-byte entries located at address range 0xFFFF thru 0xFFC0 (i.e., reading them “backwards”) into the 32 3-byte entries located at address range 0xFBA0 thru 0xFBFF, where the first byte in each entry should be set to 0xCC.

        2. Remove the 32 2-byte entries located at address range 0xFFFF thru 0xFFC0.

        3. I assume that the S9 line (the last line in the file, containing the entry point of the program) should be taken from the boot-loader file (i.e., entry point = 0x0000).

        4. Other than that, there are no conflicts between the two files.

        I haven’t tested it yet, so will update on it later for any future readers.

        Thanks again for your help!

        Like

        • Hi Barak,
          Many, many thanks for sharing all the details what is necessary to accomplish this. I’m sure many other readers can benefit from this.
          Erich

          Like

      • I have merged the boot-loader image and the application image as follows:

        1. Did not include an S0-line, since it contains only meta-data.

        2. Copied 526 S1-lines from the application image (code residing between address 0x2080 and address 0x6805).

        3. Generated the vector table as described earlier, and added 3 S1-lines containing this table (residing between address 0xFBA0 and address 0xFBFF).

        4. Copied 17 S1-lines from the boot-loader image (code residing between address 0xFC00 and address 0xFFFF).
        The last 2 bytes here seem to indicate the entry-point of the boot-loader (0xFC24).

        5. Copied the S9 line from the boot-loader.
        I think that the 2 bytes here indicate the entry-point upon power-up (0x0000).

        As you can see, the only manual work that I had to do was in section #3.
        But I am unable to test it, because for some reason, my CW task does not program the stuff that I have mentioned in section #4.

        Would you have any idea why that could possibly happen?
        I merely copied those 17 lines of code from the boot-loader exactly as they were.
        Is there anywhere within the S19 file or in the CW task configuration, where I need to indicate those extra few lines?

        Thanks 🙂

        Like

  3. Following your ‘Executing Multiple Commands as Post-Build Steps in Eclipse’ post, I am trying to call the ‘srec_cat’ executable from the Post-Build command line.
    I have placed it in the same path alongside the project itself (next to the .project and .cproject files), yet I get a ‘The system cannot find the file specified’ error.
    I’m not really sure what file the system cannot find. It could be file ‘srec_cat.exe’ itself, or either one of the input files that I pass as arguments to this utility.

    My questions are:
    1. Where exactly should I place it (relatively to the project files)?
    2. Do I need to precede it with ${cross_prefix}?
    3. What prefix do I need to use before each one of the file names that I pass as input arguments to this utility? P.S., one of them (my boot-loader image) resides in another project.

    Thanks

    Like

  4. Hi.

    I have a post-build command which performs the merging and saves the output file under the same name of the original image (i.e., application.s19).

    But when I download this image through the debugger, I don’t see the boot-loader in flash at all.
    I think that it has something to do with the corresponding ‘abs’ file (i.e., application.abs), which tells the debugger exactly which sectors should be programmed (but I’m totally unsure of that).

    Is it possible to download the merged file into the target in the same manner that we download the original image through the debugger?

    We need this in order to avoid having boot-less devices “scattered around” in the office.

    I am able to do it as follows:
    – Create a standalone flash programming task (as explained in your post at https://mcuoneclipse.com/2012/08/02/standalone-flash-programmer/)
    – Open the ‘Debug Configuration’ window
    – Switch to the ‘Debugger’ tab
    – Uncheck the ‘Perform Standard Download’ option
    – Check the ‘Execute Tasks’ option
    – Add the task that I’ve created in the first step

    But I was hoping for a simpler/cleaner process.

    Thanks 🙂

    Like

      • Are you sure about this?

        It surely doesn’t seem to be the case on my end.

        The ‘abs’ file looks like a binary file when I edit it.

        When I change ‘application.abs’ in the Debug Configuration window to ‘merged.s19’ (or even to ‘application.s19’ for that matter), the Debug button becomes disabled.

        Like

  5. Pingback: Using Eclipse to Program Binary Files to an Embedded Target | MCU on Eclipse

  6. Pingback: Converting Binary Files to Intel Hex Format with the SRecord Tool | MCU on Eclipse

  7. I know this slightly off topic, but are there any tools for merging elf files so you can easily debug a bootloader + application?

    Like

  8. Hi Erich,

    How can I merge a bootloader with an app binary files using Post-Build Steps on KDS 3.2.0? What command and what the path should I use? Which one of the projects should I select to configure the command and what ? I´ll appreciate if you explain me with print screens : )

    PS: I´m using Windows 10 (64 bits) and running SRecord on Ubuntu (installed from Windows store).

    Like

    • Hi Mario,
      best if both the bootloader and application are in S19 format. I would merge them in the application project.
      Assuming you have the rec_cat in your path, you could then use that commandline in the postbuild step:
      srec_cat bootloader.s19 application.s19 -o merged.s19
      If srec_cat is not in your path, then simply add the path to the command.
      Now it might not find the two .s19 files. Usually in Eclipse the ‘current’ directory is where the output file is built, so that would be ok for the application.s19.
      For the bootloader.s19 you I suggest a relative path, e.g. ../../bootloader_project/debug/bootloader.s19
      with of course your own path, whatever it is.
      If Ubunto or Windows, this should not matter.
      I hope this helps,
      Erich

      Like

      • Ok, it worked here, thanks!

        Just one more doubt: srec file is equal to s19 file? Can I just rename the file extention from one to another and that´s it? Because I used the srec_cat command with .srec files and worked fine.

        Like

        • There is no ‘official’ or binding file extension for S-Records/S19 files. Typical ones are .s19 or .srec, but really that does not matter.

          Like

  9. Pingback: Generating Intel Hex Files with a given Length using srec_cat | MCU on Eclipse

What do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.