rp2040: Support CanBoot as bootloader

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2022-10-21 21:50:21 -04:00
parent 42e9adcfc9
commit 6485ff800b
3 changed files with 41 additions and 14 deletions

View File

@ -47,17 +47,32 @@ config STACK_SIZE
int int
default 512 default 512
config FLASH_START
hex
default 0x10000100
###################################################################### ######################################################################
# Bootloader options # Bootloader options
###################################################################### ######################################################################
config RP2040_HAVE_STAGE2
bool
config RP2040_HAVE_BOOTLOADER
bool
default y if !RP2040_HAVE_STAGE2
choice choice
prompt "Flash chip" if LOW_LEVEL_OPTIONS prompt "Bootloader offset"
config RP2040_FLASH_START_0100
bool "No bootloader"
select RP2040_HAVE_STAGE2
config RP2040_FLASH_START_4000
bool "16KiB bootloader"
endchoice
config FLASH_START
hex
default 0x10004000 if RP2040_FLASH_START_4000
default 0x10000100
choice
prompt "Flash chip" if LOW_LEVEL_OPTIONS && RP2040_HAVE_STAGE2
config RP2040_FLASH_W25Q080 config RP2040_FLASH_W25Q080
bool "W25Q080 with CLKDIV 2" bool "W25Q080 with CLKDIV 2"
config RP2040_FLASH_GENERIC_03 config RP2040_FLASH_GENERIC_03

View File

