Skip to content
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

Add Wi-Fi firmware partition support for Pico 2 W #1969

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

will-v-pi
Copy link

This adds the ability to store and load the Wi-Fi firmware for Pico 2 W in a partition. It can be enabled by adding pico_use_partition_firmware(<exe_name>) to your CMakeLists.txt, which will embed a compatible partition table in the binary, and output lots of firmware UF2s to use (all called <exe_name>_firmware_..._.uf2, eg ..._firmware_w for Wi-Fi only, ..._firmware_wb for Wi-Fi and Bluetooth, ..._firmware_w_tbyb for TBYB). You can also create your own partition table and use that.

A Wi-Fi firmware partition is detected as having the ID 0x123456789abcdef0, and the UF2 family_is for Wi-Fi firmware blobs is 0x12345678 - these should probably both be changed to something else before merging? The default firmware partition starts at 3500K into the flash - should this be changed to depend on PICO_FLASH_SIZE_BYTES? The default firmware partition is also duplicated with A/B partitions in the same location in flash - this is required to ensure a signature check is performed before loading the Wi-Fi firmware, as there's no way to call the bootrom to check the signature of a single partition (unless chaining into it), you can only call pick_ab_partition.

The Wi-Fi firmware blob is marked in it's image_def as an RP2350 Risc-V executable, and the partition is marked as ignored_during_riscv_boot - this ensures that it can work with TBYB (as TBYB only works for executable image_defs), and that signature checks are performed before loading the firmware when Secure Boot is enabled (because signature checks are performed for all executable image_defs in a partition that is not marked ignored_during_arm_boot). This is slightly clunky, but seems to work robustly.

Supercedes #1850, as it now includes that function in this PR, and shows a use for it.

@lurch
Copy link
Contributor

lurch commented Oct 3, 2024

pinging @peterharperuk as he did a lot of the Wifi-related stuff for Pico 1.

@@ -104,6 +114,73 @@ static void cyw43_sleep_timeout_reached(async_context_t *context, __unused async
}

bool cyw43_driver_init(async_context_t *context) {
#if CYW43_USE_PARTITION_FIRMWARE
const int buf_words = (16 * 4) + 1; // maximum of 16 partitions, each with maximum of 4 words returned, plus 1
uint32_t* buffer = malloc(buf_words * 4);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

malloc is best avoided for Micropython (we use some for BT but we need to fix that). You could use cyw43_state as a temp buffer it's not needed yet?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I switch this one to use cyw43_state and leave the other one with malloc, or just leave them both as malloc?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave it as it is for now. I can't immediately spot the code in Micropython which controls the heap space we have available.

}

if (picked_p >= 0) {
uint32_t* workarea = malloc(0x1000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. That's too big for cyw43_state

@will-v-pi will-v-pi marked this pull request as ready for review October 17, 2024 09:01
@will-v-pi will-v-pi added this to the 2.0.1 milestone Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants