Github Actions to build images. WIP as we need to update the kernel

This commit is contained in:
Justin Hammond 2023-01-17 19:01:47 +08:00
parent 4536b58e26
commit 16de777ed7
7 changed files with 465 additions and 1 deletions

223
.github/workflows/buildroot.yml vendored Normal file
View file

@ -0,0 +1,223 @@
name: build-all
on:
workflow_dispatch:
push:
branches: [ main ]
paths-ignore:
- '.github/**'
tags:
- "v*.*.*"
pull_request:
branches: [ main ]
paths-ignore:
- '.github/**'
jobs:
buildroot:
strategy:
fail-fast: true
matrix:
target: [ pine64_ox64_defconfig, pine64_ox64_full_defconfig ]
runs-on: ubuntu-22.04
steps:
- name: install dependencies
run: |
sudo apt-get install -y make gcc g++ unzip git bc python3 device-tree-compiler mtd-utils xz-utils
- name: Checkout Buildroot sources
uses: actions/checkout@v3
with:
repository: buildroot/buildroot
ref: 2022.08.3
path: buildroot
- name: Checkout OpenBouffalo Buildroot
uses: actions/checkout@v3
with:
path: buildroot_bouffalo
- name: buildroot target cache
id: br-output-cache
uses: actions/cache@v3
env:
cache-name: br-output-cache
with:
path: ${{ github.workspace }}/buildroot/output/images/
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.target }}-${{ hashFiles(format('buildroot_bouffalo/configs/{0}', matrix.target), 'buildroot_bouffalo/board/pine64/ox64/**', 'buildroot_bouffalo/packages/**') }}
- name: buildroot download cache
if: steps.br-output-cache.outputs.cache-hit != 'true'
uses: actions/cache@v3
env:
cache-name: cache-download-files
with:
path: ${{ github.workspace }}/buildroot/dl/
key: ${{ runner.os }}-build-${{ env.cache-name }}-downloads
- name: Bulid
if: steps.br-output-cache.outputs.cache-hit != 'true'
run: |
export BR_BOUFFALO_OVERLAY_PATH=$(pwd)/buildroot_bouffalo
cd buildroot
make BR2_EXTERNAL=$BR_BOUFFALO_OVERLAY_PATH ${{ matrix.target }}
make
- name: Pack
run: |
cd ${{ github.workspace }}/buildroot/output/images/
ls -lah
if [ -f sdcard.img ]; then
xz -z sdcard.img
mv sdcard.img.xz sdcard-${{ matrix.target }}.img.xz
fi
if [ -f Image ]; then
mv Image Image-${{ matrix.target }}
fi
echo "PACKAGE=${{ github.workspace }}/buildroot/output/images/sdcard-${{ matrix.target }}.img.xz" >> $GITHUB_ENV
echo "KERNEL=${{ github.workspace }}/buildroot/output/images/Image-${{ matrix.target }}" >> $GITHUB_ENV
- name: Upload package
uses: actions/upload-artifact@master
with:
name: build artifacts
path: |
${{env.PACKAGE}}
${{env.KERNEL}}
lowload:
runs-on: ubuntu-22.04
if: github.event_name != 'pull_request'
steps:
- name: install dependencies
run: |
sudo apt-get install -y make gcc g++ cmake
- name: Checkout bl_mcu_sdk
uses: actions/checkout@v3
with:
repository: bouffalolab/bl_mcu_sdk
path: bl_mcu_sdk
- name: Checkout OpenBouffalo Firmware Repository
uses: actions/checkout@v3
with:
repository: openbouffalo/OBLFR
path: oblfr
- name: toolchain download cache
id: toolchain-cache
uses: actions/cache@v3
env:
cache-name: cache-toolchain-files
with:
path: ${{ github.workspace }}/toolchain_gcc_t-head_linux/
key: ${{ runner.os }}-build-${{ env.cache-name }}
- name: Download Toolchain
if: steps.toolchain-cache.outputs.cache-hit != 'true'
run: |
git clone https://gitee.com/bouffalolab/toolchain_gcc_t-head_linux.git
- name: Compile Firmware
run: |
PATH=$PATH:${{ github.workspace }}/toolchain_gcc_t-head_linux/bin/
cd ${{ github.workspace }}/oblfr/apps/d0_lowload
make
echo "D0LOWLOAD=${{ github.workspace }}/oblfr/apps/d0_lowload/build/build_out/d0_lowload_bl808_d0.bin" >> $GITHUB_ENV
cd ${{ github.workspace }}/oblfr/apps/m0_lowload
make
echo "M0LOWLOAD=${{ github.workspace }}/oblfr/apps/m0_lowload/build/build_out/m0_lowload_bl808_m0.bin" >> $GITHUB_ENV
- name: Upload Firmware
uses: actions/upload-artifact@master
with:
name: build artifacts
path: |
${{env.D0LOWLOAD}}
${{env.M0LOWLOAD}}
opensbi:
runs-on: ubuntu-22.04
if: github.event_name != 'pull_request'
steps:
- name: install dependencies
run: |
sudo apt-get install -y make gcc g++ cmake
- name: Checkout bl808_linux
uses: actions/checkout@v3
with:
repository: bouffalolab/bl808_linux
path: bl808_linux
- name: toolchain download cache
id: toolchain-cache
uses: actions/cache@v3
env:
cache-name: cache-toolchain-files
with:
path: ${{ github.workspace }}/bl808_linux/toolchain/
key: ${{ runner.os }}-build-${{ env.cache-name }}
- name: Download Toolchain
if: steps.toolchain-cache.outputs.cache-hit != 'true'
run: |
cd ${{ github.workspace }}/bl808_linux
mkdir -p toolchain/elf_newlib_toolchain toolchain/linux_toolchain
curl https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/resource//1663142243961/Xuantie-900-gcc-elf-newlib-x86_64-V2.6.1-20220906.tar.gz | tar xz -C toolchain/elf_newlib_toolchain/ --strip-components=1
curl https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/resource//1663142514282/Xuantie-900-gcc-linux-5.10.4-glibc-x86_64-V2.6.1-20220906.tar.gz | tar xz -C toolchain/linux_toolchain/ --strip-components=1
- name: Compile OpenSBI
run: |
cd ${{ github.workspace }}/bl808_linux
./switch_to_m1sdock.sh
./build.sh opensbi
echo "OPENSBI=${{ github.workspace }}/bl808_linux/out/fw_jump.bin" >> $GITHUB_ENV
- name: Upload OpenSBI
uses: actions/upload-artifact@master
with:
name: build artifacts
path: |
${{env.OPENSBI}}
createimages:
if: github.event_name != 'pull_request'
strategy:
fail-fast: true
matrix:
target: [ pine64_ox64_defconfig, pine64_ox64_full_defconfig ]
runs-on: ubuntu-22.04
needs: [buildroot, lowload, opensbi]
steps:
- name: install dependencies
run: |
sudo apt-get install -y python3 lz4
- name: Checkout OpenBouffalo Buildroot
uses: actions/checkout@v3
with:
path: buildroot_bouffalo
- name: Download build files
uses: actions/download-artifact@v3
with:
name: build artifacts
path: ${{ github.workspace }}/build
- name: Create images
run: |
cd ${{ github.workspace }}/build
lz4 -9 -f Image-${{ matrix.target }} Image.lz4
cp ${{ github.workspace }}/buildroot_bouffalo/board/pine64/ox64/bl808-pine64-ox64.dtb .
${{ github.workspace }}/buildroot_bouffalo/package/mergebin/mergebin.py
mkdir firmware
cp d0_lowload/build/build_out/*.bin firmware/
cp m0_lowload/build/build_out/*.bin firmware/
cp whole_img_linux.bin firmware/
cp sdcard-${{ matrix.target }}.img.xz firmware/
tar -czvf bl808-linux-${{ matrix.target }}.tar.gz firmware
echo "FIRMWARE=${{ github.workspace }}/build/bl808-linux-${{ matrix.target }}.tar.gz" >> $GITHUB_ENV
- name: Upload Firmware
uses: actions/upload-artifact@master
with:
name: linux-buildroot-${{ matrix.target }}
path: |
${{env.FIRMWARE}}
release:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-22.04
needs: [createimages]
permissions: write-all
steps:
- name: download firmware
uses: actions/download-artifact@v3
- name: Create images
run: |
ls -lah
ls -lah linux-buildroot-*/*.tar.gz
- name: publish artifacts
uses: softprops/action-gh-release@v1
with:
append_body: true
files: |
linux-buildroot-*/*.tar.gz

View file

@ -9,4 +9,41 @@ git clone https://github.com/openbouffalo/buildroot_bouffalo
export BR_BOUFFALO_OVERLAY_PATH=$(pwd)/buildroot_bouffalo
cd buildroot
make BR2_EXTERNAL=$BR_BOUFFALO_OVERLAY_PATH pine64_ox64_defconfig
```
make
```
## Prebuilt images
Prebuilt images are available on the releases page (for tested images) or development images are available via the github actions page
Two images are currently build - A minimal image - `sdcard-pine64_0x64_defconfig` and a more complete image - `sdcard-pine64_0x64_full_defconfig`
The SD card images are configured with a 1Gb Swap Partition, and will resize the rootfs partition on first boot to the full size of the SD card.
### Development images
Latest Development Build Result:
[![Build](https://github.com/openbouffalo/buildroot_bouffalo/actions/workflows/buildroot.yml/badge.svg)](https://github.com/openbouffalo/buildroot_bouffalo/actions/workflows/buildroot.yml)
### Released images
Released Images are [Here](https://github.com/openbouffalo/buildroot_bouffalo/releases/latest)
## Flashing Instructions
Download your prefered image above and extract the files.
- Get the latest version of DevCube from http://dev.bouffalolab.com/download
- Connect BL808 board via serial port to your PC
- Set BL808 board to programming mode
+ Press BOOT button when reseting or applying power
+ Release BOOT button
- Run DevCube, select [BL808], and switch to [MCU] page
- Select the uart port and set baudrate with 2000000
- M0 Group[Group0] Image Addr [0x58000000] [PATH to m0_low_load_bl808_m0.bin]
- D0 Group[Group1] Image Addr [0x58000000] [PATH to d0_low_load_bl808_d0.bin]
- Click 'Create & Download' and wait until it's done
- Switch to [IOT] page
- Enable 'Single Download', set Address with 0xD2000, choose [PATH to whole_image_linux.bin]
- Click 'Create & Download' again and wait until it's done
- flash the sdcard-pine64-*.img.xz to your SD card (you can use dd (after uncompressing) or https://github.com/balena-io/etcher)
- Enjoy!

Binary file not shown.

View file

@ -0,0 +1,60 @@
// SPDX-License-Identifier: (GPL-2.0+ or MIT)
/*
* Copyright (C) 2022 Jisheng Zhang <jszhang@kernel.org>
*/
/dts-v1/;
#include "bl808.dtsi"
/ {
model = "Pine64 Ox64";
compatible = "sipeed,m1s", "bouffalolab,bl808";
aliases {
serial0 = &uart0;
serial1 = &uart1;
};
chosen {
stdout-path = "serial0:2000000n8";
bootargs = "console=ttyS0,2000000 loglevel=8 earlycon=sbi root=/dev/mmcblk0p2 rootwait rootfstype=ext4";
linux,initrd-start = <0x0 0x52000000>;
linux,initrd-end = <0x0 0x52941784>;
};
memory@50000000 {
device_type = "memory";
reg = <0x50000000 0x04000000>;
};
xip_flash@58500000 {
compatible = "mtd-rom";
reg = <0x58500000 0x400000>;
linux,mtd-name = "xip-flash.0";
erase-size = <0x10000>;
bank-width = <4>;
/*rootfs@0 {
label = "rootfs";
reg = <0x00000 0x400000>;
read-only;
};*/
};
};
&uart0 {
status = "okay";
};
&uart1 {
status = "okay";
};
&sdhci0 {
status = "okay";
};
&ipclic {
status = "okay";
};

