1. 程式人生 > >從零開始構建自己的ARM Ubuntu系統

從零開始構建自己的ARM Ubuntu系統

這篇文章介紹如何構建一個完整基於ARM的Ubuntu系統。

由於改文章當初寫的時候是發表在國外產品論壇上面,故保留了原文內容

補充說明:

雖然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 [email protected] 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
Visit the following link for the more versions:
[url]http://cdimage.ubuntu.com/ubuntu-core/releases[/url]


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 mkbootimg
Build 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 -j8
or 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 initrd
SHA match for u-boot:
$ truncate -s "%4" images/initrd.img
View 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


[b]Build the rootfs[/b]
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=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.


2. Create linux filesystem on the newly created image:
$ 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:
[quote]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)[/quote]
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 rd
Notice: root access is necessary if you haven't setup udev rules.
View our Wiki for more information: 
[url]http://forum.geekbox.tv/viewtopic.php?f=2&t=42[/url]




Graphic desktop environment
NOTE: The following commands need run on your Geekbox target!
1. Plug-in a cable, then setup the network:
[email protected]:~# echo auto eth0 > /etc/network/interfaces.d/eth0
[email protected]:~# echo iface eth0 inet dhcp >> /etc/network/interfaces.d/eth0
[email protected]:~# ln -fs /run/resolvconf/resolv.conf /etc/resolv.conf
[email protected]:~# ifup eth0

2. Extend the root partition:
[email protected]:~# resize2fs /dev/disk/by-label/linuxroot
Tips: the default volume size of root partition is specify in the first step of [Build the rootfs].


3. Install desktop packages
[email protected]:~# apt-get update
[email protected]:~# apt-get upgrade
[email protected]:~# apt-get install ubuntu-desktop

4. [Optional]For bad network environment, such as: China.
Backup the ubuntu deb packages:
[email protected]:~# apt-get install openssh-server
[email protected]:~# scp /var/cache/apt/archives/*.deb [email protected]: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:
[email protected]:~# scp [email protected]:project/geekbox/ubuntu/archives/debs/*.deb  /var/cache/apt/archives/
[email protected]:~# 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.


5. Reboot and enjoy your hard but challenging work
[email protected]:~# reboot


T.B.D.

1> ubuntu system depth optimization
2> Building the arm64 ubuntu system


References
1. <Miniroot>                       [url]http://androtab.info/miniroot/[/url]
2. <Ubuntu 14.04 LTS on Radxa>      [url]http://androtab.info/radxa_rock/ubuntu/[/url]
3. <Linaro rootfs on Radxa>         [url]http://wiki.radxa.com/Rock/ubuntu[/url]
4. <T-Chip Firefly-RK3288>          [url]http://wiki.t-firefly.com/index.php/Firefly-RK3288/en[/url]
5. <RootfsFromScratch>              [url]https://wiki.ubuntu.com/ARM/RootfsFromScratch[/url]
6. <rockchip mkbootimg>             [url]https://github.com/neo-technologies/rockchip-mkbootimg[/url]
7. <rkflashtool>                    [url]https://github.com/neo-technologies/rkflashtool.git[/url]
8. <initfamfs>                      [url]https://wiki.debian.org/initramfs[/url]
9. <Linux's Documentation>          [url]http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/filesystems/ramfs-rootfs-initramfs.txt?id=HEAD[/url]


相關推薦

開始構建自己ARM Ubuntu系統

這篇文章介紹如何構建一個完整基於ARM的Ubuntu系統。 由於改文章當初寫的時候是發表在國外產品論壇上面,故保留了原文內容。 補充說明: 雖然Geekbox是基於8核64Bits Cortex-A53 ARMV8架構的CPU,該方法構建的時候採用了向下相容的32Bits

Python 開始構建自己的比特幣區塊鏈系統

本文轉自PythonCaff作者SummerHappy Coding.你是否會和我一樣,對加密數字貨幣底層的區塊鏈技術非常感興趣,特別想了解他們的執行機制。但是學習區塊鏈技術並非一帆風順,我看多了大量的視訊教程還有各種課程,最終的感覺就是真正可用的實戰課程太少。我喜歡在實踐中

開始構建嵌入式系統實踐指南

近期花費了一段時間從零搭建一個嵌入式系統,從Uboot,Kernel,檔案系統的編譯到配置一步一步的實踐,採坑到現在的順理成章,經歷了一個痛苦的過程,因此把搭建過程中的經驗整理成了一篇詳細的教程,發表在GitChat平臺上,分享給大家,共同探討,共同進步。 一個精簡完整的嵌入式系統包

LFS 8.3 開始自己系統(二)~!~

cif dump ras x86-64 users setup ace trace 找到你 六、構建LFS系統 1.準備虛擬內核文件系統 1)創建將掛載文件系統的目錄:mkdir -pv $LFS/{dev,proc,sys,run}2)創建設備節點:mknod -m 60

LFS 8.3 開始自己系統(一)~!~

網站 acc multi sda ica 光盤 erl 主機系統 再次 此文是寫給新手的教程~!~我會盡量寫的詳細一些。虛擬機軟件:我選的是VirtualBox,版本:4.3.12 r93733。如果用vmware的話,設置方面基本差不多。縮主機系統:我用的是debian

開始構建一個centos+jdk7+tomcat7的映象檔案 centos7系統下docker執行環境的搭建 準備centos基礎映象 docker pull centos 或者直接下載我準備

