1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# 安装编译工具macOS Mojave(10.14.3) $ brew install arm-linux-gnueabihf-binutils # bison on macOS is too old $ brew install bison $ export PATH="/usr/local/opt/bison/bin:$PATH" # 安装 crosstool-ng 构建GCC编译环境 $ brew install crosstool-ng $ export CT_NG_VER=$(brew list --versions crosstool-ng | tr ' ' '\n' | tail -1) $ export CT_NG_VER_SHORT=${CT_NG_VER%_*} # 安装的 crosstool-ng 的脚本文件缺少执行权限,导致无法执行,我们需要手工增加执行权限 $ chmod +x "$(brew --cellar crosstool-ng)/${CT_NG_VER}/lib/crosstool-ng-${CT_NG_VER_SHORT}/scripts/crosstool-NG.sh" # 默认情况下,macOS的文件系统不区分大小写,我们需要手工创建一个区分大小写的分区 $ hdiutil create -volname "ClockworkOS" -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 30g ClockworkOS.dmg $ hdiutil attach ClockworkOS.dmg.sparseimage -mountpoint /Volumes/ClockworkOS $ cd /Volumes/ClockworkOS $ mkdir arm-cortexa9_neon-linux $ cd arm-cortexa9_neon-linux $ ct-ng list-samples # 变更x-tools存储目录 $ export HOME=/Volumes/ClockworkOS $ ct-ng arm-cortexa9_neon-linux-gnueabihf # 修复BUG Build failed in step 'Installing m4 for build' $ brew uninstall --ignore-dependencies binutils $ brew install binutils # 安装依赖工具 $ brew install automake $ brew uninstall --ignore-dependencies gawk $ brew install gawk # 目前编译gettext-0.19.8.1的时候写死依赖automake-1.15,但是最新的已经是automake-1.16,我们通过手工编译安装automake-1.15规避这个问题 $ wget http://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz # 也可从本站下载 wget https://www.mobibrw.com/wp-content/uploads/2019/03/automake-1.15.tar.gz $ tar xvf automake-1.15.tar.gz $ cd automake-1.15 $ bash configure $ make && make install $ cd .. # 修改文件打开数量限制,修正错误 “extra-module.mk:11: *** Too many open files.” $ ulimit -n 2048 # 'scm_new_port_table_entry' was not declared in this scope $ sed -i "" "s/CT_GDB_CROSS_EXTRA_CONFIG_ARRAY=.*/CT_GDB_CROSS_EXTRA_CONFIG_ARRAY=\"--with-guile=no\"/g" .config $ export PATH="/usr/local/bin:$PATH" $ ct-ng build -j8 |
编译
u-boot
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
$ cd /Volumes/ClockworkOS # 下载u-boot代码 $ git clone https://github.com/qemu/u-boot.git $ cd u-boot $ git checkout v2019.01 -b v2019.01 $ export PATH="/Volumes/ClockworkOS/x-tools/arm-cortexa9_neon-linux-gnueabihf/bin:$PATH" $ export CROSS_COMPILE=arm-cortexa9_neon-linux-gnueabihf- $ make clean # R16又名A33 ,R16-J 代表包含Jazelle DBX $ make vexpress_ca9x4_defconfig # fix Undefined symbols for architecture x86_64: "_PyArg_ParseTuple" $ export HOSTLDFLAGS="-lpython -dynamclib" $ brew install gnu-sed # fix ./tools/../lib/bch.c:66:10: fatal error: 'endian.h' file not found $ gsed -i "s/#include <sys\/endian.h>/#include <sys\/endian.h>\n#elif defined(__APPLE__)\n#include <machine\/endian.h>\n#include <libkern\/OSByteOrder.h>/g" lib/bch.c $ gsed -i "s/#define cpu_to_be32 htobe32/#if defined(__APPLE__)\n#define cpu_to_be32 OSSwapHostToBigInt32\n#else\n#define cpu_to_be32 htobe32\n#endif/g" lib/bch.c $ gsed -i "s/#if \!defined(__DragonFly__) \&\& \!defined(__FreeBSD__)/#if \!defined(__DragonFly__) \&\& \!defined(__FreeBSD__) \&\& \!defined(__APPLE__)/g" lib/bch.c # 无视最后的失败提示,只要u-boot这个文件生成即可 $ make ARCH=arm -j8 |
编译
Linux
内核
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
$ cd /Volumes/ClockworkOS $ brew install aria2 $ aria2c -c https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.14.2.tar.xz # 也可本站下载 wget https://www.mobibrw.com/wp-content/uploads/2019/03/linux-4.14.2.tar.xz $ tar xvf linux-4.14.2.tar.xz $ cd linux-4.14.2 $ export PATH="/Volumes/ClockworkOS/x-tools/arm-cortexa9_neon-linux-gnueabihf/bin:$PATH" # for mkimage $ export PATH="/Volumes/ClockworkOS/u-boot/tools:$PATH" # 或者 brew install u-boot-tools # elf.h $ brew install libelf $ echo " #include <libelf/libelf.h> #define R_386_NONE 0 #define R_386_32 1 #define R_386_PC32 2 #define R_ARM_NONE 0 #define R_ARM_PC24 1 #define R_ARM_ABS32 2 #define R_MIPS_NONE 0 #define R_MIPS_16 1 #define R_MIPS_32 2 #define R_MIPS_REL32 3 #define R_MIPS_26 4 #define R_MIPS_HI16 5 #define R_MIPS_LO16 6 #define EF_ARM_EABIMASK 0xFF000000 #define EF_ARM_EABI_VERSION(flags) ((flags) & EF_ARM_EABIMASK)" > /usr/local/include/elf.h # xargs: illegal option -- r $ brew install findutils $ export PATH="/usr/local/opt/findutils/libexec/gnubin:$PATH" # stat: illegal option -- c $ ln -s /usr/local/bin/gstat /usr/local/bin/stat $ export PATH="/usr/local/bin:$PATH" $ export CROSS_COMPILE=arm-cortexa9_neon-linux-gnueabihf- $ export ARCH=arm $ make vexpress_defconfig $ make -j8 $ mkimage -A arm -O linux -T kernel -C none -a 0x40008000 -e 0x40008000 -n "Linux kernel" -d arch/arm/boot/zImage uImage |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
$ cd /Volumes/ClockworkOS $ brew install aria2 # 官方给出的这个地址下不到,只能用镜像地址 http://106.185.33.196/clockworkos_v0.3.img.bz2 $ aria2c -c http://clockworkpi.k15.net/clockworkos_v0.3.img.bz2 $ rm -rf clockworkos_v0.3.img $ bzip2 -d -k -vvvv clockworkos_v0.3.img.bz2 # 替换镜像中的内核文件 $ hdiutil attach clockworkos_v0.3.img -mountpoint /Volumes/clockworkos_v0.3 $ echo y | cp -i /Volumes/ClockworkOS/linux-4.14.2/uImage /Volumes/clockworkos_v0.3/uImage $ hdiutil detach /Volumes/clockworkos_v0.3 $ brew install qemu $ qemu-img convert -f raw -O qcow2 clockworkos_v0.3.img clockworkos_v0.3.qcow2 |
手工编译
qemu
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
$ cd /Volumes/ClockworkOS $ git clone https://github.com/qemu/qemu.git $ cd qemu # 从 qemu v2.1.0-rc1 开始,内存需要被映射到0x60000000开始的地址,更低的地址被映射为只读闪存,我们需要取消这种映射行为,否则执行的时候会报告错误 $ sed -i "" "s/\[VE_NORFLASHALIAS\] = 0/\[VE_NORFLASHALIAS\] = -1/g" hw/arm/vexpress.c $ bash configure $ make -j8 $ cd .. # list supported machine `qemu-system-arm -machine help` $ /Volumes/ClockworkOS/qemu/arm-softmmu/qemu-system-arm -M vexpress-a9 -m 1024M -kernel /Volumes/ClockworkOS/u-boot/u-boot -serial mon:stdio -nographic -sd clockworkos_v0.3.qcow2 -net nic,model=lan9118 -net user |
可惜到这一步了,还是没办法成功运行系统。
参考链接
- Running Clockwork OS in a Virtual Machine
- Request:Open source curcuitboard
- Progress on gameshell
- GameShell OS image files
- mac virt-manager
- Convert IMG (raw) to QCOW2
- Loading the OS on a virtual machine.(virt-manager)
- Clockwork OS on QEMU
- First impressions – A look at the OS
- Booting Linux with U-Boot on QEMU ARM
- Booting Linux with U-Boot on QEMU ARM
- 用Qemu模拟vexpress-a9 (三)--- 实现用u-boot引导Linux内核
- How to execute u-boot on qemu-system-arm
- Linux Shell 截取字符串
- Building embedded ARM systems with Crosstool-NG
- Where can I find the installed package path via brew
- Mac OSX下执行crosstool-ng提示“Your file system ‘xxxx’ is *not* case-sensitive!”
- qemu-system-arm仿真vexpress-a9踩坑记
- Build failed in step 'Installing m4 for build' #1097
- WARNING: 'automake-1.14' is missing on your system.
- ‘scm_new_port_table_entry’ was not declared in this scope #72
- 基于QEMU的ARM Cortex-A9开发板Vexpress-ca9的Linux内核的编译和运行
- building Linux kernel on Mac OS X
- 在Mac上编译uboot,linux kernel
- include/arm/elf.h
- In homebrew, how can I know xargs belongs to the findutil package?
- Is “xargs” on MacOS not the same as linux?
- 修改KVM虚机镜像中的文件的几种方法(Guestfish/Guestmount /virt-*tools)
- QEMU模拟vexpress-a9 搭建Linux kernel运行环境
- /srv/irclogs.linaro.org/2014/09/12/#linaro.txt
- Coreboot for QEMU armv7 (vexpress-a9) emulated mainboard
- MIT6.828课程JOS在macOS下的环境配置
- Mainline Debian HowTo
- 使用 monitor command 监控 QEMU 运行状态
- 在Mac OS X上用SWIG编译C
- endian.h not found on mac osx
- A33/R16
- Allwinner SoC Family
- Booting kernel from SD in qemu (ARM) with u-boot