Linux, 工作, 生活, 家人

ARM, UNIX

FreeBSD Build Kernel

Google Bing 查了半天不如問 Claude ,雖然現在LLM很方便,不過還是會有小問題,記錄一下過程

我的環境是 ARM64,所以以 ARM64 為主,編的版本是 15.0-Current

# Install git first
# pkg install git
# Install Source code from Git 
git clone https://git.freebsd.org/src.git /usr/src

cd /usr/src/sys/arm64/conf
cp GENERIC MYKERNEL
vim MYKERNEL

以下應該可以整理成一個 script

cd /usr/src

# Remove old file
mkdir /usr/obj/tmp
chflags -R noschg /usr/obj/*
rm -rf /usr/obj/*

# Build world and kernel 
# Cannot use 128 cores to build that because it might cause build problem. 
# reduce it to 16 might be better 
make -j 16 buildworld
# Clean kernel if necesssary 
# make -j 16 cleankernel KERNCONF=MYKERNEL
make -j 16 buildkernel KERNCONF=MYKERNEL

# Install world and kernel to a temperory directory
mkdir /usr/obj/tmp
make installworld DESTDIR=/usr/obj/tmp
make installkernel KERNCONF=MYKERNEL DESTDIR=/usr/obj/tmp

# copy release document to the directory
make distribution DESTDIR=/usr/obj/tmp

# build release
cd release
make -j 16 release KERNCONF=MYKERNEL NODOC=yes NOPORTS=yes NOSRC=yes

Release files (iso, image 等等) 會在
/ussr/obj/usr/src/arm64.aarch64/release 下

Clean kernel

make cleankernel KERNCONF=MYKERNEL

修改 EFI_STAGING_SIZE,修改 /usr/src/stand/efi/loader/copy.c , 找到

#define DEFAULT_EFI_STAGING_SIZE

統統改成要的值,ex: 100 ,這樣就好,暴力解決

Enable exec=”copy_staging auto” in /boot/loader.conf

這個功能因為要在編 world 放到 loader.conf 內,這樣 iso 和 memstick 檔案內才,所以我用了一個 hacker 的手法,編輯 release/Makefile ,約 Line 188,加上

echo exec=\"copy_staging disable\" >> ${.TARGET}/boot/loader.conf

Enable Early Printf In Kernel

編輯 MYKERNEL ,加上[ref]

options EARLY_PRINTF=pl011

發佈留言