Skip to content

Commit

Permalink
[DEB] Add A12 Ethernet and 8 GB RAM overlays
Browse files Browse the repository at this point in the history
and fw_printenv/fw_setenv configs with a default U-Boot environment.
This fixes boot issues with latest StarFive U-Boot builds,
which strictly boot from a partition 3 with FAT filesystem only.
Our environment uses a generic approach to boot from any filesystem
of any partition of any boot media, based on a "boot_targets" variable.

Also move packaging files out of workflow file into pre-created dir structure.

Signed-off-by: MichaIng <[email protected]>
  • Loading branch information
MichaIng committed Oct 15, 2023
1 parent c217edf commit 53e32c3
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 49 deletions.
62 changes: 13 additions & 49 deletions .github/workflows/visionfive2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,25 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions: {}
defaults:
run:
shell: sh
jobs:
build:
# https://github.com/actions/virtual-environments
runs-on: ubuntu-22.04
defaults:
run:
shell: sh
env:
CROSS_COMPILE: 'riscv64-linux-gnu-'
ARCH: 'riscv'
steps:
- name: Setup tmpfs
run: sudo mount -t tmpfs -o "noatime,lazytime,uid=$(id -u),size=3G" tmpfs "$GITHUB_WORKSPACE"
- uses: actions/checkout@v3
- name: Build init
- uses: actions/checkout@v4
- name: Install build dependencies
run: |
sudo apt-get -q update
sudo DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends -qq dist-upgrade
sudo DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends -qq install make gcc libc6-dev flex bison gcc-riscv64-linux-gnu bc libssl-dev
rm -Rf linux-image-visionfive2
mkdir -p linux-image-visionfive2/DEBIAN linux-image-visionfive2/boot/extlinux linux-image-visionfive2/lib/firmware
- name: Build Linux
run: |
> .scmversion # Avoid Git commit version suffix
Expand All @@ -36,65 +34,31 @@ jobs:
find linux-image-visionfive2/usr/lib/linux-image-visionfive2 -mindepth 1 -regextype egrep \( ! -regex '.*/(starfive|vf2-overlay.*|jh7110-visionfive-v2.*\.dtb)' -o -regex '.*/jh7110-visionfive-v2-A1[01].dtb' \) -exec rm -Rf {} +
make modules_install INSTALL_MOD_PATH='linux-image-visionfive2'
rm linux-image-visionfive2/lib/modules/*/build linux-image-visionfive2/lib/modules/*/source
mkdir -p linux-image-visionfive2/lib/firmware
curl -sSfo linux-image-visionfive2/lib/firmware/ECR6600U_transport.bin 'https://raw.githubusercontent.com/starfive-tech/buildroot/JH7110_VisionFive2_devel/package/starfive/usb_wifi/ECR6600U_transport.bin'
find linux-image-visionfive2 -type f -exec chmod 0644 {} +
find linux-image-visionfive2 -type f \( -path linux-image-visionfive2/DEBIAN -prune \) -exec chmod 0644 {} +
find linux-image-visionfive2 -type d -exec chmod 0755 {} +
- name: Build package
run: |
echo 'Obtaining kernel and package version ...'
kernelversion=$(make kernelversion)
curl -fO 'https://dietpi.com/downloads/binaries/linux-image-visionfive2.deb'
cur_version=$(dpkg-deb -f linux-image-visionfive2.deb Version)
rm linux-image-visionfive2.deb
cur_suffix=${cur_version#*-dietpi}
echo "Current package version is: $cur_version"
echo "New kernel version is: $kernelversion"
echo "Current package version is : $cur_version"
echo "New kernel version is : $kernelversion"
[ "$kernelversion-dietpi$cur_suffix" = "$cur_version" ] && version="$kernelversion-dietpi$((cur_suffix+1))" || version="$kernelversion-dietpi1"
echo "New package version will be: $version"
cat << _EOF_ > linux-image-visionfive2/boot/extlinux/extlinux.conf
label DietPi
linux /boot/vmlinuz-$kernelversion
fdt /usr/lib/linux-image-visionfive2/starfive/jh7110-visionfive-v2.dtb
append root=/dev/mmcblk1p1 rootfstype=ext4 rootwait earlycon=sbi console=ttyS0,115200 console=tty1 consoleblank=0 net.ifnames=0
_EOF_
echo '/boot/extlinux/extlinux.conf' > linux-image-visionfive2/DEBIAN/conffiles
cat << _EOF_ > linux-image-visionfive2/DEBIAN/postinst
#!/bin/dash
set -e
export DEB_MAINT_PARAMS=\$* INITRD=Yes
[ -d '/etc/kernel/postinst.d' ] && run-parts --arg='$kernelversion' --arg='/boot/vmlinuz-$kernelversion' /etc/kernel/postinst.d
sed -Ei '/^[[:blank:]]*(linux|kernel)/c\linux /boot/vmlinuz-$kernelversion' /boot/extlinux/extlinux.conf
exit 0
_EOF_
cp linux-image-visionfive2/DEBIAN/postinst linux-image-visionfive2/DEBIAN/preinst
sed -i -e '/extlinux/d' -e 's/postinst/preinst/g' linux-image-visionfive2/DEBIAN/preinst
cp linux-image-visionfive2/DEBIAN/postinst linux-image-visionfive2/DEBIAN/postrm
sed -i -e '/extlinux/d' -e 's/postinst/postrm/g' linux-image-visionfive2/DEBIAN/postrm
cp linux-image-visionfive2/DEBIAN/postinst linux-image-visionfive2/DEBIAN/prerm
sed -i -e '/extlinux/d' -e 's/postinst/prerm/g' linux-image-visionfive2/DEBIAN/prerm
chmod +x linux-image-visionfive2/DEBIAN/p*
sed -i "s/VERSION/$kernelversion/g" linux-image-visionfive2/boot/extlinux/extlinux.conf linux-image-visionfive2/DEBIAN/p*
find linux-image-visionfive2 ! \( -path linux-image-visionfive2/DEBIAN -prune \) -type f -exec md5sum {} + | sed 's|linux-image-visionfive2/||' > linux-image-visionfive2/DEBIAN/md5sums
cat << _EOF_ > linux-image-visionfive2/DEBIAN/control
Package: linux-image-visionfive2
Version: $version
Architecture: riscv64
Maintainer: MichaIng <[email protected]>
Date: $(date -u '+%a, %d %b %Y %T %z')
Standards-Version: 4.6.2.0
Installed-Size: $(du -sk 'linux-image-visionfive2' | mawk '{print $1}')
Section: kernel
Priority: optional
Homepage: https://github.com/MichaIng/linux
Vcs-Git: https://github.com/MichaIng/linux.git
Vcs-Browser: https://github.com/MichaIng/linux
Description: Linux kernel for RISC-V StarFive VisionFive 2
_EOF_
sed -i "/^Installed-Size:/c\Installed-Size: $(du -sk 'linux-image-visionfive2' | mawk '{print $1}')" linux-image-visionfive2/DEBIAN/control
sed -i -e "s/VERSION/$version/" -e "s/DATE/$(date -u '+%a, %d %b %Y %T %z')/" -e "s/SIZE/$(du -sk 'linux-image-visionfive2' | mawk '{print $1}')/" linux-image-visionfive2/DEBIAN/control
sudo chown -R 0:0 linux-image-visionfive2
dpkg-deb -b -Zxz -z9 -Sextreme linux-image-visionfive2
sudo rm -R linux-image-visionfive2
- name: Upload
run: |
[ -d ~/.ssh ] || mkdir ~/.ssh
mkdir -p ~/.ssh
umask 377
echo '${{ secrets.KNOWN_HOSTS }}' > ~/.ssh/known_hosts
echo '${{ secrets.SSH_KEY }}' > ~/.ssh/id_ed25519
Expand Down
11 changes: 11 additions & 0 deletions arch/riscv/boot/dts/starfive/vf2-overlay/8GB.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/dts-v1/;
/plugin/;
/ {
compatible = "starfive,visionfive-v2", "starfive,jh7110";
fragment@0 {
target-path = "/memory@40000000";
__overlay__ {
reg = <0x0 0x40000000 0x2 0x0>;
};
};
};
2 changes: 2 additions & 0 deletions arch/riscv/boot/dts/starfive/vf2-overlay/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# SPDX-License-Identifier: GPL-2.0
dtb-$(CONFIG_SOC_STARFIVE_JH7110) += vf2-overlay-uart3-i2c.dtbo
dtb-$(CONFIG_SOC_STARFIVE_JH7110) += 8GB.dtbo
dtb-$(CONFIG_SOC_STARFIVE_JH7110) += ethernet-A12.dtbo
23 changes: 23 additions & 0 deletions arch/riscv/boot/dts/starfive/vf2-overlay/ethernet-A12.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/dts-v1/;
/plugin/;
/ {
compatible = "starfive,visionfive-v2", "starfive,jh7110";
fragment@0 {
target-path = "/soc/ethernet@16030000/ethernet-phy@0";
__overlay__ {
tx_delay_sel = <0x9>;
tx_inverted_10 = <0x0>;
tx_inverted_100 = <0x0>;
tx_inverted_1000 = <0x0>;
};
};
fragment@1 {
target-path = "/soc/ethernet@16040000/ethernet-phy@1";
__overlay__ {
tx_delay_sel = <0x9>;
tx_inverted_10 = <0x0>;
tx_inverted_100 = <0x0>;
tx_inverted_1000 = <0x0>;
};
};
};
3 changes: 3 additions & 0 deletions linux-image-visionfive2/DEBIAN/conffiles
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/boot/extlinux/extlinux.conf
/etc/fw_env.config
/etc/u-boot-initial-env
13 changes: 13 additions & 0 deletions linux-image-visionfive2/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Package: linux-image-visionfive2
Version: VERSION
Architecture: riscv64
Maintainer: MichaIng <[email protected]>
Date: DATE
Standards-Version: 4.6.2.0
Installed-Size: SIZE
Section: kernel
Priority: optional
Homepage: https://github.com/MichaIng/linux
Vcs-Git: https://github.com/MichaIng/linux.git
Vcs-Browser: https://github.com/MichaIng/linux
Description: Linux kernel for RISC-V StarFive VisionFive 2
6 changes: 6 additions & 0 deletions linux-image-visionfive2/DEBIAN/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/dash
set -e
export DEB_MAINT_PARAMS=$* INITRD=Yes
[ -d '/etc/kernel/postinst.d' ] && run-parts --arg='VERSION' --arg='VERSION' /etc/kernel/postinst.d
sed -Ei '/^[[:blank:]]*(linux|kernel)/c\linux /boot/vmlinuz-VERSION' /boot/extlinux/extlinux.conf
exit 0
5 changes: 5 additions & 0 deletions linux-image-visionfive2/DEBIAN/postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/dash
set -e
export DEB_MAINT_PARAMS=$* INITRD=Yes
[ -d '/etc/kernel/postrm.d' ] && run-parts --arg='VERSION' --arg='VERSION' /etc/kernel/postrm.d
exit 0
5 changes: 5 additions & 0 deletions linux-image-visionfive2/DEBIAN/preinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/dash
set -e
export DEB_MAINT_PARAMS=$* INITRD=Yes
[ -d '/etc/kernel/preinst.d' ] && run-parts --arg='VERSION' --arg='VERSION' /etc/kernel/preinst.d
exit 0
5 changes: 5 additions & 0 deletions linux-image-visionfive2/DEBIAN/prerm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/dash
set -e
export DEB_MAINT_PARAMS=$* INITRD=Yes
[ -d '/etc/kernel/prerm.d' ] && run-parts --arg='VERSION' --arg='VERSION' /etc/kernel/prerm.d
exit 0
4 changes: 4 additions & 0 deletions linux-image-visionfive2/boot/extlinux/extlinux.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
label DietPi
linux /boot/vmlinuz-VERSION
fdt /usr/lib/linux-image-visionfive2/starfive/jh7110-visionfive-v2.dtb
append root=/dev/mmcblk1p1 rootfstype=ext4 rootwait earlycon=sbi console=ttyS0,115200 console=tty1 consoleblank=0 net.ifnames=0
1 change: 1 addition & 0 deletions linux-image-visionfive2/etc/fw_env.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dev/mtd1 0x00000 0x10000 0x10000
76 changes: 76 additions & 0 deletions linux-image-visionfive2/etc/u-boot-initial-env
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
kernel_addr_r=0x40200000
scriptaddr=0x43900000
pxefile_addr_r=0x45900000
fdt_addr_r=0x46000000
ramdisk_addr_r=0x46100000
fdtoverlay_addr_r=0x4f000000
kernel_comp_addr_r=0x5a000000
kernel_comp_size=0x4000000
uboot_fdt_addr=0xf7facc50
fdt_high=0xffffffffffffffff
initrd_high=0xffffffffffffffff

memory_addr=40000000
fdtcontroladdr=f7facc50

boot_prefixes=/ /boot/
boot_scripts=boot.scr.uimg boot.scr
efi_dtb_prefixes=/ /dtb/ /dtb/current/
fdtfile=starfive/jh7110-visionfive-v2.dtb
ipaddr=192.168.120.230

preboot=run chipa_set_uboot
chipa_set_uboot=fdt addr "${uboot_fdt_addr}"; run chipa_set
chipa_set=if test "${chip_vision}" = A; then echo 'VisionFive 2 revision A detected, updating device tree for Ethernet access ...'; run chipa_gmac_set; fi
chipa_gmac_set=fdt set /soc/ethernet@16030000/ethernet-phy@0 tx_inverted_10 <0x0>; fdt set /soc/ethernet@16030000/ethernet-phy@0 tx_inverted_100 <0x0>; fdt set /soc/ethernet@16030000/ethernet-phy@0 tx_inverted_1000 <0x0>; fdt set /soc/ethernet@16030000/ethernet-phy@0 tx_delay_sel <0x9>; fdt set /soc/ethernet@16040000/ethernet-phy@1 tx_inverted_10 <0x0>; fdt set /soc/ethernet@16040000/ethernet-phy@1 tx_inverted_100 <0x0>; fdt set /soc/ethernet@16040000/ethernet-phy@1 tx_inverted_1000 <0x0>; fdt set /soc/ethernet@16040000/ethernet-phy@1 tx_delay_sel <0x9>

bootcmd=setenv devnum; run fdt_rewrite; run distro_bootcmd
fdt_rewrite=for bootdev in mmc nvme; do if test "${bootdev}" = 'mmc'; then for devnum in 0 1; do run fdt_loaddtb; done; else devnum=0; pci enum; nvme scan; run fdt_loaddtb; fi; done
fdt_loaddtb=echo "Trying to load device tree from ${bootdev}${devnum} partition 3 ..."; if fatload "${bootdev}" "${devnum}:3" "${fdt_addr_r}" "/dtbs/${fdtfile}"; then fdt addr "${fdt_addr_r}"; run fdt_sizecheck; run set_fdt_distro; fi
fdt_sizecheck=fatsize "${bootdev}" "${devnum}:3" "/dtbs/${fdtfile}"
set_fdt_distro=echo "Updating device tree /dtbs/${fdtfile} on ${bootdev}${devnum} partition 3 ..."; run chipa_set_linux; run cpu_vol_set; fatwrite "${bootdev}" "${devnum}:3" "${fdt_addr_r}" "/dtbs/${fdtfile}" "${filesize}"

chipa_set_linux=run visionfive2_mem_set; run chipa_set
visionfive2_mem_set=fdt memory "${memory_addr}" "${memory_size}"; run cma_resize
cma_resize=if test "${memory_size}" -eq 40000000; then run cma_ddr1g_set; elif test "${memory_size}" -eq 80000000; then run cma_ddr2g_set; elif test "${memory_size}" -eq 100000000; then run cma_ddr4g_set; elif test "${memory_size}" -ge 200000000; then run cma_ddr8g_set; fi
cma_ddr1g_set=echo 'Updating device tree for 1 GiB RAM size ...'; fdt set "${cma_node}" size "<0x0 0x${cma_1g}>"; fdt set "${cma_node}" alloc-ranges "<0x0 0x${cma_start} 0x0 0x${cma_1g}>"
cma_ddr2g_set=echo 'Updating device tree for 2 GiB RAM size ...'; fdt set "${cma_node}" size "<0x0 0x${cma_2g}>"; fdt set "${cma_node}" alloc-ranges "<0x0 0x${cma_start} 0x0 0x${cma_2g}>"
cma_ddr4g_set=echo 'Updating device tree for 4 GiB RAM size ...'; fdt set "${cma_node}" size "<0x0 0x${cma_4g}>"; fdt set "${cma_node}" alloc-ranges "<0x0 0x${cma_start} 0x0 0x${cma_4g}>"
cma_ddr8g_set=echo 'Updating device tree for 8 GiB RAM size ...'; fdt set "${cma_node}" size "<0x0 0x${cma_8g}>"; fdt set "${cma_node}" alloc-ranges "<0x0 0x${cma_start} 0x0 0x${cma_8g}>"
cma_node=/reserved-memory/linux,cma
cma_1g=b000000
cma_2g=20000000
cma_4g=40000000
cma_8g=60000000
cma_start=70000000

cpu_vol_set=if test "${cpu_max_vol}" = 1000000; then run cpu_speed_1250_set; else run cpu_speed_1500_set; if test "${cpu_max_vol}" = 1060000; then run cpu_vol_1060_set; elif test "${cpu_max_vol}" = 1020000; then run cpu_vol_1020_set; else run cpu_vol_1040_set; fi; fi
cpu_speed_1250_set=echo 'Updating device tree for 1250 MHz CPU speed ...'; fdt rm /opp-table-0/opp-375000000; fdt rm /opp-table-0/opp-500000000; fdt rm /opp-table-0/opp-750000000; fdt rm /opp-table-0/opp-1500000000
cpu_speed_1500_set=echo 'Updating device tree for 1500 MHz CPU speed ...'; fdt rm /opp-table-0/opp-312500000; fdt rm /opp-table-0/opp-417000000; fdt rm /opp-table-0/opp-625000000; fdt rm /opp-table-0/opp-1250000000
cpu_vol_1020_set=echo 'Updating device tree for 1.02V CPU voltage ...'; fdt set /opp-table-0/opp-1500000000 opp-microvolt <1020000>
cpu_vol_1040_set=echo 'Updating device tree for 1.04V CPU voltage ...'; fdt set /opp-table-0/opp-1500000000 opp-microvolt <1040000>
cpu_vol_1060_set=echo 'Updating device tree for 1.06V CPU voltage ...'; fdt set /opp-table-0/opp-1500000000 opp-microvolt <1060000>

distro_bootcmd=for target in "${boot_targets}"; do echo "Trying to boot from ${target} ..."; run "bootcmd_${target}"; done
boot_targets=mmc1 usb0 nvme0 mmc0 dhcp
bootcmd_mmc1=devnum=1; run mmc_boot
bootcmd_usb0=devnum=0; run usb_boot
bootcmd_nvme0=devnum=0; run nvme_boot
bootcmd_mmc0=devnum=0; run mmc_boot
bootcmd_dhcp=devtype=dhcp; usb start; pci enum; if dhcp "${scriptaddr}" boot.scr.uimg; then source "${scriptaddr}"; fi; setenv efi_fdtfile "${fdtfile}"; setenv efi_old_vci "${bootp_vci}"; setenv efi_old_arch "${bootp_arch}"; setenv bootp_vci PXEClient:Arch:00027:UNDI:003000; setenv bootp_arch 0x1b; if dhcp "${kernel_addr_r}"; then tftpboot "${fdt_addr_r}" "dtb/${efi_fdtfile}"; if fdt addr "${fdt_addr_r}"; then bootefi "${kernel_addr_r}" "${fdt_addr_r}"; else bootefi "${kernel_addr_r}" "${fdtcontroladdr}"; fi; fi; setenv bootp_vci "${efi_old_vci}"; setenv bootp_arch "${efi_old_arch}"; setenv efi_fdtfile; setenv efi_old_arch; setenv efi_old_vci

mmc_boot=if mmc dev "${devnum}"; then devtype=mmc; run scan_dev_for_boot_part; fi
usb_boot=pci enum; usb reset; usb start; if usb dev "${devnum}"; then devtype=usb; run scan_dev_for_boot_part; fi
nvme_boot=pci enum; nvme scan; if nvme dev "${devnum}"; then devtype=nvme; run scan_dev_for_boot_part; fi

scan_dev_for_boot_part=part list "${devtype}" "${devnum}" -bootable devplist; env exists devplist || setenv devplist 1; for distro_bootpart in ${devplist}; do if fstype "${devtype}" "${devnum}:${distro_bootpart}" bootfstype; then run scan_dev_for_boot; fi; done; setenv devplist
scan_dev_for_boot=echo "Scanning ${devtype} ${devnum}:${distro_bootpart} ..."; for prefix in ${boot_prefixes}; do run scan_dev_for_extlinux; run scan_dev_for_scripts; done; run scan_dev_for_efi
scan_dev_for_extlinux=if test -e "${devtype}" "${devnum}:${distro_bootpart}" "${prefix}extlinux/extlinux.conf"; then echo "Found ${prefix}extlinux/extlinux.conf"; run boot_extlinux; echo 'SCRIPT FAILED: continuing ...'; fi
scan_dev_for_scripts=for script in ${boot_scripts}; do if test -e "${devtype}" "${devnum}:${distro_bootpart}" "${prefix}${script}"; then echo "Found U-Boot script ${prefix}${script}"; run boot_a_script; echo 'SCRIPT FAILED: continuing ...'; fi; done
scan_dev_for_efi=setenv efi_fdtfile "${fdtfile}"; for prefix in "${efi_dtb_prefixes}"; do if test -e "${devtype}" "${devnum}:${distro_bootpart}" "${prefix}${efi_fdtfile}"; then run load_efi_dtb; fi; done; run boot_efi_bootmgr; if test -e "${devtype}" "${devnum}:${distro_bootpart}" efi/boot/bootriscv64.efi; then echo 'Found EFI removable media binary efi/boot/bootriscv64.efi'; run boot_efi_binary; echo 'EFI LOAD FAILED: continuing ...'; fi; setenv efi_fdtfile

boot_extlinux=sysboot "${devtype}" "${devnum}:${distro_bootpart}" any "${scriptaddr}" "${prefix}extlinux/extlinux.conf"
boot_a_script=load "${devtype}" "${devnum}:${distro_bootpart}" "${scriptaddr}" "${prefix}${script}"; source "${scriptaddr}"
load_efi_dtb=load "${devtype}" "${devnum}:${distro_bootpart}" "${fdt_addr_r}" "${prefix}${efi_fdtfile}"
boot_efi_bootmgr=if fdt addr "${fdt_addr_r}"; then bootefi bootmgr "${fdt_addr_r}"; else bootefi bootmgr; fi
boot_efi_binary=load "${devtype}" "${devnum}:${distro_bootpart}" "${kernel_addr_r}" efi/boot/bootriscv64.efi; if fdt addr "${fdt_addr_r}"; then bootefi "${kernel_addr_r}" "${fdt_addr_r}"; else bootefi "${kernel_addr_r}" "${fdtcontroladdr}"; fi

0 comments on commit 53e32c3

Please sign in to comment.