Skip to content

Commit 5815f23

Browse files
committed
feat: add network boot guide
- With network boot, we can load rootfs more easily So we can debug more easily, painless
1 parent 3e8dc19 commit 5815f23

File tree

4 files changed

+69
-7
lines changed

4 files changed

+69
-7
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
*.fd
44
*.efi
55
*.EFI
6+
*.gz
7+
*vmlin*
8+
*initrd*
9+
Image*
610

711
boot.scr
812
dtb
9-
Image
1013

1114
/test
1215
/rootfs

Makefile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,23 @@ uboot-efi:
7979
-device virtio-blk-device,drive=hd0 \
8080
$(EXTRA_ARG)
8181

82+
tftp:
83+
qemu-system-aarch64 -m 4096 -smp 2 -cpu cortex-a57 -M virt -nographic \
84+
-bios u-boot.bin \
85+
-device virtio-net,netdev=net0 -netdev user,id=net0,tftp=./,net=192.168.1.0/24,hostfwd=tcp::8080-:80 \
86+
-device virtio-net,netdev=net1 -netdev user,id=net1,net=100.0.0.0/24
87+
88+
tftp-env:
89+
qemu-system-aarch64 -m 4096 -smp 2 -cpu cortex-a57 -M virt -nographic \
90+
-bios u-boot.bin \
91+
-device loader,file=u-boot/boot.scr,addr=0x40200000 \
92+
-drive file=fat:rw:u-boot \
93+
-device virtio-net,netdev=net0 -netdev user,id=net0,tftp=./,net=192.168.1.0/24,hostfwd=tcp::8080-:80 \
94+
-device virtio-net,netdev=net1 -netdev user,id=net1,net=100.0.0.0/24
95+
8296
parted-list:
8397
parted $(ARGS) unit MiB print
8498

85-
boot.src:
99+
boot.scr:
86100
mkimage -A arm64 -O linux -T script -C none \
87101
-d u-boot/boot.txt u-boot/boot.scr

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pkill -f qemu-system-aarch64
3131
openwrt-24.10.5-armsr-armv8-generic-kernel.bin
3232
openwrt-24.10.5-armsr-armv8-generic-squashfs-combined-efi.img
3333
openwrt-24.10.5-armsr-armv8-generic-squashfs-rootfs.img
34+
openwrt-24.10.5-armsr-armv8-rootfs.cpio.gz
3435
u-boot.bin
3536
```
3637

@@ -51,7 +52,7 @@ pkill -f qemu-system-aarch64
5152
make uefi-shell
5253
```
5354

54-
- U-Boot boot.src (as a disk partition)
55+
- U-Boot `boot.scr` (as a disk partition)
5556

5657
```sh
5758
mkdir -p u-boot/boot
@@ -64,12 +65,10 @@ pkill -f qemu-system-aarch64
6465
fatload virtio 1 ${kernel_addr_r} /boot/Image
6566
setenv bootargs root=fe00
6667
booti ${kernel_addr_r} - ${fdtcontroladdr}
67-
68-
echo "Boot failed!"
6968
```
7069

7170
```sh
72-
make boot.src
71+
make boot.scr
7372
make uboot-env
7473

7574
# enter u-boot
@@ -81,9 +80,16 @@ pkill -f qemu-system-aarch64
8180
CONFIG_BOOTCOMMAND="source ${scriptaddr}"
8281
```
8382

83+
### Network Boot
84+
85+
- [Network Boot](network-boot.md)
86+
8487
### Guide
8588

86-
https://openwrt.org/docs/guide-user/virtualization/qemu
89+
- https://openwrt.org/docs/guide-user/virtualization/qemu
90+
- https://linuxkernel.org.cn/doc/html/latest/admin-guide/nfs/nfsroot.html
91+
- https://linuxkernel.org.cn/doc/html/latest/filesystems/ramfs-rootfs-initramfs.html
92+
- https://linuxkernel.org.cn/doc/html/latest/admin-guide/initrd.html
8793

8894
### License
8995

network-boot.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
## Network Boot
2+
3+
### Prepare
4+
5+
Rebuild the [kernel](https://github.com/initdc/openwrt-qemu/releases) which should support `/dev/ram0`
6+
7+
```sh
8+
CONFIG_BLK_DEV_RAM=y
9+
CONFIG_BLK_DEV_RAM_COUNT=16
10+
CONFIG_BLK_DEV_RAM_SIZE=4096 # change size as you need
11+
```
12+
13+
```sh
14+
export ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
15+
16+
make defconfig
17+
make menuconfig
18+
make Image -j$(nproc)
19+
20+
file arch/arm64/boot/Image
21+
Image: Linux kernel ARM64 boot executable Image, little-endian, 4K pages
22+
```
23+
24+
### Run and test
25+
26+
then `make tftp`
27+
28+
```sh
29+
# enter u-boot
30+
dhcp
31+
32+
tftp ${kernel_addr_r} Image
33+
tftp ${ramdisk_addr_r} openwrt-24.10.5-armsr-armv8-rootfs.cpio.gz
34+
35+
setenv bootargs root=/dev/ram0
36+
booti ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdtcontroladdr}
37+
```
38+
39+
you can compile it as `boot.scr`, then `make tftp-env`

0 commit comments

Comments
 (0)