Skip to content

Commit

Permalink
Support StarFive VisionFive2(RISC-V)
Browse files Browse the repository at this point in the history
  • Loading branch information
AristoChen committed Jul 7, 2023
1 parent 6dbf4d2 commit 52583a3
Show file tree
Hide file tree
Showing 10 changed files with 252 additions and 11 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ From Linux and maker space tinkerers, to the robotics, automotive and signage in
Please see official [Ubuntu Core documentation](https://ubuntu.com/core/docs) for more infomation

## Supported devices
- Khadas VIM1
- OrangePi 3
- OrangePi 5
- OrangePi PC
- OrangePi PC2
- OrangePi Zero
- RaspberryPi 4(32 bit and 64 bit)
| SBC | ARCH | NOTE |
|----------------------|--------------|------|
| Khadas VIM1 | arm64 | |
| OrangePi 3 | arm64 | |
| OrangePi 5 | arm64 | |
| OrangePi PC | armhf | |
| OrangePi PC2 | arm64 | |
| OrangePi Zero | armhf | |
| RaspberryPi 4 | armhf, arm64 | |
| StarFive VisionFive2 | riscv | |

## How to use
**Note**: The code is only tested in Ubuntu Jammy environment, other environment are currently not tested.
Expand Down
42 changes: 42 additions & 0 deletions assertions/ubuntu-core-22-dangerous-model-riscv64.assert
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
type: model
authority-id: V2yG6LAupEYdeTz6jHQLLOMkHGd1ZG44
series: 16
brand-id: V2yG6LAupEYdeTz6jHQLLOMkHGd1ZG44
model: ubuntu-core-22
architecture: riscv64
base: core22
grade: dangerous
snaps:
-
default-channel: latest/stable
id: ThisIsADummyStringForGadgetSnaps
name: gadget-snap
type: gadget
-
default-channel: latest/stable
id: ThisIsADummyStringForKernelSnaps
name: kernel-snap
type: kernel
-
default-channel: latest/stable
id: amcUKQILKXHHTlmSa7NMdnXSx02dNeeT
name: core22
type: base
-
default-channel: latest/stable
id: PMrrV4ml8uWuEUDBT8dSGnKUYbevVhc4
name: snapd
type: snapd
timestamp: 2023-03-05T02:00:46Z
sign-key-sha3-384: J-RYIwjKa7kBS5WpVNM036ri24pNeOaAM3nbDzyv8q55iMF6Y3nJqsVYiBtI56vE

AcLBcwQAAQoAHRYhBBP9k65i7BkdXwGeTA1TXkI+U5x2BQJkj7aJAAoJEA1TXkI+U5x27zsP/3WV
RIoptbJ6FLZvP3bCDzXyXzGhFCt754aWcghfiUI0Ch/25TKROBeUe/yEmFTQeSEx3gwtEXS+mXrO
4uoGj4ORqtDObkgsW2I+0H98d+TMwXs0Z3gdiaZxm2opKtt4T7XiNAjtAhcQsV4Btoi7HLPVnXP7
TkIFcwIEcOmaKVzIfO9w5f1VNL5MWklPQr02YK2tj58Fj93lrPN2Ogw/ylBvEVnYqpAM2B1X41oo
MVECqlUmEAZkDPo1JsNwkNF/L5taT3dVw/i8H/dfBomnkottCe0tghbCvAxdG5MbOFZ+T7/qHxSi
+/x/ci9kYaTgj5Er9yisnp+haWq7vYA/CnlkAESsm+aID0NhJsAfBdqWPPkwRmqAJk5RO6DXBgQB
Eax3E6OSuuUttyms1svSnMlMGcyAQGh2YIBUbpVx7PVboW6YAbQ6SHizmCwLWDqXmhPKrAakslC2
jxRqWY1gnca18NIruPOkGfsk0IO/KY8pIzB1utPi62sznGUpGlb2MS1G07ynfO2zFIwJj9KR0qxN
kBRnSJpEgB2XGtMLhPJYqNOoFUzijNFdpQ9cY0gObUuvVeBT0UGqZ4rqMNY1+2TC0LEVFUiFL3XX
Wtkk7Nj2ScbxSJbwvwVd/lfeeEen3Vc5jGHQDPaKwqhRIYh1CO9Dcqxv5xy+B+hLedqTxve1
37 changes: 37 additions & 0 deletions assertions/ubuntu-core-22-dangerous-model-riscv64.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"type": "model",
"authority-id": "V2yG6LAupEYdeTz6jHQLLOMkHGd1ZG44",
"brand-id": "V2yG6LAupEYdeTz6jHQLLOMkHGd1ZG44",
"series": "16",
"model": "ubuntu-core-22",
"architecture": "riscv64",
"base": "core22",
"grade": "dangerous",
"snaps": [
{
"default-channel": "latest/stable",
"id": "ThisIsADummyStringForGadgetSnaps",
"name": "gadget-snap",
"type": "gadget"
},
{
"default-channel": "latest/stable",
"id": "ThisIsADummyStringForKernelSnaps",
"name": "kernel-snap",
"type": "kernel"
},
{
"default-channel": "latest/stable",
"id": "amcUKQILKXHHTlmSa7NMdnXSx02dNeeT",
"name": "core22",
"type": "base"
},
{
"default-channel": "latest/stable",
"id": "PMrrV4ml8uWuEUDBT8dSGnKUYbevVhc4",
"name": "snapd",
"type": "snapd"
}
],
"timestamp": "2023-03-05T02:00:46Z"
}
13 changes: 10 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ set -ex

