Skip to content

Commit e009c07

Browse files
committed
Add addresses instead of public bootrom_structs.h
1 parent 67e788f commit e009c07

File tree

3 files changed

+28
-226
lines changed

3 files changed

+28
-226
lines changed

src/rp2_common/pico_bootrom/bootrom.c

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,23 @@ void __attribute__((noreturn)) rom_reset_usb_boot(uint32_t usb_activity_gpio_pin
6262
}
6363

6464
#if !PICO_RP2040
65+
66+
67+
// Generated from adding the following code into the bootrom
68+
// scan_workarea_t* scan_workarea = (scan_workarea_t*)workarea;
69+
// printf("VERSION_DOWNGRADE_ERASE_ADDR %08x\n", &(always->zero_init.version_downgrade_erase_flash_addr));
70+
// printf("TBYB_FLAG_ADDR %08x\n", &(always->zero_init.tbyb_flag_flash_addr));
71+
// printf("IMAGE_DEF_VERIFIED %08x\n", (uint32_t)&(scan_workarea->parsed_block_loops[0].image_def.core.verified) - (uint32_t)scan_workarea);
72+
// printf("IMAGE_DEF_TBYB_FLAGGED %08x\n", (uint32_t)&(scan_workarea->parsed_block_loops[0].image_def.core.tbyb_flagged) - (uint32_t)scan_workarea);
73+
// printf("IMAGE_DEF_BASE %08x\n", (uint32_t)&(scan_workarea->parsed_block_loops[0].image_def.core.enclosing_window.base) - (uint32_t)scan_workarea);
74+
// printf("IMAGE_DEF_REL_BLOCK_OFFSET %08x\n", (uint32_t)&(scan_workarea->parsed_block_loops[0].image_def.core.window_rel_block_offset) - (uint32_t)scan_workarea);
75+
#define VERSION_DOWNGRADE_ERASE_ADDR *(uint32_t*)0x400e0338
76+
#define TBYB_FLAG_ADDR *(uint32_t*)0x400e0348
77+
#define IMAGE_DEF_VERIFIED(scan_workarea) *(uint32_t*)(0x64 + (uint32_t)scan_workarea)
78+
#define IMAGE_DEF_TBYB_FLAGGED(scan_workarea) *(uint32_t*)(0x4c + (uint32_t)scan_workarea)
79+
#define IMAGE_DEF_BASE(scan_workarea) *(uint32_t*)(0x54 + (uint32_t)scan_workarea)
80+
#define IMAGE_DEF_REL_BLOCK_OFFSET(scan_workarea) *(uint32_t*)(0x5c + (uint32_t)scan_workarea)
81+
6582
bool rom_get_boot_random(uint32_t out[4]) {
6683
uint32_t result[5];
6784
rom_get_sys_info_fn func = (rom_get_sys_info_fn) rom_func_lookup_inline(ROM_FUNC_GET_SYS_INFO);
@@ -104,7 +121,6 @@ int rom_add_flash_runtime_partition(uint32_t start_offset, uint32_t size, uint32
104121
}
105122

106123
int rom_pick_ab_update_partition(uint32_t *workarea_base, uint32_t workarea_size, uint partition_a_num) {
107-
scan_workarea_t* scan_workarea = (scan_workarea_t*)workarea_base;
108124
uint32_t flash_update_base = 0;
109125
bool tbyb_boot = false;
110126
uint32_t saved_erase_addr = 0;
@@ -118,43 +134,43 @@ int rom_pick_ab_update_partition(uint32_t *workarea_base, uint32_t workarea_size
118134
// A buy is pending, so the main software has not been bought
119135
tbyb_boot = true;
120136
// Save the erase address, as this will be overwritten by rom_pick_ab_partition
121-
saved_erase_addr = always->zero_init.version_downgrade_erase_flash_addr;
137+
saved_erase_addr = VERSION_DOWNGRADE_ERASE_ADDR;
122138
}
123139
}
124140
}
125141

126-
int rc = rom_pick_ab_partition((uint8_t*)scan_workarea, workarea_size, partition_a_num, flash_update_base);
142+
int rc = rom_pick_ab_partition((uint8_t*)workarea_base, workarea_size, partition_a_num, flash_update_base);
127143

128-
if (scan_workarea->parsed_block_loops[0].image_def.core.verified != RCP_MASK_TRUE) {
144+
if (IMAGE_DEF_VERIFIED(workarea_base) != RCP_MASK_TRUE) {
129145
// Chosen partition failed verification
130146
return BOOTROM_ERROR_NOT_FOUND;
131147
}
132148

133-
if (scan_workarea->parsed_block_loops[0].image_def.core.tbyb_flagged) {
149+
if (IMAGE_DEF_TBYB_FLAGGED(workarea_base)) {
134150
// The chosen partition is TBYB
135151
if (tbyb_boot) {
136152
// The boot partition is also TBYB - cannot update both, so prioritise boot partition
137153
// Restore the erase address saved earlier
138-
always->zero_init.version_downgrade_erase_flash_addr = saved_erase_addr;
154+
VERSION_DOWNGRADE_ERASE_ADDR = saved_erase_addr;
139155
return BOOTROM_ERROR_NOT_PERMITTED;
140156
} else {
141157
// Update the tbyb flash address, so that explicit_buy will clear the flag for the chosen partition
142-
always->zero_init.tbyb_flag_flash_addr =
143-
scan_workarea->parsed_block_loops[0].image_def.core.enclosing_window.base
144-
+ scan_workarea->parsed_block_loops[0].image_def.core.window_rel_block_offset + 4;
158+
TBYB_FLAG_ADDR =
159+
IMAGE_DEF_BASE(workarea_base)
160+
+ IMAGE_DEF_REL_BLOCK_OFFSET(workarea_base) + 4;
145161
}
146162
} else {
147163
// The chosen partition is not TBYB
148164
if (tbyb_boot && saved_erase_addr) {
149165
// The boot partition was TBYB, and requires an erase
150-
if (always->zero_init.version_downgrade_erase_flash_addr) {
166+
if (VERSION_DOWNGRADE_ERASE_ADDR) {
151167
// But both the chosen partition requires an erase too
152168
// As before, prioritise the boot partition, and restore it's saved erase_address
153-
always->zero_init.version_downgrade_erase_flash_addr = saved_erase_addr;
169+
VERSION_DOWNGRADE_ERASE_ADDR = saved_erase_addr;
154170
return BOOTROM_ERROR_NOT_PERMITTED;
155171
} else {
156172
// The chosen partition doesn't require an erase, so we're fine
157-
always->zero_init.version_downgrade_erase_flash_addr = saved_erase_addr;
173+
VERSION_DOWNGRADE_ERASE_ADDR = saved_erase_addr;
158174
}
159175
}
160176
}

src/rp2_common/pico_bootrom/include/pico/bootrom.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
#ifndef __ASSEMBLER__
2121
#include <string.h>
2222
#include "pico/bootrom/lock.h"
23-
#if !PICO_RP2040
24-
#include "pico/bootrom_structs.h"
25-
#endif
2623
// ROM FUNCTION SIGNATURES
2724

2825
#if PICO_RP2040

src/rp2_common/pico_bootrom/include/pico/bootrom_structs.h

Lines changed: 0 additions & 211 deletions
This file was deleted.

0 commit comments

Comments
 (0)