# 2019q1 Homework8 (smallsys)
contributed by < `zodf0055980` >
###### tags: `Linux 核心設計`
## 建立aarch64
首先先 clone [buildroot](https://github.com/buildroot/buildroot)
進入資料夾執行 `$make list-defconfigs` 可以看到許多配置,可以在裡面找到 aarch64 得配置
```shell
yuan@yuan-X555LF:~/buildroot$ make list-defconfigs
Built-in configs:
aarch64_efi_defconfig - Build for aarch64_efi
acmesystems_aria_g25_128mb_defconfig - Build for acmesystems_aria_g25_128mb
acmesystems_aria_g25_256mb_defconfig - Build for acmesystems_aria_g25_256mb
......
qemu_aarch64_virt_defconfig - Build for qemu_aarch64_virt
```
選擇 qemu_aarch64_virt_defconfig
執行 `$ make qemu_aarch64_virt_defconfig`
```shell
yuan@yuan-X555LF:~/buildroot$ make qemu_aarch64_virt_defconfig
#
# configuration written to /home/yuan/buildroot/.config
#
```
可以發現他把 buildroot/.config 做更改,接著使用 `$make menuconfig` ,可以看見 Target option -> Target Architecture 已經選擇了 AArch64 (little endian) ,可見已經做好設定。接著執行 `$make`編譯。
在 make file 有提到:
>Buildroot comes with a basic configuration for a number of boards. Run
'make list-defconfigs' to view the list of provided configurations.
>
因此發現各項設定都在 /buildroot/boards 中,進入 /buildroot/board/qemu/aarch64-virt/ ,裡面 readme.txt 有提到:
```
Run the emulation with:
qemu-system-aarch64 -M virt -cpu cortex-a53 -nographic -smp 1 -kernel output/images/Image -append "root=/dev/vda console=ttyAMA0" -netdev user,id=eth0 -device virtio-net-device,netdev=eth0 -drive file=output/images/rootfs.ext4,if=none,format=raw,id=hd0 -device virtio-blk-device,drive=hd0
The login prompt will appear in the terminal that started Qemu.
Tested with QEMU 2.12.0
```
嘗試照著它去執行,發現它需要 qemu-system-arm 套件,執行 `$ sudo apt install qemu-system-arm` 進行安裝並執行虛擬機。
```
Welcome to Buildroot
buildroot login: root
# uname -a
Linux buildroot 4.19.16 #1 SMP Mon Apr 15 01:45:14 CST 2019 aarch64 GNU/Linux
```
可以發現並不是 5.0 以上,參考 [0xff07 的共筆紀錄進行升級]( https://hackmd.io/nA2nkBfkSPKjjBLv_kKb_Q?view),把kernel 升級。
$ make menuconfig
kernel --> Linux Kernel 選 Latest version (5.0)
Toolchain --> Kernel Headers 選 Linux 5.0.x kernel headers
如果只有更動 kernel ,沒有更動 Kernel Headers,執行 $make 會出錯!!卡了好久....
結果:
```
# uname -a
Linux buildroot 5.0.7 #1 SMP Mon Apr 15 03:53:45 CST 2019 aarch64 GNU/Linux
```
# VirtIO + 9P
參考 [Documentation/9psetup](https://wiki.qemu.org/Documentation/9psetup),到 buildroot/output/build/linux-5.0.7/.config 調整組態,並 $make。
把原本要執行的指令加上
```
-fsdev local,security_model=passthrough,id=fsdev0,path=/tmp -device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=pp
```
嘗試把 /tmp 做掛載
```
# ls
mm
# mount -t 9p -o trans=virtio pp mm -oversion=9p2000.L
mount: mounting pp on mm failed: No such device
```
居然出錯了...
執行 dmesg | grep 9pnet 試試:
```
# dmesg | grep 9pnet
9pnet: Installing 9P2000 support
```
明明有顯示 9pnet 有設定成功,看來是有地方出問題。