Skip to content

Commit f7952f2

Browse files
committed
Review feedback
Add copyright headers Put ptinfo buffer on the stack, and break when partition is found Improve function description
1 parent 6cf28a3 commit f7952f2

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

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

+7-6
Original file line numberDiff line numberDiff line change
@@ -1071,16 +1071,17 @@ static inline int rom_get_last_boot_type(void) {
10711071
*/
10721072
int rom_add_flash_runtime_partition(uint32_t start_offset, uint32_t size, uint32_t permissions);
10731073

1074-
/*! \brief Pick A/B partition with TBYB guards
1074+
/*! \brief Pick A/B partition without disturbing any in progress update or TBYB boot
10751075
* \ingroup pico_bootrom
10761076
*
1077-
* This will call `rom_pick_ab_partition` with the current `flash_update_boot_window_base`, while performing extra checks to prevent disrupting a main image TBYB.
1078-
* It requires the same minimum workarea size as `rom_pick_ab_partition`.
1077+
* 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
1078+
* a main image TBYB boot. It requires the same minimum workarea size as `rom_pick_ab_partition`.
10791079
* \see rom_pick_ab_partition()
10801080
*
1081-
* For example, if an `explicit_buy` is pending then calling `pick_ab_partition` would normally clear the saved `flash_erase_addr` so the required erase would not
1082-
* occur when `explicit_buy` is called - this function saves and restores that address to prevent this issue, and returns `BOOTROM_ERROR_NOT_PERMITTED` if the
1083-
* partition chosen by `pick_ab_partition` also requires a flash erase version downgrade (as you can't erase 2 partitions with one `explicit_buy` call).
1081+
* 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,
1082+
* 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
1083+
* 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
1084+
* erase 2 partitions with one `explicit_buy` call).
10841085
*
10851086
* It also checks that the chosen partition contained a valid image (eg a signed image when using secure boot), and returns `BOOTROM_ERROR_NOT_FOUND`
10861087
* if it does not.

src/rp2_common/pico_cyw43_driver/cyw43_driver.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,8 @@ static void cyw43_sleep_timeout_reached(async_context_t *context, __unused async
121121

122122
bool cyw43_driver_init(async_context_t *context) {
123123
#if CYW43_USE_PARTITION_FIRMWARE
124-
const int buf_words = (16 * 4) + 1; // maximum of 16 partitions, each with maximum of 4 words returned, plus 1
125-
uint32_t* buffer = malloc(buf_words * 4);
126-
int ret = rom_get_partition_table_info(buffer, buf_words, PT_INFO_PARTITION_LOCATION_AND_FLAGS | PT_INFO_PARTITION_ID);
124+
uint32_t buffer[(16 * 4) + 1] = {}; // maximum of 16 partitions, each with maximum of 4 words returned, plus 1
125+
int ret = rom_get_partition_table_info(buffer, count_of(buffer), PT_INFO_PARTITION_LOCATION_AND_FLAGS | PT_INFO_PARTITION_ID);
127126

128127
assert(buffer[0] == (PT_INFO_PARTITION_LOCATION_AND_FLAGS | PT_INFO_PARTITION_ID));
129128

@@ -141,6 +140,7 @@ bool cyw43_driver_init(async_context_t *context) {
141140
id |= ((uint64_t)(buffer[i++]) << 32ull);
142141
if (id == CYW43_WIFI_FW_PARTITION_ID) {
143142
picked_p = p;
143+
break;
144144
}
145145
}
146146

@@ -162,7 +162,7 @@ bool cyw43_driver_init(async_context_t *context) {
162162
}
163163

164164
CYW43_DEBUG("Chosen CYW43 firmware in partition %d\n", picked_p);
165-
int ret = rom_get_partition_table_info(buffer, buf_words, PT_INFO_PARTITION_LOCATION_AND_FLAGS | PT_INFO_SINGLE_PARTITION | (picked_p << 24));
165+
int ret = rom_get_partition_table_info(buffer, count_of(buffer), PT_INFO_PARTITION_LOCATION_AND_FLAGS | PT_INFO_SINGLE_PARTITION | (picked_p << 24));
166166
assert(buffer[0] == (PT_INFO_PARTITION_LOCATION_AND_FLAGS | PT_INFO_SINGLE_PARTITION));
167167
assert(ret == 3);
168168

@@ -179,9 +179,7 @@ bool cyw43_driver_init(async_context_t *context) {
179179
cyw43_clm_len = *(uint32_t*)(XIP_NOCACHE_NOALLOC_NOTRANSLATE_BASE + saddr + 4);
180180
fw_data = XIP_NOCACHE_NOALLOC_NOTRANSLATE_BASE + saddr + 8;
181181
}
182-
free(buffer);
183182
} else {
184-
free(buffer);
185183
CYW43_DEBUG("No partition table, so cannot get firmware from partition - get_partition_table_info returned %d\n", ret);
186184
return false;
187185
}

src/rp2_common/pico_cyw43_driver/cyw43_firmware.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright (c) 2024 Raspberry Pi (Trading) Ltd.
4+
#
5+
# SPDX-License-Identifier: BSD-3-Clause
6+
17
import sys
28

39
with open(sys.argv[1], "r") as f:

src/rp2_common/pico_cyw43_driver/include/cyw43_partition_firmware.h

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright (c) 2024 Raspberry Pi (Trading) Ltd.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
16

27
extern int cyw43_wifi_fw_len;
38
extern int cyw43_clm_len;

src/rp2_common/pico_cyw43_driver/wifi_firmware.S

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
* Copyright (c) 2024 Raspberry Pi (Trading) Ltd.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
17
#include "boot/picobin.h"
28

39
#if PICO_CRT0_IMAGE_TYPE_TBYB

0 commit comments

Comments
 (0)