目录
获取ubuntu-base
到ubuntu官网下载Ubuntu-base https://cdimage.ubuntu.com/ubuntu-base/releases/20.04.5/release/
cd ~/hi3798mv100/rootfs
mkdir ubuntu_rootfs
sudo tar -xzvf ubuntu-base-20.04.5-base-armhf.tar.gz -C ubuntu_rootfs
sudo cp /etc/resolv.conf ubuntu_rootfs/etc/resolv.conf #配置网络域名解析
sudo vi ubuntu_rootfs/etc/apt/sources.list #替换软件源
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ focal-security main restricted universe multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ focal-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-proposed main restricted universe multiverse
这里使用清华软件源更多详情查看https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu-ports/
#1.安装qemu-user-static仿真器
sudo apt install qemu-user-static
#2.拷贝 qemu-aarch64-static 到 ubuntu_rootfs/usr/bin/ 目录下。
sudo cp /usr/bin/qemu-aarch64-static ubuntu_rootfs/usr/bin/
编写挂载脚本
#!/bin/bash
function mnt() {
echo "MOUNTING"
sudo mount -t proc /proc ${2}proc
sudo mount -t sysfs /sys ${2}sys
sudo mount -o bind /dev ${2}dev
#sudo mount -t devpts -o gid=5,mode=620 devpts ${2}dev/pts
sudo mount -o bind /dev/pts ${2}dev/pts
sudo chroot ${2}
}
function umnt() {
echo "UNMOUNTING"
sudo umount ${2}proc
sudo umount ${2}sys
sudo umount ${2}dev/pts
sudo umount ${2}dev
}
if [ "$1" == "-m" ] && [ -n "$2" ];
then
mnt $1 $2
elif [ "$1" == "-u" ] && [ -n "$2" ];
then
umnt $1 $2
else
echo ""
echo "Either 1'st, 2'nd or both parameters were missing"
echo ""
echo "1'st parameter can be one of these: -m(mount) OR -u(umount)"
echo "2'nd parameter is the full path of rootfs directory(with tralling '/')"
echo ""
echo "For example: ch-mount -m /media/sdcard"
echo ""
echo 1st parameter : ${1}
echo 2nd parameter : $[2]
fi
#增加脚本执行权限
sudo chmod +x mount.sh
#挂载根文件系统
./mount.sh -m ubuntu_rootfs/
#退出根文件系统
exit
#卸载根文件系统
./mount.sh -u ubuntu_rootfs/
挂载ubuntu_rootfs
./mount.sh -m ubuntu_rootfs/
接下来的操作将在ubuntu-base 20.04 rootfs中进行
更新软件源
apt update
Ign:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports focal InRelease
Ign:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports focal-updates InRelease
Ign:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports focal-backports InRelease
Hit:4 http://ports.ubuntu.com/ubuntu-ports focal-security InRelease
Err:5 https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports focal Release
Certificate verification failed: The certificate is NOT trusted. The certificate issuer is unknown. Could not handshake: Error in the certificate verification. [IP: 101.6.15.130 443]
Err:6 https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports focal-updates Release
Certificate verification failed: The certificate is NOT trusted. The certificate issuer is unknown. Could not handshake: Error in the certificate verification. [IP: 101.6.15.130 443]
Err:7 https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports focal-backports Release
Certificate verification failed: The certificate is NOT trusted. The certificate issuer is unknown. Could not handshake: Error in the certificate verification. [IP: 101.6.15.130 443]
Reading package lists... Done
W: https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/dists/focal/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/dists/focal-updates/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/dists/focal-backports/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/dists/focal/Release: No system certificates available. Try installing ca-certificates.
E: The repository 'https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports focal Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/dists/focal-updates/Release: No system certificates available. Try installing ca-certificates.
E: The repository 'https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports focal-updates Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/dists/focal-backports/Release: No system certificates available. Try installing ca-certificates.
E: The repository 'https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports focal-backports Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
这种报错需要修改软件源/etc/apt/sources.list 将其中的https全部替换成http
exit
sudo ./mount.sh -u ubuntu_rootfs/
sudo vi ubuntu_rootfs/etc/apt/sources.list #修改成http
sudo ./
apt update #此时应该可以成功更新
安装常用软件
apt install sudo vim language-pack-en-base
apt install systemd #安装系统服务管理器,安装过程需要手动选择地区
apt install net-tools #包含ifconfig命令
apt install usbutils #包含lsusb命令
apt install iputils-ping #包含ping命令
apt install htop #htop命令查看系统资源情况与负载
apt install ifupdown #网络管理工具,会创建/etc/network目录并生成interfaces配置文件
apt install udev #设备管理,能够将串口作为控制台
apt install openssh-server apt-utils curl network-manager kmod
启动systemd系统与服务管理器
ln -s /lib/systemd/systemd /sbin/init
## 账号设置
```bash
passwd root #设置root用户密码
adduser ubuntu #新增普通用户“ubuntu”
passwd ubuntu
为普通用户增加sudo权限
vi /etc/sudoers
在root ALL=(ALL:ALL) ALL下一行添加ubuntu ALL=(ALL:ALL) ALL
网络 DHCP 配置
echo allow-hotplug eth0 > /etc/network/interfaces.d/eth0
echo iface eth0 inet dhcp >> /etc/network/interfaces.d/eth0
DNS 配置
查看当前DNS配置
root@ubuntu:/# ll /etc/resolv.conf
lrwxrwxrwx 1 root root 39 Sep 12 2024 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf
root@ubuntu:/# cat /etc/resolv.conf
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "resolvectl status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.
nameserver 127.0.0.53
options edns0 trust-ad
search smartont.net
重写DNS配置
rm /etc/resolv.conf
echo "nameserver 8.8.8.8" > /etc/resolv.conf
echo "nameserver 114.114.114.114" >> /etc/resolv.conf
锁定DNS配置
chattr +i /etc/resolv.conf
设置本机名称和ip地址
echo "hi3798mv100" > /etc/hostname
echo "127.0.0.1 localhost" >> /etc/hosts
echo "127.0.0.1 hi3798mv100" >> /etc/hosts
清理apt
apt autoremove
apt-get autoclean
apt-get clean
apt clean
退出根文件系统
exit
./mount.sh -u ubuntu_rootfs/
打包rootfs
创建打包脚本
vi img.sh
#!/bin/bash
set -x
rootfs=$(mktemp -d)
dd if=/dev/zero of=$1 bs=1M count=1500
mkfs.ext4 -F -L linuxroot $1
mount $1 $rootfs
cp -rfp $2* $rootfs
umount $rootfs
e2fsck -p -f $1
resize2fs -M $1
执行脚本
sudo ./img.sh rootfs.img ubuntu_rootfs/
ubuntu:~/hi3798mv100/rootfs$ ll -h
total 440M
drwxrwxr-x 3 marsa marsa 4.0K Mar 24 17:52 ./
drwxrwxr-x 4 marsa marsa 4.0K Mar 24 15:05 ../
-rwxrwxr-x 1 marsa marsa 195 Mar 24 17:50 img.sh*
-rwxrwxr-x 1 marsa marsa 859 Mar 24 15:06 mount.sh*
-rw-r--r-- 1 root root 577M Mar 24 17:55 rootfs.img
-rw-rw-r-- 1 marsa marsa 23M Mar 24 15:33 ubuntu-base-20.04.5-base-armhf.tar.gz
drwxrwxr-x 17 marsa marsa 4.0K Mar 24 16:28 ubuntu_rootfs/
rootfs大小修改
修改分区表
生成的rootfs镜像577MB远超了SDK编译出的分区表规定范围,这会导致内核挂载不上rootfs。
首先修改分区表。
修改后类似下图,把rootfs长度改为-把cadata分区删除
修改fastboot参数
烧录完镜像启动机顶盒
在启动时快速多次按Ctrl+C阻止fastboot启动内核,修改bootargs
Press Ctrl+C to stop autoboot
fastboot# <INTERRUPT>
fastboot# <INTERRUPT>
fastboot# <INTERRUPT>
fastboot# <INTERRUPT>
fastboot# <INTERRUPT> #ctrl + c 取消自动启动
fastboot# printenv #查看环境变量
baudrate=115200
ipaddr=192.168.1.10
netmask=255.255.255.0
gatewayip=192.168.1.1
serverip=192.168.1.1
bootcmd=mmc read 0 0x1FFFFC0 0x21000 0x4000;bootm 0x1FFFFC0
bootargs_512M=mem=512M mmz=ddr,0,0,320M vmalloc=500M
bootargs_768M=mem=768M mmz=ddr,0,0,400M vmalloc=500M
bootargs_1G=mem=1G mmz=ddr,0,0,400M vmalloc=500M
bootargs_2G=mem=2G mmz=ddr,0,0,600M vmalloc=500M
bootargs=console=ttyAMA0,115200 root=/dev/mmcblk0p12 rootfstype=ext4 rootwait blkdevparts=mmcblk0:1M(boot),1M(bootargs),4M(baseparam),4M(pqparam),4M(logo),4M(deviceinfo),4M(softwareinfo),4M(loaderdb),32M(loader),8M(trustedcore),8M(kernel),128M(rootfs),8M(cadata),-(others)
bootdelay=0
stdin=serial
stdout=serial
stderr=serial
ethaddr=2A:95:54:F6:55:BF
ver=Fastboot 3.3.0 (xtao@ubuntu) (May 05 2017 - 11:31:39)
Environment size: 775/65532 bytes
bootargs内核参数指定了串口号为ttyAMA0,这也是上文制作rootfs时链接串口终端时使用ttyAMA0端口号的原因
修改bootargs中的分区信息
setenv bootargs console=ttyAMA0,115200 root=/dev/mmcblk0p12 rootfstype=ext4 rootwait blkdevparts=mmcblk0:1M(boot),1M(bootargs),4M(baseparam),4M(pqparam),4M(logo),4M(deviceinfo),4M(softwareinfo),4M(loaderdb),32M(loader),8M(trustedcore),8M(kernel),-(ubuntu)
saveenv
reset
至此能够挂载rootfs,但是内核还需要配置dev挂载并打开cgroup才能完成进入到登录linux账号阶段
尝试修改内核配置
分析构建内核流程
$ pwd
/home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060
$ source env.sh
$ make build -n #输出构建时将要执行的命令
make prebuilts_compose
echo "make prebuilts over"
make -C /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/boot all O=/home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/out/hi3798mv100/hi3798mdmo1f/obj/source/boot
make -C /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/kernel all
make -C /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/tools/linux/utils all
make -C /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/rootfs all
make -C /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/common/api all
make -C /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/msp/api all
make -C /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/msp/api/higo all
make -C /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/msp/api/gpu all
make -C /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/msp/api/omx all
make -C /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/component all
make -C /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/component/directfb all
make rootbox_compose
echo "rootbox is ready"
make -C /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/sample image
make cramfs squashfs extfs
rm -rf /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/out/hi3798mv100/hi3798mdmo1f/image/hi_kernel.bin /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/out/hi3798mv100/hi3798mdmo1f/image/apploader.bin /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/out/hi3798mv100/hi3798mdmo1f/image/rootfs.squashfs
make signature
#### make "build -n" completed successfully! ####
- 继续查看子makfile构建内核时做了什么操作
$ make -C /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/kernel all -n
make: Entering directory '/home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/kernel'
test -d /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/out/hi3798mv100/hi3798mdmo1f/image/emmc_image || mkdir -p /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/out/hi3798mv100/hi3798mdmo1f/image/emmc_image
(cd /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/kernel/linux-4.4.y/drivers && rm -rf common && ln -s /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/common/drv common)
(cd /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/kernel/linux-4.4.y/drivers && rm -rf msp && ln -s /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/msp/drv msp)
(cd /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/kernel/linux-4.4.y/drivers && rm -rf wifi && ln -s /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/component/wifi/drv wifi)
(cd /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/kernel/linux-4.4.y/drivers && rm -rf bluetooth_usb && ln -s /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/component/bluetooth/drv bluetooth_usb)
make -C /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/kernel/linux-4.4.y ARCH=arm \
CROSS_COMPILE=arm-histbv310-linux- \
O=/home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/out/hi3798mv100/hi3798mdmo1f/obj/source/kernel/linux-4.4.y \
\
CFLAGS_KERNEL= AFLAGS_KERNEL= hi3798mv100_defconfig
make pcie_config
make -C /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/kernel/linux-4.4.y ARCH=arm \
CROSS_COMPILE=arm-histbv310-linux- \
O=/home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/out/hi3798mv100/hi3798mdmo1f/obj/source/kernel/linux-4.4.y \
\
CFLAGS_KERNEL= AFLAGS_KERNEL= oldconfig
make -C /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/kernel/linux-4.4.y ARCH=arm \
CROSS_COMPILE=arm-histbv310-linux- \
O=/home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/out/hi3798mv100/hi3798mdmo1f/obj/source/kernel/linux-4.4.y \
CONFIG_MSP=y \
HI_CONFIG_WIFI= \
HI_CONFIG_BLUETOOTH= \
CONFIG_ADVCA= \
\
CFLAGS_KERNEL= AFLAGS_KERNEL= uImage modules
cp -f /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/out/hi3798mv100/hi3798mdmo1f/obj/source/kernel/linux-4.4.y/arch/arm/boot/uImage /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/out/hi3798mv100/hi3798mdmo1f/image/emmc_image/hi_kernel.bin
mkdir -p /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/out/hi3798mv100/hi3798mdmo1f/kmod/usb
cp -f /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/out/hi3798mv100/hi3798mdmo1f/obj/source/kernel/linux-4.4.y/drivers/usb/host/*.ko /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/out/hi3798mv100/hi3798mdmo1f/kmod/usb/
(for file in ; do ( \
mkdir -p /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/out/hi3798mv100/hi3798mdmo1f/kmod/sata && cp $file /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/out/hi3798mv100/hi3798mdmo1f/kmod/sata/ \
) done )
(find /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/out/hi3798mv100/hi3798mdmo1f/obj/source/kernel/linux-4.4.y/drivers/common -name "*.ko" | xargs cp -f -t /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/out/hi3798mv100/hi3798mdmo1f/kmod/)
(find /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/out/hi3798mv100/hi3798mdmo1f/obj/source/kernel/linux-4.4.y/drivers/msp -name "*.ko" | xargs cp -f -t /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/out/hi3798mv100/hi3798mdmo1f/kmod/)
make: Leaving directory '/home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/kernel'
#### make "-C /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/kernel all -n" completed successfully! ####
根据上面的代码,得出构建内核时主要做的事情:
- 创建输出目录
- 创建符号链接(在 linux-4.4.y/drivers 目录下创建符号链接,指向其他模块的驱动目录)
- 生成初始版本的内核配置文件.config(第一次构建时会生成初始版本的.config配置文件,后面根据需求修改内核配置时也会改变.config文件,如果再次执行构建指令make -C /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/kernel all那么就会把.config文件恢复成初始版本,这是不应该的。所以需要把删除相关操作避免覆盖.config文件)
- 编译内核和模块
- 复制内核镜像、内核模块
修改Makefile文件
修改Makefile,避免重新生成初始版本的.config文件覆盖原来的.config文件。
$ pwd
/home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060
$ cp source/kernel/Makefile source/kernel/Makefilebak #备份Makefile
$ vi source/kernel/Makefile #修改Makefile
下面是生成.config的代码,删除掉
293 $(AT)make -C $(KERNEL_SRC_DIR) ARCH=$(CFG_HI_CPU_ARCH) \
294 CROSS_COMPILE=$(CROSS_COMPILE) \
295 O=$(BUILD_DIR) \
296 $(EXTRA_FLAGS_KERNEL) \
297 CFLAGS_KERNEL=$(CFLAGS_KERNEL) AFLAGS_KERNEL=$(AFLAGS_KERNEL) $(KERNEL_CONFIG)
298 $(if $(CFG_HI_TEE_SUPPORT),make tee_config,)
299 make pcie_config
300 $(AT)make -C $(KERNEL_SRC_DIR) ARCH=$(CFG_HI_CPU_ARCH) \
301 CROSS_COMPILE=$(CROSS_COMPILE) \
302 O=$(BUILD_DIR) \
303 $(EXTRA_FLAGS_KERNEL) \
304 CFLAGS_KERNEL=$(CFLAGS_KERNEL) AFLAGS_KERNEL=$(AFLAGS_KERNEL) oldconfig
编译内核方法
上文有提及顶层makfile调用子makefile来构建内核,也就是下面这条指令
$ make -C /home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/source/kernel all
而上面的指令是由下面的构建规则执行的
175 #====================================================================================
176 # linux
177 #====================================================================================
178 .PHONY: linux linux_clean
179
180 linux:
181 $(AT)make -C $(KERNEL_DIR) all
182
183 linux_clean:
184 $(AT)make -C $(KERNEL_DIR) clean
185
186 #====================================================================================
187 # rootfs
188 #====================================================================================
所以可以在顶层makefile用make linux直接单独构建内核,而不需要使用make build构建整个SDK
$ pwd
/home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060
$ make linux
配置内核方法
make menuconfig通常用来配置内核参数。但是make menuconfig只是在内核目录下起到配置内核参数的作用,在SDK顶层目录下make menuconfig实际起到的作用是配置SDK参数
所以在顶层的Makefile中添加新的规则来配置内核参数
$ pwd
/home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060
$ vi Makefile
175 #====================================================================================
176 # linux
177 #====================================================================================
178 .PHONY: linux linux_clean
179
180 linux:
181 $(AT)make -C $(KERNEL_DIR) all
182
183 linux_clean:
184 $(AT)make -C $(KERNEL_DIR) clean
185
186 linux-menuconfig:
187 $(AT)make -C $(KERNEL_DIR) menuconfig
188
189 #====================================================================================
190 # rootfs
191 #====================================================================================
在顶层makefile配置内核:
$ pwd
/home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060
$ make linux-menuconfig
PS:通常编译内核、修改内核是到内核目录下执行 make uImage、make menuconfig,但是如果按照通常方法单独编译内核会缺少相关的环境变量,所以采用从SDK的顶层Makefile中进行编译,配置内核。
内核配置
$ pwd
/home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060
$ make linux-menuconfig
配置dev
键入/搜索devtmp 确保这两个配置项都打开了,按下数字 1 2 可快速定位到配置项
配置cgroups
确保cgroups打开
至此rootfs已经可以成功启动。使得linux正常工作还需要继续配置
配置ANDROID_PARANOID_NETWORK
ANDROID_PARANOID_NETWORK默认是打开的,这里我们需要关闭它,不然没法正常上网
配置USB
这三个配置项默认是编译成模块,这里把它们修改成编译进内核
配置CH340驱动(非必要)
$ pwd
/home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060
$ make build -j16
生成的内核镜像是
/home/marsa/hi3798mv/HiSTBLinuxV100R005C00SPC060/out/hi3798mv100/hi3798mdmo1f/image/emmc_image/hi_kernel.bin
烧录完成后进入控制台扩容rootfs
root@hi3798mv100:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
mmcblk0 179:0 0 7.3G 0 disk
|-mmcblk0p1 179:1 0 1M 0 part
|-mmcblk0p2 179:2 0 1M 0 part
|-mmcblk0p3 179:3 0 4M 0 part
|-mmcblk0p4 179:4 0 4M 0 part
|-mmcblk0p5 179:5 0 4M 0 part
|-mmcblk0p6 179:6 0 4M 0 part
|-mmcblk0p7 179:7 0 4M 0 part
|-mmcblk0p8 259:0 0 4M 0 part
|-mmcblk0p9 259:1 0 32M 0 part
|-mmcblk0p10 259:2 0 8M 0 part
|-mmcblk0p11 259:3 0 8M 0 part
`-mmcblk0p12 259:4 0 7.2G 0 part /
mmcblk0boot0 179:8 0 4M 1 disk
mmcblk0boot1 179:16 0 4M 1 disk
mmcblk0rpmb 179:24 0 4M 0 disk
mmcblk1 179:32 0 14.9G 0 disk
|-mmcblk1p1 179:33 0 14.9G 0 part
`-mmcblk1p2 179:34 0 57M 0 part
root@hi3798mv100:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 737M 479M 204M 71% /
devtmpfs 291M 0 291M 0% /dev
tmpfs 291M 0 291M 0% /dev/shm
tmpfs 59M 64K 59M 1% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 291M 0 291M 0% /sys/fs/cgroup
root@hi3798mv100:~# resize2fs /dev/mmcblk0p12
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/mmcblk0p12 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mmcblk0p12 is now 1889792 (4k) blocks long.
root@hi3798mv100:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 7.1G 483M 6.3G 7% /
devtmpfs 291M 0 291M 0% /dev
tmpfs 291M 0 291M 0% /dev/shm
tmpfs 59M 64K 59M 1% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 291M 0 291M 0% /sys/fs/cgroup
后言
Ubuntu20.04 rootfs 制作与网上教程大致一样,本人照葫芦画瓢的结果就是最后kernel没有找到合适的初始化进程最后选择了最低优先级的/bin/sh作为初始进程。结果就是pid 1 的进程是sh,这很难搞。
最后安装了systemd并创建符号链接/sbin/init才让rootfs看起来比较靠谱。
不清楚为什么网上的教程不需要安装systemd
参考链接
https://blog.csdn.net/weixin_46025014/article/details/131682463
https://www.cnblogs.com/milton/p/17599562.html
https://www.jianshu.com/p/0a0066d10190