从零开始构建自己的ARM Ubuntu系统
2016-03-16 19:49
597 查看
这篇文章介绍如何构建一个完整基于ARM的Ubuntu系统。
由于改文章当初写的时候是发表在国外产品论坛上面,故保留了原文内容。
使用到的硬件平台:Geekbox
补充说明:
虽然Geekbox是基于8核64Bits Cortex-A53 ARMV8架构的CPU,该方法构建的时候采用了向下兼容的32Bits的ARMV7架构。因此,该方法适用于Cortex-A7/A9/A15/A17/A12架构的ARM处理器。
In this guide, we will describe how to build an ubuntu system for Geekbox from scratch.
Different ways to achieve it:
1. Build the whole system in host PC with Chroot(emulator)
Link: TBD
2. Build in a removable media device, such as: SDCard or UDisk
Link: TBD
3. Build in the target device directly
Link: current article
Before starting
Carry on the following questions before you start your work:
1. Q: armhf vs arm64
A: Google for the answer
2. Q: Ubuntu vs Lubuntu/Kubuntu
A: Google for the answer
3. Q: What is included in an ubuntu system?
A: Bootloader & ramfs(kernel + initrd) & rootfs
4. Q: how to manage your ubuntu projects
A: Continue current reading and think about your own manage mothod.
Preparations
1. Create the working directories
2. Download the bootloader source code
3. Download the linux kernel source code
4. Download the toolchain
5. Download the initrd
6. Download the hardware packages for Geekbox
7. Download the ubuntu-core
由于改文章当初写的时候是发表在国外产品论坛上面,故保留了原文内容。
使用到的硬件平台:Geekbox
补充说明:
虽然Geekbox是基于8核64Bits Cortex-A53 ARMV8架构的CPU,该方法构建的时候采用了向下兼容的32Bits的ARMV7架构。因此,该方法适用于Cortex-A7/A9/A15/A17/A12架构的ARM处理器。
In this guide, we will describe how to build an ubuntu system for Geekbox from scratch.
Different ways to achieve it:
1. Build the whole system in host PC with Chroot(emulator)
Link: TBD
2. Build in a removable media device, such as: SDCard or UDisk
Link: TBD
3. Build in the target device directly
Link: current article
Before starting
Carry on the following questions before you start your work:
1. Q: armhf vs arm64
A: Google for the answer
2. Q: Ubuntu vs Lubuntu/Kubuntu
A: Google for the answer
3. Q: What is included in an ubuntu system?
A: Bootloader & ramfs(kernel + initrd) & rootfs
4. Q: how to manage your ubuntu projects
A: Continue current reading and think about your own manage mothod.
Preparations
1. Create the working directories
$ install -d ~/project/geekbox/ubuntu/{linux,initrd,rootfs,prebuilts,archives/{ubuntu-core,debs,hwpacks},images,utils,scripts} $ cd ~/project/geekbox/ubuntu
2. Download the bootloader source code
$ git clone https://github.com/geekboxzone/lollipop_u-boot u-boot
3. Download the linux kernel source code
$ git clone https://github.com/geekboxzone/lollipop_kernel -b ubuntu linux
4. Download the toolchain
$ git clone https://github.com/geekboxzone/lollipop_prebuilts_gcc_linux-x86_aarch64_aarch64-linux-android-4.9.git prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/Note the full path of "prebuilts/gcc/linux-x86/arm/arm-eabi-4.6", just to keep Makefile@linux happy
5. Download the initrd
$ git clone https://github.com/gouwa/initrd.git initrd
6. Download the hardware packages for Geekbox
$ git clone https://github.com/geekboxzone/ubuntu_hwpacks.git archives/hwpacks
7. Download the ubuntu-core
$ wget -P archives/ubuntu-core http://cdimage.ubuntu.com/ubuntu-core/releases/14.04.3/release/ubuntu-core-14.04.3-core-armhf.tar.gz[/code]Visit the following link for the more versions:
http://cdimage.ubuntu.com/ubuntu-core/releases
8. Download the rockchip upgrade tool, note to specify the "ubuntu" branch:$ git clone https://github.com/geekboxzone/utils.git -b ubuntu utils[Optional]If you want to run the command in any path:$ sudo cp -a utils/upgrade_tool /usr/local/bin
9. Download the rockchip mkbootimg tools$ git clone https://github.com/neo-technologies/rockchip-mkbootimg.git mkbootimgBuild and install mkbootimg tools:$ make -C mkbootimg/ $ sudo make install -C mkbootimg/The above steps will generate some files in /usr/local/bin/
See utils/mkbootimg/README.md file for more information
All the preparatory works above are necessary to build an ubuntu.
And we also offter some scripts to do thus work:
10. [Optional]Download the scripts:$ git clone https://github.com/geekboxzone/ubuntu_scripts.git scripts
All the steps above just need to run one time, even if you will build the Ubuntu system many times.
Build the bootloader
1. Compile:$ make rk3368_box_defconfig -C u-boot/ $ make ARCHV=aarch64 -C u-boot/
2. Copy the images to the image directory:$ cp -a u-boot/RK3368MiniLoaderAll_V*.bin u-boot/uboot.img u-boot/trust.img images/
Build the initial ramdisk
1. Compile the kernel$ alias Make='make ARCH=arm64' $ Make -C linux ugeekbox_defconfig $ Make -C linux geekbox.img -j8or 7.9-inch CrossDisplay$ Make -C linux cross.img -j8
2. Copy the images to the image directory:$ cp -a linux/resource.img images/
3. Compile the initrd$ make -C initrdSHA match for u-boot:$ truncate -s "%4" images/initrd.imgView SecureNSModeBootImageShaCheck() function in following file for the information:
u-boot/board/rockchip/common/SecureBoot/SecureVerify.c
4. Generate the ramfs.img$ mkbootimg --kernel linux/arch/arm64/boot/Image --ramdisk images/initrd.img -o images/ramfs.img
Build the rootfs
Notice: Many following steps need the root privileges, do not forget to type sudo if necessary.
1. Create a blank image file using dd:$ dd if=/dev/zero of=images/rootfs.img bs=1M count=256Modify the count value as you want.
NOTE: if you want to build the rootfs on the host PC, recommend 2.5GB for GUI building.
2. Create linux filesystem on the newly created image:$ mkfs.ext4 -F -L linuxroot images/rootfs.imgNotice: "linuxroot" is the volume-label of the rootfs, it MUST BE EXACTLY MATCH the CMDLINE in parameter:CMDLINE: console=ttyS2 root=LABEL=linuxrootOtherwise, there will be similar mistakes as follow when mount the rootfs:Gave up waiting for root device. Common problems:
- Boot args (cat /proc/cmdline)
- Check rootdelay= (did the system wait long enough?)
- Check root= (did the system wait for the right device?)
- Missing modules (cat /proc/modules; ls /dev)
ALERT! /dev/disk/by-label/<unmatch-label> does not exist. Dropping to a shell!
(initramfs)
3. Confirm that rootfs is an empty directory!!!$ rm -rf rootfs && mkdir rootfs
4. Loop mount the the new image:$ sudo mount -o loop images/rootfs.img rootfs
5. Remove the unnecessary files$ sudo rm -rf rootfs/lost+found
6. Extract the ubuntu-core tarball into the mounted dir:$ sudo tar xzf archives/ubuntu-core/ubuntu-core-14.04.3-core-armhf.tar.gz -C rootfs/Tips: ubuntu-core is the minimal root file system.
7. Add hardware packages$ sudo cp -a archives/hwpacks/system/ rootfs/
8. Add Wifi & Bluetooth support$ sudo cp archives/hwpacks/wifibt/wifion rootfs/usr/local/bin/ $ sudo cp archives/hwpacks/wifibt/wifioff rootfs/usr/local/bin/ $ sudo cp archives/hwpacks/wifibt/wifi.conf rootfs/etc/init $ sudo cp archives/hwpacks/wifibt/bluetooth.conf rootfs/etc/init $ sudo cp archives/hwpacks/wifibt/bluetooth-ap6354.conf rootfs/etc/init
9. Setup serial console, booting as root user:$ sudo sed -e 's/tty1/ttyS2/g' -e '/^exec/c exec /sbin/getty -a root -L 115200 ttyS2 vt100' < rootfs/etc/init/tty1.conf > ttyS2.conf $ sudo mv ttyS2.conf rootfs/etc/init/ttyS2.conf
10. Setup the hostname:$ echo Geekbox > hostname $ sudo mv hostname rootfs/etc/hostname
Congratulations!
At this point, you have completed all the minimal-ubuntu images.
And so, all you should do is to burn these images down to device.
Download the images
1. Download the U-Boot first-level loader$ upgrade_tool ul images/RK3368MiniLoaderAll_V2.40.bin
2. Download the parameter$ upgrade_tool di -p utils/rockdev/parameter
3. Download the U-Boot second-level loader$ upgrade_tool di uboot images/uboot.img $ upgrade_tool di trust images/trust.img
4. Download the resource.img$ upgrade_tool di resource images/resource.img
5. Download the ramfs.img$ upgrade_tool di ramfs images/ramfs.img
6. Download the rootfs.img$ upgrade_tool di linuxroot images/rootfs.img
7. Boot the device$ upgrade_tool rdNotice: root access is necessary if you haven't setup udev rules.
View our Wiki for more information:
http://forum.geekbox.tv/viewtopic.php?f=2&t=42
Graphic desktop environment
NOTE: The following commands need run on your Geekbox target!
1. Plug-in a cable, then setup the network:root@Geekbox:~# echo auto eth0 > /etc/network/interfaces.d/eth0 root@Geekbox:~# echo iface eth0 inet dhcp >> /etc/network/interfaces.d/eth0 root@Geekbox:~# ln -fs /run/resolvconf/resolv.conf /etc/resolv.conf root@Geekbox:~# ifup eth0
2. Extend the root partition:root@Geekbox:~# resize2fs /dev/disk/by-label/linuxrootTips: the default volume size of root partition is specify in the first step of [Build the rootfs].
3. Install desktop packagesroot@Geekbox:~# apt-get update root@Geekbox:~# apt-get upgrade root@Geekbox:~# apt-get install ubuntu-desktop
4. [Optional]For bad network environment, such as: China.
Backup the ubuntu deb packages:root@Geekbox:~# apt-get install openssh-server root@Geekbox:~# scp /var/cache/apt/archives/*.deb gouwa@192.168.1.168:project/geekbox/ubuntu/archives/debsIf you did this, next time when you rebuilt the ubuntu system,
you can manually pull the deb packages into the apt debs archives path of target-device:root@Geekbox:~# scp gouwa@192.168.1.168:project/geekbox/ubuntu/archives/debs/*.deb /var/cache/apt/archives/ root@Geekbox:~# apt-get update && apt-get upgrade && apt-get install ubuntu-desktopThis will save you a lot of time to download them from the website.
5. Reboot and enjoy your hard but challenging workroot@Geekbox:~# reboot
T.B.D.
1> ubuntu system depth optimization
2> Building the arm64 ubuntu system
References
1. <Miniroot> http://androtab.info/miniroot/
2. <Ubuntu 14.04 LTS on Radxa> http://androtab.info/radxa_rock/ubuntu/
3. <Linaro rootfs on Radxa> http://wiki.radxa.com/Rock/ubuntu
4. <T-Chip Firefly-RK3288> http://wiki.t-firefly.com/index.php/Firefly-RK3288/en
5. <RootfsFromScratch> https://wiki.ubuntu.com/ARM/RootfsFromScratch
6. <rockchip mkbootimg> https://github.com/neo-technologies/rockchip-mkbootimg
7. <rkflashtool> https://github.com/neo-technologies/rkflashtool.git
8. <initfamfs> https://wiki.debian.org/initramfs
9. <Linux's Documentation> http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/filesystems/ramfs-rootfs-initramfs.txt?id=HEAD
相关文章推荐
- #新闻拍一拍# IBM 招聘广告要求应聘者具备至少 12 年 K8S 使用经验
- Ubuntu 默认壁纸历代记
- Ubuntu Remix Cinnamon 20.04 评测:Ubuntu 与 Cinnamon 的完美融合
- Linux socket 初步
- 关于Ubuntu 11.10启动提示waiting for the network configuration的问题
- 在 Ubuntu 桌面中使用文件和文件夹
- Linux Kernel 4.0 RC5 发布!
- linux lsof详解
- linux 文件权限
- Linux 执行数学运算
- 10 篇对初学者和专家都有用的 Linux 命令教程
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- ubuntu下chrome无法同步问题解决
- 运维入门
- 运维提升
- Linux 自检和 SystemTap