Skip to content

Commit c314793

Browse files
committed
Default to externally powered RPis
Addresses issues in #86
1 parent dad68ab commit c314793

File tree

19 files changed

+269
-237
lines changed

19 files changed

+269
-237
lines changed

Diff for: 06_drivers_gpio_uart/README.md

+11-16
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,23 @@ init_uart_clock=48000000
4949
- [bootcode.bin](https://github.com/raspberrypi/firmware/raw/master/boot/bootcode.bin)
5050
- [fixup.dat](https://github.com/raspberrypi/firmware/raw/master/boot/fixup.dat)
5151
- [start.elf](https://github.com/raspberrypi/firmware/raw/master/boot/start.elf)
52-
4. Run `make` and copy the [kernel8.img](kernel8.img) onto the SD card.
52+
4. Run `make`.
5353

5454
### Pi 4
5555

5656
3. Copy the following files from the [Raspberry Pi firmware repo](https://github.com/raspberrypi/firmware/tree/master/boot) onto the SD card:
5757
- [fixup4.dat](https://github.com/raspberrypi/firmware/raw/master/boot/fixup4.dat)
5858
- [start4.elf](https://github.com/raspberrypi/firmware/raw/master/boot/start4.elf)
5959
- [bcm2711-rpi-4-b.dtb](https://github.com/raspberrypi/firmware/raw/master/boot/bcm2711-rpi-4-b.dtb)
60-
4. Run `BSP=rpi4 make` and copy the [kernel8.img](kernel8.img) onto the SD card.
60+
4. Run `BSP=rpi4 make`.
61+
6162

6263
_**Note**: Should it not work on your RPi4, try renaming `start4.elf` to `start.elf` (without the 4)
6364
on the SD card._
6465

6566
### Common again
6667

67-
5. Insert the SD card into the RPi and connect the USB serial to your host PC.
68-
- Wiring diagram at [top-level README](../README.md#usb-serial).
68+
5. Copy the [kernel8.img](kernel8.img) onto the SD card and insert it back into the RPi.
6969
6. Run the `miniterm` target, which opens the UART device on the host:
7070

7171
```console
@@ -81,14 +81,16 @@ $ make miniterm
8181
$ DEV_SERIAL=/dev/tty.usbserial-0001 make miniterm
8282
```
8383

84-
7. Hit <kbd>Enter</kbd> after seeing "`Connected`" to kick off the kernel boot process and observe
85-
the output:
84+
7. Connect the USB serial to your host PC.
85+
- Wiring diagram at [top-level README](../README.md#usb-serial-output).
86+
- Make sure that you **DID NOT** connect the power pin of the USB serial. Only RX/TX and GND.
87+
8. Connect the RPi to the (USB) power cable and observe the output:
8688

8789
```console
8890
Miniterm 1.0
8991

90-
91-
[MT] ✅ Connected
92+
[MT] ⏳ Waiting for /dev/ttyUSB0
93+
[MT] ✅ Serial connected
9294
[0] Booting on: Raspberry Pi 3
9395
[1] Drivers loaded:
9496
1. BCM GPIO
@@ -1212,7 +1214,7 @@ diff -uNr 05_safe_globals/src/main.rs 06_drivers_gpio_uart/src/main.rs
12121214
mod memory;
12131215
mod panic_wait;
12141216
mod print;
1215-
@@ -116,16 +126,53 @@
1217+
@@ -116,16 +126,46 @@
12161218
/// # Safety
12171219
///
12181220
/// - Only a single core must be active and running this function.
@@ -1239,13 +1241,6 @@ diff -uNr 05_safe_globals/src/main.rs 06_drivers_gpio_uart/src/main.rs
12391241
+ use console::interface::All;
12401242
+ use driver::interface::DriverManager;
12411243
+
1242-
+ // Wait for user to hit Enter.
1243-
+ loop {
1244-
+ if bsp::console::console().read_char() == '\n' {
1245-
+ break;
1246-
+ }
1247-
+ }
1248-
+
12491244
+ println!("[0] Booting on: {}", bsp::board_name());
12501245
+
12511246
+ println!("[1] Drivers loaded:");

Diff for: 06_drivers_gpio_uart/src/main.rs

-7
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,6 @@ fn kernel_main() -> ! {
147147
use console::interface::All;
148148
use driver::interface::DriverManager;
149149

150-
// Wait for user to hit Enter.
151-
loop {
152-
if bsp::console::console().read_char() == '\n' {
153-
break;
154-
}
155-
}
156-
157150
println!("[0] Booting on: {}", bsp::board_name());
158151

159152
println!("[1] Drivers loaded:");

Diff for: 07_uart_chainloader/README.md

+49-36
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ Our chainloader is called `MiniLoad` and is inspired by [raspbootin].
2525

2626
You can try it with this tutorial already:
2727
1. Depending on your target hardware:`make` or `BSP=rpi4 make`.
28-
2. Copy `kernel8.img` to the SD card.
29-
3. Execute `make chainboot` or `BSP=rpi4 make chainboot`.
30-
4. Now plug in the USB Serial.
31-
5. Observe the loader fetching a kernel over `UART`:
28+
1. Copy `kernel8.img` to the SD card.
29+
1. Execute `make chainboot` or `BSP=rpi4 make chainboot`.
30+
1. Connect the USB serial to your host PC.
31+
- Wiring diagram at [top-level README](../README.md#usb-serial-output).
32+
- Make sure that you **DID NOT** connect the power pin of the USB serial. Only RX/TX and GND.
33+
1. Connect the RPi to the (USB) power cable.
34+
1. Observe the loader fetching a kernel over `UART`:
3235

3336
> **NOTE**: By default, `make chainboot` tries to connect to `/dev/ttyUSB0`.
3437
> Should the USB serial on your system have a different name, you have to provide it explicitly. For
@@ -44,7 +47,8 @@ $ make chainboot
4447
Minipush 1.0
4548

4649
[MP] ⏳ Waiting for /dev/ttyUSB0
47-
[MP] ✅ Connected
50+
[MP] ✅ Serial connected
51+
[MP] 🔌 Please power the target now
4852
__ __ _ _ _ _
4953
| \/ (_)_ _ (_) | ___ __ _ __| |
5054
| |\/| | | ' \| | |__/ _ \/ _` / _` |
@@ -53,7 +57,7 @@ Minipush 1.0
5357
Raspberry Pi 3
5458

5559
[ML] Requesting binary
56-
[MP] ⏩ Pushing 7 KiB ==========================================🦀 100% 0 KiB/s Time: 00:00:00
60+
[MP] ⏩ Pushing 6 KiB ==========================================🦀 100% 0 KiB/s Time: 00:00:00
5761
[ML] Loaded! Executing the payload now
5862

5963
[0] Booting on: Raspberry Pi 3
@@ -429,18 +433,23 @@ diff -uNr 06_drivers_gpio_uart/src/main.rs 07_uart_chainloader/src/main.rs
429433
mod runtime_init;
430434
mod synchronization;
431435

432-
@@ -144,35 +148,52 @@
436+
@@ -144,28 +148,52 @@
433437

434438
/// The main function running after the early init.
435439
fn kernel_main() -> ! {
436440
+ use bsp::console::console;
437441
use console::interface::All;
438442
- use driver::interface::DriverManager;
443+
-
444+
- println!("[0] Booting on: {}", bsp::board_name());
439445

440-
- // Wait for user to hit Enter.
441-
- loop {
442-
- if bsp::console::console().read_char() == '\n' {
443-
- break;
446+
- println!("[1] Drivers loaded:");
447+
- for (i, driver) in bsp::driver::driver_manager()
448+
- .all_device_drivers()
449+
- .iter()
450+
- .enumerate()
451+
- {
452+
- println!(" {}. {}", i + 1, driver.compatible());
444453
+ println!(" __ __ _ _ _ _ ");
445454
+ println!("| \\/ (_)_ _ (_) | ___ __ _ __| |");
446455
+ println!("| |\\/| | | ' \\| | |__/ _ \\/ _` / _` |");
@@ -458,8 +467,17 @@ diff -uNr 06_drivers_gpio_uart/src/main.rs 07_uart_chainloader/src/main.rs
458467
+ // Notify `Minipush` to send the binary.
459468
+ for _ in 0..3 {
460469
+ console().write_char(3 as char);
461-
+ }
462-
+
470+
}
471+
472+
- println!(
473+
- "[2] Chars written: {}",
474+
- bsp::console::console().chars_written()
475+
- );
476+
- println!("[3] Echoing input now");
477+
-
478+
- loop {
479+
- let c = bsp::console::console().read_char();
480+
- bsp::console::console().write_char(c);
463481
+ // Read the binary's size.
464482
+ let mut size: u32 = u32::from(console().read_char() as u8);
465483
+ size |= u32::from(console().read_char() as u8) << 8;
@@ -475,34 +493,15 @@ diff -uNr 06_drivers_gpio_uart/src/main.rs 07_uart_chainloader/src/main.rs
475493
+ // Read the kernel byte by byte.
476494
+ for i in 0..size {
477495
+ core::ptr::write_volatile(kernel_addr.offset(i as isize), console().read_char() as u8)
478-
}
496+
+ }
479497
}
480-
481-
- println!("[0] Booting on: {}", bsp::board_name());
498+
+
482499
+ println!("[ML] Loaded! Executing the payload now\n");
483500
+ console().flush();
484-
485-
- println!("[1] Drivers loaded:");
486-
- for (i, driver) in bsp::driver::driver_manager()
487-
- .all_device_drivers()
488-
- .iter()
489-
- .enumerate()
490-
- {
491-
- println!(" {}. {}", i + 1, driver.compatible());
492-
- }
501+
+
493502
+ // Use black magic to get a function pointer.
494503
+ let kernel: fn() -> ! = unsafe { core::mem::transmute(kernel_addr) };
495-
496-
- println!(
497-
- "[2] Chars written: {}",
498-
- bsp::console::console().chars_written()
499-
- );
500-
- println!("[3] Echoing input now");
501-
-
502-
- loop {
503-
- let c = bsp::console::console().read_char();
504-
- bsp::console::console().write_char(c);
505-
- }
504+
+
506505
+ // Jump to loaded kernel!
507506
+ kernel()
508507
}
@@ -583,4 +582,18 @@ diff -uNr 06_drivers_gpio_uart/src/runtime_init.rs 07_uart_chainloader/src/runti
583582
pub unsafe fn runtime_init() -> ! {
584583
zero_bss();
585584

585+
586+
diff -uNr 06_drivers_gpio_uart/update.sh 07_uart_chainloader/update.sh
587+
--- 06_drivers_gpio_uart/update.sh
588+
+++ 07_uart_chainloader/update.sh
589+
@@ -0,0 +1,8 @@
590+
+#!/usr/bin/env bash
591+
+
592+
+cd ../06_drivers_gpio_uart
593+
+BSP=rpi4 make
594+
+cp kernel8.img ../07_uart_chainloader/demo_payload_rpi4.img
595+
+make
596+
+cp kernel8.img ../07_uart_chainloader/demo_payload_rpi3.img
597+
+rm kernel8.img
598+
586599
```

Diff for: 07_uart_chainloader/demo_payload_rpi3.img

-672 Bytes
Binary file not shown.

Diff for: 07_uart_chainloader/demo_payload_rpi4.img

-648 Bytes
Binary file not shown.

Diff for: 07_uart_chainloader/update.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
cd ../06_drivers_gpio_uart
4+
BSP=rpi4 make
5+
cp kernel8.img ../07_uart_chainloader/demo_payload_rpi4.img
6+
make
7+
cp kernel8.img ../07_uart_chainloader/demo_payload_rpi3.img
8+
rm kernel8.img

Diff for: 08_timestamps/README.md

+25-12
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ $ make chainboot
1515
Minipush 1.0
1616

1717
[MP] ⏳ Waiting for /dev/ttyUSB0
18-
[MP] ✅ Connected
18+
[MP] ✅ Serial connected
19+
[MP] 🔌 Please power the target now
1920
__ __ _ _ _ _
2021
| \/ (_)_ _ (_) | ___ __ _ __| |
2122
| |\/| | | ' \| | |__/ _ \/ _` / _` |
@@ -24,19 +25,18 @@ Minipush 1.0
2425
Raspberry Pi 3
2526

2627
[ML] Requesting binary
27-
[MP] ⏩ Pushing 12 KiB =========================================🦀 100% 0 KiB/s Time: 00:00:00
28+
[MP] ⏩ Pushing 11 KiB =========================================🦀 100% 0 KiB/s Time: 00:00:00
2829
[ML] Loaded! Executing the payload now
2930

30-
[ 0.586140] Booting on: Raspberry Pi 3
31-
[ 0.587227] Architectural timer resolution: 52 ns
32-
[ 0.589530] Drivers loaded:
33-
[ 0.590876] 1. BCM GPIO
34-
[ 0.592309] 2. BCM PL011 UART
35-
[W 0.594005] Spin duration smaller than architecturally supported, skipping
36-
[ 0.597392] Spinning for 1 second
37-
[ 1.599001] Spinning for 1 second
38-
[ 2.599872] Spinning for 1 second
39-
31+
[ 0.543941] Booting on: Raspberry Pi 3
32+
[ 0.545059] Architectural timer resolution: 52 ns
33+
[ 0.547358] Drivers loaded:
34+
[ 0.548703] 1. BCM GPIO
35+
[ 0.550135] 2. BCM PL011 UART
36+
[W 0.551828] Spin duration smaller than architecturally supported, skipping
37+
[ 0.555212] Spinning for 1 second
38+
[ 1.556818] Spinning for 1 second
39+
[ 2.557690] Spinning for 1 second
4040
```
4141

4242
## Diff to previous
@@ -754,4 +754,17 @@ diff -uNr 07_uart_chainloader/src/time.rs 08_timestamps/src/time.rs
754754
+ }
755755
+}
756756

757+
diff -uNr 07_uart_chainloader/update.sh 08_timestamps/update.sh
758+
--- 07_uart_chainloader/update.sh
759+
+++ 08_timestamps/update.sh
760+
@@ -1,8 +0,0 @@
761+
-#!/usr/bin/env bash
762+
-
763+
-cd ../06_drivers_gpio_uart
764+
-BSP=rpi4 make
765+
-cp kernel8.img ../07_uart_chainloader/demo_payload_rpi4.img
766+
-make
767+
-cp kernel8.img ../07_uart_chainloader/demo_payload_rpi3.img
768+
-rm kernel8.img
769+
757770
```

Diff for: 09_hw_debug_JTAG/README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ $ make jtagboot
157157
Minipush 1.0
158158

159159
[MP] ⏳ Waiting for /dev/ttyUSB0
160-
[MP] ✅ Connected
160+
[MP] ✅ Serial connected
161+
[MP] 🔌 Please power the target now
161162
__ __ _ _ _ _
162163
| \/ (_)_ _ (_) | ___ __ _ __| |
163164
| |\/| | | ' \| | |__/ _ \/ _` / _` |
@@ -166,10 +167,10 @@ Minipush 1.0
166167
Raspberry Pi 3
167168

168169
[ML] Requesting binary
169-
[MP] ⏩ Pushing 8 KiB ==========================================🦀 100% 0 KiB/s Time: 00:00:00
170+
[MP] ⏩ Pushing 7 KiB ==========================================🦀 100% 0 KiB/s Time: 00:00:00
170171
[ML] Loaded! Executing the payload now
171172

172-
[ 0.372110] Parking CPU core. Please connect over JTAG now.
173+
[ 0.394532] Parking CPU core. Please connect over JTAG now.
173174
```
174175

175176
It is important to keep the USB serial connected and the terminal with the `jtagboot` open and

Diff for: 10_privilege_level/README.md

+16-15
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ $ make chainboot
192192
Minipush 1.0
193193

194194
[MP] ⏳ Waiting for /dev/ttyUSB0
195-
[MP] ✅ Connected
195+
[MP] ✅ Serial connected
196+
[MP] 🔌 Please power the target now
196197
__ __ _ _ _ _
197198
| \/ (_)_ _ (_) | ___ __ _ __| |
198199
| |\/| | | ' \| | |__/ _ \/ _` / _` |
@@ -201,22 +202,22 @@ Minipush 1.0
201202
Raspberry Pi 3
202203

203204
[ML] Requesting binary
204-
[MP] ⏩ Pushing 15 KiB =========================================🦀 100% 0 KiB/s Time: 00:00:00
205+
[MP] ⏩ Pushing 13 KiB =========================================🦀 100% 0 KiB/s Time: 00:00:00
205206
[ML] Loaded! Executing the payload now
206207

207-
[ 0.703812] Booting on: Raspberry Pi 3
208-
[ 0.704900] Current privilege level: EL1
209-
[ 0.706811] Exception handling state:
210-
[ 0.708592] Debug: Masked
211-
[ 0.710156] SError: Masked
212-
[ 0.711719] IRQ: Masked
213-
[ 0.713283] FIQ: Masked
214-
[ 0.714848] Architectural timer resolution: 52 ns
215-
[ 0.717149] Drivers loaded:
216-
[ 0.718496] 1. BCM GPIO
217-
[ 0.719929] 2. BCM PL011 UART
218-
[ 0.721623] Timer test, spinning for 1 second
219-
[ 1.723753] Echoing input now
208+
[ 0.637617] Booting on: Raspberry Pi 3
209+
[ 0.638737] Current privilege level: EL1
210+
[ 0.640645] Exception handling state:
211+
[ 0.642424] Debug: Masked
212+
[ 0.643986] SError: Masked
213+
[ 0.645548] IRQ: Masked
214+
[ 0.647110] FIQ: Masked
215+
[ 0.648672] Architectural timer resolution: 52 ns
216+
[ 0.650971] Drivers loaded:
217+
[ 0.652316] 1. BCM GPIO
218+
[ 0.653748] 2. BCM PL011 UART
219+
[ 0.655440] Timer test, spinning for 1 second
220+
[ 1.657567] Echoing input now
220221
```
221222

222223
## Diff to previous

0 commit comments

Comments
 (0)