從零開始構建一個centos+jdk7+tomcat7的映象檔案 準備centos基礎映象 docker pull centos 或者直接下載我準備好的映象 docker pull registry.cn-hangzhou.aliyuncs.com/repos_zy

開始構建一個的asp.net Core 項目(二)

mage .... cfi web execute 運行 figure 今天 deb 接著上一篇博客繼續進行。上一篇博客只是顯示了簡單的MVC視圖頁,這篇博客接著進行,連接上數據庫,進行簡單的CRUD。 首先我在Controllers文件夾點擊右鍵,添加->控制器 彈

webpack開始構建多頁項目(mpa)

www .html log targe 環境 分開 webpack 支持 博客 歷時一個星期左右,自己參考webpack官網等,從零開始構建webpack項目。本次的博客也是對前面的webpack項目搭建一文的補充。 在本wepack搭建的項目中,自己實現了下面的這些功

開始構建一個centos+jdk7+tomcat7的docker鏡像文件

entos 命名 doc 讀取 com 工作目錄 perm 後臺運行 star 從零開始構建一個centos+jdk7+tomcat7的鏡像文件 centos7系統下docker運行環境的搭建 準備centos基礎鏡像 docker pull centos 或者直接下載我

Maven系列(一)開始構建Java應用程序

.so 構建java項目 cti maven生命周期 包含 兩個類 簡述 work pil 前段時間面試,面試官要我簡述一下Maven生命周期,what?Maven不就是用來構建一個項目的麽,生命周期是什麽東東(我之前一直做.net,但是想找關於java的工作,之前使用Ma

開始搭建口袋妖怪管理系統(1)-Angular1.x開始

style ppc href rip initial 官方庫 從零開始 table 技術分享 開坑,一直喜歡口袋妖怪,想著能寫點有關的程序。 最近項目要改寫管理系統,所以用Angular1.x搭建一個口袋妖怪管理系統試試。 鞏固Ng1.x的知識+學習庫的用法,然後算是記錄一

開始搭建自己的VueJS2.0+ElementUI單頁面網站(一、環境搭建)

如圖所示 增刪改 type default sdn orm rain exp 名稱 原網址:https://blog.csdn.net/u012907049/article/details/72764151 前言 VueJS可以說是近些年來最火的前端框架之一,越來越多的

開始構建 Hadoop 集群

mod ase 壓縮 memory ssh-key frame In 文件 cor 一、簡介 當今只要談到大數據,自然想到Hadoop,以前Hadoop還只是個軟件、系統,而如今更多代表的是一個大數據生態圈。 本文談的 Hadoop 特指一個軟件,它是 Apache 基

開始搭建自己的.NET Core Api框架】(二)搭建項目的整體架構

config 七層 數據 TP 暫時 整體架構 比較 架構 其他 本來打算將搭建項目架構和集成SqlSugar放在一起講的,但是感覺東西有點多,還是分成兩章吧~ 這一章講搭建項目的整體架構,這裏先把搭建完成後的最終效果放出來,然後再逐個解釋每層的作用。 可以看到這裏一

開始搭建自己的.NET Core Api框架】(三)集成輕量級ORM——SqlSugar:3.3 自動生成實體類

i++ 點運算 自己的 yui content project style ref 數據庫表 系列目錄 一. 創建項目並集成swagger   1.1 創建   1.2 完善 二. 搭建項目整體架構 三. 集成輕量級ORM框架——SqlSugar   3.1 搭建環境  

開始搭建自己的.NET Core Api框架】(六)泛型倉儲的作用

tar write ges 分享圖片 () dex 抽象 .sql cut 系列目錄 一. 創建項目並集成swagger   1.1 創建   1.2 完善 二. 搭建項目整體架構 三. 集成輕量級ORM框架——SqlSugar   3.1 搭建環境   3.2 實戰篇:

開始-打造自己的虛擬實驗室-3

兩臺 分享圖片 本地 roc 綁定 cto ffffff ado 技術 虛擬交換機:用於虛擬機之間的網絡通訊 專用:本地虛擬機和虛擬機之間的通訊 在虛擬機的虛擬網卡中可以選擇虛擬交換機的連接 外部:用於虛擬機和外部網絡進行通

開始-打造自己的虛擬實驗室

rtu 封裝 快速 confirm 系統 硬件要求 download size 教育 實驗的計算機硬件要求CPU和主板:i5以上、VT虛擬化,SLA二級緩存優化、主板的BIOS中啟用VT虛擬化技術 內存:16GB以上 磁盤:專

開始自己的PHP框架系列教程(二)[App.php]

porting col config exce tro efault fig 默認 clas 從這一個文件開始以後加載的均以類加載,請註意命名空間和所在文件的路徑 APP.php的這個類所在路徑:根目錄\framework\App.php 直接上代碼 namespace

區塊鏈學習—開始建立自己的區塊鏈應用

閱讀物件 本文閱讀物件,主要是希望和即將從事區塊鏈開發的專案架構師,開發工程師,專案設計或產品設計師。要求閱讀者具備一定的“區塊鏈”基礎知識、概念和以及相關的技術知識。 如果你只需要對區塊鏈應用做一個更深更直觀的瞭解,通過本文的例子更清晰瞭解區塊鏈是怎麼回事,大概是怎麼開發出來的,怎麼使用,那麼