Skip to content

Commit a30a140

Browse files
committed
Tidy up variable names, add assets on correct chars, and improve documentation
1 parent d323d12 commit a30a140

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ App|Description
5252
[hello_anything](binary_info/hello_anything) | Uses `bi_ptr` variables to create a configurable hello_world binary - see the separate [README](binary_info/README.md) for more details
5353

5454
### Bootloaders (RP235x Only)
55+
56+
These examples all produce multiple UF2s - a bootloader UF2, and then a separate UF2 of the program that the bootloader will load and boot. To load them onto a device with empty flash, first load the bootloader UF2, then reset to BOOTSEL mode and load the program UF2. This ordering is required because the bootloaders contain embedded partition tables - see section 5.10.6 in the RP2350 datasheet for more details on those.
57+
5558
App|Description
5659
---|---
5760
[enc_bootloader](bootloaders/encrypted) | A bootloader which decrypts binaries from flash into SRAM. See the separate [README](bootloaders/encrypted/README.md) for more information

bootloaders/uart/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ add_executable(uart_boot
55
# pull in common dependencies
66
target_link_libraries(uart_boot pico_stdlib hardware_flash)
77

8+
# add partition table
89
pico_embed_pt_in_binary(uart_boot ${CMAKE_CURRENT_LIST_DIR}/uart-pt.json)
10+
11+
# create absolute UF2
912
pico_set_uf2_family(uart_boot "absolute")
1013

1114
# create map/bin/hex file etc.
@@ -15,6 +18,7 @@ pico_add_extra_outputs(uart_boot)
1518
example_auto_set_url(uart_boot)
1619

1720

21+
# Create separate binary to be loaded onto other device
1822
add_executable(uart_binary
1923
uart_binary.c
2024
)
@@ -23,6 +27,8 @@ add_executable(uart_binary
2327
target_link_libraries(uart_binary pico_stdlib)
2428

2529
pico_set_binary_type(uart_binary no_flash)
30+
31+
# package uf2 in flash
2632
pico_package_uf2_output(uart_binary 0x10000000)
2733

2834
# create map/bin/hex/uf2 file etc.

bootloaders/uart/uart_boot.c

+15-12
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ void uart_boot() {
3737

3838
if (uart_is_readable_within_us(UART_ID, 1000)) {
3939
char in = uart_getc(UART_ID);
40+
assert(in == 'n');
4041
printf("%c\n", in);
4142
break;
4243
} else {
@@ -61,18 +62,18 @@ void uart_boot() {
6162
assert(ret == 3);
6263

6364
uint32_t location_and_permissions = buffer[1];
64-
uint32_t saddr = XIP_BASE + ((location_and_permissions >> PICOBIN_PARTITION_LOCATION_FIRST_SECTOR_LSB) & 0x1fffu) * FLASH_SECTOR_SIZE;
65-
uint32_t eaddr = XIP_BASE + (((location_and_permissions >> PICOBIN_PARTITION_LOCATION_LAST_SECTOR_LSB) & 0x1fffu) + 1) * FLASH_SECTOR_SIZE;
66-
printf("Start %08x, end %08x\n", saddr, eaddr);
65+
uint32_t start_addr = XIP_BASE + ((location_and_permissions & PICOBIN_PARTITION_LOCATION_FIRST_SECTOR_BITS) >> PICOBIN_PARTITION_LOCATION_FIRST_SECTOR_LSB) * FLASH_SECTOR_SIZE;
66+
uint32_t end_addr = XIP_BASE + (((location_and_permissions & PICOBIN_PARTITION_LOCATION_LAST_SECTOR_BITS) >> PICOBIN_PARTITION_LOCATION_LAST_SECTOR_LSB) + 1) * FLASH_SECTOR_SIZE;
67+
printf("Start %08x, end %08x\n", start_addr, end_addr);
6768

6869
free(buffer);
6970

7071
printf("Writing binary\n");
71-
uint32_t tstart = time_us_32();
72-
uint32_t caddr = saddr;
73-
while (caddr < eaddr) {
72+
uint32_t time_start = time_us_32();
73+
uint32_t current_addr = start_addr;
74+
while (current_addr < end_addr) {
7475
uart_putc_raw(UART_ID, 'w');
75-
char *buf = (char*)caddr;
76+
char *buf = (char*)current_addr;
7677
for (int i=0; i < 32; i++) {
7778
uart_putc_raw(UART_ID, buf[i]);
7879
}
@@ -84,11 +85,12 @@ void uart_boot() {
8485
}
8586
char in = uart_getc(UART_ID);
8687
printf("%c\n", in);
87-
caddr += 32;
88+
assert(in == 'w');
89+
current_addr += 32;
8890
}
8991

90-
uint32_t tend = time_us_32();
91-
printf("Write took %dus\n", tend - tstart);
92+
uint32_t time_end = time_us_32();
93+
printf("Write took %dus\n", time_end - time_start);
9294
printf("Write complete - executing\n");
9395
uart_putc_raw(UART_ID, 'x');
9496
if (!uart_is_readable_within_us(UART_ID, 500)) {
@@ -99,6 +101,7 @@ void uart_boot() {
99101
}
100102
char in = uart_getc(UART_ID);
101103
printf("%c\n", in);
104+
assert(in == 'x');
102105
}
103106

104107

@@ -133,12 +136,12 @@ int main()
133136
if (i > 0) {
134137
printf(" ...Read done\n");
135138
}
136-
char *ptr = memchr(buf, 'R', sizeof(buf));
139+
char *ptr = memchr(buf, splash[0], sizeof(buf));
137140
if (ptr && strncmp(ptr, splash, sizeof(splash) - 1) == 0) {
138141
printf("Splash found\n");
139142
uart_boot();
140143
} else {
141-
ptr = memchr(buf, 'H', sizeof(buf));
144+
ptr = memchr(buf, hello[0], sizeof(buf));
142145
if (ptr && strncmp(ptr, hello, sizeof(hello) - 1) == 0) {
143146
printf("Device is running\n");
144147
} else {

0 commit comments

Comments
 (0)