Arm-Linux 移植 Ubuntu
<div style="display: none">---title: Arm-Linux 移植 Ubuntu
date:2020-06-22 07:31:59
categories:
tags:
- arm
- ubuntu
- rootfs
---</div>
<blockquote>
<p>https://blog.csdn.net/igouwa/article/details/50907861</p>
</blockquote>
<p>前言:</p>
<p>这篇文章介绍如何构建一个完整基于ARM的Ubuntu系统。</p>
<blockquote>
<p>由于该文章当初写的时候是发表在国外产品论坛上面,故保留了原文内容。</p>
<p>使用到的硬件平台:Geekbox</p>
<p>补充说明:</p>
<p>虽然Geekbox是基于8核64Bits Cortex-A53 ARMV8架构的CPU,该方法构建的时候采用了向下兼容的32Bits的ARMV7架构。因此,该方法适用于Cortex-A7/A9/A15/A17/A12架构的ARM处理器。</p>
</blockquote>
<p>In this guide, we will describe how to build an ubuntu system for Geekbox from scratch.</p>
<p>Different ways to achieve it:</p>
<ol>
<li>
<p>Build the whole system in host PC with Chroot(emulator)</p>
</li>
<li>
<p>Build in a removable media device, such as: SDCard or UDisk</p>
</li>
<li>
<p>Build in the target device directly 【current article】</p>
</li>
</ol>
<h3 id="before-starting">Before starting</h3>
<p>Carry on the following questions before you start your work:</p>
<blockquote>
<p>Q: What is included in an ubuntu system?</p>
<p>A: Bootloader & ramfs(kernel + initrd) & rootfs</p>
</blockquote>
<blockquote>
<p>Q: how to manage your ubuntu projects</p>
<p>A: Continue current reading and think about your own manage mothod.</p>
</blockquote>
<h3 id="preparations">Preparations</h3>
<ol>
<li>Create the working directories</li>
</ol>
<pre><code class="language-bash">$ install -d ~/project/geekbox/ubuntu/{linux,initrd,rootfs,prebuilts,archives/{ubuntu-core,debs,hwpacks},images,utils,scripts}$ cd ~/project/geekbox/ubuntu
</code></pre>
<ol start="2">
<li>Download the bootloader source code</li>
</ol>
<pre><code class="language-bash">$ git clone https://github.com/geekboxzone/lollipop_u-boot u-boot
</code></pre>
<ol start="3">
<li>Download the linux kernel source code</li>
</ol>
<pre><code class="language-bash">$ git clone https://github.com/geekboxzone/lollipop_kernel -b ubuntu linux
</code></pre>
<ol start="4">
<li>Download the toolchain</li>
</ol>
<pre><code class="language-bash">$ 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*
</code></pre>
<ol start="5">
<li>Download the initrd</li>
</ol>
<pre><code class="language-bash">$ git clone https://github.com/gouwa/initrd.git initrd
</code></pre>
<ol start="6">
<li>Download the hardware packages for Geekbox</li>
</ol>
<pre><code class="language-bash">$ git clone https://github.com/geekboxzone/ubuntu_hwpacks.git archives/hwpacks
</code></pre>
<ol start="7">
<li>Download the ubuntu-core</li>
</ol>
<pre><code class="language-bash">$ 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
# Visit the following link for the more versions:
# http://cdimage.ubuntu.com/ubuntu-core/releases
</code></pre>
<ol start="8">
<li>Download the rockchip upgrade tool, note to specify the 'ubuntu' branch:</li>
</ol>
<pre><code class="language-bash">$ git clone https://github.com/geekboxzone/utils.git -b ubuntu utils
# If you want to run the command in any path:
# $ sudo cp -a utils/upgrade_tool /usr/local/bin
</code></pre>
<ol start="9">
<li>Download the rockchip mkbootimg tools</li>
</ol>
<pre><code class="language-bash">$ git clone https://github.com/neo-technologies/rockchip-mkbootimg.git mkbootimg
</code></pre>
<h1 id="build-and-install-mkbootimg-tools">Build and install mkbootimg tools:</h1>
<p>$ make -C mkbootimg/$ sudo make install -C mkbootimg/</p>
<pre><code class="language-bash">
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. Download the scripts:
```bash
$ git clone https://github.com/geekboxzone/ubuntu_scripts.git scripts
</code></pre>
<p>All the steps above just need to run one time, even if you will build the Ubuntu system many times.</p>
<h3 id="build-the-bootloader">Build the bootloader</h3>
<ol>
<li>Compile:</li>
</ol>
<pre><code class="language-bash">$ make rk3368_box_defconfig -C u-boot/$ make ARCHV=aarch64 -C u-boot/
</code></pre>
<ol start="2">
<li>Copy the images to the image directory:</li>
</ol>
<pre><code class="language-bash">$ cp -a u-boot/RK3368MiniLoaderAll_V*.bin u-boot/uboot.img u-boot/trust.img images/
</code></pre>
<h3 id="build-the-initial-ramdisk">Build the initial ramdisk</h3>
<ol>
<li>Compile the kernel</li>
</ol>
<pre><code class="language-bash">$ alias Make='make ARCH=arm64'$ Make -C linux ugeekbox_defconfig$ Make -C linux geekbox.img -j8
or 7.9-inch CrossDisplay
$ Make -C linux cross.img -j8
</code></pre>
<ol start="2">
<li>Copy the images to the image directory:</li>
</ol>
<pre><code class="language-bash">$ cp -a linux/resource.img images/
</code></pre>
<ol start="3">
<li>Compile the initrd</li>
</ol>
<pre><code class="language-bash">$ make -C initrd
</code></pre>
<p>SHA match for u-boot:</p>
<pre><code class="language-bash">$ truncate -s '%4' images/initrd.img
#View SecureNSModeBootImageShaCheck() function in following file for the information:
#u-boot/board/rockchip/common/SecureBoot/SecureVerify.c
</code></pre>
<ol start="4">
<li>Generate the ramfs.img</li>
</ol>
<pre><code class="language-bash">$ mkbootimg --kernel linux/arch/arm64/boot/Image --ramdisk images/initrd.img -o images/ramfs.img
</code></pre>
<h3 id="build-the-rootfs">Build the rootfs</h3>
<p>Notice: Many following steps need the root privileges, do not forget to type sudo if necessary.</p>
<ol>
<li>Create a blank image file using dd:</li>
</ol>
<pre><code class="language-bash">$ dd if=/dev/zero of=images/rootfs.img bs=1M count=256
# Modify the count value as you want.
# NOTE: if you want to build the rootfs on the host PC, recommend 2.5GB for GUI building.
</code></pre>
<ol start="2">
<li>Create linux filesystem on the newly created image:</li>
</ol>
<pre><code class="language-bash">$ mkfs.ext4 -F -L linuxroot images/rootfs.img
Notice: 'linuxroot' is the volume-label of the rootfs, it MUST BE EXACTLY MATCH the CMDLINE in parameter:
CMDLINE: console=ttyS2 root=LABEL=linuxroot
Otherwise, 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/ does not exist.Dropping to a shell!
(initramfs)
</code></pre>
<ol start="3">
<li>Confirm that rootfs is an empty directory!!!</li>
</ol>
<pre><code class="language-bash">$ rm -rf rootfs && mkdir rootfs
</code></pre>
<ol start="4">
<li>Loop mount the the new image:</li>
</ol>
<pre><code class="language-bash">$ sudo mount -o loop images/rootfs.img rootfs
</code></pre>
<ol start="5">
<li>Remove the unnecessary files</li>
</ol>
<pre><code class="language-bash">$ sudo rm -rf rootfs/lost+found
</code></pre>
<ol start="6">
<li>Extract the ubuntu-core tarball into the mounted dir:</li>
</ol>
<pre><code class="language-bash">$ 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.
</code></pre>
<ol start="7">
<li>Add hardware packages</li>
</ol>
<pre><code class="language-bash">$ sudo cp -a archives/hwpacks/system/ rootfs/
</code></pre>
<ol start="8">
<li>Add Wifi & Bluetooth support</li>
</ol>
<pre><code class="language-bash">$ 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:
```bash
$ sudo sed -e 's/tty1/ttyS2/g' -e '/^exec/c exec /sbin -a root -L 115200 ttyS2 vt100' < rootfs/etc/init/tty1.conf > ttyS2.conf
$ sudo mv ttyS2.conf rootfs/etc/init/ttyS2.conf
</code></pre>
<ol start="10">
<li>Setup the hostname:</li>
</ol>
<pre><code class="language-bash">$ echo Geekbox > hostname$ sudo mv hostname rootfs/etc/hostname
</code></pre>
<p>Congratulations!</p>
<p>At this point, you have completed all the minimal-ubuntu images.</p>
<p>And so, all you should do is to burn these images down to device.</p>
<h3 id="download-the-images">Download the images</h3>
<ol>
<li>Download the U-Boot first-level loader</li>
</ol>
<pre><code class="language-bash">$ upgrade_tool ul images/RK3368MiniLoaderAll_V2.40.bin
</code></pre>
<ol start="2">
<li>Download the parameter</li>
</ol>
<pre><code class="language-bash">$ upgrade_tool di -p utils/rockdev/parameter
</code></pre>
<ol start="3">
<li>Download the U-Boot second-level loader</li>
</ol>
<pre><code class="language-bash">$ upgrade_tool di uboot images/uboot.img$ upgrade_tool di trust images/trust.img
</code></pre>
<ol start="4">
<li>Download the resource.img</li>
</ol>
<pre><code class="language-bash">$ upgrade_tool di resource images/resource.img
</code></pre>
<ol start="5">
<li>Download the ramfs.img</li>
</ol>
<pre><code class="language-bash">$ upgrade_tool di ramfs images/ramfs.img
</code></pre>
<ol start="6">
<li>Download the rootfs.img</li>
</ol>
<pre><code class="language-bash">$ upgrade_tool di linuxroot images/rootfs.img
</code></pre>
<ol start="7">
<li>Boot the device</li>
</ol>
<pre><code class="language-bash">$ upgrade_tool rd
# Notice: 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
</code></pre>
<h3 id="graphic-desktop-environment">Graphic desktop environment</h3>
<p>NOTE: The following commands need run on your Geekbox target!</p>
<ol>
<li>Plug-in a cable, then setup the network:</li>
</ol>
<pre><code class="language-bsah">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
</code></pre>
<ol start="2">
<li>Extend the root partition:</li>
</ol>
<pre><code>root@Geekbox:~# resize2fs /dev/disk/by-label/linuxroot
Tips: the default volume size of root partition is specify in the first step of .
</code></pre>
<ol start="3">
<li>Install desktop packages</li>
</ol>
<pre><code>root@Geekbox:~# apt-get update
root@Geekbox:~# apt-get upgrade
root@Geekbox:~# apt-get install ubuntu-desktop
</code></pre>
<ol start="4">
<li>For bad network environment, such as: China.</li>
</ol>
<p>Backup the ubuntu deb packages:</p>
<pre><code>root@Geekbox:~# apt-get install openssh-server
root@Geekbox:~# scp /var/cache/apt/archives/*.deb gouwa@192.168.1.168:project/geekbox/ubuntu/archives/debs
# If 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-desktop
# This will save you a lot of time to download them from the website.
</code></pre>
<ol start="5">
<li>Reboot and enjoy your hard but challenging work</li>
</ol>
<pre><code class="language-bash">root@Geekbox:~# reboot
</code></pre>
<p>T.B.D.</p>
<p>1> ubuntu system depth optimization</p>
<p>2> Building the arm64 ubuntu system</p>
<h3 id="references">References</h3>
<ol>
<li>
<p>http://androtab.info/miniroot/</p>
</li>
<li>
<p>http://androtab.info/radxa_rock/ubuntu/</p>
</li>
<li>
<p>http://wiki.radxa.com/Rock/ubuntu</p>
</li>
<li>
<p>http://wiki.t-firefly.com/index.php/Firefly-RK3288/en</p>
</li>
<li>
<p>https://wiki.ubuntu.com/ARM/RootfsFromScratch</p>
</li>
<li>
<p>https://github.com/neo-technologies/rockchip-mkbootimg</p>
</li>
<li>
<p>https://github.com/neo-technologies/rkflashtool.git</p>
</li>
<li>
<p>https://wiki.debian.org/initramfs</p>
</li>
<li>
<p>http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/filesystems/ramfs-rootfs-initramfs.txt?id=HEAD</p>
</li>
</ol>
</div>
<div id="MySignature" role="contentinfo">
如果说我的文章对你有用,只不过是我站在巨人的肩膀上再继续努力罢了。<br>若在页首无特别声明,本篇文章由 Schips 经过整理后发布。<br>博客地址:https://www.cnblogs.com/schips/<br><br>
来源:https://www.cnblogs.com/schips/p/12126275.html
頁:
[1]