Skip to main content

Download and Build

开发环境

硬件配置

推荐配置:

  • CPU:12th Gen Intel(R) Core(TM) i5或以上
  • Memory:16GB或以上
  • Disk:SSD,256GB或以上

操作系统

推荐Ubuntu 20.04或更新LTS版本,其他Linux发行版本没有测试。

安装依赖

Ubuntu 16.04 and 18.04:

sudo apt-get install git build-essential cpio unzip rsync file bc wget python3 libncurses5-dev libssl-dev dosfstools mtools u-boot-tools flex bison python3-pip
sudo pip3 install pyyaml

Ubuntu 20.04 or higher:

sudo apt-get install git build-essential cpio unzip rsync file bc wget python3 python-is-python3 libncurses5-dev libssl-dev dosfstools mtools u-boot-tools flex bison python3-pip
sudo pip3 install pyyaml

下载

使用repo(版本 >= 2.41)下载完整SDK。如果没有repo,参考Git Repo 镜像使用帮助安装。

Bianbu Linux代码托管在Gitee上,下载前先参考这篇文档设置SSH Keys。

下载代码,例如下载bl-v1.0.y分支:

mkdir ~/bianbu-linux
cd ~/bianbu-linux
repo init -u git@gitee.com:bianbu-linux/manifests.git -b main -m bl-v1.0.y.xml
repo sync
repo start bl-v1.0.y --all

推荐提前下载buildroot依赖的第三方软件包,并在团队内部分发,避免主服务器网络拥塞。

wget -c -r -nv -np -nH -R "index.html*" http://archive.spacemit.com/buildroot/dl

目录结构:

├── bsp-src               # 存放linux kernel、uboot、opensbi源码
│ ├── linux-6.1
│ ├── opensbi
│ └── uboot-2022.10
├── buildroot # buildroot主目录
├── buildroot-ext # 客制化扩展,包含board、configs、package、patches子目录
├── Makefile # 顶层Makefile
├── package-src # 本地展开的应用或库源码目录
│ ├── ai-support
│ ├── drm-test
│ ├── img-gpu-powervr
│ ├── k1x-cam
│ ├── k1x-jpu
│ ├── k1x-vpu-firmware
│ ├── k1x-vpu-test
│ ├── mesa3d
│ ├── mpp
│ └── v2d-test
└── scripts # 编译使用到的脚本

交叉编译

首次完整编译

首次编译,建议使用make envconfig完整编译。修改了buildroot-ext/configs/spacemit_k1_defconfig,要使用make envconfig编译。其他情况,使用make编译即可。

cd ~/bianbu-linux
make envconfig
Available configs in buildroot-ext/configs/:
1. spacemit_k1_defconfig
2. spacemit_k1_minimal_defconfig
3. spacemit_k1_plt_defconfig


your choice (1-3):

输入1,然后回车即开始编译。

编译过程可能需要下载一些第三方软件包,具体耗时和网络环境相关。如果提前下载buildroot依赖的第三方软件包,推荐硬件配置编译耗时约为1小时。

编译完成,可以看到:

Images successfully packed into /home/username/bianbu-linux/output/k1/images/bianbu-linux-k1.zip


Generating sdcard.img...................................
INFO: cmd: "mkdir -p "/home/username/bianbu-linux/output/k1/build/genimage.tmp"" (stderr):
INFO: cmd: "rm -rf "/home/username/bianbu-linux/output/k1/build/genimage.tmp"/*" (stderr):
INFO: cmd: "mkdir -p "/home/username/bianbu-linux/output/k1/images"" (stderr):
INFO: hdimage(sdcard.img): adding partition 'bootinfo' from 'factory/bootinfo_sd.bin' ...
INFO: hdimage(sdcard.img): adding partition 'fsbl' (in MBR) from 'factory/FSBL.bin' ...
INFO: hdimage(sdcard.img): adding partition 'env' (in MBR) from 'env.bin' ...
INFO: hdimage(sdcard.img): adding partition 'opensbi' (in MBR) from 'opensbi.itb' ...
INFO: hdimage(sdcard.img): adding partition 'uboot' (in MBR) from 'u-boot.itb' ...
INFO: hdimage(sdcard.img): adding partition 'bootfs' (in MBR) from 'bootfs.img' ...
INFO: hdimage(sdcard.img): adding partition 'rootfs' (in MBR) from 'rootfs.ext4' ...
INFO: hdimage(sdcard.img): adding partition '[MBR]' ...
INFO: hdimage(sdcard.img): adding partition '[GPT header]' ...
INFO: hdimage(sdcard.img): adding partition '[GPT array]' ...
INFO: hdimage(sdcard.img): adding partition '[GPT backup]' ...
INFO: hdimage(sdcard.img): writing GPT
INFO: hdimage(sdcard.img): writing protective MBR
INFO: hdimage(sdcard.img): writing MBR
Successfully generated at /home/username/work/bianbu-linux/output/k1/images/bianbu-linux-k1-sdcard.img

其中bianbu-linux-k1.zip适用于Titan Flasher,或者解压后用fastboot刷机;bianbu-linux-k1-sdcard.img为sdcard固件,解压后可以用dd命令或者balenaEtcher写入sdcard。

Titan Flasher使用指南:刷机工具使用指南

固件默认用户名:root,v1.0alpha2版本的密码:spacemit,v1.0beta3.1和之后版本的密码:bianbu

配置

buildroot

配置:

make menuconfig

保存配置,默认保存到buildroot-ext/configs/spacemit_k1_defconfig

make savedefconfig

linux

配置:

make linux-menuconfig

保存配置,默认保存到bsp-src/linux-6.1/arch/riscv/configs/k1_defconfig

make linux-update-defconfig

u-boot

配置:

make uboot-menuconfig

保存配置,默认保存到bsp-src/uboot-2022.10/configs/k1_defconfig

make uboot-update-defconfig

编译指定包

buildroot支持编译指定package,可以make help查看指南。

常用命令:

  • 删除<pkg>的编译目录:make <pkg>-dirclean
  • 编译<pkg>make <pkg>

编译内核:

make linux-rebuild

编译u-boot:

make uboot-rebuild

编译指定包之后,可以单独下载到设备验证,或者编进固件:

make

单独编译

交叉编译器下载地址:http://archive.spacemit.com/toolchain/,解压即可使用。

设置环境变量:

export PATH=/path/to/spacemit-toolchain-linux-glibc-x86_64-v0.3.3/bin:$PATH
export CROSS_COMPILE=riscv64-unknown-linux-gnu-
export ARCH=riscv

编译opensbi

cd /path/to/opensbi
make -j$(nproc) PLATFORM_DEFCONFIG=k1_defconfig PLATFORM=generic

编译u-boot

cd /path/to/uboot-2022.10
make k1_defconfig
make -j$(nproc)

v1.0beta3.1和之后的版本默认会根据board/spacemit/k1-x/k1-x.env生成env.bin,方案的env_k1-x.txt配置会overlay该文件。

编译linux

cd /path/to/linux-6.1
make k1_defconfig
LOCALVERSION="" make -j$(nproc)

v1.0aplha2版本需要手动生成uImage.itb,

cd arch/riscv/boot
cp ../../../../../buildroot-ext/board/spacemit/k1/kernel_fdt.its .
mkimage -f kernel_fdt.its -r uImage.itb

本地编译

将opensbi、u-boot或linux代码下载到Bianbu Desktop,即可本地编译。

编译opensbi

cd /path/to/opensbi
make -j$(nproc) PLATFORM_DEFCONFIG=k1_defconfig PLATFORM=generic

platform/generic/firmware/fw_dynamic.itb用fastboot写入opensbi分区即可。

编译u-boot

cd /path/to/uboot-2022.10
make k1_defconfig
make -j$(nproc)

FSBL.binenv.binu-boot.itb用fastboot写入对应分区即可。

编译linux

cd /path/to/linux-6.1
make k1_defconfig
LOCALVERSION="" make -j$(nproc)

arch/riscv/boot/Image.itbarch/riscv/boot/dts/spacemit/k1-x_deb1.dtb替换bootfs分区对应文件即可。

v1.0aplha2版本需要手动生成uImage.itb,

cd arch/riscv/boot
cp /path/to/buildroot-ext/board/spacemit/k1/kernel_fdt.its .
mkimage -f kernel_fdt.its -r uImage.itb

arch/riscv/boot/uImage.itbarch/riscv/boot/dts/spacemit/k1-x_deb1.dtb替换bootfs分区对应文件即可。