Skip to content

Commit 0fecdab

Browse files
committed
Disable XIP, use cramfs, other kernel changes
1 parent 46399d7 commit 0fecdab

File tree

15 files changed

+253
-308
lines changed

15 files changed

+253
-308
lines changed

.github/.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ RUN SNIPPET="export PROMPT_COMMAND='history -a' && export HISTFILE=/commandhisto
4141

4242
# buildroot dependencies
4343
RUN apt-get update \
44-
&& apt-get install -y --no-install-recommends cpio bc \
44+
&& apt-get install -y --no-install-recommends cpio bc device-tree-compiler \
4545
&& rm -rf /var/lib/apt/lists/*
4646

4747
# avoid permission issues with cargo if cargo install runs as root

.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,9 @@
2525
"python.analysis.diagnosticMode": "workspace",
2626
"python.analysis.packageIndexDepths": [{ "name": "jinja2", "depth": 2 }],
2727
"files.eol": "\n",
28-
"yaml.customTags": ["tag:yaml.org,2002:python/object/apply:builtins.range sequence"]
28+
"yaml.customTags": [
29+
"tag:yaml.org,2002:python/object/apply:builtins.range sequence",
30+
"tag:yaml.org,2002:python/object/apply:builtins.sum sequence"
31+
],
32+
"git.detectSubmodules": false
2933
}

linux/Makefile

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
MAKEFLAGS += --no-builtin-rules
2-
.SUFFIXES:
3-
41
THIS_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
52

63
BR2_EXTERNAL_SRC := $(THIS_DIR)/buildroot
@@ -18,18 +15,44 @@ MAKE_BUILDROOT = $(MAKE) -C $(BUILDROOT) BR2_EXTERNAL=$(BR2_EXTERNAL)
1815
setup-buildroot:
1916
curl --location "$(BUILDROOT_RELEASE)" | tar xzv --directory $(BUILDROOT)
2017

18+
.PHONY: everything
19+
everything: load-configs dtbs all zsbl get-images
20+
21+
.PHONY: dtbs-rebuild
22+
dtbs-rebuild: dtbs opensbi-rebuild zsbl get-images
23+
24+
.PHONY: load-configs
25+
load-configs: mlogv32_defconfig
26+
2127
.PHONY: get-images
2228
get-images:
2329
rm -rf $(THIS_DIR)/output
2430

2531
mkdir -p $(THIS_DIR)/output/images
2632
cp -r $(BUILDROOT)/output/images $(THIS_DIR)/output
27-
-riscv32-unknown-linux-gnu-objdump -d $(THIS_DIR)/output/images/fw_jump.elf > $(THIS_DIR)/output/images/fw_jump.dump
28-
-riscv32-unknown-linux-gnu-objdump -d $(THIS_DIR)/output/images/zsbl.elf > $(THIS_DIR)/output/images/zsbl.dump
2933

3034
mkdir -p $(THIS_DIR)/output/build
3135
cp $(BUILDROOT)/output/build/linux-*/vmlinux $(THIS_DIR)/output/build
32-
-riscv32-unknown-linux-gnu-objdump -d $(THIS_DIR)/output/build/vmlinux > $(THIS_DIR)/output/build/vmlinux.dump
36+
37+
.PHONY: dump-images
38+
dump-images:
39+
-riscv32-unknown-linux-gnu-objdump \
40+
--wide \
41+
--disassemble \
42+
$(THIS_DIR)/output/images/fw_jump.elf > $(THIS_DIR)/output/images/fw_jump.dump
43+
44+
-riscv32-unknown-linux-gnu-objdump \
45+
--wide \
46+
--disassemble \
47+
--show-all-symbols \
48+
--section .text \
49+
--section .loader \
50+
$(THIS_DIR)/output/images/zsbl.elf > $(THIS_DIR)/output/images/zsbl.dump
51+
52+
-riscv32-unknown-linux-gnu-objdump \
53+
--wide \
54+
--disassemble \
55+
$(THIS_DIR)/output/build/vmlinux > $(THIS_DIR)/output/build/vmlinux.dump
3356

3457
# copy this directory to/from BR2_EXTERNAL to make buildroot run faster when this directory is in a Windows Docker volume
3558
%:
@@ -38,5 +61,5 @@ ifeq ($(BR2_EXTERNAL_SRC),$(BR2_EXTERNAL))
3861
else
3962
rsync --archive --delete $(BR2_EXTERNAL_SRC)/ $(BR2_EXTERNAL)
4063
-$(MAKE_BUILDROOT) $@
41-
cp -r --no-target-directory $(BR2_EXTERNAL) $(BR2_EXTERNAL_SRC)
64+
cp -r --update --no-target-directory $(BR2_EXTERNAL) $(BR2_EXTERNAL_SRC)
4265
endif
484 Bytes
Binary file not shown.