function prepare_build_env()
{
snap list snapcraft && sudo snap refresh snapcraft --channel=latest/stable --classic \
|| sudo snap install snapcraft --channel=latest/stable --classic
snap list snapcraft && sudo snap refresh snapcraft --channel=latest/edge --classic \
|| sudo snap install snapcraft --channel=latest/edge --classic
snap list ubuntu-image && sudo snap refresh ubuntu-image --channel=latest/stable --classic \
|| sudo snap install ubuntu-image --channel=latest/stable --classic
snap list yq && sudo snap refresh yq --channel=latest/stable --devmode \
Expand Down Expand Up @@ -49,6 +49,11 @@ function apply_patches()
PATCH_DIR="${CACHE_DIR}/patch"
mkdir -p "${PATCH_DIR}"
cp -r "${ROOT_DIR}/configs/patch/${BOARD}/"* "${PATCH_DIR}"

if [ -d "${PATCH_DIR}"/gadget_snap/additional ]; then
cp -r "${PATCH_DIR}"/gadget_snap/additional/* "${CACHE_DIR}"/gadget_snap/
fi

if [ ! -f "${CACHE_DIR}/.done_apply_patch" ]; then
# For gadget.yaml in gadget_snap
if [ -f "${PATCH_DIR}/${GADGET_SNAP_GADGET_YAML}" ]; then
Expand Down Expand Up @@ -126,7 +131,9 @@ function load_config()
fi
fi

apply_patches
if [ -d "${ROOT_DIR}/configs/patch/${BOARD}/" ]; then
apply_patches
fi

cd "${BOARD_BUILD_DIR}"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/dts-v1/;

/ {
description = "Ubuntu Core FIT boot firmware";
#address-cells = <2>;

images {
firmware {
description = "Ubuntu-Core-Bootloader";
data = /incbin/("./fw_payload.bin");
type = "firmware";
arch = "riscv";
os = "u-boot";
compression = "none";
load = <0x40000000>;
entry = <0x40000000>;
};
};

configurations {
default = "firmware-1";

fimware-1 {
description = "__DEVICE__ firmware";
firmware = "firmware";
};
};
};
15 changes: 15 additions & 0 deletions configs/patch/starfive_visionfive2/gadget_snap/gadget.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
volumes:
ubuntu-core:
structure:
- name: spl
offset: 2097152
size: 1M
type: 0C,2E54B353-1271-4842-806F-E436D6AF6985
content:
- image: u-boot-spl.bin.normal.out
- name: bootloader
offset: 4194304
size: 8M
type: 0C,5B193300-FC78-40CD-8002-E86C45580B47
content:
- image: visionfive2_fw_payload.img
71 changes: 71 additions & 0 deletions configs/patch/starfive_visionfive2/gadget_snap/snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
parts:
u-boot:
override-build: |
cat << EOF >> configs/__BOOTLOADER_DEFCONFIG__
CONFIG_FIT=y
CONFIG_LOCALVERSION_AUTO=n
EOF
sed -i "s/CONFIG_BOOTCOMMAND=\"\(.*\)\"/\
CONFIG_BOOTCOMMAND=\"load mmc 1:3 \${scriptaddr} boot.scr; source \${scriptaddr}\"/g" \
configs/__BOOTLOADER_DEFCONFIG__
sed -i "s/CONFIG_BOOTARGS=\"\(.*\)\"/\
CONFIG_BOOTARGS=\"console=tty1 console=ttyS0,115200 earlycon=sbi\"/g" \
configs/__BOOTLOADER_DEFCONFIG__
make __BOOTLOADER_DEFCONFIG__
make -j$(nproc) LOCALVERSION="-uc22"
cp u-boot.bin "${CRAFT_PART_INSTALL}"/
cp spl/u-boot-spl.bin "${CRAFT_PART_INSTALL}"/
cp arch/riscv/dts/starfive_visionfive2.dtb "${CRAFT_PART_INSTALL}"/
# Copy licenses
mkdir -p "${CRAFT_PART_INSTALL}"/usr/share/doc/u-boot
cp -a Licenses/* "${CRAFT_PART_INSTALL}"/usr/share/doc/u-boot
mkenvimage -s 4096 -o "${CRAFT_PART_INSTALL}"/boot.sel - < /dev/null
touch "${CRAFT_PART_INSTALL}"/uboot.conf
prime:
- -u-boot-spl.bin
- -starfive_visionfive2.dtb

spl:
after:
- u-boot
plugin: nil
source: https://github.com/starfive-tech/soft_3rdpart.git
source-type: git
source-depth: 1
source-branch: JH7110_VisionFive2_devel
override-build: |
cd spl_tool
make
./spl_tool -c -f "${CRAFT_STAGE}"/u-boot-spl.bin
cp "${CRAFT_STAGE}"/u-boot-spl.bin.normal.out "${CRAFT_PART_INSTALL}"/
open-sbi:
after:
- u-boot
plugin: nil
source: https://github.com/starfive-tech/opensbi.git
source-type: git
source-depth: 1
source-branch: master
build-environment:
- on amd64:
- CROSS_COMPILE: riscv64-linux-gnu-
- CFLAGS: "-mabi=lp64d -march=rv64imafdc_zicsr_zifencei_zba_zbb"
override-build: |
mkdir output
make PLATFORM=generic FW_PAYLOAD_PATH="${CRAFT_STAGE}"/u-boot.bin \
FW_FDT_PATH="${CRAFT_STAGE}"/starfive_visionfive2.dtb \
FW_TEXT_START=0x40000000 O=output
cp "${CRAFT_PROJECT_DIR}"/its/firmware.its .
cp output/platform/generic/firmware/fw_payload.bin .
mkimage -f firmware.its -A riscv -O u-boot -T firmware \
"${CRAFT_PART_INSTALL}"/visionfive2_fw_payload.img
boot-script:
override-build: |
sed -i 's/setenv mmc_seed_part 1/setenv mmc_seed_part 3/g' boot.cmd
sed -i 's/setenv mmc_boot_part 2/setenv mmc_boot_part 4/g' boot.cmd
mkimage -C none -A arm -T script -d boot.cmd "${CRAFT_PART_INSTALL}"/boot.scr
28 changes: 28 additions & 0 deletions configs/starfive_visionfive2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# StarFive JH7110 quad core
DEVICE="StarFive_VisionFive2"
ARCH=riscv64
CROSS_COMPILER=riscv64-linux-gnu-
CROSS_COMPILER_DEB_PACKAGE=gcc-riscv64-linux-gnu

PARTITION_SCHEMA=gpt
BOOTLOADER_GIT_SOURCE=https://github.com/starfive-tech/u-boot
BOOTLOADER_GIT_BRANCH=JH7110_VisionFive2_devel
BOOTLOADER_DEFCONFIG=starfive_visionfive2_defconfig
BOOTLOADER_BINARY=u-boot.bin
BOOTLOADER_BINARY_RENAME=false
BOOTLOADER_BOOTARGS=""

CLOUD_INIT_ENABLED=true

MMC_DEV_NUM=1
KERNEL_LOAD_ADDR=0x40200000
RAMDISK_LOAD_ADDR=0x46100000
FDT_LOAD_ADDR=0x46000000
FIT_LOAD_ADDR=0xa0000000

ITS_KERNEL_COMPRESSION="none"
ITS_FDT_NAME=jh7110-visionfive-v2.dtb

KERNEL_GIT_SOURCE=https://github.com/starfive-tech/linux.git
KERNEL_GIT_BRANCH=JH7110_VisionFive2_devel
KERNEL_DEFCONFIG=starfive_visionfive2_defconfig
1 change: 0 additions & 1 deletion kernel_snap/its/kernel.its
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,5 @@
ramdisk = "ramdisk-uc";
fdt = "fdt-uc";
};

};
};
11 changes: 11 additions & 0 deletions kernel_snap/snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,18 @@ parts:
- CONFIG_SYSTEM_REVOCATION_KEYS=""
- CONFIG_LOCALVERSION="-uc22"
- CONFIG_DEFAULT_SECURITY_APPARMOR=y
- CONFIG_ENCRYPTED_KEYS=y
- CONFIG_SQUASHFS=y
- CONFIG_SQUASHFS_XATTR=y
- CONFIG_SQUASHFS_XZ=y
- CONFIG_SQUASHFS_LZO=y
- CONFIG_SECURITY=y
- CONFIG_SECURITY_APPARMOR=y
- CONFIG_SYN_COOKIES=y
- CONFIG_STRICT_DEVMEM=y
- CONFIG_SECCOMP=y
- CONFIG_SECCOMP_FILTER=y

kernel-initrd-modules:
- nls_iso8859-1
override-build: |
Expand Down

0 comments on commit 52583a3

Please sign in to comment.