View file

@ -0,0 +1,45 @@
BR2_riscv=y
BR2_riscv_custom=y
BR2_RISCV_ISA_CUSTOM_RVM=y
BR2_RISCV_ISA_CUSTOM_RVF=y
BR2_RISCV_ISA_CUSTOM_RVC=y
BR2_RISCV_ABI_LP64=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y
BR2_TOOLCHAIN_EXTERNAL_URL="https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/resource//1663142514282/Xuantie-900-gcc-linux-5.10.4-glibc-x86_64-V2.6.1-20220906.tar.gz"
BR2_TOOLCHAIN_EXTERNAL_CUSTOM_PREFIX="riscv64-unknown-linux-gnu"
BR2_TOOLCHAIN_EXTERNAL_GCC_10=y
BR2_TOOLCHAIN_EXTERNAL_HEADERS_5_10=y
BR2_TOOLCHAIN_EXTERNAL_CUSTOM_GLIBC=y
# BR2_TOOLCHAIN_EXTERNAL_INET_RPC is not set
BR2_TOOLCHAIN_EXTERNAL_CXX=y
BR2_CPAN_MIRROR="http://cpan.metacpan.org"
BR2_GLOBAL_PATCH_DIR="$(BR2_EXTERNAL_BOUFFALO_BR_PATH)/board/pine64/ox64/patches/"
BR2_TARGET_GENERIC_HOSTNAME="ox64"
BR2_ROOTFS_OVERLAY="$(BR2_EXTERNAL_BOUFFALO_BR_PATH)/board/pine64/ox64/rootfs-overlay"
BR2_ROOTFS_POST_IMAGE_SCRIPT="support/scripts/genimage.sh"
BR2_ROOTFS_POST_SCRIPT_ARGS="-c $(BR2_EXTERNAL_BOUFFALO_BR_PATH)/board/pine64/ox64/genimage.cfg"
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_CUSTOM_VERSION=y
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="v6.2-rc2"
BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="$(BR2_EXTERNAL_BOUFFALO_BR_PATH)/board/pine64/ox64/linux_defconfig"
BR2_LINUX_KERNEL_LZ4=y
BR2_LINUX_KERNEL_DTS_SUPPORT=y
BR2_LINUX_KERNEL_DTB_IS_SELF_BUILT=y
BR2_LINUX_KERNEL_INTREE_DTS_NAME="bouffalolab/bl808-sipeed-m1s.dts"
BR2_PACKAGE_E2FSPROGS_RESIZE2FS=y
BR2_PACKAGE_E2TOOLS=y
BR2_PACKAGE_GPTFDISK=y
BR2_PACKAGE_GPTFDISK_SGDISK=y
BR2_PACKAGE_LSHW=y
BR2_PACKAGE_PARTED=y
BR2_PACKAGE_PICOCOM=y
BR2_PACKAGE_UTIL_LINUX_PARTX=y
BR2_TARGET_ROOTFS_EXT2=y
BR2_TARGET_ROOTFS_EXT2_4=y
BR2_TARGET_ROOTFS_EXT2_SIZE="512M"
# BR2_TARGET_ROOTFS_TAR is not set
BR2_PACKAGE_HOST_GENIMAGE=y
BR2_PACKAGE_HOST_MTOOLS=y
BR2_PACKAGE_CLOUDUTILS=y

