300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 12 编译最新的BusyBox rootfs 1.35.0源码 并用QEMU模拟器运行

12 编译最新的BusyBox rootfs 1.35.0源码 并用QEMU模拟器运行

时间:2021-10-03 23:23:30

相关推荐

12 编译最新的BusyBox rootfs 1.35.0源码 并用QEMU模拟器运行

编译最新的BusyBox rootfs 1.35.0源码,并用QEMU模拟器运行

Gitee源码和工程地址:才鲸嵌入式 / 嵌入式QEMU教程CSDN文章地址:项目介绍:嵌入式QEMU教程

前提:编译U-Boot和Linux kernel源码时,源码版本、PC主机Linux系统版本、交叉编译器版本都有影响,最好按照网上教程中相同的版本来尝试,要不然经常会遇到编译时遇到了问题,但又搜不到解决方法的尴尬局面。

必须在Linux系统中编译(如Ubuntu),不能在MSYS2中编译。

1)直接编译Linux源码并运行

2、Busybox生成文件系统需要的系统应用程序和制作根文件系统

MSYS2中的QEMU不能引导文件系统(未尝试去查找解决该问题),在Linux下运行QEMU能正常引导。

在Ubuntu下安装QEMU:sudo apt install qemu-system-arm

从官网下载最新的BusyBox发布版本:busybox-1.35.0.tar.bz2

如果想要尝试最新的未形成版本的源码,则下载 busybox-snapshot.tar.bz2

因为BusyBox源码更新较慢,ARM最新的编译器11.3编译BusyBox报错无法解决,所以我改用老版本的编译器,能编译通过

10.2版本编译器ARM官方下载地址:gcc-arm-10.2-.11-x86_64-arm-none-linux-gnueabihf.tar.xz

解压后需要重新输出编译器路径:

交叉编译环境的配置方法和上面编译U-Boot时相同

# 因为我当前不编译Linux PC下的程序,所以我直接将整个环境都配成交叉编译的export ARCH=armexport CROSS_COMPILE=arm-none-linux-gnueabihf-# 增加交叉编译器的路径,修改成你自己解压的路径export PATH=$PATH:/home/jim/Desktop/tools/gcc-arm-10.2/bin# 如果之前以及输出了别的版本gcc的路径,则需并重新注销或者重启Ubuntu后再执行上面的步骤

编译: make menuconfig设置 Build Options 开启静态编译(提示: 可使用 / 搜索static) 在第一行Settings —>上回车,在滚动到中间位置,找到 [ ] Build static binary (no shared libs)并按空格,让括号内多一个星号表示选中,再按两次Esc,在弹出框中按回车保存配置 make -j4make install 编译过程中报错时需要安装的依赖库 sudo apt install libncurses5-dev

以下内容无效。以下为尝试解决最新的ARM GCC编译器编译时的问题,但最终失败,但保留重新编译安装coreutils工具集的步骤:

遇到报错无法解决:

coreutils/dd.c: 在函数‘dd_output_status’中:coreutils/dd.c:123:21: 编译器内部错误: 非法指令123 | #define G (*(struct globals*)bb_common_bufsiz1)| ^~~~~~~coreutils/dd.c:192:29: 附注: in expansion of macro ‘G’192 | seconds = (now_us - G.begin_time_us) / 1000000.0;| ^free(): invalid next size (fast)editors/awk.c: 在函数‘next_token’中:editors/awk.c:1121:17: 编译器内部错误: 已放弃1121 | debug_printf_parse("%s: using concat-inserted token\n", __func__);| ^~~~~~~~~~~~~~~~~~

重新编译安装coreutils也无法解决报错的问题: sudo apt install gitgit clone git://git./coreutils 编译步骤参考:coreutils.git/plain/README 注释掉

export ARCH=armexport CROSS_COMPILE=arm-none-linux-gnueabihf-export PATH=$PATH:/home/jim/Desktop/tools/arm-gnu-toolchain-11.3/bin

然后登出系统(注销),再重新登入(或者重启也可以),去掉当前环境中的交叉编译环境变量进入coreutils目录./bootstrap 运行要一会儿,且没有打印提示,可以通过看自己CPU占用率来判断是否结束执行时报错,则: sudo apt-get install autoconfsudo apt-get install autopointsudo apt-get install gperfsudo apt-get install texinfo ./configuremake CFLAGS=‘-w’ -j4sudo make install重新编译Busybox仍然报错。以上内容无效。

