<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>FreeBSD &#8211; richliu&#039;s blog</title>
	<atom:link href="https://blog.richliu.com/tag/freebsd/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.richliu.com</link>
	<description>Linux, 工作, 生活, 家人</description>
	<lastBuildDate>Fri, 13 Sep 2024 01:43:13 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.2</generator>
	<item>
		<title>FreeBSD Build Kernel</title>
		<link>https://blog.richliu.com/2024/09/11/6040/freebsd-build-kernel/</link>
					<comments>https://blog.richliu.com/2024/09/11/6040/freebsd-build-kernel/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Tue, 10 Sep 2024 16:13:42 +0000</pubDate>
				<category><![CDATA[ARM]]></category>
		<category><![CDATA[UNIX]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[kernel]]></category>
		<guid isPermaLink="false">https://blog.richliu.com/?p=6040</guid>

					<description><![CDATA[<p>Google Bing 查了半天不如問 Claude ，雖然現在LLM很方便，不過還是會有小問題，記錄一下過程 [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://blog.richliu.com/2024/09/11/6040/freebsd-build-kernel/">FreeBSD Build Kernel</a> appeared first on <a rel="nofollow" href="https://blog.richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Google Bing 查了半天不如問 Claude ，雖然現在LLM很方便，不過還是會有小問題，記錄一下過程</p>



<span id="more-6040"></span>



<p>我的環境是 ARM64，所以以 ARM64 為主，編的版本是 15.0-Current</p>



<pre class="wp-block-preformatted"># 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</pre>



<p>以下應該可以整理成一個 script</p>



<pre class="wp-block-preformatted">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</pre>



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



<h3 class="wp-block-heading">Clean kernel </h3>



<pre class="wp-block-preformatted">make cleankernel KERNCONF=MYKERNEL</pre>



<p>修改 EFI_STAGING_SIZE，修改 /usr/src/stand/efi/loader/copy.c , 找到</p>



<pre class="wp-block-preformatted">#define DEFAULT_EFI_STAGING_SIZE</pre>



<p>統統改成要的值，ex: 100 ，這樣就好，暴力解決</p>



<h3 class="wp-block-heading">Enable exec=&#8221;copy_staging auto&#8221; in /boot/loader.conf</h3>



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



<pre class="wp-block-preformatted">echo exec=\"copy_staging disable\" >> ${.TARGET}/boot/loader.conf</pre>



<h3 class="wp-block-heading">Enable Early Printf In Kernel </h3>



<p>編輯  MYKERNEL ，加上[<a href="https://github.com/freebsd/freebsd-src/blob/3c95262007ef934c9e98b87460a48889bf42c1b9/sys/kern/kern_cons.c#L76" target="_blank" rel="noopener">ref</a>]</p>



<pre class="wp-block-preformatted">options EARLY_PRINTF=pl011</pre>



<p></p>
<p>The post <a rel="nofollow" href="https://blog.richliu.com/2024/09/11/6040/freebsd-build-kernel/">FreeBSD Build Kernel</a> appeared first on <a rel="nofollow" href="https://blog.richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.richliu.com/2024/09/11/6040/freebsd-build-kernel/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
