Skip to content

Commit d083a6a

Browse files
committed
Makefile: Add NO_VIRTIO arg to skip patching DT
When running boot_initramfs, we might sometimes not care/want the virtio devices to be added to the DT (if we want to test a pure upstream configuration of kernel/DTB). boot.py adds these nodes to the DT automatically. Add a makefile arg to prevent this.
1 parent 11f7fd9 commit d083a6a

2 files changed

Lines changed: 49 additions & 43 deletions

File tree

‎Makefile‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ SHELL := /bin/bash
3939

4040
nproc := $(shell nproc)
4141

42+
ifeq ($(NO_VIRTIO), 1)
43+
DT_NO_VIRTIO_DEVICES := --dt_no_virtio_devices
44+
endif
45+
4246
# Uncomment this to make the shell rules verbose
4347
# SHELL_VERBOSE := set -x ;
4448

@@ -97,7 +101,7 @@ boot: _need_linux _need_opensbi _need_dtb _need_rootfs _need_hosttool _need_pyth
97101

98102
# Boot one L2CPU in Blackhole RISC-V CPU into an initramfs specified by $(INITRAMFS)
99103
boot_initramfs: _need_linux _need_opensbi _need_dtb _need_rootfs _need_hosttool _need_python _need_luwen _need_ttkmd _need_pylibfdt
100-
$(PYTHON) boot.py --boot --ttdevice $(TTDEVICE) --l2cpu $(L2CPU) --opensbi_bin fw_jump.bin --opensbi_dst 0x400030000000 --rootfs_dst 0x4000e5000000 --kernel_bin Image --kernel_dst 0x400030200000 --dtb_bin blackhole-card.dtb --dtb_dst 0x400030100000 --boot_device initramfs --rootfs_bin $(INITRAMFS)
104+
$(PYTHON) boot.py --boot --ttdevice $(TTDEVICE) --l2cpu $(L2CPU) --opensbi_bin fw_jump.bin --opensbi_dst 0x400030000000 --rootfs_dst 0x4000e5000000 --kernel_bin Image --kernel_dst 0x400030200000 --dtb_bin blackhole-card.dtb --dtb_dst 0x400030100000 --boot_device initramfs --rootfs_bin $(INITRAMFS) $(DT_NO_VIRTIO_DEVICES)
101105
./console/tt-bh-linux --ttdevice $(TTDEVICE) --l2cpu $(L2CPU) --disk $(DISK_IMAGE)
102106

103107
# boot_all: _need_linux _need_opensbi _need_dtb _need_dtb_all _need_rootfs _need_hosttool _need_python _need_luwen _need_ttkmd _need_pylibfdt

‎boot.py‎

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def parse_args():
3939

4040
# If using FW_PAYLOAD, set these args for rootfs and opensbi
4141
parser.add_argument("--boot_device", type=str, required=False, default="vda", help="Options: vda, vdaX or initramfs")
42+
parser.add_argument("--dt_no_virtio_devices", action="store_true", help="Don't patch DT to add virtio device nodes")
4243

4344
# Only used for initramfs
4445
parser.add_argument("--rootfs_bin", type=str, required=False, help="Path to initramfs")
@@ -149,48 +150,49 @@ def main():
149150
print("memory node not found in DT. Exiting")
150151
exit(1)
151152

