Skip to content

Commit

Permalink
boot of child process
Browse files Browse the repository at this point in the history
  • Loading branch information
guancio committed Jan 11, 2025
1 parent 2db6c7f commit 5f313c2
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 11 deletions.
5 changes: 3 additions & 2 deletions common/inc/plat/qemu_esp32c3.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@

#define INIT_CAPS \
{ \
[0] = cap_mk_pmp(pmp_napot_encode(0x3c000000, 0x08000000), MEM_RWX), \
[4] = cap_mk_time(0, 0, S3K_SLOT_CNT), \
[0] = cap_mk_pmp(pmp_napot_encode(0x42000000 + 0x10000, 0x10000), MEM_RWX), \
[1] = cap_mk_pmp(pmp_napot_encode(0x3FC80000 + 0x10000, 0x10000), MEM_RWX), \
[4] = cap_mk_time(0, 0, S3K_SLOT_CNT), \
[8] = cap_mk_monitor(0, S3K_PROC_CNT), \
[9] = cap_mk_channel(0, S3K_CHAN_CNT), \
}
4 changes: 2 additions & 2 deletions kernel/linker.ld
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
ENTRY(_start)

_payload = ORIGIN(ram) + LENGTH(ram);
_payload = ORIGIN(irom) + LENGTH(irom);

MEMORY
{
irom (x): org = 0x42000000, len = 0x400000
irom (x): org = 0x42000000, len = 64K
drom (r): org = 0x3C000000, len = 0x400000
ram (rw): org = 0x3FC80000, len = 0x50000
rtc_ram (rx): org = 0x50000000, len = 0x2000
Expand Down
2 changes: 0 additions & 2 deletions kernel/src/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include "proc.h"
#include "sched.h"

__attribute__((section(".header"))) const unsigned long header_data[2] = {0xaedb041d, 0xaedb041d};

void kernel_init(void)
{
alt_init();
Expand Down
1 change: 1 addition & 0 deletions kernel/src/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ void proc_init(void)
procs[0].state = 0;
procs[0].regs[REG_PC] = (val_t)_payload;
KASSERT(cap_pmp_load(ctable_get(0, 0), 0) == SUCCESS);
KASSERT(cap_pmp_load(ctable_get(0, 1), 1) == SUCCESS);
}

proc_t *proc_get(pid_t pid)
Expand Down
11 changes: 9 additions & 2 deletions projects/tutorial.01.hello-world/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,22 @@ gdb: kernel ${APPS}
gdb-openocd: kernel ${APPS}
@ELFS="${ELFS}" ${ROOT}/scripts/gdb-openocd.sh

qemu_flash.bin: kernel
image: kernel ${APPS}
./merge.sh

qemu_flash.bin: image
esptool.py --chip=esp32c3 merge_bin --output=${BUILD}/qemu_flash.bin \
--fill-flash-size=2MB --flash_mode dio --flash_freq 80m \
--flash_size 2MB 0x0 ${BUILD}/kernel.bin
--flash_size 2MB 0x0 ${BUILD}/merged.bin

debug: qemu_flash.bin
qemu-system-riscv32 -M esp32c3 \
-drive file=${BUILD}/qemu_flash.bin,if=mtd,format=raw -nographic -s -S

run: qemu_flash.bin
qemu-system-riscv32 -M esp32c3 \
-drive file=${BUILD}/qemu_flash.bin,if=mtd,format=raw -nographic

size: ${ELFS}
${SIZE} ${ELFS}

Expand Down
3 changes: 2 additions & 1 deletion projects/tutorial.01.hello-world/app0.ld
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
MEMORY {
RAM (rwx) : ORIGIN = 0x80010000, LENGTH = 0x10000
IRAM (rwx) : ORIGIN = 0x42010000, LENGTH = 0x10000
RAM (rw): org = 0x3FC80000 + 0x10000, len = 0x10000
}

PROVIDE(uart_tx_one_char = 0x40000068);
Expand Down
4 changes: 2 additions & 2 deletions projects/tutorial.01.hello-world/default.ld
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SECTIONS {
.text : {
*( .init )
*( .text .text.* )
} > RAM
} > IRAM

.data : {
_data = . ;
Expand All @@ -31,5 +31,5 @@ SECTIONS {
. += __stack_size;
__stack_pointer = .;
_end = .;
}
} > RAM
}
27 changes: 27 additions & 0 deletions projects/tutorial.01.hello-world/merge.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env sh

# Input files
file1="build/qemu_esp32c3/kernel.bin"
file2="build/qemu_esp32c3/app0.bin"
output="build/qemu_esp32c3/merged.bin"

# Base address for the first file
base1=0x0

# Get size of the first file
size1=$(stat -f%z "$file1")

# Calculate next aligned address
start2=65536

# Generate padding
padding_size=$((start2 - (size1 + base1)))
dd if=/dev/zero bs=1 count=$padding_size > build/qemu_esp32c3/padding.bin

# Merge files
cat "$file1" build/qemu_esp32c3/padding.bin "$file2" > "$output"

# Cleanup
rm build/qemu_esp32c3/padding.bin

echo "Merged $file1 and $file2 into $output starting at $base1 and $start2"

0 comments on commit 5f313c2

Please sign in to comment.