Skip to content

Commit 58d000f

Browse files
authored
Improve rom_pick_ab_update_partition docs (#2577)
* Improve rom_pick_ab_update_partition docs * Some review fixups Add more `\ref`s and tidy up wording * Move function docs next to rom_pick_ab_partition * Add \return to rom_pick_ab_partition docs * Rename rom_pick_ab_update_partition -> rom_pick_ab_partition_during_update and replace "call"
1 parent bf4906b commit 58d000f

File tree

3 files changed

+30
-27
lines changed

3 files changed

+30
-27
lines changed

src/rp2_common/pico_bootrom/bootrom.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ int rom_add_flash_runtime_partition(uint32_t start_offset, uint32_t size, uint32
112112
return PICO_ERROR_INSUFFICIENT_RESOURCES;
113113
}
114114

115-
int rom_pick_ab_update_partition(uint32_t *workarea_base, uint32_t workarea_size, uint partition_a_num) {
115+
int rom_pick_ab_partition_during_update(uint32_t *workarea_base, uint32_t workarea_size, uint partition_a_num) {
116116
#if !PICO_RP2040
117117
// Generated from adding the following code into the bootrom
118118
// scan_workarea_t* scan_workarea = (scan_workarea_t*)workarea;

src/rp2_common/pico_bootrom/include/pico/bootrom.h

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -750,12 +750,13 @@ static inline int rom_load_partition_table(uint8_t *workarea_base, uint32_t work
750750
* NOTE: This method does not look at owner partitions, only the A partition passed and it's corresponding B partition.
751751
*
752752
* NOTE: You should not call this method directly when performing a Flash Update Boot before calling `explicit_buy`, as it may prevent
753-
* any version downgrade from occuring - instead see \ref rom_pick_ab_update_partition() which wraps this function.
753+
* any version downgrade from occuring - instead see \ref rom_pick_ab_partition_during_update() which wraps this function.
754754
*
755755
* \param workarea_base base address of work area
756756
* \param workarea_size size of work area
757757
* \param partition_a_num the A partition of the pair
758758
* \param flash_update_boot_window_base the flash update base, to pick that partition instead of the normally "better" partition
759+
* \return >= 0 the chosen partition number out of the A/B pair
759760
*/
760761
static inline int rom_pick_ab_partition(uint8_t *workarea_base, uint32_t workarea_size, uint partition_a_num, uint32_t flash_update_boot_window_base) {
761762
rom_pick_ab_partition_fn func = (rom_pick_ab_partition_fn) rom_func_lookup_inline(ROM_FUNC_PICK_AB_PARTITION);
@@ -766,6 +767,32 @@ static inline int rom_pick_ab_partition(uint8_t *workarea_base, uint32_t workare
766767
return rc;
767768
}
768769

770+
/*! \brief Pick A/B partition without disturbing any in progress Flash Update boot or TBYB boot
771+
* \ingroup pico_bootrom
772+
*
773+
* This will perform the same function as \ref rom_pick_ab_partition(), using the `flash_update_boot_window_base` from the current boot, while performing
774+
* extra checks to prevent disrupting a main image TBYB boot. It requires the same minimum workarea size as \ref rom_pick_ab_partition().
775+
*
776+
* This should be used instead of \ref rom_pick_ab_partition() when performing a Flash Update Boot before calling \ref rom_explicit_buy(), and can still be
777+
* used without issue when a Flash Update Boot is not in progress.
778+
*
779+
* This function is necessary because if an `explicit_buy` is pending then calling `pick_ab_partition` would clear the saved flash erase address for
780+
* the version downgrade, so the required erase of the other partition would not occur when `explicit_buy` is called. This function saves and restores
781+
* that address to prevent this issue, and returns `BOOTROM_ERROR_NOT_PERMITTED` if the partition chosen by `pick_ab_partition` also requires a flash
782+
* erase version downgrade (as you can't erase two partitions with one `explicit_buy` call).
783+
*
784+
* This function also checks that the chosen partition contained a valid image (e.g. a signed image when using secure boot), and returns
785+
* `BOOTROM_ERROR_NOT_FOUND` if it does not.
786+
*
787+
* \param workarea_base base address of work area
788+
* \param workarea_size size of work area
789+
* \param partition_a_num the A partition of the pair
790+
* \return >= 0 the partition number picked by \ref rom_pick_ab_partition()
791+
* BOOTROM_ERROR_NOT_PERMITTED if not possible to do an update correctly, e.g. if both main image and data image are TBYB
792+
* BOOTROM_ERROR_NOT_FOUND if the chosen partition failed verification
793+
*/
794+
int rom_pick_ab_partition_during_update(uint32_t *workarea_base, uint32_t workarea_size, uint partition_a_num);
795+
769796
/*!
770797
* \brief Get B partition
771798
* \ingroup pico_bootrom
@@ -1094,30 +1121,6 @@ static inline int rom_get_last_boot_type(void) {
10941121
*/
10951122
int rom_add_flash_runtime_partition(uint32_t start_offset, uint32_t size, uint32_t permissions);
10961123

1097-
/*! \brief Pick A/B partition without disturbing any in progress update or TBYB boot
1098-
* \ingroup pico_bootrom
1099-
*
1100-
* This will call `rom_pick_ab_partition` using the `flash_update_boot_window_base` from the current boot, while performing extra checks to prevent disrupting
1101-
* a main image TBYB boot. It requires the same minimum workarea size as `rom_pick_ab_partition`.
1102-
* \see rom_pick_ab_partition()
1103-
*
1104-
* For example, if an `explicit_buy` is pending then calling `pick_ab_partition` would normally clear the saved flash erase address for the version downgrade,
1105-
* so the required erase of the other partition would not occur when `explicit_buy` is called - this function saves and restores that address to prevent this
1106-
* issue, and returns `BOOTROM_ERROR_NOT_PERMITTED` if the partition chosen by `pick_ab_partition` also requires a flash erase version downgrade (as you can't
1107-
* erase 2 partitions with one `explicit_buy` call).
1108-
*
1109-
* It also checks that the chosen partition contained a valid image (e.g. a signed image when using secure boot), and returns `BOOTROM_ERROR_NOT_FOUND`
1110-
* if it does not.
1111-
*
1112-
* \param workarea_base base address of work area
1113-
* \param workarea_size size of work area
1114-
* \param partition_a_num the A partition of the pair
1115-
* \return >= 0 the partition number picked
1116-
* BOOTROM_ERROR_NOT_PERMITTED if not possible to do an update correctly, e.g. if both main image and data image are TBYB
1117-
* BOOTROM_ERROR_NOT_FOUND if the chosen partition failed verification
1118-
*/
1119-
int rom_pick_ab_update_partition(uint32_t *workarea_base, uint32_t workarea_size, uint partition_a_num);
1120-
11211124
#endif
11221125

11231126
#ifdef __cplusplus

src/rp2_common/pico_cyw43_driver/cyw43_driver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ bool cyw43_driver_init(async_context_t *context) {
152152
rom_set_bootrom_stack(&stack);
153153
#endif
154154
uint32_t* workarea = malloc(0x1000);
155-
picked_p = rom_pick_ab_update_partition(workarea, 0x1000, picked_p);
155+
picked_p = rom_pick_ab_partition_during_update(workarea, 0x1000, picked_p);
156156
free(workarea);
157157
#ifdef __riscv
158158
// Reset bootrom stack

0 commit comments

Comments
 (0)