Build System: More better
Split code into generic, arch, and platform Made QEMU its own platform Added shitty uart upload script for lichee board until I can get fel to actually upload uboot payloads without hanging TODO: Move platform selection out of build script TODO: Move arch specific stuff from kernel to arch TODO: Common linker script for arch instead of having a copy in each platform
This commit is contained in:
parent
e50fb2de2c
commit
b35d58df1f
10 changed files with 147 additions and 26 deletions
9
kernel/arch/riscv/meson.build
Normal file
9
kernel/arch/riscv/meson.build
Normal file
|
@ -0,0 +1,9 @@
|
|||
arch_sources = [
|
||||
files(
|
||||
'entry.S'
|
||||
),
|
||||
kernel_sources
|
||||
]
|
||||
|
||||
subdir('platform/' + platform)
|
||||
|
51
kernel/arch/riscv/platform/allwinner-d1/meson.build
Normal file
51
kernel/arch/riscv/platform/allwinner-d1/meson.build
Normal file
|
@ -0,0 +1,51 @@
|
|||
objcopy = find_program('riscv64-linux-gnu-objcopy')
|
||||
mkimage = find_program('mkimage')
|
||||
|
||||
arch_sources += [
|
||||
|
||||
]
|
||||
|
||||
elf = executable(
|
||||
'kernel.elf',
|
||||
arch_sources,
|
||||
link_args: [
|
||||
'-Wl,-T,' + meson.current_source_dir() + '/platform.ld',
|
||||
'-static'
|
||||
],
|
||||
link_depends: files('platform.ld'),
|
||||
install: true,
|
||||
install_dir: meson.build_root()
|
||||
)
|
||||
|
||||
bin = custom_target(
|
||||
'kernel.bin',
|
||||
command: [objcopy, '-O', 'binary', '@INPUT@', '@OUTPUT@'],
|
||||
input: elf,
|
||||
output: 'kernel.bin'
|
||||
)
|
||||
|
||||
uboot_img = custom_target(
|
||||
'kernel.uboot',
|
||||
command: [
|
||||
mkimage,
|
||||
'-d', '@INPUT@',
|
||||
'-A', 'riscv',
|
||||
'-O', 'u-boot',
|
||||
'-a', '0x45000000',
|
||||
'-e', '0x45000000',
|
||||
'-C', 'none',
|
||||
'@OUTPUT@'
|
||||
],
|
||||
input: bin,
|
||||
output: 'kernel.uboot',
|
||||
install: true,
|
||||
install_dir: meson.build_root()
|
||||
)
|
||||
|
||||
run_target('uart',
|
||||
command: [
|
||||
find_program(meson.source_root() + '/tools/uboot_upload'),
|
||||
elf
|
||||
]
|
||||
)
|
||||
|
27
kernel/arch/riscv/platform/qemu/meson.build
Normal file
27
kernel/arch/riscv/platform/qemu/meson.build
Normal file
|
@ -0,0 +1,27 @@
|
|||
elf = executable(
|
||||
'kernel.elf',
|
||||
arch_sources,
|
||||
link_args: [
|
||||
'-Wl,-T,' + meson.current_source_dir() + '/platform.ld',
|
||||
'-static'
|
||||
],
|
||||
link_depends: files('platform.ld'),
|
||||
install: true,
|
||||
install_dir: meson.build_root()
|
||||
)
|
||||
|
||||
run_target('qemu',
|
||||
command: [
|
||||
find_program('qemu-system-riscv64'),
|
||||
'-machine', 'virt',
|
||||
'-cpu', 'rv64',
|
||||
'-bios', 'opensbi-riscv64-generic-fw_dynamic.bin',
|
||||
'-m', '256m',
|
||||
'-serial', 'stdio',
|
||||
'-s',
|
||||
'-display', 'none',
|
||||
# '-d', 'int',
|
||||
'-kernel', elf
|
||||
]
|
||||
)
|
||||
|
25
kernel/arch/riscv/platform/qemu/platform.ld
Normal file
25
kernel/arch/riscv/platform/qemu/platform.ld
Normal file
|
@ -0,0 +1,25 @@
|
|||
OUTPUT_ARCH("riscv")
|
||||
OUTPUT_FORMAT("elf64-littleriscv")
|
||||
ENTRY(_start)
|
||||
SECTIONS {
|
||||
/* R-X segment. */
|
||||
. = 0x81000000;
|
||||
|
||||
.text : { *(.text) *(.text.*) }
|
||||
|
||||
/* R-- segment. */
|
||||
. = ALIGN(0x1000) + (. & (0xFFF));
|
||||
/* For some reason, ld does not emit a read-only segment without an additional gap. */
|
||||
. += 0x1000;
|
||||
|
||||
.rodata : { *(.rodata) *(.rodata.*) }
|
||||
.note.gnu.build-id : { *(.note.gnu.build-id) }
|
||||
|
||||
/* RW- segment. */
|
||||
. = ALIGN(0x1000) + (. & (0xFFF));
|
||||
|
||||
.data : { *(.data) *(.data.*) }
|
||||
.got : { *(.got) }
|
||||
.got.plt : { *(.got.plt) }
|
||||
.bss : { *(.bss) *(.bss.*) }
|
||||
}
|
|
@ -281,11 +281,13 @@ extern "C" void kmain(unsigned long hart, void *dtb) {
|
|||
|
||||
//fmt("test\n");
|
||||
|
||||
/*
|
||||
volatile uint32_t *cfg = (uint32_t *)0x2000060;
|
||||
volatile uint32_t *dat = (uint32_t *)0x2000070;
|
||||
|
||||
*cfg = 0x10;
|
||||
*dat = 0xFF;
|
||||
*/
|
||||
|
||||
fmt("y");
|
||||
|
||||
|
@ -306,11 +308,11 @@ extern "C" void kmain(unsigned long hart, void *dtb) {
|
|||
cli();
|
||||
|
||||
unsigned long time;
|
||||
volatile uint32_t *meme = (uint32_t *)0x6011010;
|
||||
//volatile uint32_t *meme = (uint32_t *)0x6011010;
|
||||
//while(true) {
|
||||
time = read_csr("time");
|
||||
fmt("hello world {}\n", time);
|
||||
*meme = *meme | (0xA57 << 1) | (1 << 0);
|
||||
//*meme = *meme | (0xA57 << 1) | (1 << 0);
|
||||
//}
|
||||
|
||||
// Identity map the first 512GiB.
|
||||
|
@ -339,9 +341,9 @@ extern "C" void kmain(unsigned long hart, void *dtb) {
|
|||
create_task(&task2, task2_main);
|
||||
|
||||
time = read_csr("time");
|
||||
//sbi_call1(0x54494D45, 0, time + 100000);
|
||||
sbi_call1(0x54494D45, 0, time + 100000);
|
||||
|
||||
//save_stack(switch_task, 0);
|
||||
save_stack(switch_task, 0);
|
||||
|
||||
sbi_call1(8, 0, 0);
|
||||
|
||||
|
|
8
kernel/meson.build
Normal file
8
kernel/meson.build
Normal file
|
@ -0,0 +1,8 @@
|
|||
kernel_sources = [
|
||||
files(
|
||||
'kernel.cpp'
|
||||
)
|
||||
]
|
||||
|
||||
subdir('arch/' + arch)
|
||||
|
36
meson.build
36
meson.build
|
@ -1,26 +1,18 @@
|
|||
project('riscv-qtech-os', ['c', 'cpp'])
|
||||
|
||||
kernel = executable('kernel',
|
||||
'kernel/boot.S',
|
||||
'kernel/kernel.cpp',
|
||||
link_args: [
|
||||
'-Wl,-T,' + (meson.current_source_dir() / 'kernel/kernel.ld'),
|
||||
'-static'
|
||||
project('riscv-qtech-os', ['c', 'cpp'],
|
||||
default_options: [
|
||||
'cpp_std=gnu++20',
|
||||
'c_std=gnu11',
|
||||
'c_flags=-Wall -Werror -Wextra',
|
||||
'cpp_flags=-Wall -Werror -Wextra'
|
||||
]
|
||||
)
|
||||
|
||||
run_target('qemu',
|
||||
command: [
|
||||
find_program('qemu-system-riscv64'),
|
||||
'-machine', 'virt',
|
||||
'-cpu', 'rv64',
|
||||
'-bios', 'opensbi-riscv64-generic-fw_dynamic.bin',
|
||||
'-m', '256m',
|
||||
'-serial', 'stdio',
|
||||
'-s',
|
||||
'-display', 'none',
|
||||
# '-d', 'int',
|
||||
'-kernel', kernel
|
||||
]
|
||||
)
|
||||
if not meson.is_cross_build()
|
||||
error('Kernel must be cross compiled')
|
||||
endif
|
||||
|
||||
arch = host_machine.cpu_family()
|
||||
platform = 'allwinner-d1'
|
||||
# platform = 'qemu'
|
||||
|
||||
subdir('kernel')
|
||||
|
|
7
tools/uboot_upload
Executable file
7
tools/uboot_upload
Executable file
|
@ -0,0 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
stty -F /dev/ttyUSB0 115200 -echo -icrnl
|
||||
echo "loadx" > /dev/ttyUSB0
|
||||
sx -vv -X -k $1 < /dev/ttyUSB0 > /dev/ttyUSB0
|
||||
echo "bootelf" > /dev/ttyUSB0
|
||||
cat - < /dev/ttyUSB0
|
Loading…
Reference in a new issue