Skip to content

Apache NuttX RTOS for Pine64 Star64 JH7110 RISC-V SBC

Compare
Choose a tag to compare
@lupyuen lupyuen released this 07 Aug 08:30

Read the articles...

Build Script

#!/usr/bin/env bash
#  Build NuttX for Star64

set -e  #  Exit when any command fails
set -x  #  Echo commands

git clone --branch 860571471da095948fa0c39ce8ac6593a1efbad7 https://github.com/apache/nuttx
git clone --branch ee71af840f543b067c72077ec7fe74c2c7153998 https://github.com/apache/nuttx-apps apps
cd nuttx

## Download the microSD Image sdcard.img
## - https://github.com/starfive-tech/VisionFive2/releases/download/VF2_v3.1.5/sdcard.img
## Write the downloaded image to a microSD Card with Balena Etcher or GNOME Disks.
## Check that microSD has been inserted.
if [ ! -d "/Volumes/NO NAME" ] 
then
  echo "Insert microSD"
  exit 0
fi

## Clean up the NuttX Project
make distclean || true

## Show the version of GCC
riscv64-unknown-elf-gcc -v

## Configure and Build NuttX
rm -f nuttx.bin
tools/configure.sh star64:nsh
make
riscv64-unknown-elf-objcopy -O binary nuttx nuttx.bin
ls -l nuttx.bin

## Build Apps Filesystem as Initial RAM Disk
rm -f initrd
make export
pushd ../apps
tools/mkimport.sh -z -x ../nuttx/nuttx-export-*.tar.gz
make import
popd
genromfs -f initrd -d ../apps/bin -V "NuttXBootVol"
ls -l initrd

## Generate FIT Image
rm -f nuttx.its jh7110-visionfive-v2.dtb starfiveu.fit
wget https://raw.githubusercontent.com/lupyuen/nuttx-star64/main/nuttx.its
wget https://github.com/starfive-tech/VisionFive2/releases/download/VF2_v3.1.5/jh7110-visionfive-v2.dtb
mkimage -f nuttx.its -A riscv -O linux -T flat_dt starfiveu.fit
ls -l starfiveu.fit

## Copy to microSD
cp starfiveu.fit "/Volumes/NO NAME"
ls -l "/Volumes/NO NAME/starfiveu.fit"

## Unmount microSD
## TODO: Verify that /dev/disk2 is microSD
diskutil unmountDisk /dev/disk2

## Show the size
riscv64-unknown-elf-size nuttx

## Copy the config
cp .config nuttx.config

## Dump the disassembly to nuttx.S
riscv64-unknown-elf-objdump \
  -t -S --demangle --line-numbers --wide \
  nuttx \
  >nuttx.S \
  2>&1

## Dump the init disassembly to init.S
riscv64-unknown-elf-objdump \
  -t -S --demangle --line-numbers --wide \
  ../apps/bin/init \
  >init.S \
  2>&1

## Boot Star64 with the microSD Card

(See the Build Log)

Output Log

