NetBSD 9.0をFreeBSD 12.1でビルドしてみた

今日の今日まで知らなかったのですがNetBSDはNetBSD以外でもビルドできるようなので、[こちら](https://qiita.com/t-yoshi/items/6c4031d55301fcdee969)のページを参考にFreeBSDでビルドしてみました。

tarファイルをダウンロードします。

```
% ftp ftp://ftp2.jp.netbsd.org/pub/NetBSD/NetBSD-9.0/source/sets/
ftp> get gnusrc.tgz
ftp> get sharesrc.tgz
ftp> get src.tgz
ftp> get syssrc.tgz
```
展開して、toolsをビルドします

```
% ./build.sh -U -m evbarm -T /usr/home/hiroki/NetBSD9/usr/tools/evbarm tools

===> Summary of results:
	 build.sh command:    ./build.sh -U -m evbarm -T /usr/home/hiroki/NetBSD9/usr/tools/evbarm tools
	 build.sh started:    Fri Mar 27 09:19:12 JST 2020
	 NetBSD version:      9.0
	 MACHINE:             evbarm
	 MACHINE_ARCH:        earm
	 Build platform:      FreeBSD 12.1-RELEASE-p2 amd64
	 HOST_SH:             /bin/sh
	 No $TOOLDIR/bin/nbmake, needs building.
	 Bootstrapping nbmake
	 MAKECONF file:       /etc/mk.conf (File not found)
	 TOOLDIR path:        /usr/home/hiroki/NetBSD9/usr/tools/evbarm
	 DESTDIR path:        /usr/home/hiroki/NetBSD9/usr/src/obj/destdir.evbarm
	 RELEASEDIR path:     /usr/home/hiroki/NetBSD9/usr/src/obj/releasedir
	 Created /usr/home/hiroki/NetBSD9/usr/tools/evbarm/bin/nbmake
	 Updated makewrapper: /usr/home/hiroki/NetBSD9/usr/tools/evbarm/bin/nbmake-evbarm
	 Tools built to /usr/home/hiroki/NetBSD9/usr/tools/evbarm
	 build.sh ended:      Fri Mar 27 09:59:23 JST 2020
===> .
```

Microserver Gen6で40分くらい。

kernelをビルドします


```
% ./build.sh -U -m evbarm -T /usr/home/hiroki/NetBSD9/usr/tools/evbarm -V CPUFLAGS=-march=armv5te kernel=SHEEVAPLUG

===> Summary of results:
	 build.sh command:    ./build.sh -U -m evbarm -T /usr/home/hiroki/NetBSD9/usr/tools/evbarm -V CPUFLAGS=-march=armv5te kernel=SHEEVAPLUG
	 build.sh started:    Fri Mar 27 10:02:50 JST 2020
	 NetBSD version:      9.0
	 MACHINE:             evbarm
	 MACHINE_ARCH:        earm
	 Build platform:      FreeBSD 12.1-RELEASE-p2 amd64
	 HOST_SH:             /bin/sh
	 MAKECONF file:       /etc/mk.conf (File not found)
	 TOOLDIR path:        /usr/home/hiroki/NetBSD9/usr/tools/evbarm
	 DESTDIR path:        /usr/home/hiroki/NetBSD9/usr/src/obj/destdir.evbarm
	 RELEASEDIR path:     /usr/home/hiroki/NetBSD9/usr/src/obj/releasedir
	 Updated makewrapper: /usr/home/hiroki/NetBSD9/usr/tools/evbarm/bin/nbmake-evbarm
	 Building kernel without building new tools
	 Building kernel:     SHEEVAPLUG
	 Build directory:     /usr/home/hiroki/NetBSD9/usr/src/sys/arch/evbarm/compile/obj/SHEEVAPLUG
	 Kernels built from SHEEVAPLUG:
	  /usr/home/hiroki/NetBSD9/usr/src/sys/arch/evbarm/compile/obj/SHEEVAPLUG/netbsd
	 build.sh ended:      Fri Mar 27 10:11:58 JST 2020
===> .
```

だいたい10分くらい。

user landをビルドします。

```
% ./build.sh -U -m evbarm -T /usr/home/hiroki/NetBSD9/usr/tools/evbarm -V CPUFLAGS=-march=armv5te -V ALL_KERNELS=SHEEVAPLUG release
```

5時間くらい経って終わらなかったのであきらめましたが、多分できると思います。

せっかくなので[SHEEVAPLUG](https://qiita.com/yamori813/items/df71b1d0eea037e62bb4)のrootfsのマウントポイントの設定とsdmmcのエラーメッセージが出ないようにしたカーネルを作ってみます。

usr/src/sys/arch/evbarm/confのSHEEVAPLUGを以下のように修正しました。

```
% diff SHEEVAPLUG.org SHEEVAPLUG
150c150,151
< config		netbsd		root on ? type ?
---
> #config		netbsd		root on ? type ?
> config		netbsd		root on sd0a type ffs
209,210c210,211
< mvsdio* at mvsoc? offset ? irq ?
< sdmmc*	at mvsdio?
---
> #mvsdio* at mvsoc? offset ? irq ?
> #sdmmc*	at mvsdio?
212c213
< ld*	at sdmmc?
---
> #ld*	at sdmmc?
388c389
< sbt* at sdmmc?
---
> #sbt* at sdmmc?
```

これでビルドすると、usr/src/sys/arch/evbarm/compile/obj/SHEEVAPLUG/netbsd.ubというkernelが出来上がるので、これを使えば良いようです。

NetBSD 9.3もビルドしてみました。

```
===> Summary of results:
         build.sh command:    ./build.sh -j8 -U -m evbarm -T /usr/home/hiroki/NetBSD93/usr/tools/evbarm tools
         build.sh started:    Thu Oct 27 12:10:35 JST 2022
         NetBSD version:      9.3
         MACHINE:             evbarm
         MACHINE_ARCH:        earm
         Build platform:      FreeBSD 13.1-RELEASE amd64
         HOST_SH:             /bin/sh
         No $TOOLDIR/bin/nbmake, needs building.
         Bootstrapping nbmake
         MAKECONF file:       /etc/mk.conf (File not found)
         TOOLDIR path:        /usr/home/hiroki/NetBSD93/usr/tools/evbarm
         DESTDIR path:        /usr/home/hiroki/NetBSD93/usr/src/obj/destdir.evbarm
         RELEASEDIR path:     /usr/home/hiroki/NetBSD93/usr/src/obj/releasedir
         Created /usr/home/hiroki/NetBSD93/usr/tools/evbarm/bin/nbmake
         Updated makewrapper: /usr/home/hiroki/NetBSD93/usr/tools/evbarm/bin/nbmake-evbarm
         Tools built to /usr/home/hiroki/NetBSD93/usr/tools/evbarm
         build.sh ended:      Thu Oct 27 12:18:43 JST 2022
===> .
```

```
===> Summary of results:
         build.sh command:    ./build.sh -j8 -U -m evbarm -T /usr/home/hiroki/NetBSD93/usr/tools/evbarm -V CPUFLAGS=-march=armv5te kernel=SHEEVAPLUG_INSTALL
         build.sh started:    Thu Oct 27 12:22:22 JST 2022
         NetBSD version:      9.3
         MACHINE:             evbarm
         MACHINE_ARCH:        earm
         Build platform:      FreeBSD 13.1-RELEASE amd64
         HOST_SH:             /bin/sh
         MAKECONF file:       /etc/mk.conf (File not found)
         TOOLDIR path:        /usr/home/hiroki/NetBSD93/usr/tools/evbarm
         DESTDIR path:        /usr/home/hiroki/NetBSD93/usr/src/obj/destdir.evbarm
         RELEASEDIR path:     /usr/home/hiroki/NetBSD93/usr/src/obj/releasedir
         Updated makewrapper: /usr/home/hiroki/NetBSD93/usr/tools/evbarm/bin/nbmake-evbarm
         Building kernel without building new tools
         Building kernel:     SHEEVAPLUG_INSTALL
         Build directory:     /usr/home/hiroki/NetBSD93/usr/src/sys/arch/evbarm/compile/obj/SHEEVAPLUG_INSTALL
         Kernels built from SHEEVAPLUG_INSTALL:
          /usr/home/hiroki/NetBSD93/usr/src/sys/arch/evbarm/compile/obj/SHEEVAPLUG_INSTALL/netbsd
         build.sh ended:      Thu Oct 27 12:23:08 JST 2022
===> .
```

現在開発中のソースでもビルドしてみました。

```
===> Summary of results:
         build.sh command:    ./build.sh -j8 -U -m evbarm -a earmv5 -T /usr/home/hiroki/netbsd-tools/evbarm tools
         build.sh started:    Sat Oct 29 10:04:45 JST 2022
         NetBSD version:      9.99.104
         MACHINE:             evbarm
         MACHINE_ARCH:        earmv5
         Build platform:      FreeBSD 13.1-RELEASE amd64
         HOST_SH:             /bin/sh
         No $TOOLDIR/bin/nbmake, needs building.
         Bootstrapping nbmake
         MAKECONF file:       /etc/mk.conf (File not found)
         TOOLDIR path:        /usr/home/hiroki/netbsd-tools/evbarm
         DESTDIR path:        /usr/home/hiroki/netrbsd-src/obj/destdir.evbarm
         RELEASEDIR path:     /usr/home/hiroki/netrbsd-src/obj/releasedir
         Created /usr/home/hiroki/netbsd-tools/evbarm/bin/nbmake
         Updated makewrapper: /usr/home/hiroki/netbsd-tools/evbarm/bin/nbmake-evbarm
         Tools built to /usr/home/hiroki/netbsd-tools/evbarm
         build.sh ended:      Sat Oct 29 10:14:50 JST 2022
===> .
```

```
===> Summary of results:
         build.sh command:    ./build.sh -j8 -U -m evbarm -a earmv5 -T /usr/home/hiroki/netbsd-tools/evbarm -V CPUFLAGS=-march=armv5te kernel=SHEEVAPLUG
         build.sh started:    Sat Oct 29 10:16:54 JST 2022
         NetBSD version:      9.99.104
         MACHINE:             evbarm
         MACHINE_ARCH:        earmv5
         Build platform:      FreeBSD 13.1-RELEASE amd64
         HOST_SH:             /bin/sh
         MAKECONF file:       /etc/mk.conf (File not found)
         TOOLDIR path:        /usr/home/hiroki/netbsd-tools/evbarm
         DESTDIR path:        /usr/home/hiroki/netrbsd-src/obj/destdir.evbarm
         RELEASEDIR path:     /usr/home/hiroki/netrbsd-src/obj/releasedir
         Updated makewrapper: /usr/home/hiroki/netbsd-tools/evbarm/bin/nbmake-evbarm
         Building kernel without building new tools
         Building kernel:     SHEEVAPLUG
         Build directory:     /usr/home/hiroki/netrbsd-src/sys/arch/evbarm/compile/obj/SHEEVAPLUG
         Kernels built from SHEEVAPLUG:
          /usr/home/hiroki/netrbsd-src/sys/arch/evbarm/compile/obj/SHEEVAPLUG/netbsd
         build.sh ended:      Sat Oct 29 10:18:04 JST 2022
===> .
```

```
===> Summary of results:
         build.sh command:    ./build.sh -j8 -U -m evbarm -a earmv5 -T /usr/home/hiroki/netbsd-tools/evbarm -V CPUFLAGS=-march=armv5te -V ALL_KERNELS=SHEEVAPLUG release
         build.sh started:    Sat Oct 29 10:19:19 JST 2022
         NetBSD version:      9.99.104
         MACHINE:             evbarm
         MACHINE_ARCH:        earmv5
         Build platform:      FreeBSD 13.1-RELEASE amd64
         HOST_SH:             /bin/sh
         MAKECONF file:       /etc/mk.conf (File not found)
         TOOLDIR path:        /usr/home/hiroki/netbsd-tools/evbarm
         DESTDIR path:        /usr/home/hiroki/netrbsd-src/obj/destdir.evbarm
         RELEASEDIR path:     /usr/home/hiroki/netrbsd-src/obj/releasedir
         Updated makewrapper: /usr/home/hiroki/netbsd-tools/evbarm/bin/nbmake-evbarm
         Successful make release
         build.sh ended:      Sat Oct 29 11:03:00 JST 2022
===> .
```