Step1: build with busybox.

Signed-off-by: Chen Wang <wangchen20@iscas.ac.cn>
This commit is contained in:
2025-11-24 16:22:33 +08:00
committed by Chen Wang
commit d35682f2b7
163 changed files with 15660 additions and 0 deletions

79
package/opensbi/hello.s Normal file
View File

@@ -0,0 +1,79 @@
# hello.s - RISC-V 64 , "hello world!"
.section .text
.global _start
_start:
# 0x80000000 <- OpenSBI
# 0x80200000 <- hello.bin
# 0x80210000 <-
#
li sp, 0x80210000
#
call print_hello
# 退 qemu Ctrl+A X
1: j 1b
# "hello world!"
print_hello:
#
addi sp, sp, -8
sd ra, 0(sp)
#
la a0, hello_string
#
call puts
#
ld ra, 0(sp)
addi sp, sp, 8
ret
# void puts(char *str)
# a0:
puts:
#
addi sp, sp, -16
sd ra, 8(sp)
sd s0, 0(sp)
mv s0, a0 #
PRINT_LOOP:
#
lb a0, 0(s0)
beq a0, zero, PRINT_DONE # '\0'
#
call putc
#
addi s0, s0, 1
j PRINT_LOOP
PRINT_DONE:
#
ld s0, 0(sp)
ld ra, 8(sp)
addi sp, sp, 16
ret
# void putc(char c)
# a0:
putc:
# 使 SBI (console_putchar)
li a7, 0x01 # SBI_EXT_0_1_CONSOLE_PUTCHAR
ecall
ret
#
.section .rodata
hello_string:
.asciz "\nHello RISC-V world!\n"
# 4
.align 2

19
package/opensbi/hello.sh Executable file
View File

@@ -0,0 +1,19 @@
#!/usr/bin/bash
source $(dirname "$0")/../common.sh
rm -f hello.o hello.elf hello.bin
# 编译
${CROSS_COMPILE}as hello.s -o hello.o
${CROSS_COMPILE}ld hello.o -Ttext=0x80200000 -o hello.elf
${CROSS_COMPILE}objcopy -O binary hello.elf hello.bin
# 运行
echo "Running in QEMU..."
echo "Press Ctrl+A then X to exit"
qemu-system-riscv64 \
-M virt \
-m 256M \
-nographic \
-bios ${IMAGES_DIR}/fw_jump.bin \
-kernel hello.bin

37
package/opensbi/make.sh Executable file
View File

@@ -0,0 +1,37 @@
#!/usr/bin/bash
source $(dirname "$0")/../common.sh
PKGNAME=opensbi
PKGVERSION=1.6
PKGSOURCE_DIR=opensbi
PKGSOURCE=opensbi-1.6.tar.gz
PKGURL=https://github.com/riscv-software-src/opensbi/archive/v1.6/opensbi-1.6.tar.gz
PKGBUILDNAME=${PKGNAME}
PKGBUILD_DIR=${BUILD_DIR}/${PKGBUILDNAME}-${PKGVERSION}
echo "----> Building ${PKGBUILDNAME} ..."
stamp_downloaded
step_start extract
mkdir -p ${PKGBUILD_DIR}
gzip -d -c ${DL_DIR}/${PKGSOURCE_DIR}/${PKGSOURCE} | tar --strip-components=1 -C ${PKGBUILD_DIR} -xf -
chmod -R +rw ${PKGBUILD_DIR}
step_end extract
stamp_patched
stamp_configured
step_start build
eval "${TARGET_MAKE_ENV} CROSS_COMPILE=${CROSS_COMPILE} PLATFORM=generic /usr/bin/make -j${MAXNUM_CPUS} -C ${PKGBUILD_DIR}"
step_end build
step_start install-image
/usr/bin/install -m 0644 -D ${PKGBUILD_DIR}/build/platform/generic/firmware/fw_jump.bin ${IMAGES_DIR}/fw_jump.bin
step_end install-image
stamp_installed
echo "<---- ${PKGBUILDNAME} build complete."