# Regulart Meeting (2020.6.7)
* 1 How to change pynq-z2 to zybo-z7 (Last week)
* 2 Build Component of OS
* 2.1 Component of OS
* 2.1.1 Build *u-boot* (aka bootloader) for arm
* 2.1.2 Build Linux-kernel for arm
* 2.1.3 Build *busybox* (aka rootfs) for arm
* 2.2 Cost of build time
* 2.3 The trade-off between *busybox* and *buildroot*
## 1 How to change build board from pynq-z2 to zybo-z7
[Refer to here](https://github.com/curly-wei/xvc-zybo-z7/tree/main/src/hw/script)
Modify 3 place:
* PS-Preset
* In the `hw/script/top.tcl`
* To generate preset file
1. [Install board file](https://reference.digilentinc.com/software/vivado/board-files?redirect=1)
2. Open vivado create a project with your board 
3. Open/create IP integrator, place zynq-7000-proc 
4. Double click zynq-7000-proc, *Re-customize IP* window will show up 
5. Click *Preset* -> *Default* 
6. Click OK to close window
7. Click `Run block Automation` 
8. Double click zynq-7000-proc again
9. Click *Preset* -> *Save Configuration*
10. Fill output field, click OK ,the `output.tcl` is your preset file ![]()
* FPGA-PART
* In the hw build script file `hw/script/top.tcl`
* Physical Pin & HDL Port mapping file
* In the `hw/xdc/top.xdc`
## 2 Build Component of OS
Fully flow of build for XVC
```mermaid
flowchart TB
subgraph HW
subgraph HDL-codes
jtag-pl.v
axi-jtag.v
end
HDL-codes
--> build_hw-scripts.tcl
-- vivado-tcl
--> xsa_hw(xvc-top.xsa)
end
subgraph OS/SW
build_busybox.sh
-- download src from github \n linaro-arm-linux-gcc-7.5
--> busybox(busybox rootfs dir _install)
build_kernel.sh
-- download src from github \n linaro-arm-linux-gcc-7.5
--> uImage
build_uboot.sh
-- download src from github \n linaro-arm-linux-gcc-7.5
--> uboot.elf
-- copy to
--> boot.bin_srcs
u-boot-conf
--> boot.bin_srcs
xsa_os(xvc-top.xsa)
--> build_fsbl.tcl
-- xilinx-vitis-xsct
--> fsbl.elf
-- copy to
--> boot.bin_srcs
xsa_os(xvc-top.xsa)
--> gen_base_dt.tcl
-- xilinx-vitis-xsct
--> base_dt_dir(bast dt dir)
dt_patch
-- patch to
--> base_dt_dir(bast dt dir)
-- dtc
--> xvc.dtb
-- copy to
--> boot.bin_srcs
boot.bin_srcs
-- xilinx-bootgen
--> boot.bin
subgraph xvc_srcs
xvc.c
xvc.h
end
xvc_srcs
--> Makefile
-- linaro-arm-linux-gcc-7.5
--> xvc.elf
end
HW --> OS/SW
```
### 2.1 Component of OS
#### 2.1.1 Build u-boot
* [build-code](https://github.com/curly-wei/xvc-zybo-z7/blob/main/src/os/script/build_uboot.sh)
* Reason
* Boot Loader is necessary while using Linux
* Using default conf:
``` bash
export CROSS_COMPILE=arm-linux-gnueabihf-
export ARCH=arm
make xilinx_zynq_virt_defconfig #default conf
make -j 12 #MAX CPU thread to build, our cpu is 12 core
```
#### 2.1.2 Build Linux-kernel
* [build-code](https://github.com/curly-wei/xvc-zybo-z7/blob/main/src/os/script/build_kernel.sh)
* Reason
* Ensuring necessary kernel module has been included, such as UIO-module
* `UIO` has benn enabled default in the newer kernel version
* Using default conf:
``` bash
export CROSS_COMPILE=arm-linux-gnueabihf-
export ARCH=arm
make xilinx_zynq_defconfig #default conf
make -j 12 #MAX CPU thread to build, our cpu is 12 core
```
#### 2.1.3 Build busybox
* [build-code](https://github.com/curly-wei/xvc-zybo-z7/blob/main/src/os/script/build_busybox.sh)
* Reason
* Root filesystem is necessary (`/bin /usr /etc ...` )
* Minimalist (only `/usr/bin/* -> busybox`)
* See [following](#23-The-trade-off-between-busybox-and-buildroot)
* Using default conf:
``` bash
export CROSS_COMPILE=arm-linux-gnueabihf-
export ARCH=arm
make defconfig #default conf
make -j 12 #MAX CPU thread to build, our cpu is 12 core
```
### 2.2 Cost of build time
| |Tool used|Download src time (sec)|Build time (sec)|
|:--:|:---:|:---------------------:|:--------------:|
|u-boot|arm-linux-eabihf-gcc-v7.5|~4 <br> (FileSize ~25MB)|~20|
|Linux kernel|arm-linux-eabihf-gcc-v7.5|~120 <br> (FileSize ~200MB)|~80|
|busybox|arm-linux-eabihf-gcc-v7.5|~2 <br> (FileSize ~3.2MB)|~19|
|HDL-Hardware|xilinx-vivado <br> tcl mode|N/A|~130|
|fsbl|xilinx-xsct <br> tcl mode|N/A|~60|
|base-dt|xilinx-xsct <br> tcl mode|N/A|~20|
Note:
1. Build kernel with 1 thread(make -j 1), build time ~11Minute
2. gcc: [linaro-arm-linux-gcc-7.5](https://www.linaro.org/membership/)
### 2.3 The trade-off between *busybox* and *buildroot*
* The role of *zynq-7000* between zynq-soc series
* All are *FPGA + ARM-CPU*
* 
* So *zynq-7000* similar to **Micro-controller**
* Others 3 of zynq series similar to **computer**
* The *busybox*
* Minimalist
* 
* without common linux package such as
* Package manager, e.g. `apt-get` `yum` `dnf` `pacman`
* `systemd` componets
* `systemd-networkd`: network manager
* `systemd-udev`: auto mount device
* Trace deps.(tree) and dead porgs. on the background
* openssl
* [...etc.](https://en.wikipedia.org/wiki/Systemd)
* Use like *systemV-init* solution, similar to `BSD-OS`
* Minimalist -> $E=mc^2$
* $Error$ = $(More).(Code)^2$
* Considering a circustance: A program call *opencv* lib
* main program: `/usr/bin/prog.elf`
* libs: `/usr/lib/libopencv-core.so`
* `/usr/lib/libopencv-core.so` depedent on
* `libffmpeg`
* `libgtk3`
* `others...dependency`
* How do I solved above problem of dynamic linked deps?
* install all deps.....
* Too complex and too west time
* compability of each version
* Static-link (only one execute file)
* Heavey bin file
* Higher cost of build time
* Change one line, all of project need to rebuild
* The *buildroot*
* Opposite to *busybox*
* Demo
* [Some embeded developer hate apply *systemd* for embeded system](https://elinux.org/images/6/69/Demystifying_Systemd.pdf)
* Trade-off between *busybox* and *buildroot*
* *busybox*
* Applicable to **Micro-controller**
* simple env
* Circustance: HW-> 2-core-cpu, <512MB RAM, <2GB drive
* Zynq-7000
* Prefer to linke (deps)libarary with **static**
* *buildroot*
* Applicable to **computer**
* Complex env
* Circustance: HW-> 4-core-cpu, >4GB RAM, >10GB drive
* Zynq-Ultrascal+ above
* *systemd* + *package manger*
* So you can configre (deps)libarary as **dynamic**
* More complex application for Zynq-7000
* Must install a lot of program for application
* e.g. Image process + AI + robot
* Need to use IPC(Inter Process Communications)
###### tags: `Regular Meeting` `DeWei`