4 Replies Latest reply on Aug 19, 2016 4:05 AM by Mike Hibbett

    Access start and end address of firmware from ROM code

    aschaller

      Dear all,

       

      I would like to find and access information about the start address and size / end address of the firmware code (text segment) from ROM code. In the linker script rom.ld there are the following variables:

        

          __data_lma = LOADADDR(.data);

          __data_vma = ADDR(.data);

          __data_size = SIZEOF(.data);

          __bss_start = ADDR(.bss);

          __bss_end = __bss_start + SIZEOF(.bss);

       

       

      Alhtough __data_lma and __data_size seem to be the variables I am looking for, I guess, that they only refer to the text segment of the ROM code as the same variables are defined in quark_d2000.ld. Thus, I added the following code to quark_d2000.ld in the hope to be able to access it in startup_rom.c:

       

      SECTIONS

      {

          .text :

          {

              _text = .;

              *(.text.entry)

              *(.text)

              *(.text.last)

              *(.text.*)

          } >flash

      ...

       

      /* Symbols for C runtime init code. */

          __data_lma = LOADADDR(.data);

          __data_vma = ADDR(.data);

          __data_size = SIZEOF(.data);

          __bss_start = ADDR(.bss);

          __bss_end = __bss_start + SIZEOF(.bss);

          __text_size = SIZEOF(.text);

       

      But of course, since quark_d2000.ld is not used for building the rom code, the variable __text_size isn't available as well. Any suggestions on how to do it except for hard-coding the beginning and end of the firmware's text section?

       

      Thanks

        • 1. Re: Access start and end address of firmware from ROM code
          PabloM_Intel

          Hi aschaller,

           

          Let us investigate to see if it’s possible to access this information. We’ll get back to you soon.

           

          Regards,

          -Pablo

          • 2. Re: Access start and end address of firmware from ROM code
            Mike Hibbett

            Hi aschaller,

             

            as you point out the linker variables are of no use to you - the bootrom is an independently linked program in it's own right. Four possible solutions spring to mind, each with their own merits and drawbacks:

             

            1) Have your application scan the OTP flash memory, from the end of that region back towards the beginning, looking for the first location that is not 0xFFFFFFFF.

             

            2) When you build your application, have your "make" script get the size of the rom image binary file in your file system, and use that value.

             

            3) Add a "maigic" sequence of bytes at the end of the bootrom code (we supply the source code, you can make your own changes) and have your application scan the OTP flash memory for that sequence.

             

            4) Modify the bootrom code to pass the end address to the application when it transfers control at the end of startup. You can see this code in the file

            firmware\bsp\1.1\soc\quark_d2000\rom\rom_startup.c

            inside the rom_startup() function.

             

            Step 4) would be trickier but the more elegant solution to my mind, as it will be faster and less prone to error.

             

            Regards,

             

            Mike.

            • 3. Re: Access start and end address of firmware from ROM code
              aschaller

              Hi Mike,

               

              first, many thanks for all the creative ideas! Although all your suggestions seem feasible to implement, I guess you understood that I would want to get access to the end address of the ROM from firmware. Indeed, it is the other way around: I would like to get access to the end address of the FW's text segment within the ROM. I guess I will go with the approach of adding a sequence of magic bytes to the end of the FW and have the ROM code scan for it.

               

              Thanks again!

              • 4. Re: Access start and end address of firmware from ROM code
                Mike Hibbett

                Hi,

                 

                No problem, it's an interesting question. The 'magic number' sequence is one I have used several times in recent years, even on a very large project. We used a 128 bit sequence, and just checked that it wasn't a valid sequence of CPU instructions. I got my initials in there, and it even past a design review

                 

                - Mike.