buildroot_001.png

這次Build toolchian 要用ubuntu 16.04, 16.04 及之前版本的預設桌面為經典 Unity,18.04 開始為 Gnome 3,但您仍可手動安裝 Unity 並進行切換。

https://blog.xuite.net/yh96301/blog/242333268-%E5%AE%89%E8%A3%9DUbuntu+16.04

 

這次要在VirtualBox內在使用Docker, Docker 是屬於另外一種虛擬化技術,它透過 container 的方式將應用程式與相關所需的執行環境包起來,讓每個應用程式共用系統核心(kernel),但還是都有各自獨立的根目錄、檔案系統、網路環境、行程管理等,對於程式而言就好像在一般的獨立的系統上執行一樣。由於他很小執行速度較快可以在VM上很容易有好幾個Dcoker的Container

How To Install and Use Docker on Ubuntu 16.04'

 

查看 Docker 的版本資訊:

docker version

ip218@ip218-VirtualBox:~$ docker version
Client:
 Version:          18.09.7
 API version:     1.39
 Go version:      go1.10.4
 Git commit:     2d0083d
 Built:               Wed Jul  3 13:38:22 2019
 OS/Arch:         linux/amd64
 Experimental:   false

Server:
 Engine:
  Version:         18.09.7
  API version:    1.39 (minimum version 1.12)
  Go version:     go1.10.4
  Git commit:    2d0083d
  Built:              Mon Jul  1 19:31:53 2019
  OS/Arch:        linux/amd64
  Experimental:  false

 

若要下載 container 映像檔,可以使用 pull 並且指定 container 的名稱:
docker pull ubuntu:16.04

 

docker 的 images 指令可以列出目前系統上所有的 container 映像檔:

ip218@ip218-VirtualBox:~$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
peter_buildroot     2010.02.rc1         0634648b94a8        2 months ago        3.6GB
ubuntu                16.04                  2a697363a870       3 months ago        119MB
ubuntu                latest                  d131e0fa2585        3 months ago        102MB

 

有個 container 映像檔之後,我們就可以在 container 中執行程式了,若要進入 Docker container 中的執行環境,可以使用 docker 的 run 指令,加上 -i 與 -t 參數進入互動式的操作介面並且配置 tty:
docker run -it ubuntu:16:04

 

buildroot_002.png

當你使用 volume 時,docker 會在你的本機上隨機新增一個資料夾(Local storage area),大部分會在 /var 底下,然後讓這個資料夾跟 container 裡面的某個資料夾互通。

因為他們是互通的,所以當你 container 裡面那個資料夾有任何變更時,本地的資料夾也會跟著變,而且很重要的一點是:container 被刪掉時那個資料夾還會原封不動保留在那邊 ,在啟動時加一個 -v 參數,就可以指定 volume 要跟容器內哪一個資料夾連通,這邊用的是 /db/data,實際上使用時可以換成資料庫存放資料的路徑

 

上面那種先 create 再使用的 volume 稱作 named volume,而現在要介紹另外一種叫做 host volume,用來直接指定某個資料夾跟容器內的資料夾連通

docker run -it -v /home/ip218/SDK/IP218_UART_SDK_KIC11108_20180122:/home/SDK ubuntu:16.04 /bin/bash

host  :/home/ip218/SDK/IP218_UART_SDK_KIC11108_20180122
docker:/home/SDK

 

有時候從Docker鏡像倉庫中下載的鏡像不能滿足要求,我們可以基於一個基礎鏡像構建一個自己的鏡像

兩種方式:

    更新鏡像:使用docker commit命令
    構建鏡像:使用docker build命令,需要創建Dockerfile文件

commit 提交為新鏡像
docker commit -m "Added Git package" -a "Starter" 88400ddfbf99 ubuntu:v2

docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
-a :提交的镜像作者;
-c :使用Dockerfile指令来创建镜像;
-m :提交时的说明文字;
-p :在commit时,将容器暂停。

https://kknews.cc/zh-tw/other/ppl4k6j.html

