1. 程式人生 > >基於Zynq Linux環境搭建(四)

基於Zynq Linux環境搭建(四)

https://www.cnblogs.com/ifpga/p/8182036.html

此篇編譯根檔案系統

下載busybox和dropbear,

 

1

2

3

4

5

6

7

8

9

10

11

12

13

[#73#13:04:52 [email protected] ~/Zybo_Demo/XilinxFS]$wget --no-check-certificate https://git.busybox.net/busybox/snapshot/busybox-1_23_1.tar.gz

--2017-08-14 13:04:56--  https:

//git.busybox.net/busybox/snapshot/busybox-1_23_1.tar.gz

Resolving git.busybox.net (git.busybox.net)... 140.211.167.122

Connecting to git.busybox.net (git.busybox.net)|140.211.167.122|:443... connected.

WARNING: no certificate subject alternative name matches

        

requested host name `git.busybox.net'.

HTTP request sent, awaiting response... 200 OK

Length: unspecified [application/x-gzip]

Saving to: `busybox-1_23_1.tar.gz'

 

    [                                                 <=>                ] 2,800,283    230K/s   

in 13s    

 

2017-08-14 13:05:14 (211 KB/s) - `busybox-1_23_1.tar.gz' saved [2800283]

  

1

2

3

4

5

6

7

8

9

10

11

[#74#13:05:14 [email protected] ~/Zybo_Demo/XilinxFS]$wget http://matt.ucc.asn.au/dropbear/releases/dropbear-0.53.1.tar.gz

--2017-08-14 13:06:25--  http://matt.ucc.asn.au/dropbear/releases/dropbear-0.53.1.tar.gz

Resolving matt.ucc.asn.au (matt.ucc.asn.au)... 130.95.13.18, 2405:3c00:5200:100::18

Connecting to matt.ucc.asn.au (matt.ucc.asn.au)|130.95.13.18|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 1772583 (1.7M) [application/x-gzip]

Saving to: `dropbear-0.53.1.tar.gz'

 

100%[===================================================================>] 1,772,583    156K/s   in 12s    

 

2017-08-14 13:06:39 (143 KB/s) - `dropbear-0.53.1.tar.gz' saved [1772583/1772583]

  

 

在busybox目錄下,預設配置並初始化

make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi- defconfig

視覺化配置

make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi- menuconfig

 

 

 

安裝根檔案系統到指定目錄

make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi- install

 

 

 

在dropbear目錄下配置dropbear

/home/fpgadeveloper/Zybo_Demo/XilinxFS/dropbear-0.53.1

 

1

./configure --prefix=/home/fpgadeveloper/Zybo_Demo/XilinxFS/RootFS --host=arm-xilinx-linux-gnueabi --disable-zlib CC=arm-xilinx-linux-gnueabi-gcc LDFLAGS="-Wl,--gc-sections" CFLAGS="-ffunction-sections -fdata-sections -Os"

  

編譯dropbear

make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" MULTI=1 strip

安裝dropbear並建立符號連結

sudo make install

 

 

建立軟連線,進入/home/fpgadeveloper/Zybo_Demo/XilinxFS/RootFS/usr/bin

 

1

[#23#23:28:47 [email protected] ~/Zybo_Demo/XilinxFS/RootFS/usr/bin]$ln -s ../../sbin/dropbear ./scp

  

將交叉編譯庫拷貝到下述目錄

sudo cp ~/SDK2015/lin/arm-xilinx-linux-gnueabi/libc/lib/* lib -r

sudo cp ~/SDK2015/lin/arm-xilinx-linux-gnueabi/libc/sbin/* sbin -r

sudo cp ~/SDK2015/lin/arm-xilinx-linux-gnueabi/libc/usr/bin/* usr/bin/ -r

 

1

2

3

4

[#123#23:37:50 [email protected] ~/Zybo_Demo/XilinxFS/RootFS]$mkdir lib

[#124#23:38:30 [email protected] ~/Zybo_Demo/XilinxFS/RootFS]$sudo cp ~/SDK2015/lin/arm-xilinx-linux-gnueabi/libc/lib/* lib -r

[#125#23:38:33 [email protected] ~/Zybo_Demo/XilinxFS/RootFS]$sudo cp ~/SDK2015/lin/arm-xilinx-linux-gnueabi/libc/sbin/* sbin -r

[#126#23:38:35 [email protected] ~/Zybo_Demo/XilinxFS/RootFS]$sudo cp ~/SDK2015/lin/arm-xilinx-linux-gnueabi/libc/usr/bin/* usr/bin/ -r

  

在usr目錄下建立lib目錄

 

1

2

3

4

5

6

[#125#23:38:33 [email protected] ~/Zybo_Demo/XilinxFS/RootFS]$cd usr/

[#126#23:42:37 [email protected] ~/Zybo_Demo/XilinxFS/RootFS/usr]$ls

bin  sbin

[#127#23:42:39 [email protected] ~/Zybo_Demo/XilinxFS/RootFS/usr]$mkdir lib

[#128#23:42:43 [email protected] ~/Zybo_Demo/XilinxFS/RootFS/usr]$ls

bin  lib  sbin

  

sudo cp ~/ SDK2015 /lin/arm-xilinx-linux-gnueabi/libc/usr/lib/* usr/lib/ -r

進入到usr/lib路徑下,刪除

sudo rm -rf locale

sudo rm -rf audit

sudo rm -rf bin

sudo rm -rf gconv

sudo rm *.a

sudo rm *.o

 

1

2

3

4

5

6

7

8

9

[#132#23:43:42 [email protected] ~/Zybo_Demo/XilinxFS/RootFS]$sudo cp ~/SDK2015/lin/arm-xilinx-linux-gnueabi/libc/usr/lib/* usr/lib/ -r

[#133#23:45:12 [email protected] ~/Zybo_Demo/XilinxFS/RootFS]$cd usr/lib/

[#134#23:46:52 [email protected] ~/Zybo_Demo/XilinxFS/RootFS/usr/lib]$sudo rm -rf locale

[#135#23:47:00 [email protected] ~/Zybo_Demo/XilinxFS/RootFS/usr/lib]$sudo rm -rf audit

[#136#23:47:00 [email protected] ~/Zybo_Demo/XilinxFS/RootFS/usr/lib]$sudo rm -rf bin

[#137#23:47:00 [email protected] ~/Zybo_Demo/XilinxFS/RootFS/usr/lib]$sudo rm -rf gconv

[#138#23:47:00 [email protected] ~/Zybo_Demo/XilinxFS/RootFS/usr/lib]$sudo rm *.a

[#139#23:47:00 [email protected] ~/Zybo_Demo/XilinxFS/RootFS/usr/lib]$sudo rm *.o

[#140#23:47:00 [email protected] ~/Zybo_Demo/XilinxFS/RootFS/usr/lib]$

  

在檔案根目錄下執行

mkdir dev etc etc/dropbear etc/init.d mnt opt proc root sys tmp var var/log var/www

其中檔案都用Xilinx提供的ramdisk裡面的檔案,並拷貝到相關資料夾中

建立"etc/fstab"檔案,內容如下

touch etc/fstab

 

1

2

3

4

5

6

touch etc/fstab                                            

echo "LABEL=/ / tmpfs defaults 0 0            " >> etc/fstab

echo "none /dev/pts devpts gid=5,mode=620 0 0 " >> etc/fstab

echo "none /proc proc defaults 0 0            " >> etc/fstab

echo "none /sys sysfs defaults 0 0            " >> etc/fstab

echo "none /tmp tmpfs defaults 0 0            " >> etc/fstab

  

建立"etc/inittab"檔案,內容如下

 

1

2

3

4

5

6

7

8

9

10

touch etc/inittab                                                 

echo "::sysinit:/etc/init.d/rcS                    " >> etc/inittab

echo "# /bin/ash                                   " >> etc/inittab

echo "#                                            " >> etc/inittab

echo "# Start an askfirst shell on the serial ports" >> etc/inittab

echo "ttyPS0::respawn:-/bin/ash                    " >> etc/inittab

echo "# What to do when restarting the init process" >> etc/inittab

echo "::restart:/sbin/init                         " >> etc/inittab

echo "# What to do before rebooting                " >> etc/inittab

echo "::shutdown:/bin/umount -a -r                 " >> etc/inittab

  

建立"etc/passwd"檔案,內容如下

 

1

2

touch etc/passwd                                                                    

echo "root:$1$qC.CEbjC$SVJyqm.IG.gkElhaeM.FD0:0:0:root:/root:/bin/sh" >> etc/passwd 

  

建立檔案"etc/init.d/rcS" ,內容如下

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

#!/bin/sh

echo "Starting rcS..."

echo "++ Mounting filesystem"

mount -t proc none /proc

mount -t sysfs none /sys

mount -t tmpfs none /tmp

echo "++ Setting up mdev"

echo /sbin/mdev > /proc/sys/kernel/hotplug

mdev -s

mkdir -p /dev/pts

mkdir -p /dev/i2c

mount -t devpts devpts /dev/pts

echo "++ Starting telnet daemon"

telnetd -l /bin/sh

echo "++ Starting http daemon"

httpd -h /var/www

echo "++ Starting ftp daemon"

tcpsvd 0:21 ftpd ftpd -w /&

echo "++ Starting dropbear (ssh) daemon"

dropbear

echo "rcS Complete"

  

修改許可權

sudo chmod 755 etc/init.d/rcS

sudo chown root:root etc/init.d/rcS

製作檔案系統

複製程式碼

dd if=/dev/zero of=ramdisknew.image bs=1024 count=32768
mke2fs -F ramdisknew.image -L "ramdisk" -b 1024 -m 0
tune2fs ramdisknew.image -i 0
chmod a+rwx ramdisknew.image
sudo mount -o loop ramdisknew.image tmp_mnt_new/
sudo cp -R /home/fpgadeveloper/Zybo_Demo/XilinxFS/RootFS/* tmp_mnt_new/
cd tmp_mnt_new
cd bin/
sudo cp -rf /home/fpgadeveloper/Zybo_Demo/UART_Tools/lrzsz-0.12.20/src/lrz .
sudo cp -rf /home/fpgadeveloper/Zybo_Demo/UART_Tools/lrzsz-0.12.20/src/lsz .
cd ..
cd ..
sudo umount tmp_mnt_new
gzip ramdisknew.image
mkimage -A arm -T ramdisk -C gzip -d ramdisknew.image.gz uramdisk.image.gz

複製程式碼

拷貝uboot dtb *uramdisk.image.gz uImage等檔案,在SDK環境下合併

可通過qspi flash 或者SD卡啟動進行系統載入