-
Notifications
You must be signed in to change notification settings - Fork 678
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
zephyr: arm: Update reading the flash image reset vector #1661
Conversation
cc @d3zd3z |
Seems like a duplicate of #1569 |
@nordicjm, it looks like the #1569 is addressing a larger issue and has been in draft mode since January. This particular PR is fairly focused on a single problem we encountered as described in the initial text above. Do you think it would be easier to get this one approved and merged before your referenced PR? |
boot/zephyr/main.c
Outdated
|
||
/* Jump to flash image */ | ||
rc = flash_device_base(rsp->br_flash_dev_id, &flash_base); | ||
area_id = flash_area_id_from_image_slot(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this breaks XIP
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it does, because it hardcodes vt to primary slot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am unclear how this breaks XIP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
XIP can boot from either slot, you are hardcoding this to slot 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is'nt that what we currently do i.e boot with respect to flash_base.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is not related to rsp->br_image_off
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nordicjm I am not understanding the above comment.
The current implementation will always read the Zephyr binary with address CONFIG_FLASH_BASE_ADDRESS
as the starting point.
This PR adds more flexibility on the starting address where to look for Zephyr binary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR adds more flexibility on the starting address where to look for Zephyr binary.
No, it completely breaks XIP, that is not more flexible. I've pointed this out many times now, you need to follow the code. Old code:
rsp->br_image_off = boot_img_slot_off(state, active_slot);
rc = flash_device_base(rsp->br_flash_dev_id, &flash_base);
vt = (struct arm_vector_table *)(flash_base +
rsp->br_image_off +
rsp->br_hdr->ih_hdr_size);
So yes, the base flash address which I never ever mentioned is the same, the image offset which would point to the base of the selected image is now completely absent from this code:
area_id = flash_area_id_from_image_slot(0);
rc = flash_area_read(fap, rsp->br_hdr->ih_hdr_size, dst, 8);
vt = (struct arm_vector_table *)dst;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nordicjm @de-nordic @d3zd3z I have pushed an update to the implementation after understanding the XIP issues that were highlighted by the prior implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nordicjm @de-nordic @d3zd3z can you help re-review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Breaks XIP
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the status here? Is this still needed? |
9c42d03
to
715bc06
Compare
@nordicjm @de-nordic @d3zd3z , can you help review this PR. |
It is still unclear what problem this is solving. The end of this function jumps to an address in flash, so it only makes sense when there is XIP in flash. Is it just finding the wrong address? Could that be fixed a little easier? |
My understanding of the issue is as follows: say you have a system where MCUBoot will boot from internal flash (memory mapped to In the current implementation of MCUBoot for ARM, the function |
So then how about fixing |
I don't see an API in Zephyr where we could get this information from a device. Do you suggest I propose a change to Zephyr flash API to get this information? |
|
@mmahadevan108 Given that we do have an API to do this, I think this fix makes the most sense |
|
Sure- I understand the reasoning behind the current approach. However couldn't we also simply update the way |
The issue is we do not have a |
The dts has the reg address, use that? |
This is a good solution for internal flash devices, but it is not always that easy for external ones. To give a concrete example, NXP's FlexSPI peripheral supports memory mapped access to external flash parts. Multiple flash chips can be present on one FlexSPI, and their contents will be placed sequentially in the memory map (based on the chip select index for each flash chip). However, the "reg" property of these flash parts will be set to their chip select value, since the FlexSPI is considered a SPI device, and in that context the "reg" property means SPI chip select index. In order to really effectively support reading the flash base address for these parts, I think we'd need to add to the flash API. Personally, I'm convinced @mmahadevan108's solution makes sense here. Reading the stack pointer and the reset vector via the flash API should be reliable for XIP from the same flash chip or another device, based on my understanding of how the flash area API works. Do you have a specific concern with implementing the boot process this way, versus extracting the flash base address? |
@d3zd3z @nordicjm @de-nordic, can you help revisit this PR. |
@d3zd3z @nordicjm @de-nordic, any comments? |
The flash partition's reg address should point to the correct memory mapped address if it's being used in memory mapped mode, and that address should be absolute |
We cannot use the |
You have a |
Here is the partitions I am using in my overlay file. As shared earlier, we cannot get the address of the Flash device from this. The only thing available is the offset within the flash device. What is also available is the Flash Device node, we are using this to access the Flash device via the Flash API's
|
So you are using the external flash from MCUboot in SPI mode then somehow switching to memory mapped mode to execute the slot itself? Where is that code? |
boot/zephyr/main.c
Outdated
vt = (struct arm_vector_table *)(flash_base + | ||
rsp->br_image_off + | ||
rsp->br_hdr->ih_hdr_size); | ||
rc = flash_area_read(fap, rsp->br_hdr->ih_hdr_size, dst, 8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Th read size should not be hardcoded here, should be picked from the dst
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have made this change.
715bc06
to
92fceb4
Compare
This change uses the flash functions to read the applications reset vector. This allow flexibility on which flash device the application is programmed. For e.g: MCUBoot can be programmed and running from Internal Flash while Zephyr can be loaded from a different Flash device. This change is made for ARM platform, it can be extended to non-ARM platforms as well. Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
92fceb4
to
ea306df
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested swap using move and direct XIP on nrf52840dk, both working
@de-nordic can you help re-review. |
@d3zd3z, can this PR be merged? |
I think this looks good to make it into the next release. Please remember to add release notes. I'll go ahead and merge this, and put the release notes in an update for the release. |
This change uses the flash functions to read the applications reset vector. This allows flexibility on where the application image is programmed.
The current implementation in Zephyr for ARM does not allow the use-case where the application is programmed to a different flash device than where mcuboot is programmed and running from.
This was tested on NXP ARM platforms for the case where the Zephyr and mcuboot are in the same flash device and for the case where Zephyr and mcuboot are on different flash devices.