From b63e54c14d7757fa8d963052654811c845653a8f Mon Sep 17 00:00:00 2001 From: Luke Wren Date: Wed, 3 Feb 2021 12:40:20 +0000 Subject: [PATCH] Add PICO_NO_FPGA_CHECK define to remove FPGA check and save some bytes --- src/rp2_common/pico_platform/include/pico/platform.h | 10 ++++++++++ src/rp2_common/pico_platform/platform.c | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/rp2_common/pico_platform/include/pico/platform.h b/src/rp2_common/pico_platform/include/pico/platform.h index 718a5ec..fcf704a 100644 --- a/src/rp2_common/pico_platform/include/pico/platform.h +++ b/src/rp2_common/pico_platform/include/pico/platform.h @@ -63,7 +63,17 @@ void __attribute__((noreturn)) panic_unsupported(); void __attribute__((noreturn)) panic(const char *fmt, ...); +// PICO_CONFIG: PICO_NO_FPGA_CHECK, Remove the FPGA platform check for small code size reduction, type=bool, default=0, advanced=true, group=pico_runtime +#ifndef PICO_NO_FPGA_CHECK +#define PICO_NO_FPGA_CHECK 0 +#endif + +#if PICO_NO_FPGA_CHECK +static inline bool running_on_fpga() {return false;} +#else bool running_on_fpga(); +#endif + uint8_t rp2040_chip_version(); static inline uint8_t rp2040_rom_version() { diff --git a/src/rp2_common/pico_platform/platform.c b/src/rp2_common/pico_platform/platform.c index 86167ab..293ec27 100644 --- a/src/rp2_common/pico_platform/platform.c +++ b/src/rp2_common/pico_platform/platform.c @@ -9,9 +9,19 @@ #include "hardware/regs/tbman.h" #include "hardware/regs/sysinfo.h" +// Note we leave the FPGA check in by default so that we can run bug repro +// binaries coming in from the wild on the FPGA platform. It takes up around +// 48 bytes if you include all the calls, so you can pass PICO_NO_FPGA_CHECK=1 +// to remove it. The FPGA check is used to skip initialisation of hardware +// (mainly clock generators and oscillators) that aren't present on FPGA. + +#if !PICO_NO_FPGA_CHECK +// Inline stub provided in header if this code is unused (so folding can be +// done in each TU instead of relying on LTO) bool running_on_fpga() { return !!((*(io_ro_32 *)TBMAN_BASE) & TBMAN_PLATFORM_FPGA_BITS); } +#endif #define MANUFACTURER_RPI 0x927 #define PART_RP2 0x2