From dee8272d072f54cc9e1c6c7e20e0686ad7b95271 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Mon, 4 Nov 2024 12:44:52 -0600 Subject: [PATCH 1/4] Minor header cleanups and ASM compatibility --- .../include/boot/picoboot_constants.h | 2 +- .../boot_uf2_headers/include/boot/uf2.h | 11 ++++-- .../include/boot/bootrom_constants.h | 39 ++++++++++--------- .../include/pico/platform/compiler.h | 2 + 4 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/common/boot_picoboot_headers/include/boot/picoboot_constants.h b/src/common/boot_picoboot_headers/include/boot/picoboot_constants.h index ac78ea213..3a8455c46 100644 --- a/src/common/boot_picoboot_headers/include/boot/picoboot_constants.h +++ b/src/common/boot_picoboot_headers/include/boot/picoboot_constants.h @@ -9,7 +9,7 @@ #define REBOOT2_TYPE_MASK 0x0f -// note these match REBOOT_TYPE in pico/bootrom_constants.h (also 0 is used for PC_SP for backwards compatibility with RP2040) +// note these match REBOOT_TYPE in pico/bootrom_constants.h // values 0-7 are secure/non-secure #define REBOOT2_FLAG_REBOOT_TYPE_NORMAL 0x0 // param0 = diagnostic partition #define REBOOT2_FLAG_REBOOT_TYPE_BOOTSEL 0x2 // param0 = bootsel_flags, param1 = gpio_config diff --git a/src/common/boot_uf2_headers/include/boot/uf2.h b/src/common/boot_uf2_headers/include/boot/uf2.h index 271540a20..ffdcb90d1 100644 --- a/src/common/boot_uf2_headers/include/boot/uf2.h +++ b/src/common/boot_uf2_headers/include/boot/uf2.h @@ -20,10 +20,11 @@ #define UF2_MAGIC_START1 0x9E5D5157u #define UF2_MAGIC_END 0x0AB16F30u -#define UF2_FLAG_NOT_MAIN_FLASH 0x00000001u -#define UF2_FLAG_FILE_CONTAINER 0x00001000u -#define UF2_FLAG_FAMILY_ID_PRESENT 0x00002000u -#define UF2_FLAG_MD5_PRESENT 0x00004000u +#define UF2_FLAG_NOT_MAIN_FLASH 0x00000001u +#define UF2_FLAG_FILE_CONTAINER 0x00001000u +#define UF2_FLAG_FAMILY_ID_PRESENT 0x00002000u +#define UF2_FLAG_MD5_PRESENT 0x00004000u +#define UF2_FLAG_EXTENSION_FLAGS_PRESENT 0x00008000u #define RP2040_FAMILY_ID 0xe48bff56u #define ABSOLUTE_FAMILY_ID 0xe48bff57u @@ -33,6 +34,8 @@ #define RP2350_ARM_NS_FAMILY_ID 0xe48bff5bu #define FAMILY_ID_MAX 0xe48bff5bu +// 04 e3 57 99 +#define UF2_EXTENSION_RP2_IGNORE_BLOCK 0x9957e304 struct uf2_block { // 32 byte header diff --git a/src/rp2_common/boot_bootrom_headers/include/boot/bootrom_constants.h b/src/rp2_common/boot_bootrom_headers/include/boot/bootrom_constants.h index fcf4c652c..37eb0dec9 100644 --- a/src/rp2_common/boot_bootrom_headers/include/boot/bootrom_constants.h +++ b/src/rp2_common/boot_bootrom_headers/include/boot/bootrom_constants.h @@ -255,6 +255,12 @@ typedef int (*bootrom_api_callback_generic_t)(uint32_t r0, uint32_t r1, uint32_t #define BOOTROM_NS_API_get_b_partition 7 #define BOOTROM_NS_API_COUNT 8 +#define OTP_CMD_ROW_BITS 0x0000ffffu +#define OTP_CMD_ROW_LSB _u(0) +#define OTP_CMD_WRITE_BITS 0x00010000u +#define OTP_CMD_WRITE_LSB _u(6) +#define OTP_CMD_ECC_BITS 0x00020000u + #ifndef __ASSEMBLER__ typedef struct { @@ -263,11 +269,6 @@ typedef struct { } resident_partition_t; static_assert(sizeof(resident_partition_t) == 8, ""); -#define OTP_CMD_ROW_BITS 0x0000ffffu -#define OTP_CMD_ROW_LSB 0u -#define OTP_CMD_WRITE_BITS 0x00010000u -#define OTP_CMD_ECC_BITS 0x00020000u - typedef struct otp_cmd { uint32_t flags; } otp_cmd_t; @@ -304,37 +305,37 @@ typedef struct cflash_flags { uint32_t flags; } cflash_flags_t; +#endif + // Bits which are permitted to be set in a flags variable -- any other bits being set is an error #define CFLASH_FLAGS_BITS 0x00070301u // Used to tell checked flash API which space a given address belongs to #define CFLASH_ASPACE_BITS 0x00000001u -#define CFLASH_ASPACE_LSB 0u -#define CFLASH_ASPACE_VALUE_STORAGE 0u -#define CFLASH_ASPACE_VALUE_RUNTIME 1u +#define CFLASH_ASPACE_LSB _u(0) +#define CFLASH_ASPACE_VALUE_STORAGE _u(0) +#define CFLASH_ASPACE_VALUE_RUNTIME _u(1) // Used to tell checked flash APIs the effective security level of a flash access (may be forced to // one of these values for the NonSecure-exported version of this API) #define CFLASH_SECLEVEL_BITS 0x00000300u -#define CFLASH_SECLEVEL_LSB 8u +#define CFLASH_SECLEVEL_LSB _u(8) // Zero is not a valid security level: -#define CFLASH_SECLEVEL_VALUE_SECURE 1u -#define CFLASH_SECLEVEL_VALUE_NONSECURE 2u -#define CFLASH_SECLEVEL_VALUE_BOOTLOADER 3u +#define CFLASH_SECLEVEL_VALUE_SECURE _u(1) +#define CFLASH_SECLEVEL_VALUE_NONSECURE _u(2) +#define CFLASH_SECLEVEL_VALUE_BOOTLOADER _u(3) #define CFLASH_OP_BITS 0x00070000u -#define CFLASH_OP_LSB 16u +#define CFLASH_OP_LSB _u(16) // Erase size_bytes bytes of flash, starting at address addr. Both addr and size_bytes must be a // multiple of 4096 bytes (one flash sector). -#define CFLASH_OP_VALUE_ERASE 0u +#define CFLASH_OP_VALUE_ERASE _u(0) // Program size_bytes bytes of flash, starting at address addr. Both addr and size_bytes must be a // multiple of 256 bytes (one flash page). -#define CFLASH_OP_VALUE_PROGRAM 1u +#define CFLASH_OP_VALUE_PROGRAM _u(1) // Read size_bytes bytes of flash, starting at address addr. There are no alignment restrictions on // addr or size_bytes. -#define CFLASH_OP_VALUE_READ 2u -#define CFLASH_OP_MAX 2u - -#endif +#define CFLASH_OP_VALUE_READ _u(2) +#define CFLASH_OP_MAX _u(2) #endif diff --git a/src/rp2_common/pico_platform_compiler/include/pico/platform/compiler.h b/src/rp2_common/pico_platform_compiler/include/pico/platform/compiler.h index cd1ad526f..486758be3 100644 --- a/src/rp2_common/pico_platform_compiler/include/pico/platform/compiler.h +++ b/src/rp2_common/pico_platform_compiler/include/pico/platform/compiler.h @@ -150,10 +150,12 @@ extern "C" { #define pico_default_asm(...) __asm (".syntax unified\n" __VA_ARGS__) #define pico_default_asm_volatile(...) __asm volatile (".syntax unified\n" __VA_ARGS__) #define pico_default_asm_goto(...) __asm goto (".syntax unified\n" __VA_ARGS__) +#define pico_default_asm_volatile_goto(...) __asm volatile goto (".syntax unified\n" __VA_ARGS__) #else #define pico_default_asm(...) __asm (__VA_ARGS__) #define pico_default_asm_volatile(...) __asm volatile (__VA_ARGS__) #define pico_default_asm_goto(...) __asm goto (__VA_ARGS__) +#define pico_default_asm_volatile_goto(...) __asm volatile goto (__VA_ARGS__) #endif /*! \brief Ensure that the compiler does not move memory access across this method call From 92adc763b45ac15b39dfc3f8d9b6ff9a3344f716 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Mon, 4 Nov 2024 20:21:36 -0600 Subject: [PATCH 2/4] review commet; and fix flagrant bug --- .../boot_bootrom_headers/include/boot/bootrom_constants.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rp2_common/boot_bootrom_headers/include/boot/bootrom_constants.h b/src/rp2_common/boot_bootrom_headers/include/boot/bootrom_constants.h index 37eb0dec9..195140f6b 100644 --- a/src/rp2_common/boot_bootrom_headers/include/boot/bootrom_constants.h +++ b/src/rp2_common/boot_bootrom_headers/include/boot/bootrom_constants.h @@ -258,10 +258,13 @@ typedef int (*bootrom_api_callback_generic_t)(uint32_t r0, uint32_t r1, uint32_t #define OTP_CMD_ROW_BITS 0x0000ffffu #define OTP_CMD_ROW_LSB _u(0) #define OTP_CMD_WRITE_BITS 0x00010000u -#define OTP_CMD_WRITE_LSB _u(6) +#define OTP_CMD_WRITE_LSB _u(16) #define OTP_CMD_ECC_BITS 0x00020000u +#define OTP_CMD_ECC_LSB _u(17) #ifndef __ASSEMBLER__ +static_assert(OTP_CMD_WRITE_BITS == (1 << OTP_CMD_WRITE_LSB), ""); +static_assert(OTP_CMD_ECC_BITS == (1 << OTP_CMD_ECC_LSB), ""); typedef struct { uint32_t permissions_and_location; From cb4544de79e511c9f2b5bef5d6d965e1dbc63d76 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Mon, 4 Nov 2024 20:31:39 -0600 Subject: [PATCH 3/4] fix reboot param comments --- .../boot_picoboot_headers/include/boot/picoboot_constants.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/boot_picoboot_headers/include/boot/picoboot_constants.h b/src/common/boot_picoboot_headers/include/boot/picoboot_constants.h index 3a8455c46..642f54e6a 100644 --- a/src/common/boot_picoboot_headers/include/boot/picoboot_constants.h +++ b/src/common/boot_picoboot_headers/include/boot/picoboot_constants.h @@ -12,8 +12,8 @@ // note these match REBOOT_TYPE in pico/bootrom_constants.h // values 0-7 are secure/non-secure #define REBOOT2_FLAG_REBOOT_TYPE_NORMAL 0x0 // param0 = diagnostic partition -#define REBOOT2_FLAG_REBOOT_TYPE_BOOTSEL 0x2 // param0 = bootsel_flags, param1 = gpio_config -#define REBOOT2_FLAG_REBOOT_TYPE_RAM_IMAGE 0x3 // param0 = image_base, param1 = image_end +#define REBOOT2_FLAG_REBOOT_TYPE_BOOTSEL 0x2 // param0 = gpio_pin_number, param1 = flags +#define REBOOT2_FLAG_REBOOT_TYPE_RAM_IMAGE 0x3 // param0 = image_regio_base, param1 = image_region_size #define REBOOT2_FLAG_REBOOT_TYPE_FLASH_UPDATE 0x4 // param0 = update_base // values 8-15 are secure only @@ -39,4 +39,4 @@ #define UF2_STATUS_ABORT_BAD_ADDRESS 0x20 #define UF2_STATUS_ABORT_WRITE_ERROR 0x40 #define UF2_STATUS_ABORT_REBOOT_FAILED 0x80 -#endif \ No newline at end of file +#endif From 1379406b3c096f9654d320b51ae02f8550bfe509 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Tue, 5 Nov 2024 12:56:38 -0600 Subject: [PATCH 4/4] some review changes --- .../boot_picoboot_headers/include/boot/picoboot_constants.h | 2 +- .../boot_bootrom_headers/include/boot/bootrom_constants.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/boot_picoboot_headers/include/boot/picoboot_constants.h b/src/common/boot_picoboot_headers/include/boot/picoboot_constants.h index 642f54e6a..ffb3b8cc4 100644 --- a/src/common/boot_picoboot_headers/include/boot/picoboot_constants.h +++ b/src/common/boot_picoboot_headers/include/boot/picoboot_constants.h @@ -13,7 +13,7 @@ // values 0-7 are secure/non-secure #define REBOOT2_FLAG_REBOOT_TYPE_NORMAL 0x0 // param0 = diagnostic partition #define REBOOT2_FLAG_REBOOT_TYPE_BOOTSEL 0x2 // param0 = gpio_pin_number, param1 = flags -#define REBOOT2_FLAG_REBOOT_TYPE_RAM_IMAGE 0x3 // param0 = image_regio_base, param1 = image_region_size +#define REBOOT2_FLAG_REBOOT_TYPE_RAM_IMAGE 0x3 // param0 = image_region_base, param1 = image_region_size #define REBOOT2_FLAG_REBOOT_TYPE_FLASH_UPDATE 0x4 // param0 = update_base // values 8-15 are secure only diff --git a/src/rp2_common/boot_bootrom_headers/include/boot/bootrom_constants.h b/src/rp2_common/boot_bootrom_headers/include/boot/bootrom_constants.h index 195140f6b..c1107f66b 100644 --- a/src/rp2_common/boot_bootrom_headers/include/boot/bootrom_constants.h +++ b/src/rp2_common/boot_bootrom_headers/include/boot/bootrom_constants.h @@ -308,7 +308,7 @@ typedef struct cflash_flags { uint32_t flags; } cflash_flags_t; -#endif +#endif // #ifdef __ASSEMBLER__ // Bits which are permitted to be set in a flags variable -- any other bits being set is an error #define CFLASH_FLAGS_BITS 0x00070301u