1、移植说明
(1)硬件:使用的是迅为的4412开发板,运行内存2G
(2)软件:迅为提供的u-boot2020.10和5.3.18设备树内核(4412_SCP_5.3.18_V_2.0.tar.bz2),ubuntu-base-22.04.3
(3)移植环境:虚拟机 ubuntu20.04
2、编译uboot
(1)修改源码,实现env的保存功能
env/mmc.c的env_mmc_load函数,在函数中增加下面代码
ret = env_import(buf, 1, H_EXTERNAL);
static int env_mmc_load(void)
{
#if !defined(ENV_IS_EMBEDDED)
ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
struct mmc *mmc;
u32 offset;
int ret;
int dev = mmc_get_env_dev();
const char *errmsg;
mmc = find_mmc_device(dev);
errmsg = init_mmc_for_env(mmc);
if (errmsg) {
ret = -EIO;
goto err;
}
if (mmc_get_env_addr(mmc, 0, &offset)) {
ret = -EIO;
goto fini;
}
if (read_env(mmc, CONFIG_ENV_SIZE, offset, buf)) {
errmsg = "!read failed";
ret = -EIO;
goto fini;
}
ret = env_import(buf, 1, H_EXTERNAL);
fini:
fini_mmc_for_env(mmc);
err:
if (ret)
env_set_default(errmsg, 0);
#endif
return ret;
}
(2)修改源码,初始化2G内存
-
arch/arm/mach-exynos/dmc_init_exynos4.c的dmc_init函数,增加以下代码
/* Memory Channel Inteleaving Size */ writel((0x80000000 | 0x1F), &dmc->ivcontrol);
static void dmc_init(struct exynos4_dmc *dmc)
{
/*
* DLL Parameter Setting:
* Termination: Enable R/W
* Phase Delay for DQS Cleaning: 180' Shift
*/
writel(mem.control1, &dmc->phycontrol1);
/*
* ZQ Calibration
* Termination: Disable
* Auto Calibration Start: Enable
*/
writel(mem.zqcontrol, &dmc->phyzqcontrol);
sdelay(0x100000);
/*
* Update DLL Information:
* Force DLL Resyncronization
*/
phy_control_reset(1, dmc);
phy_control_reset(0, dmc);
/* Set DLL Parameters */
writel(mem.control1, &dmc->phycontrol1);
/* DLL Start */
writel((mem.control0 | CTRL_START | CTRL_DLL_ON), &dmc->phycontrol0);
writel(mem.control2, &dmc->phycontrol2);
/* Set Clock Ratio of Bus clock to Memory Clock */
writel(mem.concontrol, &dmc->concontrol);
/* Memory Channel Inteleaving Size */
writel((0x80000000 | 0x1F), &dmc->ivcontrol);
/*
* Memor Burst length: 8
* Number of chips: 2
* Memory Bus width: 32 bit
* Memory Type: DDR3
* Additional Latancy for PLL: 1 Cycle
*/
writel(mem.memcontrol, &dmc->memcontrol);
writel(mem.memconfig0, &dmc->memconfig0);
writel(mem.memconfig1, &dmc->memconfig1);
/* Config Precharge Policy */
writel(mem.prechconfig, &dmc->prechconfig);
/*
* TimingAref, TimingRow, TimingData, TimingPower Setting:
* Values as per Memory AC Parameters
*/
writel(mem.timingref, &dmc->timingref);
writel(mem.timingrow, &dmc->timingrow);
writel(mem.timingdata, &dmc->timingdata);
writel(mem.timingpower, &dmc->timingpower);
/* Chip0: NOP Command: Assert and Hold CKE to high level */
writel(DIRECT_CMD_NOP, &dmc->directcmd);
sdelay(0x100000);
/* Chip0: EMRS2, EMRS3, EMRS, MRS Commands Using Direct Command */
dmc_config_mrs(dmc, 0);
sdelay(0x100000);
/* Chip0: ZQINIT */
writel(DIRECT_CMD_ZQ, &dmc->directcmd);
sdelay(0x100000);
writel((DIRECT_CMD_NOP | DIRECT_CMD_CHIP1_SHIFT), &dmc->directcmd);
sdelay(0x100000);
/* Chip1: EMRS2, EMRS3, EMRS, MRS Commands Using Direct Command */
dmc_config_mrs(dmc, 1);
sdelay(0x100000);
/* Chip1: ZQINIT */
writel((DIRECT_CMD_ZQ | DIRECT_CMD_CHIP1_SHIFT), &dmc->directcmd);
sdelay(0x100000);
phy_control_reset(1, dmc);
sdelay(0x100000);
/* turn on DREX0, DREX1 */
writel((mem.concontrol | AREF_EN), &dmc->concontrol);
}
-
arch/arm/mach-exynos/itop4412_setup.h
#define CHIP_MASK (0xC0 << 16) 改为 #define CHIP_MASK (0x80 << 16)
-
include/configs/itop4412.h
#define SDRAM_BANK_SIZE (256 << 20) 改为 #define SDRAM_BANK_SIZE (512 << 20)
3、编译5.3.18内核
在迅为的默认配置上修改
(1)配置Kernel command line type
配置为使用uboot内核传参
Boot options --->
Kernel command line type(Use bootloader kernel arguments if available)
(2)添加docker内核支持
修改内核配置,确保以下配置是启用的
"ipvs" match support的前置条件是IP virtual server support
Bridged IP/ARP packets filtering的前置条件是802.1d Ethernet Bridging
Support for eBPF programs attached to cgroups的前置条件是Enable bpf() system call
4、移植ubuntu-base-22.04.3
基于ubuntu-base构建根文件系统并移植到RK3568开发板 (yii666.com)
移植Ubuntu Base 20.04 LTS (Focal Fossa)到4412开发板 (taodudu.cc)
(1)安装工具
apt install qemu-user-static
(2)解压
(3)进入解压路径,cp /usr/bin/qemu-arm-static usr/bin/
如果ubuntu-base是aarch64架构,cp /usr/bin/qemu-aarch64-static ubuntu_rootfs/usr/bin
(4)配置DNS,cp /etc/resolv.conf etc/resolv.conf
(5)修改软件源
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse
#deb http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe multiverse
#deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-proposed main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-proposed main restricted universe multiverse
(6)挂载
./mount.sh -m a/
(7) 设置用户和账户密码(默认设置为root)
passwd root
(8)设置主机名和host
echo "4412'"> /etc/hostname
echo "127.0.0.1 localhost" > /etc/hosts
(9)安装常用命令和软件
若apt update失败,检查主机网络是否有问题,重启网卡命令service network-manager restart
export LC_ALL=C
apt update
apt install sudo
apt install language-pack-en-base
apt install ssh
apt install net-tools
apt install ethtool
apt install ifupdown
apt install iputils-ping
apt install rsyslog
apt install htop
apt install vim
apt install apt-utils
chmod 0400 /etc/ssh/ssh_host_*key
echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config
(10) 配置串口终端
ln -s /lib/systemd/system/getty\@.service /etc/systemd/system/getty.target.wants/getty\@ttySAC2.service
(11)配置网络
echo auto eth0 > /etc/network/interfaces.d/eth0
echo iface eth0 inet dhcp >> /etc/network/interfaces.d/eth0
(12)退出并解挂
exit
./mount.sh -u a/
(13)打包文件系统并复制到sd卡
// 打包文件系统
tar -czvf ../Image/ubuntu_22.04.tar.gz ./
// 查看sd卡挂载名
df -l
// 解压到sd卡中
tar -zxvf ./
5、验证系统可行性
(1)下载编译好的uboot和kernel和设备树文件,插入sd卡,选择EMMC启动
(2)确保command line为root=/dev/mmcblk0p2 rw rootfstype=ext4 init=/sbin/init console=ttySAC2,115200
// 设置环境变量
setenv bootargs root=/dev/mmcblk0p2 rw rootfstype=ext4 init=/sbin/init console=ttySAC2,115200
// 保存环境变量
saveenv
6、安装docker
Ubuntu Docker 安装 | 菜鸟教程 (it028.com)
最详细的ubuntu 安装 docker教程_ubuntu docker-CSDN博客
(1)检查卸载老版本docker
如果没有安装过,跳过该步骤
apt remove docker docker-engine docker.io containerd runc
(2)更新软件
apt update
apt upgrade
(3)安装依赖
apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
(4)来添加GPG密钥
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
(5)添加Docker的软件源
add-apt-repository "deb [arch=armhf] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
(6)安装docker
apt install docker-ce docker-ce-cli containerd.io
(7)查看docker版本
docker --version
(8)启动docker
/lib/systemd/systemd-sysv-install enable docker
systemctl start docker
(9)解决启动报错
问题:
error obtaining controller instance: unable to add return rule in DOCKER-ISOLATION-STAGE-1 chain
解决(执行以下指令):
update-alternatives --set iptables /usr/sbin/iptables-legacy
(10)配置docker的镜像源,设置管理docker日志的cground组为systemd
cat >> /etc/docker/daemon.json << EOF
{
"registry-mirrors": ["https://b9pmyelo.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
}
}
EOF
(11)重启docker
systemctl daemon-reload
systemctl restart docker
7、安装HomeAssistant
(1)运行容器
docker run -d -p 8123:8123 --name="home-assistant" -v /opt/HomeAssistant/config:/config -v /etc/localtime:/etc/localtime:ro homeassistant/home-assistant
(2)验证HomeAssistant
浏览器查看,http://IP地址:8123/
或者app查看,App下载地址GitHub - home-assistant/android: :iphone: Home Assistant Companion for Android
(3)安装docker-compose
-
最新发行的版本地址:Releases · docker/compose · GitHub
-
下载命令
建议使用daocloud下载,github访问太慢了
// 由于uname -s和uname -m在开发板上的输出值有点问题,不要直接使用该指令
curl -L "https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
// 或者
curl -L https://get.daocloud.io/docker/compose/releases/download/v2.23.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
使用替换uname -s和uname -m的指令
curl -L "https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-linux-armv7" -o /usr/local/bin/docker-compose
// 或者
curl -L "https://get.daocloud.io/docker/compose/releases/download/v2.23.0/docker-compose-linux-armv7" -o /usr/local/bin/docker-compose
-
增加可执行权限
chmod +x /usr/local/bin/docker-compose
-
添加软链接
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
-
查看版本
docker-compose --version
-
增加docker-compose命令补全
// 安装bash-completion
apt install bash-completion -y
// 下载docker-compose自动补全文件,注意版本号
curl -L https://raw.githubusercontent.com/docker/compose/v2.23.0/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-compose
// 重新加载bash配置
source /etc/bash_completion.d/docker-compose
有可能下载不了,那就在github下载,docker-compose的命令补全 - 厚礼蝎 - 博客园 (cnblogs.com)
GitHub - docker/compose: Define and run multi-container applications with Docker
切换到release分支
在contrib/completion/bash/路径下
点击复制
在/etc/bash_completion.d/下新建docker-compose文件,保存退出后
vim /etc/bash_completion.d/docker-compose
(4)用docker-compse管理HomeAssistant服务
创建yaml文件(路径自己定义就好),vi docker-compose.yml
version: '3'
services:
home-assistant:
image: homeassistant/home-assistant:latest
container_name: home-assistant
restart: always
ports:
- 8123:8123
volumes:
- /etc/localtime:/etc/localtime:ro
- /opt/HomeAssistant/config:/config
先停掉之前的HomeAssistant,再运行
docker ps -a
docker stop <容器id>
docker rm <容器id>
// 启动服务
docker-compose up -d
未完,待续......
2023/10/22
DGY(编)