Docker 筆記 Part 2 |指令操作

 

準備docker image: docker pull ubuntu:16.04

執行container: docker run -it -v /home/ip218/SDK/IP218_UART_SDK_KIC11108_20180122:/home/SDK ubuntu:16.04 /bin/bash

 

Lexra MIPS CPU patch

Lexra was a semiconductor intellectual property core company based in Waltham, Massachusetts. It was founded in 1997 and began developing and licensing semiconductor intellectual property cores that implemented the MIPS I architecture, except for the four unaligned load and store (lwl, lwr, swl, swr) instructions.

所以要避免編出這4個指令lwl, lwr, swl, swr

有3個要patch 1:binutil, 2:gcc,3:uClibc

1:binutil其實並不一定要patch所以先略過

2:gcc patch

--- gcc-4.3.4-orig/gcc/config/mips/mips.md      2019-07-24 06:40:58.517000000 +0000
+++ gcc-4.3.4/gcc/config/mips/mips.md   2019-07-24 06:46:53.937000000 +0000

@@ -3135,7 +3135,7 @@
        (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
                     (match_operand:QI 2 "memory_operand" "m")]
                    UNSPEC_LOAD_LEFT))]

-  "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
+  "!TARGET_MIPS16 && !TARGET_LEXRA && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
   "<load>l\t%0,%2"
   [(set_attr "type" "load")
    (set_attr "mode" "<MODE>")])

@@ -3146,7 +3146,7 @@
                     (match_operand:QI 2 "memory_operand" "m")
                     (match_operand:GPR 3 "register_operand" "0")]
                    UNSPEC_LOAD_RIGHT))]

-  "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
+  "!TARGET_MIPS16 && !TARGET_LEXRA && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
   "<load>r\t%0,%2"
   [(set_attr "type" "load")
    (set_attr "mode" "<MODE>")])
@@ -3156,7 +3156,7 @@
        (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
                     (match_operand:QI 2 "memory_operand" "m")]
                    UNSPEC_STORE_LEFT))]

-  "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
+  "!TARGET_MIPS16 && !TARGET_LEXRA && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
   "<store>l\t%z1,%2"
   [(set_attr "type" "store")
    (set_attr "mode" "<MODE>")])

@@ -3167,7 +3167,7 @@
                     (match_operand:QI 2 "memory_operand" "m")
                     (match_dup 0)]
                    UNSPEC_STORE_RIGHT))]

-  "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
+  "!TARGET_MIPS16 && !TARGET_LEXRA && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
   "<store>r\t%z1,%2"
   [(set_attr "type" "store")
    (set_attr "mode" "<MODE>")])

--- gcc-4.3.4-orig/gcc/config/mips/mips.h       2019-07-24 07:53:01.749000000 +0000
+++ gcc-4.3.4/gcc/config/mips/mips.h    2019-07-24 07:50:07.237000000 +0000

@@ -87,6 +87,8 @@
   unsigned short memory_latency;
 };

+#define TARGET_LEXRA 1
+

 /* Which ABI to use.  ABI_32 (original 32, or o32), ABI_N32 (n32),
    ABI_64 (n64) are all defined by SGI.  ABI_O64 is o32 extended
    to work on a 64-bit machine.  */

--- gcc-4.3.4-orig/gcc/config/mips/mips.c       2019-08-13 07:38:48.001979792 +0000
+++ gcc-4.3.4/gcc/config/mips/mips.c    2009-03-02 20:42:24.000000000 +0000

@@ -5704,6 +5704,8 @@
   if (MEM_ALIGN (src) == BITS_PER_WORD / 2
       && MEM_ALIGN (dest) == BITS_PER_WORD / 2)
     bits = BITS_PER_WORD / 2;

+  else if (TARGET_LEXRA)
+    bits = MIN (MEM_ALIGN (src), MEM_ALIGN (dest));

   else
     bits = BITS_PER_WORD;