linux/buildroot/board/mlogv32/dts/mlogv32.dts

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,27 @@
1111
stdout-path = &uart0;
1212
};
1313

14+
rom@0 {
15+
compatible = "mtd-rom";
16+
reg = <0x0 (16*1024*1024)>;
17+
#address-cells = <1>;
18+
#size-cells = <1>;
19+
bank-width = <1>; // 8-bit "bus"
20+
21+
// align rootfs to pgdir boundary
22+
rootfs@1000 {
23+
label = "rootfs";
24+
reg = <0x1000 (16*1024*1024 - 0x1000)>;
25+
bank-width = <1>;
26+
read-only;
27+
linux,rootfs;
28+
};
29+
};
30+
1431
memory@80000000 {
1532
device_type = "memory";
16-
reg = <0x80000000 (16 * 1024*1024 - 256 * 1024)>;
33+
// the last 256K are reserved for OpenSBI
34+
reg = <0x80000000 (16*1024*1024 - 256*1024)>;
1735
};
1836

1937
cpus {
@@ -25,13 +43,32 @@
2543
device_type = "cpu";
2644
compatible = "riscv";
2745
mmu-type = "riscv,sv32";
28-
reg = <0>;
29-
riscv,isa = "rv32ima";
46+
reg = <0>; // hart id
3047
riscv,isa-base = "rv32i";
31-
riscv,isa-extensions = "i", "m", "a", "zicntr", "zicsr", "zifencei";
48+
riscv,isa-extensions =
49+
"i",
50+
"m",
51+
"a",
52+
"zicntr",
53+
"zicsr",
54+
"zifencei",
55+
"zihintpause",
56+
"sstc",
57+
"svade";
58+
59+
intc: interrupt-controller {
60+
compatible = "riscv,cpu-intc";
61+
#interrupt-cells = <1>;
62+
interrupt-controller;
63+
};
3264
};
3365
};
3466