152-
mem = fdt.getprop(memory_node, "reg")
153-
mem_start, mem_size = struct.unpack('>QQ', mem)
154-
mem_end = mem_start + mem_size
155-
156-
reserved_memory_offset = fdt.path_offset("/reserved-memory", libfdt.QUIET_NOTFOUND)
157-
if reserved_memory_offset < 0:
158-
reserved_memory_offset = fdt.add_subnode(0, "reserved-memory")
159-
fdt.setprop_u32(reserved_memory_offset, "#address-cells", 2)
160-
fdt.setprop_u32(reserved_memory_offset, "#size-cells", 2)
161-
fdt.setprop(reserved_memory_offset, "ranges", b'')
162-
163-
virtio_reserved_offset = fdt.add_subnode(reserved_memory_offset, "memory@4000afa00000")
164-
reserved_reg = struct.pack('>QQ', mem_end - 0x600000, 0x600000)
165-
fdt.setprop(virtio_reserved_offset, "reg", reserved_reg)
166-
fdt.setprop(virtio_reserved_offset, "no-map", b'')
167-
168-
soc_offset = fdt.path_offset("/soc", libfdt.QUIET_NOTFOUND)
169-
if soc_offset < 0:
170-
print("soc node not found in DT. Exiting")
171-
exit(1)
172-
173-
plic_offset = fdt.path_offset("/soc/interrupt-controller@c000000", libfdt.QUIET_NOTFOUND)
174-
if plic_offset < 0:
175-
print("plic node not found in DT. Exiting")
176-
exit(1)
177-
178-
plic_phandle = fdt.get_phandle(plic_offset)
179-
if plic_phandle == 0:
180-
# PLIC node doesn't have a phandle, create a unique one
181-
plic_phandle = libfdt.fdt_get_max_phandle(fdt._fdt) + 1
182-
fdt.setprop_u32(plic_offset, "phandle", plic_phandle)
183-
184-
for i in range(3, -1, -1):
185-
virtio_addr = mem_end - 0x200000 * (i + 1)
186-
virtio_irq = 33 - i
187-
188-
virtio_offset = fdt.add_subnode(soc_offset, f"virtio@{virtio_addr:x}")
189-
fdt.setprop_str(virtio_offset, "compatible", "virtio,mmio")
190-
virtio_reg = struct.pack('>QQ', virtio_addr, 0x200000)
191-
fdt.setprop(virtio_offset, "reg", virtio_reg)
192-
fdt.setprop_u32(virtio_offset, "interrupts", virtio_irq)
193-
fdt.setprop_u32(virtio_offset, "interrupt-parent", plic_phandle)
153+
if not args.dt_no_virtio_devices:
154+
mem = fdt.getprop(memory_node, "reg")
155+
mem_start, mem_size = struct.unpack('>QQ', mem)
156+
mem_end = mem_start + mem_size
157+
158+
reserved_memory_offset = fdt.path_offset("/reserved-memory", libfdt.QUIET_NOTFOUND)
159+
if reserved_memory_offset < 0:
160+
reserved_memory_offset = fdt.add_subnode(0, "reserved-memory")
161+
fdt.setprop_u32(reserved_memory_offset, "#address-cells", 2)
162+
fdt.setprop_u32(reserved_memory_offset, "#size-cells", 2)
163+
fdt.setprop(reserved_memory_offset, "ranges", b'')
164+
165+
virtio_reserved_offset = fdt.add_subnode(reserved_memory_offset, "memory@4000afa00000")
166+
reserved_reg = struct.pack('>QQ', mem_end - 0x600000, 0x600000)
167+
fdt.setprop(virtio_reserved_offset, "reg", reserved_reg)
168+
fdt.setprop(virtio_reserved_offset, "no-map", b'')
169+
170+
soc_offset = fdt.path_offset("/soc", libfdt.QUIET_NOTFOUND)
171+
if soc_offset < 0:
172+
print("soc node not found in DT. Exiting")
173+
exit(1)
174+
175+
plic_offset = fdt.path_offset("/soc/interrupt-controller@c000000", libfdt.QUIET_NOTFOUND)
176+
if plic_offset < 0:
177+
print("plic node not found in DT. Exiting")
178+
exit(1)
179+
180+
plic_phandle = fdt.get_phandle(plic_offset)
181+
if plic_phandle == 0:
182+
# PLIC node doesn't have a phandle, create a unique one
183+
plic_phandle = libfdt.fdt_get_max_phandle(fdt._fdt) + 1
184+
fdt.setprop_u32(plic_offset, "phandle", plic_phandle)
185+
186+
for i in range(3, -1, -1):
187+
virtio_addr = mem_end - 0x200000 * (i + 1)
188+
virtio_irq = 33 - i
189+
190+
virtio_offset = fdt.add_subnode(soc_offset, f"virtio@{virtio_addr:x}")
191+
fdt.setprop_str(virtio_offset, "compatible", "virtio,mmio")
192+
virtio_reg = struct.pack('>QQ', virtio_addr, 0x200000)
193+
fdt.setprop(virtio_offset, "reg", virtio_reg)
194+
fdt.setprop_u32(virtio_offset, "interrupts", virtio_irq)
195+
fdt.setprop_u32(virtio_offset, "interrupt-parent", plic_phandle)
194196

195197
fdt.pack()
196198
dtb_bytes = fdt._fdt

0 commit comments

Comments
 (0)