-
Notifications
You must be signed in to change notification settings - Fork 262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Guessing the VTOR wrong #314
Comments
Thanks @pfef-to, that's an interesting find. We'll look into this and pass this through our tests. For the record, you can always override the guessing with I wonder what's the source of your layout - is this some very specific linker script? Is it something we could reproduce? |
The project is built with XPCC https://github.com/roboterclubaachen/xpcc (which - admittedly - is deprecated). The linkerscript is compiled from the macros in https://github.com/roboterclubaachen/xpcc/tree/develop/src/xpcc/architecture/platform/driver/core/cortex |
My understanding of the VTOR register (as accessed via SCB->VTOR) in Cortex M is that it starts life as 0 upon chip reset. Any change to that value is then the responsibility of software. For example, a bootloader loaded at 0 would do this to load an application built for 0x1000: SCB->VTOR = 0x1000; Alternatively, the application could set it itself. In fact, the CMSIS standard startup/system code does this for you: Device/ARM/ARMCM3/Source/system_ARMCM3.c: SCB->VTOR = (uint32_t) &__VECTOR_TABLE; MCU vendors (I use SiliconLabs parts) do similar in their supplied startup files. Given this, I am confused why/how there is any 'guessing' of the VTOR. |
Yeah sorry that wording might've been wrong. As I understand it, it is guessing the vectors table address - so in other words the value to assign to the VTOR. It is basically doing what the bootloader would do and but it doesn't know about the 0x1000 from your example so it has to guess (@PiotrZierhoffer correct me if I'm wrong). |
@tobermory that's exactly the case: we don't always run all the bootloaders, because we don't have to. Very often we just run our ELFs to memory and execute from there, but this means that we need to have some idea about the processor configuration. It's customary that Cortex-M binaries begin with VTOR, so that's why we can guess it. You don't have to - you can set it manually, but it turns out that for most of the software we tried guessing is good enough. @pfef-to it took us some time to schedule this, but we'll be testing your changes very soon. |
Looking at the initialization code for Cortex-M, it seems that the VTOR is guessed by finding the ELF section with the lowest address. The function used is called
GetSectionPhysicalAddress
, yet it actually looks up theSectionLoadAddress
. In my case, this returns the wrong VTOR address, as my binary contains an allocatable empty section with no address (LoadAddress is zero).I'd suggest using the lowest physical segment address for loaded segments instead, as these are sure to be loaded at the specified address.
Snippet from the section table of my example:
Snippet from the segment table of my example:
The text was updated successfully, but these errors were encountered: