5. 进阶-自定义固件#

1. 概述#

备注

本章节主要讲述如何进行如何进行K230 CanMV的开发,若无自定义需求可略过本章节

K230 CanMV是基于K230 SDK开发的一个运行micropython + OpenMV的应用,用户可通过python语言使用硬件的各种资源。

2. 开发环境搭建#

主机环境

描述

Ubuntu 20.04.4 LTS (x86_64)

可以在ubuntu 20.04环境下编译

K230 CanMV需要在linux环境下编译

K230 CanMV没有在其他Linux版本的主机环境下验证过,不保证可以在其他环境下编译通过。

2.1 本地构建环境#

  • 更新APT源(可选)

sudo bash -c 'cp /etc/apt/sources.list /etc/apt/sources_bak.list && \
  sed -i "s/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g" /etc/apt/sources.list && \
  sed -i "s/security.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g" /etc/apt/sources.list'
  • 安装软件依赖

# 添加386 arch
sudo bash -c 'dpkg --add-architecture i386 && \
  apt-get clean all && \
  apt-get update && \
  apt-get install -y --fix-broken --fix-missing --no-install-recommends \
    sudo vim wget curl git git-lfs openssh-client net-tools sed tzdata expect mtd-utils inetutils-ping locales \
    sed make cmake binutils build-essential diffutils gcc g++ bash patch gzip bzip2 perl tar cpio unzip rsync \
    file bc findutils dosfstools mtools bison flex autoconf automake python3 python3-pip python3-dev python-is-python3 \
    lib32z1 scons libncurses5-dev kmod fakeroot pigz tree doxygen gawk pkg-config libyaml-dev libconfuse2 libconfuse-dev \
    libssl-dev libc6-dev-i386 libncurses5:i386'
  • 更新PIP源(可选)

pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \
pip3 config set global.extra-index-url "https://mirrors.aliyun.com/pypi/simple https://mirrors.cloud.tencent.com/pypi/simple"
  • 安装Python依赖

pip3 install -U pyyaml pycryptodome gmssl
  • 安装repo工具

mkdir -p ~/.bin
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/.bin/repo
chmod a+rx ~/.bin/repo
echo 'export PATH="${HOME}/.bin:${PATH}"' >> ~/.bashrc
source ~/.bashrc

3. 编译流程#

3.1 源码下载#

repo init -u https://github.com/canmv-k230/manifest -b master --repo-url=https://github.com/canmv-k230/git-repo.git
repo sync

3.2 代码准备#

# 第一次执行,下载工具链
make dl_toolchain

3.3 编译#

# 列出配置列表
make list_def
# 选择对应板子配置文件
make xxxx_defconfig
# 编译
time make log

编译完成后会在k230_canmv/output/xxxx/images目录下生成镜像

4. 代码目录说明#

k230_canmv
.
├── boards
├── configs
├── include
├── output
├── src
│   ├── applications
│   ├── canmv
│   ├── opensbi
│   ├── rtsmart
│   └── uboot
└── tools

目录介绍:

  1. boards: 板子相关文件

  2. configs: 存放配置列表

  3. include: 自动生成,不用关系

  4. output: 编译产物,镜像文件,临时文件等

  5. src/applications: 用户程序

  6. src/canmv: CanMV相关文件

  7. src/opensbi: OpenSBI

  8. src/rtsmart: RT-Smart和MPP相关文件

  9. src/uboot: Uboot相关文件

  10. scripts: 编译系统相关脚本