# OSDI LAB ###### tags: `OSDI` ## LAB ### LAB 0 * QEMU 安裝 * 用`apt-get install`安裝會沒有`raspi3` machine * 先安裝dependency ```basj sudo apt-get install build-essential zlib1g-dev pkg-config libglib2.0-dev binutils-dev libboost-all-dev autoconf libtool libssl-dev libpixman-1-dev libpython-dev python-pip python-capstone virtualenv ``` * Download Source Code: [Github](https://github.com/qemu/qemu) * 進去資料夾之後 ```bash # 先建build資料夾 mkdir bin cd bin ../configure --target-list=aarch64-softmmu --enable-debug-tcg --enable-debug make -j4 sudo make install ``` * 安裝後就可以動起來了 ``` qemu-system-aarch64 -M raspi3 -kernel kernel8.img -display none -d in_asm ``` > 也有這種說法 > 把machine type改成`versatilepb`,但執行結果怪怪的 > http://guildwar23.blogspot.com/2012/11/qemu-raspberry-pi.html > ``` > qemu-system-arm -M versatilepb -cpu arm1176 -kernel zImage -m 512 -append root=/dev/sda2 -net nic -net user -hda 2012-10-28-wheezy-raspbian.img > ``` > * Raspberry * GPIO: * ![Raspberry Pi GPIO](https://www.raspberrypi.org/documentation/usage/gpio/images/GPIO-Pinout-Diagram-2.png) * Interact with R Pi3 * 在燒img的時候,`/dev/sdb` 是disk,`/dev/sdb1`是partition要注意。 * 就是要燒在disk上:`dd if=nctuos.img of=/dev/sdb` * 燒完要去partition看結果 ```bash sudo mkdir /mnt/card_reader sudo mount /dev/sdb1 /mnt/card_reader ``` * 裡面應該要有下面幾個檔案 * `bootcode.bin` * `fixup.dat` * `start.elf` * `kernel8.img` * 在用screen連進去的時候,假如是用VM來做作業的話,要先在windows調設定。 * 要在裝置管理員中 設定baud rate,預設是9600會不work。 ![](https://i.imgur.com/I9LzFkL.png) * 設定完,就可以使用MobaXterm連進去做事啦 * Question: * Q1: What’s the RAM size of Raspberry Pi 3B+? * A1: 1GB SRAM > SRAM(static RAM). The term static differentiates SRAM from DRAM (dynamic random-access memory) which must be periodically refreshed. * Q2: What’s the cache size and level of Raspberry Pi 3B+? * A2: 32kB Level 1 and 512kB Level 2 cache memory > [Cortex-A comparison table (Armv8-A)](https://developer.arm.com/ip-products/processors/cortex-a/cortex-a53) * Q3: Explain each line of the follow linker script. ``` SECTIONS { . = 0x80000; .text : { *(.text) } } ``` ### LAB 1 * [UART](https://makerpro.cc/2016/04/understand-what-is-uart),就是在板子上的一個介面,這個介面會用來和電腦溝通。 * [MMIO](https://blog.xuite.net/locktas/twblog/190770724-%E9%9B%BB%E8%85%A6%E5%B0%8F%E5%B8%B8%E8%AD%98-%E9%9B%BB%E8%85%A6%E6%8F%924G%E8%A8%98%E6%86%B6%E9%AB%94%E5%8F%AA%E6%8A%93%E5%88%B03.8G%E8%80%8C%E5%B7%B2..%E9%80%99%E6%98%AF%E6%80%8E%E4%B8%80%E5%9B%9E%E4%BA%8B),簡單的講MMIO 就是CPU和周邊溝通的介面之一,就是直接去找週邊要的方式。如果週邊還有其他的溝通方式如 Port IO 就可以不用 MMIO。如果只有MMIO, 那 Disable MMIO 就好像關掉大門 就沒得溝通了 * [MMU](https://zh.wikipedia.org/wiki/%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86%E5%8D%95%E5%85%83),當CPU要存取記憶體空間時會需要的工具,實體or虛擬記憶體的定址。 * [Changing the default pin configuration - Raspberry Pi Documentation](https://www.raspberrypi.org/documentation/configuration/pin-configuration.md),改變GPIO預設定義。 * https://cs140e.sergio.bz/docs/BCM2837-ARM-Peripherals.pdf * https://elinux.org/BCM2835_registers#PM ### GDB * 安裝`aarch64-linux-gnu-gdb`: * 要用這個東西沒辦法用`apt-get install` 安裝。 * [載點](https://releases.linaro.org/components/toolchain/binaries/latest-5/aarch64-linux-gnu/gcc-linaro-5.5.0-2017.10-x86_64_aarch64-linux-gnu.tar.xz) * 下載下來進行解壓 ``` tar Jxvf ``` * 軟連結放到/usr/bin底下 ``` ln -s gcc-linaro-5.5.0-2017.10-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gdb usr/bin/aarch64-gdb ``` * compile sorce code * 搭配`-ggdb -Og -O0` flag。 * qemu動起來 ``` $(EMULATOR) -M raspi3 -kernel kernel8.img -serial stdio -s -S ``` * gdb 動起來 ``` aarch64-gdb # 剛剛軟連結名字有改 file *.elf # 把elf的位置放進來 directory *.* # 就是專案的資料夾 target remote localhost:1234 # localhost:1234是qemu預設會開的位置。