View file

@ -0,0 +1,3 @@
Script used to merge the Kernel, DTB, and OpenSBI Binaries into a single binary file.
TODO: Automate this in buildroot when we integrate OpenSBI and low_load functions

96
package/mergebin/mergebin.py Executable file
View file

@ -0,0 +1,96 @@
#!/bin/python3
# Description: Merge the Kernel, DTB, and OpenSBI into a single binary
# From @BBBSnowball
import struct
from math import inf
kB = 1024
MB = 1024*1024
def format_size(x):
if (x % MB) == 0:
return "%d MB" % (x/MB)
elif (x % kB) == 0:
return "%d kB" % (x/kB)
else:
return "%d bytes" % x
class FlashRegion(object):
def __init__(self, from_file, flash_offset, load_address, max_size=inf):
self.from_file = from_file
self.flash_offset = flash_offset
self.load_address = load_address
self.max_size = max_size
def read(self):
if self.from_file is None:
self.data = b""
else:
with open(self.from_file, 'rb') as f:
self.data = f.read()
class FlashRegions(object):
def __init__(self, flash_size):
self.flash_size = flash_size
self.regions = {}
def add(self, name, *args, **kwargs):
v = FlashRegion(*args, **kwargs)
self.regions[name] = v
setattr(self, name, v)
def read(self):
for k,v in self.regions.items():
v.read()
def check(self):
# reduce max_size based on where the next item starts in flash
next_start = self.flash_size
for region in sorted(self.regions.values(), key=lambda x: x.flash_offset, reverse=True):
#print("DEBUG: offset=%08x, next=%08x, diff=%08x" % (region.flash_offset, next_start, next_start - region.flash_offset))
region.max_size = min(region.max_size, next_start - region.flash_offset)
next_start = region.flash_offset
for k,v in self.regions.items():
currsz = len(v.data)
maxsz = v.max_size
print("%-18s %8d (%3d %%, max %7s)" % (k + " size:", currsz, 100*currsz/maxsz, format_size(maxsz)))
#if len(v.data) > v.max_size:
# raise Exception("Region %s is too big: %d > %d" % (k, currsz, maxsz))
def collect_data(self):
data = bytearray(b'\xff' * self.flash_size)
for k,v in self.regions.items():
data[v.flash_offset:v.flash_offset+len(v.data)] = v.data
return data
whole_img_base = 0xD2000
def make_regions():
regions = FlashRegions(8*MB)
#NOTE There are additional size requirements, which are checked by the linker scripts for low_load.
#regions.add("low_load_m0", "low_load_bl808_m0.bin", 0x00002000, 0x58000000)
#regions.add("low_load_d0", "low_load_bl808_d0.bin", 0x00052000, 0x58000000) # same load address because it will be "loaded" by XIP mapping
regions.add("dtb", "bl808-pine64-ox64.dtb", whole_img_base, 0x51ff8000)
regions.add("opensbi", "fw_jump.bin", whole_img_base+0x10000, 0x3eff0000, max_size=0xc800) # only with patched low_load_d0; otherwise, 0xc000
regions.add("linux", "Image.lz4", whole_img_base+0x20000, 0x50000000)
regions.add("linux_header", None, regions.linux.flash_offset - 8, 0)
return regions
if __name__ == '__main__':
regions = make_regions()
regions.read()
# old script was adding a zero byte to the dtb so let's do the same
# -> actually, let's skip that because it was adding a zero byte to everything.
#regions.dtb.data += b'\0'
# add header to Linux image (TODO: what does it do? is this for LZ4?)
regions.linux_header.data = b'\0\0\0\x50' + struct.pack('<I', len(regions.linux.data))
regions.check()
flash_data = regions.collect_data()
flash_data = flash_data[whole_img_base:] # low_load_* is programmed with BLDevCube; we start at dtb
with open("whole_img_linux.bin", "wb+") as f:
f.write(flash_data)