@@ -5964,6 +5966,8 @@
     }
   else
     {

+      if (TARGET_LEXRA)
+        return false;

       emit_insn (gen_mov_lwl (temp, src, left));
       emit_insn (gen_mov_lwr (dest, copy_rtx (src), right, temp));
     }

@@ -5999,6 +6003,8 @@
     }
   else
     {

+      if (TARGET_LEXRA)
+        return false;

       emit_insn (gen_mov_swl (dest, src, left));
       emit_insn (gen_mov_swr (copy_rtx (dest), copy_rtx (src), right));
     }

 

這是之前所compile出來的busybox用mips-linux-objdump -d disassemble 來看有lwl, lwr, swl, swr, gcc patch過應該就沒有了
root@41c2494ddf70:/home/ip218_release# user/bin/mips-linux-objdump -d  build/initramfs/bin/busybox | grep lwl
  436210:    8a22000c     lwl    v0,12(s1)
  437098:    8ac20014     lwl    v0,20(s6)
  438c5c:    8a2300ec     lwl    v1,236(s1)
  471e68:    8ba2001a     lwl    v0,26(sp)
root@41c2494ddf70:/home/ip218_release# user/bin/mips-linux-objdump -d  build/initramfs/bin/busybox | grep lwr
  436218:    9a22000f     lwr    v0,15(s1)
  4370a0:    9ac20017     lwr    v0,23(s6)
  438c64:    9a2300ef     lwr    v1,239(s1)
  471e70:    9ba2001d     lwr    v0,29(sp)
root@41c2494ddf70:/home/ip218_release# user/bin/mips-linux-objdump -d  build/initramfs/bin/busybox | grep swl
  433e58:    aa110000     swl    s1,0(s0)
  436034:    aa020004     swl    v0,4(s0)
  438d4c:    aa0300ec     swl    v1,236(s0)
root@41c2494ddf70:/home/ip218_release# user/bin/mips-linux-objdump -d  build/initramfs/bin/busybox | grep swr
  433e60:    ba110003     swr    s1,3(s0)
  436038:    ba020007     swr    v0,7(s0)
  438d54:    ba0300ef     swr    v1,239(s0)

 

 

3:uClibc patch

uClibc主要是修改assemble因為C已經不會編出lwl, lwr, swl, swr

assmeble tips

LB  rT, offset(rS)    Load Byte
LBU rT, offset(rS)    Load Byte Unsigned
LH  rT, offset(rS)    Load Halfword
LHU rT, offset(rS)    Load Halfword Unsigned
LW  rT, offset(rS)    Load Word

rT ¬ Memory[rS + offset]

Reg rT is loaded from data memory. The memory address is computed as base + offset, where the base is reg rS and the offset is the 16-bit offset sign-extended to 32 bits. LB, LBU addresses are interpreted as byte addresses to data memory; LH, LHU as halfword (16-bit) addresses; LWas word (32-bit) addresses.
The data fetched in LB, LH (LBU, LHU) is sign-extended (zeroextended) to 32-bits for storage to reg rT.
rT cannot be referenced in the instruction following a load instruction.

Branch or jump instructions may optionally store in a general purpose register the address of the instruction at the memory location following the branch delay slot of a jump or a branch which is taken

 

 

將修改過的patch file& shell script file上傳到github

apt-get install git

git init
git add .
git config --global user.email "peter27863043@yahoo.com"
git config --global user.name "peter27863043"
git commit -m "first commit"
git remote add origin https://github.com/peter27863043/buildroot-2010.02-rc1.git
git push -u origin master

在docker /home 下執行git init並從github下載所有patch & shell script file

git init
git remote add origin https://github.com/peter27863043/buildroot-2010.02-rc1.git
git pull origin master

 

在docker /home 下執行buildroot-2010.02-rc1.sh 即可自行download buildroot-2010.02-rc1並patch且安裝所需元件

root@a67e262edc86:/home# ./buildroot-2010.02-rc1.sh

buildroot_2010.02.rc1.sh:

