Skip to content

Commit 7080a00

Browse files
committed
Boot linux!
1 parent 0fecdab commit 7080a00

File tree

10 files changed

+320
-41
lines changed

10 files changed

+320
-41
lines changed

console.sh

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,49 @@
11
#!/bin/bash
22

3+
host=localhost
4+
port=5000
5+
device=uart0
6+
direction=both
7+
disconnectOnHalt=true
8+
sendRequest=true
9+
10+
while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in
11+
h | --host )
12+
shift; host=$1
13+
;;
14+
-p | --port )
15+
shift; port=$1
16+
;;
17+
-d | --device )
18+
shift; device=$1
19+
;;
20+
--no-disconnect )
21+
shift; disconnectOnHalt=false
22+
;;
23+
--no-request )
24+
shift; sendRequest=false
25+
;;
26+
*)
27+
echo "Unknown option: $1"
28+
exit 1
29+
esac; shift; done
30+
if [[ "$1" == '--' ]]; then shift; fi
31+
332
state=$(stty -g)
4-
if [[ "${DIRECTION:=both}" == "tx" ]]; then
33+
if [[ "$direction" == "tx" ]]; then
534
stty raw opost
635
else
736
stty raw opost -echo
837
fi
938

10-
{
11-
echo "{\"type\": \"serial\", \"device\": \"${DEVICE:=uart0}\", \"overrun\": false, \"direction\": \"${DIRECTION}\", \"disconnectOnHalt\": ${DISCONNECT_ON_HALT:=true}}"
12-
cat
13-
} | netcat -v "${HOST:=localhost}" "${PORT:=5000}"
39+
if [[ "$sendRequest" == "true" ]]; then
40+
{
41+
echo "{\"type\": \"serial\", \"device\": \"$device\", \"overrun\": false, \"direction\": \"$direction\", \"disconnectOnHalt\": $disconnectOnHalt}"
42+
cat
43+
} | netcat -v "$host" "$port"
44+
else
45+
netcat -v "$host" "$port"
46+
fi
1447

1548
stty "$state"
1649

linux/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ setup-buildroot:
1616
curl --location "$(BUILDROOT_RELEASE)" | tar xzv --directory $(BUILDROOT)
1717

1818
.PHONY: everything
19-
everything: load-configs dtbs all zsbl get-images
19+
everything: load-configs dtbs all opensbi-rebuild zsbl get-images
2020

2121
.PHONY: dtbs-rebuild
2222
dtbs-rebuild: dtbs opensbi-rebuild zsbl get-images

linux/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Linux
2+
3+
## Debugging
4+
5+
### objdump
6+
7+
```
8+
riscv32-unknown-linux-gnu-objdump --disassembler-color=on --visualize-jumps=color --start-address=0xc00109ac --stop-address=0xc0010a2c --disassemble --source --line-numbers --show-all-symbols --wide output/build/vmlinux
9+
```
10+
11+
### GDB
12+
13+
- Start the terminal server:
14+
```sh
15+
python -m mlogv32.scripts.terminal_server
16+
```
17+
- Connect gdb to the debug port:
18+
```sh
19+
riscv32-unknown-linux-gnu-gdb output/build/vmlinux
20+
tar rem host.docker.internal:5001
21+
```
-442 Bytes
Binary file not shown.

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

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,24 @@
77
chassis-type = "embedded";
88

99
chosen {
10-
bootargs = "earlycon=sbi console=ttyS0";
10+
// SBI: console=hvc
11+
// UART0: console=ttyS0
12+
// for debugging: kgdboc_earlycon=sbi kgdboc=ttyS0 kgdbwait
13+
bootargs = "earlycon=sbi console=hvc";
1114
stdout-path = &uart0;
1215
};
1316

