diff options
author | Lasse Dalegaard <dalegaard@gmail.com> | 2021-07-04 10:24:29 +0200 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2021-07-04 12:43:45 -0400 |
commit | ba958468b7a98e3a61bc0e5cbe30686abe6e16aa (patch) | |
tree | b1515bf1e97de7b677c6852e45f1354d0d4bcec5 /src/rp2040/bootrom.c | |
parent | 0597210cb9f550cd2f410214ec8b48503ce94c81 (diff) | |
download | kutter-ba958468b7a98e3a61bc0e5cbe30686abe6e16aa.tar.gz kutter-ba958468b7a98e3a61bc0e5cbe30686abe6e16aa.tar.xz kutter-ba958468b7a98e3a61bc0e5cbe30686abe6e16aa.zip |
rp2040: add chipid support
The rp2040 doesn't have a chip ID, but the flash chip connected does. We
can get this ID by asking the flash chip directly, but doing so requires
disengaging the XIP layer, performing the interrogation of the flash
chip, and then re-enabling the XIP layer. This gives us a 64-bit unique
ID that we can use as our USB serial number.
Signed-off-by: Lasse Dalegaard <dalegaard@gmail.com>
Diffstat (limited to 'src/rp2040/bootrom.c')
-rw-r--r-- | src/rp2040/bootrom.c | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/src/rp2040/bootrom.c b/src/rp2040/bootrom.c index da2da18e..b0cfeefb 100644 --- a/src/rp2040/bootrom.c +++ b/src/rp2040/bootrom.c @@ -5,8 +5,17 @@ // This file may be distributed under the terms of the GNU GPLv3 license. #include <stdint.h> // uint16_t, uint32_t, uintptr_t +#include <string.h> // memcpy +#include "compiler.h" // noinline, __section -static void * +#define ROM_TABLE_CODE(c1, c2) ((c1) | ((c2) << 8)) + +// All functions in here need to be RAM-resident, as we may need +// to (especially for the flash functions) call while the XIP layer +// is unavailable. +#define noinline_ram noinline __section(".ramfunc.read_chip_id") + +static void * noinline_ram rom_func_lookup(uint32_t code) { // Table and lookup function are provided by the BOOTROM @@ -16,10 +25,31 @@ rom_func_lookup(uint32_t code) return fn(table, code); } -void +void noinline_ram reset_to_usb_boot(uint32_t gpio_activity_pin_mask , uint32_t disable_interface_mask) { - void (*reset_to_usb_boot)(uint32_t, uint32_t) = rom_func_lookup(0x4255); - reset_to_usb_boot(gpio_activity_pin_mask, disable_interface_mask); + void (*fn)(uint32_t, uint32_t) = rom_func_lookup(ROM_TABLE_CODE('U', 'B')); + fn(gpio_activity_pin_mask, disable_interface_mask); +} + +void noinline_ram +connect_internal_flash(void) +{ + void (*fn)(void) = rom_func_lookup(ROM_TABLE_CODE('I', 'F')); + fn(); +} + +void noinline_ram +flash_exit_xip(void) +{ + void (*fn)(void) = rom_func_lookup(ROM_TABLE_CODE('E', 'X')); + fn(); +} + +void noinline_ram +flash_flush_cache(void) +{ + void (*fn)(void) = rom_func_lookup(ROM_TABLE_CODE('F', 'C')); + fn(); } |