apt-get update
apt-get -y install wget
apt-get -y install curl
apt-get -y install bzip2
wget https://buildroot.org/downloads/buildroot-2010.02-rc1.tar.bz2
bunzip2 buildroot-2010.02-rc1.tar.bz2
tar -xvf buildroot-2010.02-rc1.tar
apt-get -y install gcc-4.8 g++-4.8 g++-4.8-multilib gcc-4.8-multilib
apt-get -y install make
apt-get -y install bison flex gettext
apt-get -y install g++
apt-get -y install libncurses5-dev
apt-get -y install patch

apt-get install -y cpio
apt-get install -y lzma

wget http://ftp.gnu.org/gnu/texinfo/texinfo-4.13.tar.gz
gzip -dc < texinfo-4.13.tar.gz | tar -xf -
cd texinfo-4.13
./configure
make
make install
cd ..

cd buildroot-2010.02-rc1

mkdir dl
cd dl
wget https://www.nektar.info/thirdparty/zlib-1.2.3.tar.bz2
wget download http://sources.buildroot.net/module-init-tools-3.2.2.tar.bz2
wget https://launchpad.net/genext2fs/main/1.4/+download/genext2fs-1.4.tar.gz
wget http://repository.timesys.com/buildsources/f/fakeroot/fakeroot-1.9.5/fakeroot-1.9.5.tar.gz
cp fakeroot-1.9.5.tar.gz fakeroot_1.9.5.tar.gz
cd ..

在buildroot-2010.02-rc1目錄下執行make menuconfig不需要修改甚麼因為buildroot的.config已經patch好了

再執行make即可

 

有一個patch要手動加上去個!這是makedevs的waring視為error

/usr/bin/gcc -Wall -Werror -O2 /home/buildroot-2010.02-rc1/output/build/makedevs-host/makedevs.c -o /home/buildroot-2010.02-rc1/output/build/makedevs-host/makedevs
/home/buildroot-2010.02-rc1/output/build/makedevs-host/makedevs.c: In function 'main':
/home/buildroot-2010.02-rc1/output/build/makedevs-host/makedevs.c:366:6: error: variable 'ret' set but not used [-Werror=unused-but-set-variable]
  int ret = EXIT_SUCCESS;
      ^
cc1: all warnings being treated as errors
target/makedevs/makedevs.mk:16: recipe for target '/home/buildroot-2010.02-rc1/output/build/makedevs-host/makedevs' failed
make: *** [/home/buildroot-2010.02-rc1/output/build/makedevs-host/makedevs] Error 1

手動執行下面兩個copy再make即可
cp ../buildroot-2010.02-rc1-patch/makedevs.c output/build/makedevs-host/
cp ../buildroot-2010.02-rc1-patch/makedevs.c target/makedevs/

toolchain library 比較