1417
rom@0 {
1518
compatible = "mtd-rom";
1619
reg = <0x0 (16*1024*1024)>;
20+
bank-width = <1>; // 8-bit "bus"
21+
1722
#address-cells = <1>;
1823
#size-cells = <1>;
19-
bank-width = <1>; // 8-bit "bus"
2024

21-
// align rootfs to pgdir boundary
2225
rootfs@1000 {
2326
label = "rootfs";
2427
reg = <0x1000 (16*1024*1024 - 0x1000)>;
25-
bank-width = <1>;
26-
read-only;
2728
linux,rootfs;
2829
};
2930
};
@@ -78,37 +79,12 @@
7879
uart0: serial@f0000010 {
7980
compatible = "ns16550a";
8081
reg = <0xf0000010 0x20>;
81-
clock-frequency = <10000000>;
82-
reg-shift = <2>;
83-
no-loopback-test = <1>;
84-
fifo-size = <253>;
85-
};
86-
87-
uart1: serial@f0000030 {
88-
compatible = "ns16550a";
89-
reg = <0xf0000030 0x20>;
90-
clock-frequency = <10000000>;
91-
reg-shift = <2>;
92-
no-loopback-test = <1>;
93-
fifo-size = <253>;
94-
};
95-
96-
uart2: serial@f0000050 {
97-
compatible = "ns16550a";
98-
reg = <0xf0000050 0x20>;
99-
clock-frequency = <10000000>;
100-
reg-shift = <2>;
101-
no-loopback-test = <1>;
102-
fifo-size = <253>;
103-
};
104-
105-
uart3: serial@f0000070 {
106-
compatible = "ns16550a";
107-
reg = <0xf0000070 0x20>;
108-
clock-frequency = <10000000>;
10982
reg-shift = <2>;
110-
no-loopback-test = <1>;
83+
interrupts-extended = <&intc 9>;
84+
clock-frequency = <(38400*16)>;
11185
fifo-size = <253>;
86+
no-loopback-test;
87+
// TODO: https://github.com/torvalds/linux/blob/8c2e52ebbe885c7eeaabd3b7ddcdc1246fc400d2/drivers/tty/serial/8250/8250_of.c#L233
11288
};
11389