67+
timer {
68+
compatible = "riscv,timer";
69+
interrupts-extended = <&intc 5>;
70+
};
71+
3572
soc {
3673
#address-cells = <1>;
3774
#size-cells = <1>;

linux/buildroot/board/mlogv32/linux.config

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
1-
CONFIG_BLK_DEV_INITRD=y
2-
CONFIG_INITRAMFS_SOURCE="${BR_BINARIES_DIR}/rootfs.cpio"
1+
CONFIG_NO_HZ_IDLE=y
32
CONFIG_NONPORTABLE=y
43
CONFIG_ARCH_RV32I=y
54
# CONFIG_RISCV_ISA_C is not set
5+
# CONFIG_RISCV_ISA_ZAWRS is not set
6+
# CONFIG_RISCV_ISA_ZABHA is not set
7+
# CONFIG_RISCV_ISA_ZACAS is not set
68
# CONFIG_RISCV_ISA_ZBA is not set
9+
# CONFIG_RISCV_ISA_ZBB is not set
10+
# CONFIG_RISCV_ISA_ZBC is not set
11+
# CONFIG_RISCV_ISA_ZBKB is not set
12+
# CONFIG_RISCV_ISA_ZICBOM is not set
13+
# CONFIG_RISCV_ISA_ZICBOZ is not set
714
# CONFIG_FPU is not set
815
CONFIG_RISCV_EMULATED_UNALIGNED_ACCESS=y
916
CONFIG_HZ_100=y
10-
CONFIG_XIP_KERNEL=y
11-
CONFIG_XIP_PHYS_ADDR=0x400000
12-
CONFIG_BUILTIN_DTB=y
13-
CONFIG_BUILTIN_DTB_NAME="mlogv32"
17+
# CONFIG_EFI is not set
18+
CONFIG_PHYS_RAM_BASE_FIXED=y
19+
# CONFIG_RISCV_ISA_FALLBACK is not set
20+
# CONFIG_SUSPEND is not set
21+
CONFIG_JUMP_LABEL=y
22+
# CONFIG_STRICT_KERNEL_RWX is not set
1423
# CONFIG_GCC_PLUGINS is not set
15-
CONFIG_SPARSEMEM_MANUAL=y
24+
# CONFIG_MQ_IOSCHED_DEADLINE is not set
25+
# CONFIG_MQ_IOSCHED_KYBER is not set
1626
CONFIG_DEVTMPFS=y
1727
CONFIG_DEVTMPFS_MOUNT=y
28+
CONFIG_MTD=y
29+
CONFIG_MTD_ROM=y
30+
CONFIG_MTD_PHYSMAP=y
31+
CONFIG_MTD_PHYSMAP_OF=y
32+
CONFIG_BLK_DEV_RAM=y
1833
# CONFIG_INPUT_MOUSE is not set
1934
CONFIG_SERIAL_8250=y
2035
CONFIG_SERIAL_8250_CONSOLE=y
@@ -23,21 +38,15 @@ CONFIG_SERIAL_EARLYCON_RISCV_SBI=y
2338
CONFIG_POWER_RESET=y
2439
CONFIG_POWER_RESET_SYSCON=y
2540
CONFIG_POWER_RESET_SYSCON_POWEROFF=y
41+
# CONFIG_HWMON is not set
2642
CONFIG_DUMMY_CONSOLE_COLUMNS=70
2743
CONFIG_DUMMY_CONSOLE_ROWS=38
2844
# CONFIG_HID_SUPPORT is not set
2945
# CONFIG_USB_SUPPORT is not set
30-
CONFIG_ROMFS_FS=y
31-
CONFIG_PRINTK_CALLER=y
32-
CONFIG_DEBUG_KERNEL=y
33-
CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y
34-
CONFIG_DEBUG_INFO_REDUCED=y
46+
# CONFIG_VIRTIO_MENU is not set
47+
# CONFIG_VHOST_MENU is not set
48+
# CONFIG_NVMEM is not set
49+
CONFIG_CRAMFS=y
50+
CONFIG_CRAMFS_MTD=y
51+
CONFIG_PRINTK_TIME=y
3552
CONFIG_FRAME_WARN=2048
36-
CONFIG_READABLE_ASM=y
37-
CONFIG_DEBUG_PAGEALLOC=y
38-
CONFIG_DEBUG_OBJECTS=y
39-
CONFIG_DEBUG_VM=y
40-
CONFIG_DEBUG_VIRTUAL=y
41-
CONFIG_PANIC_ON_OOPS=y
42-
CONFIG_DEBUG_KOBJECT=y
43-
# CONFIG_FTRACE is not set
Lines changed: 73 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,85 @@
1-
.section .text.start
2-
.global _start
3-
_start:
4-
// initialize icache
5-
la t0, _etext
6-
.insn i CUSTOM_0, 0, zero, t0, 0
7-
8-
// copy payload to RAM
9-
la t0, _sipayload
10-
la t1, _spayload
11-
la t2, _epayload
1+
.set UART0_BASE, 0xf0000010
2+
3+
.macro log message
4+
la a0, 1f
5+
call do_print
6+
.pushsection .rodata
7+
1: .asciz "[zsbl] \message\r\n"
8+
.popsection
9+
.endm
10+
11+
.macro copy name
12+
la t0, _si\name
13+
la t1, _s\name
14+
la t2, _e\name
1215
1:
1316
lw t3, 0(t0)
1417
sw t3, 0(t1)
1518
addi t0, t0, 4
1619
addi t1, t1, 4
1720
bltu t1, t2, 1b
21+
.endm
22+
23+
.section .text
24+
.global _start
25+
_start:
26+
// enable UART
27+
la t0, UART0_BASE
28+
li t1, 1
29+
sb t1, 8(t0)
1830

19-
// hartid
20-
li a0, 0
31+
// copy loader to RAM
32+
log "loading kernel..."
33+
copy loader
2134

22-
// DTB
23-
li a1, 0
35+
// copy kernel to RAM
36+
call loader
37+
38+
// copy OpenSBI to RAM
39+
log "loading OpenSBI..."
40+
copy opensbi
41+
42+
log "done!"
43+
44+
// wait for UART THR to drain so we don't lose any logs if OpenSBI initializes UART0 in the same tick
45+
la t0, UART0_BASE
46+
1:
47+
lbu t1, 0x14(t0)
48+
andi t1, t1, 0b100000
49+
beqz t1, 1b
50+
51+
// jump to OpenSBI
52+
li a0, 0 // hartid
53+
li a1, 0 // DTB (null)
54+
tail _sopensbi
55+
56+
do_print:
57+
la t0, UART0_BASE
58+
1:
59+
lbu t1, 0(a0)
60+
beqz t1, 2f
61+
sb t1, 0(t0)
62+
addi a0, a0, 1
63+
j 1b
64+
2:
65+
ret
2466

25-
// jump to payload
26-
call _spayload
67+
.section .loader, "ax", @progbits
68+
.balign 4
69+
loader:
70+
// copy kernel to RAM
71+
// we do this here so the copy operation can be covered by the icache
72+
copy kernel
73+
ret
2774

28-
// if the payload returns, halt the processor
29-
li t0, 0xfffffff0
30-
sw zero, 0(t0)
75+
.section .rootfs, "a", @progbits
76+
.balign 4
77+
.incbin ZSBL_ROOTFS_PATH
3178

32-
.section .data.payload
33-
.align 4
34-
.incbin ZSBL_PAYLOAD_PATH
79+
.section .kernel, "ax", @progbits
80+
.balign 4
81+
.incbin ZSBL_KERNEL_PATH
3582

36-
.section .rodata.kernel
37-
.align 4
38-
.incbin ZSBL_KERNEL_PATH
83+
.section .opensbi, "ax", @progbits
84+
.balign 4
85+
.incbin ZSBL_OPENSBI_PATH

0 commit comments

Comments
 (0)