Firmware update from firmware not possible #545
Labels
No labels
bazel
bluetooth
board settings
boot_stage2
bug
build
c++
can't reproduce
clang
clib-interface
cmsis
code cleanliness
code size
compiler version issues
cyw43_driver
debug
discussion
documentation
duplicate
dynamic_clock
elf2uf2
enhancement
errata
filesystem
flash layout
floating point
FreeRTOS
hardware_adc
hardware_claim
hardware_clocks
hardware_dma
hardware_exception
hardware_flash
hardware_gpio
hardware_i2c
hardware_irq
hardware_pio
hardware_pwm
hardware_rcp
hardware_rtc
hardware_spi
hardware_sync
hardware_uart
hardware_vreg
hardware_watchdog
hardware_xosc
help wanted
host
IAR
installation
invalid
linker scripts
lto
lwip
mbedtls
missing API
needs reporter detail
networking
newlib
newlib-multicore
non-c
non-cmake
non-gcc
openocd
orphan PR
OS integration
pico_async_context
pico_base
pico_binary_info
pico_flash
picolibc
pico_lwip
pico_malloc
pico_multicore
pico_printf
pico_runtime
pico_stdio
pico_stdio_usb
pico_sync
pico_time
pico_util
pioasm
port
question
review
review2
rtos interop
runtime init
static library
svd
test
tinyusb
vscode
wifi integration
wontfix
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-raspberrypi/pico-sdk#545
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I'm trying to update the RP2040 firmware from firmware running on that same RP2040. I download new firmware (via USB) into an unused region in flash and when done copy that data to the start of the flash and then reboot.
So the function that copies from flash to flash and then waits for reboot must run entirely from memory and never ever from flash. This, however, is currently not possible because the function
rom_func_lookup, which bothflash_range_eraseandflash_range_programcall, is still in flash.When I wrap
rom_func_lookupwith a__not_in_flash_func(and make sure the compiler doesn't usememcpyin flash-to-flash) it all works fine.Ah yes, that is a weird oversight
Is any of the discussion in #410 applicable here?
Hmm, hadn't noticed that issue. Yes, I'd say this is a duplicate.
It might be worth adding that decorator, though the user in #410 also saw functions like this one fail to inline, which was surprising:
Erasing the image you are currently XIPing from is pretty fraught, for the reasons mentioned in #410. With all the dependencies of
hardware_flasheither in RAM or force-inlined, it's still dangerous, because there is a period of many milliseconds where you have no bootable image in flash, because it just erased itself, so if you lose power, you brick your board until you can access the USB boot and reflash.Slightly cleaner approach is to have a self-contained stub program in e.g. the first 4k of flash which:
You then need to build your actual program to install and run at an offset into flash. You can take a copy of the default linker script, edit this line
To say
And add a
pico_set_linker_script()to your CMake file to select your modified linker script. This tells the linker to build your main program as though the first 4k of flash doesn't exist, so your main program can coexist with the bootloader stub at the start of flash.This really should have been a macro but I don't want to change it now in case there is some weird reliance in existing code, but I am changing it to
__force_inlinewhich should solve the problemmerged into develop