11490
syscon: syscon@fffffff0 {

linux/buildroot/board/mlogv32/linux.config

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
CONFIG_NO_HZ_IDLE=y
2+
CONFIG_KALLSYMS_ALL=y
23
CONFIG_NONPORTABLE=y
34
CONFIG_ARCH_RV32I=y
45
# CONFIG_RISCV_ISA_C is not set
@@ -26,14 +27,20 @@ CONFIG_JUMP_LABEL=y
2627
CONFIG_DEVTMPFS=y
2728
CONFIG_DEVTMPFS_MOUNT=y
2829
CONFIG_MTD=y
30+
CONFIG_MTD_BLOCK_RO=y
2931
CONFIG_MTD_ROM=y
3032
CONFIG_MTD_PHYSMAP=y
3133
CONFIG_MTD_PHYSMAP_OF=y
3234
CONFIG_BLK_DEV_RAM=y
3335
# CONFIG_INPUT_MOUSE is not set
36+
CONFIG_VT_HW_CONSOLE_BINDING=y
3437
CONFIG_SERIAL_8250=y
38+
# CONFIG_SERIAL_8250_DEPRECATED_OPTIONS is not set
39+
# CONFIG_SERIAL_8250_16550A_VARIANTS is not set
3540
CONFIG_SERIAL_8250_CONSOLE=y
41+
CONFIG_SERIAL_OF_PLATFORM=y
3642
CONFIG_SERIAL_EARLYCON_RISCV_SBI=y
43+
CONFIG_HVC_RISCV_SBI=y
3744
# CONFIG_HW_RANDOM is not set
3845
CONFIG_POWER_RESET=y
3946
CONFIG_POWER_RESET_SYSCON=y
@@ -46,7 +53,15 @@ CONFIG_DUMMY_CONSOLE_ROWS=38
4653
# CONFIG_VIRTIO_MENU is not set
4754
# CONFIG_VHOST_MENU is not set
4855
# CONFIG_NVMEM is not set
56+
CONFIG_OVERLAY_FS=y
57+
CONFIG_TMPFS=y
4958
CONFIG_CRAMFS=y
5059
CONFIG_CRAMFS_MTD=y
5160
CONFIG_PRINTK_TIME=y
61+
CONFIG_DEBUG_KERNEL=y
62+
# CONFIG_DEBUG_MISC is not set
63+
CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y
64+
CONFIG_GDB_SCRIPTS=y
5265
CONFIG_FRAME_WARN=2048
66+
CONFIG_KGDB=y
67+
# CONFIG_FTRACE is not set
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
From 6dd1871b195d17d3ea2121cc030663c76da309e1 Mon Sep 17 00:00:00 2001
2+
From: object-Object <[email protected]>
3+
Date: Wed, 9 Jul 2025 16:50:43 -0400
4+
Subject: [PATCH 1/2] Add sbi_debug_console_read support to SBI earlycon
5+
6+
---
7+
drivers/tty/serial/earlycon-riscv-sbi.c | 11 +++++++++--
8+
1 file changed, 9 insertions(+), 2 deletions(-)
9+
10+
diff --git a/drivers/tty/serial/earlycon-riscv-sbi.c b/drivers/tty/serial/earlycon-riscv-sbi.c
11+
index 0162155f0c83..a526974c5416 100644
12+
--- a/drivers/tty/serial/earlycon-riscv-sbi.c
13+
+++ b/drivers/tty/serial/earlycon-riscv-sbi.c
14+
@@ -37,12 +37,19 @@ static void sbi_dbcn_console_write(struct console *con,
15+
}
16+
}
17+
18+
+static int sbi_dbcn_console_read(struct console *con,
19+
+ char *s, unsigned int n)
20+
+{
21+
+ return sbi_debug_console_read(s, n);
22+
+}
23+
+
24+
static int __init early_sbi_setup(struct earlycon_device *device,
25+
const char *opt)
26+
{
27+
- if (sbi_debug_console_available)
28+
+ if (sbi_debug_console_available) {
29+
device->con->write = sbi_dbcn_console_write;
30+
- else if (IS_ENABLED(CONFIG_RISCV_SBI_V01))
31+
+ device->con->read = sbi_dbcn_console_read;
32+
+ } else if (IS_ENABLED(CONFIG_RISCV_SBI_V01))
33+
device->con->write = sbi_0_1_console_write;
34+
else
35+
return -ENODEV;
36+
37+
base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
38+
--
39+
2.25.1
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
From 3d22caf2bee6f6ff4b9ce1c53a3bc046cfcd14e4 Mon Sep 17 00:00:00 2001
2+
From: object-Object <[email protected]>
3+
Date: Fri, 11 Jul 2025 16:43:41 -0400
4+
Subject: [PATCH 2/2] Hack: remove contents of flush_icache_pte
5+
6+
---
7+
arch/riscv/mm/cacheflush.c | 6 ------
8+
1 file changed, 6 deletions(-)
9+
10+
diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c
11+
index 4ca5aafce22e..667ab1659bb9 100644
12+
--- a/arch/riscv/mm/cacheflush.c
13+
+++ b/arch/riscv/mm/cacheflush.c
14+
@@ -99,12 +99,6 @@ void flush_icache_mm(struct mm_struct *mm, bool local)
15+
#ifdef CONFIG_MMU
16+
void flush_icache_pte(struct mm_struct *mm, pte_t pte)
17+
{
18+
- struct folio *folio = page_folio(pte_page(pte));
19+
-
20+
- if (!test_bit(PG_dcache_clean, &folio->flags)) {
21+
- flush_icache_mm(mm, false);
22+
- set_bit(PG_dcache_clean, &folio->flags);
23+
- }
24+
}
25+
#endif /* CONFIG_MMU */
26+
27+
--
28+
2.25.1

python/src/mlogv32/processor_access.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,25 @@ def status(self):
7676
self._send_request(StatusRequest())
7777
return self._recv_response(StatusResponse)
7878

79+
def serial(
80+
self,
81+
device: UartDevice,
82+
*,
83+
overrun: bool = False,
84+
stop_on_halt: bool = False,
85+
disconnect_on_halt: bool = False,
86+
):
87+
self._send_request(
88+
SerialRequest(
89+
device=device,
90+
overrun=overrun,
91+
direction="both",
92+
stopOnHalt=stop_on_halt,
93+
disconnectOnHalt=disconnect_on_halt,
94+
)
95+
)
96+
return self.socket
97+
7998
def _send_request(self, request: Request) -> None:
8099
message = request.model_dump_json() + "\n"
81100
logger.log(self.log_level, f"Sending request: {message.rstrip()}")
@@ -144,14 +163,30 @@ class StatusRequest(BaseModel):
144163
type: Literal["status"] = "status"
145164

146165

166+
type UartDevice = Literal["uart0", "uart1", "uart2", "uart3"]
167+
168+
169+
type UartDirection = Literal["both", "rx", "tx"]
170+
171+
172+
class SerialRequest(BaseModel):
173+
type: Literal["serial"] = "serial"
174+
device: UartDevice
175+
overrun: bool
176+
direction: UartDirection
177+
stopOnHalt: bool
178+
disconnectOnHalt: bool
179+
180+
147181
type Request = Annotated[
148182
FlashRequest
149183
| DumpRequest
150184
| StartRequest
151185
| WaitRequest
152186
| UnpauseRequest
153187
| StopRequest
154-
| StatusRequest,
188+
| StatusRequest
189+
| SerialRequest,
155190
Field(discriminator="type"),
156191
]
157192

0 commit comments

Comments
 (0)