// original  lib                                                                           // new lib       
  26692 Jan 17  2009 ld-uClibc-0.9.30.so*                                   26668 Aug 14 08:02 ld-uClibc-0.9.30.2.so*
     19 Oct  8  2013 ld-uClibc.so.0 -> ld-uClibc-0.9.30.so*                  21 Aug 14 08:02 ld-uClibc.so.0 -> ld-uClibc-0.9.30.2.so*
     
     19 Oct  8  2013 libc.so.0 -> libuClibc-0.9.30.so                           21 Aug 14 08:02 libc.so.0 -> libuClibc-0.9.30.2.so*
 414732 Jan 17  2009 libuClibc-0.9.30.so                                  467148 Aug 14 08:02 libuClibc-0.9.30.2.so*
     
  13584 Jan 17  2009 libcrypt-0.9.30.so                                      11704 Aug 14 08:02 libcrypt-0.9.30.2.so*
     18 Oct  8  2013 libcrypt.so.0 -> libcrypt-0.9.30.so                       20 Aug 14 08:02 libcrypt.so.0 -> libcrypt-0.9.30.2.so*
     
   9480 Jan 17  2009 libdl-0.9.30.so                                            9496 Aug 14 08:02 libdl-0.9.30.2.so*
     15 Oct  8  2013 libdl.so.0 -> libdl-0.9.30.so                                17 Aug 14 08:02 libdl.so.0 -> libdl-0.9.30.2.so*
     
     13 Oct  8  2013 libgcc_s.so -> libgcc_s.so.1
 210350 Jan 17  2009 libgcc_s.so.1                                       1494553 Aug 14 08:02 libgcc_s.so.1
 
 122404 Jan 17  2009 libm-0.9.30.so                                        110672 Aug 14 08:02 libm-0.9.30.2.so*
     14 Oct  8  2013 libm.so.0 -> libm-0.9.30.so                                16 Aug 14 08:02 libm.so.0 -> libm-0.9.30.2.so*
     
   4896 Jan 17  2009 libnsl-0.9.30.so                                           1680 Aug 14 08:02 libnsl-0.9.30.2.so*
     16 Oct  8  2013 libnsl.so.0 -> libnsl-0.9.30.so                             18 Aug 14 08:02 libnsl.so.0 -> libnsl-0.9.30.2.so*
     
  87364 Jan 17  2009 libpthread-0.9.30.so                                  83548 Aug 14 08:02 libpthread-0.9.30.2.so*
     20 Oct  8  2013 libpthread.so.0 -> libpthread-0.9.30.so                22 Aug 14 08:02 libpthread.so.0 -> libpthread-0.9.30.2.so*
     
   4900 Jan 17  2009 libresolv-0.9.30.so                                       1684 Aug 14 08:02 libresolv-0.9.30.2.so*
     19 Oct  8  2013 libresolv.so.0 -> libresolv-0.9.30.so                     21 Aug 14 08:02 libresolv.so.0 -> libresolv-0.9.30.2.so*

   5312 Jan 17  2009 librt-0.9.30.so                                             5552 Aug 14 08:02 librt-0.9.30.2.so*
     15 Oct  8  2013 librt.so.0 -> librt-0.9.30.so                                 17 Aug 14 08:02 librt.so.0 -> librt-0.9.30.2.so*
     
     18 Oct  8  2013 libstdc++.so -> libstdc++.so.6.0.3*
     18 Oct  8  2013 libstdc++.so.6 -> libstdc++.so.6.0.3*
 810538 Jan 11  2011 libstdc++.so.6.0.3*
 
 
   5088 Jan 17  2009 libutil-0.9.30.so                                          5012 Aug 14 08:02 libutil-0.9.30.2.so*
     17 Oct  8  2013 libutil.so.0 -> libutil-0.9.30.so                           19 Aug 14 08:02 libutil.so.0 -> libutil-0.9.30.2.so*    
     
    

toolchain build出來的image 比較

//Original                                               New                                                      New+debug messgae= -g1
3534479 Aug 22 07:10 initramfs.gz        3547782 Aug 22 07:22 initramfs.gz          3166014 Aug 22 07:51 initramfs.gz
 372518 Aug 22 06:57 u-boot-rom*          446978 Aug 22 07:15 u-boot-rom*            250277 Aug 22 07:45 u-boot-rom*
 153492 Aug 22 06:57 u-boot-rom.bin*      151896 Aug 22 07:15 u-boot-rom.bin*     151896 Aug 22 07:45 u-boot-rom.bin*
1625488 Aug 22 07:04 uImage.vmlinuz   1641996 Aug 22 07:21 uImage.vmlinuz    1642831 Aug 22 07:50 uImage.vmlinuz

 

現在還差libstdc++由於太大所以沒放進去以致 initramfs.gz小很多

 2529799 Aug 22 06:43 libstdc++.so.6.0.10*

執行

 output/staging/usr/bin/mips-linux-strip -g output/target/usr/lib/libstdc++.so.6.0.10

strip後小太多了

728239 Aug 22 08:30 libstdc++.so.6.0.10*

 

 

 

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 peter27863043 的頭像
    peter27863043

    檸檬傻斌-無料

    peter27863043 發表在 痞客邦 留言(0) 人氣()