02-對(duì)PRI-BUILD.md的搬運(yùn)和翻譯
這篇文章是對(duì)于PRI-BUILD.md的翻譯,GitHub原文放在文章末尾
非黑色字體以及圖片均為我自己添加
在樹莓派4上進(jìn)行編譯
????????在不使用其他編譯設(shè)備的情況下跟著這篇教程對(duì)樹莓派進(jìn)行編譯時(shí)可能的(并不十分簡單)
????????可能最簡單路線就是首先用樹莓派的操作系統(tǒng)(Beta)對(duì)你的系統(tǒng)進(jìn)行重新建立鏡像,然后使用預(yù)先置入的交叉編譯器:
????????從64位鏡像列表里面下載壓縮好的 .img 鏡像文件,使用最新的更新.
????????解壓,然后使用樹莓派鏡像工具(https://downloads.raspberrypi.org/raspios_arm64/images )將其寫入你的SD卡,從選項(xiàng)中選擇 "Use costum"并且指向你下載好的文件

????????啟動(dòng)樹莓派并按照設(shè)置向?qū)泶_保你能連上網(wǎng).
????????碰碰運(yùn)氣,運(yùn)行 sudo apt update
????????你需要在ARM的網(wǎng)站上下載交叉編譯器.
????????你需要找到是?AArch64 ELF bare-metal target (aarch64-none-elf) .如果這個(gè)鏈接不知道怎么著斷掉了,那么你可以谷歌搜?"Arm GNU-A linux hosted cross compilers"
????????然后打開文檔文件,使用命令 " tar -xf <filename>" .你最后會(huì)得到一個(gè)gcc目錄(雖然名字比較長),這里面包含一個(gè)bin文件夾,里面放著一個(gè)gcc可執(zhí)行文件(同樣,名字有點(diǎn)長).記住這個(gè)路徑.
????????注意:你現(xiàn)在可以避免給樹莓派重裝鏡像,而是自己建立交叉編譯器. (https://wiki.osdev.org/GCC_Cross-Compiler)
????????現(xiàn)在,讓我們干點(diǎn)活:
????????使用 git 來克隆這個(gè)倉庫 :?git clone https://github.com/isometimes/rpi4-osdev.git
????????你想要編譯的那一部分相關(guān)的設(shè)備: 我喜歡利用 part5-framebuffer 進(jìn)行測試(它可以被看見,所以你知道它什么時(shí)候成功工作)
????????把 Makefile.gcc 粘貼到 Makefile中.
????????編輯Makefile來確保 GCCPATH 變量指向能找到你的交叉編譯器的那個(gè)子文件夾
????????在命令行中敲下 make 應(yīng)該可以正確無誤的工作
????????如果你想使用這個(gè)啟動(dòng),那么你需要按照本教程所講的復(fù)制 kernel8.img 文件到您準(zhǔn)備好的SD卡上.為了對(duì)其進(jìn)行測試,我做了以下的事(注意:它會(huì)破壞你安裝的操作系統(tǒng),除非你進(jìn)行了備份,之后你可以把它挪回原位):
????????1. sudo cp kernel8.img /boot
????????2. 然后編輯 /etc/config.txt 只包含這幾行(對(duì)于 part5-framebuffer,不然完整的閱讀教程,以對(duì)其他部分的設(shè)置進(jìn)行必要的更改
????????hdmi_group=1
????????hdmi_mode=16
????????core_freq_min=500
????????重新啟動(dòng)后,您應(yīng)該看到part5-framebuffer演示程序啟動(dòng)了!

Writing a "bare metal" operating system for Raspberry Pi 4
Building on the RPi4 itself
It's possible (but not super-simple) to follow this tutorial on the Raspberry Pi without need for an additional build device.
Perhaps the easiest route is to firstly re-image your Pi to use the 64-bit Raspberry Pi OS (Beta), and then use a pre-built cross-compiler:
?* Download a zipped _.img_ image file from the [64-bit image list](https://downloads.raspberrypi.org/raspios_arm64/images/), picking the newest update
?* Unzip it and use the [Raspberry Pi Imager](https://www.raspberrypi.org/software/) to write it to your SD card, selecting "Use custom" from the options and pointing it at your downloaded _.img_ file
?* Boot the Pi and follow the setup wizard to ensure you have a working Internet connection
?* Just for luck, run `sudo apt update`
You'll then need to download a cross-compiler from the Arm website.
What you're looking for is the current [AArch64 ELF bare-metal target (aarch64-none-elf)](https://developer.arm.com/-/media/Files/downloads/gnu-a/10.2-2020.11/binrel/gcc-arm-10.2-2020.11-aarch64-aarch64-none-elf.tar.xz). If this link is somehow broken, you can use Google to search for "Arm GNU-A linux hosted cross compilers".
Then unpack the archive using `tar -xf <filename>`. You'll end up with a _gcc_ directory (albeit with a slightly longer name), which itself contains a _bin_ subdirectory, wherein you'll find the _gcc_ executable (again - with a longer name!). Remember this path.
Note: you can avoid re-imaging the Pi, by instead [building a cross-compiler yourself](https://wiki.osdev.org/GCC_Cross-Compiler).
Now let's build something:
?* Use `git` to clone this repo: `git clone https://github.com/isometimes/rpi4-osdev.git`
?* Decide which part you want to build - I like testing with _part5-framebuffer_ (it's visual, so you'll know when it works!)
?* Copy the _Makefile.gcc_ to _Makefile_
?* Edit the _Makefile_ and ensure the `GCCPATH` variable points to the _bin_ subdirectory where your cross-compiler is to be found
?* Type `make` at the command line and it should build without errors
If you want to then boot with this, you'll need to copy the _kernel8.img_ file to a prepped SD card as the tutorial discusses. For the purposes of testing this process, I did the following (NOTE: it will trash your OS install unless you backup the old files so you can move them back later):
?* `sudo cp kernel8.img /boot`
?* Then edit _/boot/config.txt_ to include only these lines (for _part5-framebuffer_ anyway, otherwise read the tutorial in full for any necessary config changes for other parts...):
```
hdmi_group=1
hdmi_mode=16
core_freq_min=500
```
Reboot and you should see the _part5-framebuffer_ demo firing up!
[Go to part1-bootstrapping >](./part1-bootstrapping/)