已在BusyBox源码文件夹下生成了_install目录,里面有板子上能用到的各种系统命令制作根文件系统:mkdir my_mntdd if=/dev/zero of=rootfs.img bs=1024 count=16384 # 创建 16MB 虚拟磁盘mkfs.ext2 rootfs.img # 格式化成 ext2 格式文件系统sudo mount -o loop rootfs.img my_mnt# 将镜像文件和块设备关联并挂载设备到my_mntsudo cp -r _install/* my_mnt # 将 BUsybox 所有生成的程序拷贝到根目录# 创建4个tty设备(c代表字符设备,4是主设备号,1~4分别是次设备号)sudo mkdir -p my_mnt/devsudo mknod my_mnt/dev/tty1 c 4 1sudo mknod my_mnt/dev/tty2 c 4 2sudo mknod my_mnt/dev/tty3 c 4 3sudo mknod my_mnt/dev/tty4 c 4 4# 创建终端sudo mknod -m 666 my_mnt/console c 5 1sudo umount my_mnt

将生成的rootfs.img拷贝Ubuntu桌面将之前的u-boot和vexpress-v2p-ca9.dtb拷贝到Ubuntu桌面编译好的rootfs.img、zImage和vexpress-v2p-ca9.dtb文件我已经放在另一个仓库中,地址为:/langcai1943/linux_kernel_u-boot_busybox_code_comments/tree/develop/bin/v1.0.0在Ubuntu桌面上打开终端在Ubuntu终端中执行 qemu-system-arm -M vexpress-a9 -m 256M -nographic -kernel zImage -dtb vexpress-v2p-ca9.dtb -sd rootfs.img -append “root=/dev/mmcblk0 rw console=ttyAMA0”可以看到效果:

jim@jim:~/Desktop/usr$ qemu-system-arm -M vexpress-a9 -m 256M -nographic -kernel zImage -dtb vexpress-v2p-ca9.dtb -sd rootfs.img -append "root=/dev/mmcblk0 rw console=ttyAMA0" WARNING: Image format was not specified for 'rootfs.img' and probing guessed raw.Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.Specify the 'raw' format explicitly to remove the restrictions.pulseaudio: set_sink_input_volume() failedpulseaudio: Reason: Invalid argumentpulseaudio: set_sink_input_mute() failedpulseaudio: Reason: Invalid argumentBooting Linux on physical CPU 0x0Linux version 6.1.0-rc6 (jim@jim) (arm-none-linux-gnueabihf-gcc (Arm GNU Toolchain 11.3.Rel1) 11.3.1 0712, GNU ld (Arm GNU Toolchain 11.3.Rel1) 2.38.0708) #1 SMP Fri Nov 25 23:17:29 CST CPU: ARMv7 Processor [410fc090] revision 0 (ARMv7), cr=10c5387dCPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cacheOF: fdt: Machine model: V2P-CA9Memory policy: Data cache writebackReserved memory: created DMA memory pool at 0x4c000000, size 8 MiBOF: reserved mem: initialized node vram@4c000000, compatible id shared-dma-poolcma: Reserved 16 MiB at 0x6f000000Zone ranges:Normal [mem 0x0000000060000000-0x000000006fffffff]Movable zone start for each nodeEarly memory node rangesnode 0: [mem 0x0000000060000000-0x000000006fffffff]Initmem setup node 0 [mem 0x0000000060000000-0x000000006fffffff]CPU: All CPU(s) started in SVC mode.percpu: Embedded 15 pages/cpu s30612 r8192 d22636 u61440Built 1 zonelists, mobility grouping on. Total pages: 65024Kernel command line: root=/dev/mmcblk0 rw console=ttyAMA0printk: log_buf_len individual max cpu contribution: 4096 bytesprintk: log_buf_len total cpu_extra contributions: 12288 bytesprintk: log_buf_len min size: 16384 bytesprintk: log_buf_len: 32768 bytesprintk: early log buf free: 14944(91%)......can't run '/etc/init.d/rcS': No such file or directoryPlease press Enter to activate this console. / # lsbin dev linuxrclost+found sbin usr/ #

参考网址QEMU 实验(一): u-boot 和 kernel 编译linux系统移植(qemu)+文件系统制作(busybox)+nfs根文件系统及Busybox详解之一

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。