usedbytes / rp2040-serial-bootloader

A serial bootloader for the Raspberry Pi RP2040 (Pico)
86 stars 29 forks source link

Bootloader not jumping to program? #3

Closed jubthegreat closed 2 years ago

jubthegreat commented 2 years ago

Hi,

I am trying to get this working with blink_noboot (https://github.com/usedbytes/pico-blink-noboot2) and the RP2040 serial bootloader (https://github.com/usedbytes/rp2040-serial-bootloader).

I have read through the previous issue thread and changed the bootloader size to 28k. Are the following memories now correct? bootloader.ld: MEMORY { FLASH(rx) : ORIGIN = 0x10000000, LENGTH = 24k RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k }

combined.ld: MEMORY { FLASH_BL(rx) : ORIGIN = 0x10000000, LENGTH = 24k FLASH_IMGHDR(rx) : ORIGIN = 0x10000000 + 24k, LENGTH = 4k FLASH_APP(rx) : ORIGIN = 0x10000000 + 28k, LENGTH = 2048k - 28k RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k }

blink_noboot2.ld: MEMORY { FLASH(rx) : ORIGIN = 0x10000000 + 28k, LENGTH = 2048k - 28k RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k }

main.c (bootloader): '#define IMAGE_HEADER_OFFSET (24 * 1024)'

I have also added the following to the end of the while(1) in the bootloader main.c, I believe this should make the bootloader jump to blink_noboot2 when i disconnect BOOTLOADER_ENTRY_PIN?

if (!should_stay_in_bootloader()) { uint32_t vtor = XIP_BASE + (1024 * 28); disable_interrupts(); reset_peripherals(); jump_to_vtor(vtor); }

I am doing the following steps: 1)Build bootloader 2) Copy the .uf2 to the Pi Pico using the mass storage USB bootloader 3) Build blink_noboot2 and copy the .uf2 to desktop 4) Open the command terminal (windows) and run serial-flash COM9 blink_noboot2.uf2 0x10007000 5) I get the following output: Opened COM9 Synchronising: 1 / 5 [==========>--------------------------------------------] 20.00% 29/s 0s Querying device info: 1 / 1 [======================================================] 100.00% 101/s 0s Erasing: 40960 / 40960 [===========================================] 100.00% 122346/s 0s Writing: 40960 / 40960 [============================================] 100.00% 64226/s 0s Finalising: 1 / 1 [=======================================================] 100.00% 67/s 0s Error: seal: received error response` 6) RP2040 LED is on. If I disconnect the BOOTLOADER_ENTRY_PIN, the LED stays on, indicating I am not jumping to program? 7) If I power cycle the RP2040 with the BOOTLOADER_ENTRY_PIN disconnected (high), I get a brief flash, then nothing.

Any guidance you can give on this would be much appreciated.

usedbytes commented 2 years ago

Hi,

Your address modifications look OK. If all you need is more space though, I've already created a branch which gives 32kB for the bootloader: https://github.com/usedbytes/rp2040-serial-bootloader/tree/bl32k can you just use that?

I have also added the following to the end of the while(1) in the bootloader main.c, I believe this should make the bootloader jump to blink_noboot2 when i disconnect BOOTLOADER_ENTRY_PIN?

That doesn't sound like a good idea. What are you hoping that will do? If you pull BOOTLOADER_ENTRY_PIN low before resetting the Pico, then it will stay in the bootloader, otherwise, if there's a valid image loaded, it will immediately jump to the program. That's handled by this part of the code:

    gpio_init(BOOTLOADER_ENTRY_PIN);
    gpio_pull_up(BOOTLOADER_ENTRY_PIN);
    gpio_set_dir(BOOTLOADER_ENTRY_PIN, 0);

    ...

    struct image_header *hdr = (struct image_header *)(XIP_BASE + IMAGE_HEADER_OFFSET);

    if (!should_stay_in_bootloader() && image_header_ok(hdr)) {
        uint32_t vtor = *((uint32_t *)(XIP_BASE + IMAGE_HEADER_OFFSET));
        disable_interrupts();
        reset_peripherals();
        jump_to_vtor(vtor);
    }

serial-flash COM9 blink_noboot2.uf2 0x10007000

serial-flash doesn't support uf2 files. It will be treating your uf2 as a raw binary and writing it - so that won't be valid. You need to either give a .bin + address to serial-flash, or a .elf

Error: seal: received error response

This error is important, it means that the uploaded image isn't valid - but I guess that would be expected if you program a uf2 file as a raw binary. This is actually "working as expected" 🙂 there are checks in the bootloader to try and stop you programming invalid code and then not being able to get back to the bootloader.

Please try programming blink_noboot2.elf (without specifying an address), and perhaps try the bl32k branch of the bootloader too

jubthegreat commented 2 years ago

Thanks for your quick response. My bad for not realising it had to be the .elf!

I will try with try again