Script started on Mon Aug  7 16:27:21 2023
command: screen /dev/tty.usbserial-1420 115200
�[?1049h�[!p�[?3;4l�[4l�>�[4l�[?1h�=�[0m�(B�[1;61r�[H�[2J�[H�[2J
U-Boot SPL 2021.10 (Jan 19 2023 - 04:09:41 +0800)
DDR version: dc2e84f0.
Trying to boot from SPI

OpenSBI v1.2
   ____                    _____ ____ _____
  / __ \                  / ____|  _ \_   _|
 | |  | |_ __   ___ _ __ | (___ | |_) || |
 | |  | | '_ \ / _ \ '_ \ \___ \|  _ < | |
 | |__| | |_) |  __/ | | |____) | |_) || |_
  \____/| .__/ \___|_| |_|_____/|____/_____|
        | |
        |_|

Platform Name             : StarFive VisionFive V2
Platform Features         : medeleg
Platform HART Count       : 5
Platform IPI Device       : aclint-mswi
Platform Timer Device     : aclint-mtimer @ 4000000Hz
Platform Console Device   : uart8250
Platform HSM Device       : jh7110-hsm
Platform PMU Device       : ---
Platform Reboot Device    : pm-reset
Platform Shutdown Device  : pm-reset
Firmware Base             : 0x40000000
Firmware Size             : 288 KB
Runtime SBI Version       : 1.0

Domain0 Name              : root
Domain0 Boot HART         : 1
Domain0 HARTs             : 0*,1*,2*,3*,4*
Domain0 Region00          : 0x0000000002000000-0x000000000200ffff (I)
Domain0 Region01          : 0x0000000040000000-0x000000004007ffff ()
Domain0 Region02          : 0x0000000000000000-0xffffffffffffffff (R,W,X)
Domain0 Next Address      : 0x0000000040200000
Domain0 Next Arg1         : 0x0000000042200000
Domain0 Next Mode         : S-mode
Domain0 SysReset          : yes

Boot HART ID              : 1
Boot HART Domain          : root
Boot HART Priv Version    : v1.11
Boot HART Base ISA        : rv64imafdcbx
Boot HART ISA Extensions  : none
Boot HART PMP Count       : 8
Boot HART PMP Granularity : 4096
Boot HART PMP Address Bits: 34
Boot HART MHPM Count      : 2
Boot HART MIDELEG         : 0x0000000000000222
Boot HART MEDELEG         : 0x000000000000b109


U-Boot 2021.10 (Jan 19 2023 - 04:09:41 +0800), Build: jenkins-github_visionfive2-6

CPU:   rv64imacu
Model: StarFive VisionFive V2
DRAM:  8 GiB
MMC:   sdio0@16010000: 0, sdio1@16020000: 1
Loading Environment from SPIFlash... SF: Detected gd25lq128 with page size 256 Bytes, erase size 4 KiB, total 16 MiB
OK
StarFive EEPROM format v2

--------EEPROM INFO--------
Vendor : PINE64
Product full SN: STAR64V1-2310-D008E000-00000003
data version: 0x2
PCB revision: 0xc1
BOM revision: A
Ethernet MAC0 address: 6c:cf:39:00:75:5d
Ethernet MAC1 address: 6c:cf:39:00:75:5e
--------EEPROM INFO--------

In:    serial@10000000
Out:   serial@10000000
Err:   serial@10000000
Model: StarFive VisionFive V2
Net:   eth0: ethernet@16030000, eth1: ethernet@16040000
switch to partitions #0, OK
mmc1 is current device
found device 1
bootmode flash device 1
Failed to load 'uEnv.txt'
Can't set block device
Hit any key to stop autoboot:  2 ��� 1 ��� 0 
1579 bytes read in 5 ms (307.6 KiB/s)
Importing environment from mmc1 ...
Can't set block device
## Warning: defaulting to text format
switch to partitions #0, OK
mmc1 is current device
10232366 bytes read in 438 ms (22.3 MiB/s)
## Loading kernel from FIT Image at a0000000 ...
   Using 'nuttx' configuration
   Trying 'vmlinux' kernel subimage
     Description:  vmlinux
     Type:         Kernel Image
     Compression:  uncompressed
     Data Start:   0xa00000b4
     Data Size:    2097800 Bytes = 2 MiB
     Architecture: RISC-V
     OS:           Linux
     Load Address: 0x40200000
     Entry Point:  0x40200000
   Verifying Hash Integrity ... OK
## Loading fdt from FIT Image at a0000000 ...
   Using 'nuttx' configuration
   Trying 'fdt' fdt subimage
     Description:  unavailable
     Type:         Flat Device Tree
     Compression:  uncompressed
     Data Start:   0xa09b58bc
     Data Size:    50235 Bytes = 49.1 KiB
     Architecture: RISC-V
     Load Address: 0x46000000
     Hash algo:    sha256
     Hash value:   42767c996f0544f513280805b41f996446df8b3956c656bdbb782125ae8ffeec
   Verifying Hash Integrity ... sha256+ OK
   Loading fdt from 0xa09b58bc to 0x46000000
   Booting using the fdt blob at 0x46000000
## Loading loadables from FIT Image at a0000000 ...
   Trying 'ramdisk' loadables subimage
     Description:  buildroot initramfs
     Type:         RAMDisk Image
     Compression:  uncompressed
     Data Start:   0xa02003f0
     Data Size:    8082432 Bytes = 7.7 MiB
     Architecture: RISC-V
     OS:           Linux
     Load Address: 0x46100000
     Entry Point:  unavailable
     Hash algo:    sha256
     Hash value:   41cdaae1d74fbf5f03e1a9c52ca91a13b14efc3de12f6ad690cf7b45474703a7
   Verifying Hash Integrity ... sha256+ OK
   Loading loadables from 0xa02003f0 to 0x46100000
   Loading Kernel Image
## Error: "cpu_vol_set" not defined
Booting kernel in
## Flattened Device Tree blob at 46000000
   Booting using the fdt blob at 0x46000000
   Using Device Tree in place at 0000000046000000, end 000000004600ffff

Starting kernel ...

clk u5_dw_i2c_clk_core already disabled
clk u5_dw_i2c_clk_apb already disabled
BC
NuttShell (NSH) NuttX-12.2.1-RC0
nsh> 
nsh> uname -a
NuttX 12.2.1-RC0 8605714 Aug  7 2023 16:20:45 risc-v star64
nsh> 
nsh> free
                   total       used       free    largest  nused  nfree
        Kmem:    2065400      14600    2050800    2049440     50      3
        Page:   20971520     643072   20328448   20328448
nsh> 
nsh> ls -l
/:
 dr--r--r--       0 dev/
 dr--r--r--       0 proc/
 dr--r--r--       0 system/
nsh> 
nsh> help
help usage:  help [-v] [<cmd>]

    .         break     dd        exit      kill      printf    sleep     uname     
    [         cat       df        false     ls        ps        source    umount    
    ?         cd        dmesg     fdinfo    mkdir     pwd       test      unset     
    alias     cp        echo      free      mkrd      rm        time      uptime    
    unalias   cmp       env       help      mount     rmdir     true      usleep    
    basename  dirname   exec      hexdump   mv        set       truncate  xd        
nsh> 
nsh> ls -l /dev
/dev:
 crw-rw-rw-       0 console
 crw-rw-rw-       0 null
 brw-rw-rw-16777216 ram0
 crw-rw-rw-       0 ttyS0
 crw-rw-rw-       0 zero
nsh> 
nsh> ls -l /system
/system:
 dr-xr-xr-x       0 bin/
nsh> 
nsh> ls -l /system/bin
/system/bin:
 -r-xr-xr-x  895184 getprime
 -r-xr-xr-x  512432 hello
 -r-xr-xr-x 3346072 init
 -r-xr-xr-x 3327736 sh
nsh> 
nsh> ls -l /system/bin/hello
 -r-xr-xr-x  512432 /system/bin/hello
nsh> 
nsh> hello
Hello, World!!
nsh> 
nsh> getprime
Set thread priority to 10
Set thread policy to SCHED_RR
Start thread #0
thread #0 started, looking for primes < 10000, doing 10 run(s)
thread #0 finished, found 1230 primes, last one was 9973
Done
getprime took 0 msec
nsh> 
nsh> 
Script done on Mon Aug  7 16:28:20 2023