Repository navigation
14 raspi image
Language: English | 中文
Goal: pack the whole system into an SD card and boot it on a real Raspberry Pi. Includes: an inventory of build artifacts, the SD card partition layout, config.txt, flashing steps, and watching over serial.
Recall the boot conventions from Ch. 03. The SD card must have this layout:
SD card
├── Partition 1 (FAT32, label bootfs) ← the GPU firmware only understands FAT32
│ ├── bootcode.bin / start.elf / fixup.dat GPU firmware
│ ├── bcm2710-rpi-3-b.dtb etc. device trees (per model)
│ ├── config.txt boot configuration
│ └── kernel8.img ★ our kernel
│
└── Partition 2 (ext3, label rootfs)
└── the complete root filesystem (/bin /sbin /etc /drivers ...)
The GPU firmware (bootcode.bin etc.) and the config.txt templates for
all boards are in tools/bootfs/raspix/, ready
to use out of the box.
The key contents of config.txt
(config.txt):
[all]
arm_64bit=1 # 64-bit boot (loads kernel8.img)
enable_uart=1 # enable the UART (essential for watching boot logs)
force_turbo=1
[pi3]
core_freq=250 # fixed GPU clock → stable Mini UART baud rate
...> cd hardwares/raspix/system
> make # produces ../kernel/kernel8.img and the rootfs
> make sd # packs the rootfs into root_aarch64.img (a 512MB ext3 image)Where the artifacts live:
| File | Description |
|---|---|
hardwares/raspix/kernel/kernel8.img |
the kernel (goes to partition 1) |
hardwares/raspix/system/root_aarch64.img |
the root filesystem image (written to partition 2) |
Important pitfall: building a single driver/app directory only updates the files under
system/build/aarch64/raspix/rootfs/— it does not updateroot_aarch64.img. You must re-runmake sdbefore flashing, or you'll be flashing the old system. When in doubt, compare timestamps:ls -l root_aarch64.imgshould be newer than the binaries you just compiled.
The repo provides a one-shot partitioning script
tools/makesd.sh. What it does: unmount all
partitions → create an MBR partition table → format partition 1 as FAT32
(label bootfs) → format partition 2 with mke2fs -t ext3 -b 4096 -I 128.
# First confirm the SD card's device number (be very sure — don't pick your hard drive!)
> diskutil list
> sudo tools/makesd.sh /dev/disk4Then:
# 1. Write the firmware and kernel into partition 1 (FAT32; macOS mounts it directly)
> cp tools/bootfs/raspix/* /Volumes/bootfs/
> cp hardwares/raspix/kernel/kernel8.img /Volumes/bootfs/
> diskutil unmountDisk /dev/disk4Note: macOS cannot mount ext3, so partition 2's content must be written in a Linux environment (or a Linux VM/QEMU). Two ways:
# Method A (recommended, on Linux): dd the image straight into partition 2
> sudo dd if=systems/raspix/root_aarch64.img of=/dev/sdX2 bs=1M
> sudo e2fsck -f /dev/sdX2 # verify
# Method B (on Linux): copy in with e2cp
> sudo e2cp -rap rootfs-dir/* /dev/sdX2:/Don't "find a way" to mount ext3 on macOS to copy files — third-party drivers will corrupt permissions, symlinks, and device nodes.
> lsblk # confirm the device, e.g. /dev/sdX
> if sudo tools/makesd.sh is unavailable, partition manually:
> sudo parted /dev/sdX mklabel msdos
> sudo parted /dev/sdX mkpart primary fat32 4MiB 132MiB
> sudo parted /dev/sdX mkpart primary ext3 132MiB 100%
> sudo mkfs.vfat -F 32 -n bootfs /dev/sdX1
> sudo dd if=.../root_aarch64.img of=/dev/sdX2 bs=1M
> sudo mount /dev/sdX1 /mnt/boot
> sudo cp tools/bootfs/raspix/* hardwares/raspix/kernel/kernel8.img /mnt/boot/Strongly recommended: use a USB-to-TTL serial cable to watch the boot process (it also serves as the interactive terminal):
USB-TTL cable Pi 40-pin header
─────────────────────────────────────
GND (black) ──────────► Pin 6 (GND)
RXD (white) ──────────► Pin 8 (GPIO14 TXD)
TXD (green) ──────────► Pin 10 (GPIO15 RXD)
Cross-connect: the cable's RX goes to the Pi's TX, the cable's TX to the Pi's RX. Wire it up before powering on.
Open a serial terminal on your computer:
# macOS
> screen /dev/tty.usbserial-XXXX 115200 # Ctrl-A K to exit
# Linux
> minicom -D /dev/ttyUSB0 -b 115200Insert the SD card, connect the cable, power on. A few seconds later the familiar text appears in the serial console:
=== ewokos booting ===
kernel: init kernel malloc ... [OK]
...
-----------------------------------------------------
______ ______ _ _ ...
Then init starts the services, and finally the prompt appears — this is your own operating system, running on real hardware.
If there's no graphics output, don't panic: first confirm over serial that
the system is fine, then check the HDMI/display and the display settings in
config.txt.
Experience from practice:
-
Hardware QEMU can't emulate can only be tested on real machines: the
Pi's SDIO/WiFi (
wland) and similar hardware are not emulated by QEMU, so related changes can only be verified by flashing a card; - Flash a fresh image after every change: see the pitfall note in §14.2;
- There's no GDB on a real machine; the serial log is the primary scene —
build the habit of adding
klog/slogon suspicious paths (Ch. 15); - Model differences: Pi2/3's MMIO base is
0x3F000000, Pi4's is0xFE000000— that's why start.c branches on the CPU model when mapping the page tables.
- Walk the whole path once: build → flash → serial boot; screenshot your first real-hardware boot;
- Change
enable_uart=0inconfig.txt, observe what happens, then change it back; - Run the
hellocommand you wrote in Ch. 12 on the real machine.
- The SD card has two partitions: FAT32 bootfs (firmware + config.txt + kernel) + ext3 rootfs;
-
make sdproduces the root filesystem image; after changing the system you must repack; - macOS handles partitioning and the bootfs; writing the ext3 rootfs must happen in a Linux environment;
- The serial cable is the lifeline of real-machine development.
Next chapter: systematic debugging methods and the roadmap ahead — the course's final chapter.
EwokOS OS Tutorial / EwokOS 操作系统教学
Part 1: Getting Started / 第 1 部分:起步
Part 2: The Kernel / 第 2 部分:内核
Part 3: Userland / 第 3 部分:用户态
Part 4: The Full System / 第 4 部分:完整系统
Part 5: The ewokos Series (Libraries) / 第 5 部分:ewokos 系列(库生态)
Part 6: GPU & Compute / 第 6 部分:GPU 与计算
Appendix / 附录