@ -8,10 +8,6 @@ dirs-y += src/rp2040 src/generic lib/rp2040/elf2uf2 lib/fast-hash lib/can2040
CFLAGS += -mcpu=cortex-m0plus -mthumb -Ilib/cmsis-core CFLAGS += -mcpu=cortex-m0plus -mthumb -Ilib/cmsis-core
CFLAGS += -Ilib/rp2040 -Ilib/rp2040/cmsis_include -Ilib/fast-hash -Ilib/can2040 CFLAGS += -Ilib/rp2040 -Ilib/rp2040/cmsis_include -Ilib/fast-hash -Ilib/can2040
CFLAGS_klipper.elf += --specs=nano.specs --specs=nosys.specs
CFLAGS_klipper.elf += -T $(OUT)src/rp2040/rp2040_link.ld
$(OUT)klipper.elf: $(OUT)stage2.o $(OUT)src/rp2040/rp2040_link.ld
# Add source files # Add source files
src-y += rp2040/main.c rp2040/gpio.c rp2040/adc.c generic/crc16_ccitt.c src-y += rp2040/main.c rp2040/gpio.c rp2040/adc.c generic/crc16_ccitt.c
src-y += generic/armcm_boot.c generic/armcm_irq.c generic/armcm_reset.c src-y += generic/armcm_boot.c generic/armcm_irq.c generic/armcm_reset.c
@ -38,11 +34,8 @@ $(OUT)stage2.o: lib/rp2040/boot_stage2/$(STAGE2_FILE) $(OUT)autoconf.h
$(Q)$(OBJCOPY) -O binary $(OUT)stage2raw.o $(OUT)stage2raw.bin $(Q)$(OBJCOPY) -O binary $(OUT)stage2raw.o $(OUT)stage2raw.bin
$(Q)lib/rp2040/boot_stage2/pad_checksum -s 0xffffffff $(OUT)stage2raw.bin $(OUT)stage2.S $(Q)lib/rp2040/boot_stage2/pad_checksum -s 0xffffffff $(OUT)stage2raw.bin $(OUT)stage2.S
$(Q)$(CC) $(CFLAGS) -c $(OUT)stage2.S -o $(OUT)stage2.o $(Q)$(CC) $(CFLAGS) -c $(OUT)stage2.S -o $(OUT)stage2.o
OBJS_klipper.elf += $(OUT)stage2.o
# Binary output file rules
target-y += $(OUT)klipper.uf2
# Binary output file rules when using stage2
$(OUT)lib/rp2040/elf2uf2/elf2uf2: lib/rp2040/elf2uf2/main.cpp $(OUT)lib/rp2040/elf2uf2/elf2uf2: lib/rp2040/elf2uf2/main.cpp
@echo " Building $@" @echo " Building $@"
$(Q)g++ -g -O -Ilib/rp2040 $< -o $@ $(Q)g++ -g -O -Ilib/rp2040 $< -o $@
@ -51,11 +44,28 @@ $(OUT)klipper.uf2: $(OUT)klipper.elf $(OUT)lib/rp2040/elf2uf2/elf2uf2
@echo " Creating uf2 file $@" @echo " Creating uf2 file $@"
$(Q)$(OUT)lib/rp2040/elf2uf2/elf2uf2 $< $@ $(Q)$(OUT)lib/rp2040/elf2uf2/elf2uf2 $< $@
target-$(CONFIG_RP2040_HAVE_STAGE2) += $(OUT)klipper.uf2
rplink-$(CONFIG_RP2040_HAVE_STAGE2) := $(OUT)src/rp2040/rp2040_link.ld
stage2-$(CONFIG_RP2040_HAVE_STAGE2) := $(OUT)stage2.o
# rp2040 building when using a bootloader
$(OUT)klipper.bin: $(OUT)klipper.elf
@echo " Creating bin file $@"
$(Q)$(OBJCOPY) -O binary $< $@
target-$(CONFIG_RP2040_HAVE_BOOTLOADER) += $(OUT)klipper.bin
rplink-$(CONFIG_RP2040_HAVE_BOOTLOADER) := $(OUT)src/generic/armcm_link.ld
# Set klipper.elf linker rules
CFLAGS_klipper.elf += --specs=nano.specs --specs=nosys.specs -T $(rplink-y)
OBJS_klipper.elf += $(stage2-y)
$(OUT)klipper.elf: $(stage2-y) $(rplink-y)
# Flash rules
lib/rp2040_flash/rp2040_flash: lib/rp2040_flash/rp2040_flash:
@echo " Building rp2040_flash" @echo " Building rp2040_flash"
$(Q)make -C lib/rp2040_flash rp2040_flash $(Q)make -C lib/rp2040_flash rp2040_flash
# Flash rules
flash: $(OUT)klipper.uf2 lib/rp2040_flash/rp2040_flash flash: $(OUT)klipper.uf2 lib/rp2040_flash/rp2040_flash
@echo " Flashing $< to $(FLASH_DEVICE)" @echo " Flashing $< to $(FLASH_DEVICE)"
$(Q)$(PYTHON) ./scripts/flash_usb.py -t $(CONFIG_MCU) -d "$(FLASH_DEVICE)" $(if $(NOSUDO),--no-sudo) $(OUT)klipper.uf2 $(Q)$(PYTHON) ./scripts/flash_usb.py -t $(CONFIG_MCU) -d "$(FLASH_DEVICE)" $(if $(NOSUDO),--no-sudo) $(OUT)klipper.uf2

View File

@ -6,6 +6,7 @@
#include <stdint.h> // uint32_t #include <stdint.h> // uint32_t
#include "board/misc.h" // bootloader_request #include "board/misc.h" // bootloader_request
#include "generic/armcm_reset.h" // try_request_canboot
#include "hardware/structs/clocks.h" // clock_hw_t #include "hardware/structs/clocks.h" // clock_hw_t
#include "hardware/structs/pll.h" // pll_hw_t #include "hardware/structs/pll.h" // pll_hw_t
#include "hardware/structs/resets.h" // sio_hw #include "hardware/structs/resets.h" // sio_hw
@ -45,6 +46,7 @@ DECL_INIT(watchdog_init);
void void
bootloader_request(void) bootloader_request(void)
{ {
try_request_canboot();
// Use the bootrom-provided code to reset into BOOTSEL mode // Use the bootrom-provided code to reset into BOOTSEL mode
reset_to_usb_boot(0, 0); reset_to_usb_boot(0, 0);
} }