§2023-09-11

¶1. Installation requirements

¶2. build the kernel

$ sudo losetup /dev/loop27 gentoo-32G-systemd-rpi-2023-09-06.img
$ sudo mount /dev/loop27p2 root
$ sudo arch-chroot root /bin/bash
SurfacePro / # source /etc/profile
(chroot) SurfacePro / 
 # pwd
/usr/src/raspberrypi/linux   --> git clone --depth=1 https://github.com/raspberrypi/linux -b rpi-6.1.y
# ARCH=arm64 CROSS_COMPILE=aarch64-unknown-linux-gnu- make  clean              --->  clean old make
# ARCH=arm64 CROSS_COMPILE=aarch64-unknown-linux-gnu- make  mrproper           --->  clean old menuconfig
# ARCH=arm64 CROSS_COMPILE=aarch64-unknown-linux-gnu- make  bcm2711_defconfig   ---> menuconfig
# time ARCH=arm64 CROSS_COMPILE=aarch64-unknown-linux-gnu- make  -j4            ---> compile
real    38m51.990s
user    139m25.728s
sys     13m6.511s
# ls -l arch/arm64/boot/
合計 30564
-rw-r--r--  1 root root 22962688 Sep 11 11:16 Image
-rw-r--r--  1 root root  8472340 Sep 11 11:16 Image.gz
-rw-r--r--  1 root root     1198 Sep  6 15:49 Makefile
drwxr-xr-x 35 root root     4096 Sep  6 15:49 dts
-rwxr-xr-x  1 root root      962 Sep  6 15:49 install.sh

¶3. Prepare MicroSD

Not in chroot mode

デバイス   起動 開始位置 最後から   セクタ サイズ Id タイプ
/dev/sdc1           2048   526335   524288   256M  c W95 FAT32 (LBA)
/dev/sdc2         526336 62333951 61807616  29.5G 83 Linux
$ sudo mount /dev/sdc2 /mnt/gentoo/

$ sudo tar xpvf stage3-arm64-systemd-20230903T203159Z.tar.xz --xattrs-include='.' --numeric-owner -C /mnt/gentoo

- Install a Gentoo repository snapshot

$ sudo mkdir /mnt/gentoo/var/db/repos/gentoo $ sudo tar xvpf portage-latest.tar.bz2 --strip-components=1 -C /mnt/gentoo/var/db/repos/gentoo

>--strip-components=1: This option tells tar to remove the first component (directory)

¶4. get into chroot again

- first create

mkdir /mnt/{root,boot} ---> watch out /mnt/{root, boot} no space between root and boot

ls /mnt

boot root

- mount /dev/sd??

mount /dev/sdc1 /mnt/boot

mount /dev/sdc2 /mnt/root

lsblk /dev/sdc*

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sdc 8:32 1 29.7G 0 disk ├─sdc1 8:33 1 256M 0 part /mnt/boot └─sdc2 8:34 1 29.5G 0 part /mnt/root sdc1 8:33 1 256M 0 part /mnt/boot sdc2 8:34 1 29.5G 0 part /mnt/root


- install kernel

pwd

/usr/src/raspberrypi/linux

cp -v arch/arm64/boot/Image /mnt/boot/kernel8.img

- install kernel modules

pwd

/usr/src/raspberrypi/linux

ARCH=arm64 CROSS_COMPILE=aarch64-unknown-linux-gnu- make modules_install INSTALL_MOD_PATH=/mnt/root

... XZ /mnt/root/lib/modules/6.1.51-v8+/kernel/sound/usb/misc/snd-ua101.ko.xz INSTALL /mnt/root/lib/modules/6.1.51-v8+/kernel/sound/usb/snd-usb-audio.ko XZ /mnt/root/lib/modules/6.1.51-v8+/kernel/sound/usb/snd-usb-audio.ko.xz INSTALL /mnt/root/lib/modules/6.1.51-v8+/kernel/sound/usb/snd-usbmidi-lib.ko XZ /mnt/root/lib/modules/6.1.51-v8+/kernel/sound/usb/snd-usbmidi-lib.ko.xz DEPMOD /mnt/root/lib/modules/6.1.51-v8+

- Build and install the device tree and overlays by running make dtbs, then copy the resulting device tree and overlay files to /boot

pwd

/usr/src/raspberrypi/linux

ARCH=arm64 CROSS_COMPILE=aarch64-unknown-linux-gnu- make dtbs

mkdir -p /mnt/boot/overlays

cp -vR arch/arm64/boot/dts/overlays/*.dtbo /mnt/boot/overlays

cp -v arch/arm64/boot/dts/broadcom/bcm2711-rpi-4-b.dtb /mnt/boot/

ls -l /mnt/boot/

合計 22502 -rwxr-xr-x 1 root root 54388 Sep 11 12:58 bcm2711-rpi-4-b.dtb -rwxr-xr-x 1 root root 22962688 Sep 11 12:47 kernel8.img drwxr-xr-x 2 root root 24064 Sep 11 12:58 overlays

- In order to install the kernel on a Pi 400, install the relative device tree

pwd

/usr/src/raspberrypi/linux

cp -v arch/arm64/boot/dts/broadcom/bcm2711-rpi-400.dtb /mnt/boot/

ls -l /mnt/boot/

合計 22555 -rwxr-xr-x 1 root root 54388 Sep 11 12:58 bcm2711-rpi-4-b.dtb -rwxr-xr-x 1 root root 54477 Sep 11 13:00 bcm2711-rpi-400.dtb -rwxr-xr-x 1 root root 22962688 Sep 11 12:47 kernel8.img drwxr-xr-x 2 root root 24064 Sep 11 12:58 overlays


¶5. Install the firmware

All the firmware needed to boot the Pi is found in the sys-boot/raspberrypi-firmware package:

emerge --ask sys-boot/raspberrypi-firmware

These are the packages that would be merged, in order:

Calculating dependencies... done! Dependency resolution took 5.59 s.

!!! All ebuilds that could satisfy "sys-boot/raspberrypi-firmware" have been masked. !!! One of the following masked packages is required to complete your request:

For more information, see the MASKED PACKAGES section in the emerge man page or refer to the Gentoo Handbook.

- to solve
- put this line in /etc/portage/make.conf

ACCEPT_LICENSE="raspberrypi-videocore-bin"


Will solve `A copy of the 'raspberrypi-videocore-bin' license is located at '/var/db/repos/gentoo/licenses/raspberrypi-videocore-bin'.`

- but

emerge --ask sys-boot/raspberrypi-firmware

These are the packages that would be merged, in order:

Calculating dependencies... done! Dependency resolution took 0.34 s.

!!! All ebuilds that could satisfy "sys-boot/raspberrypi-firmware" have been masked. !!! One of the following masked packages is required to complete your request:

For more information, see the MASKED PACKAGES section in the emerge man page or refer to the Gentoo Handbook.


- nano `/etc/portage/package.accept_keywords/raspberrypi-firmware`

cat /etc/portage/package.accept_keywords/raspberrypi-firmware

sys-boot/raspberrypi-firmware arm64 ~arm64 -amd64 -~amd64

# emerge --ask sys-boot/raspberrypi-firmware

 * IMPORTANT: 10 news items need reading for repository 'gentoo'.
 * Use eselect news read to view new items.


These are the packages that would be merged, in order:

Calculating dependencies... done!
Dependency resolution took 0.51 s.

[ebuild  N    *] sys-boot/raspberrypi-firmware-1.20230106 

Would you like to merge these packages? [Yes/No] Yes
>>> Install sys-boot/raspberrypi-firmware-1.20230106 into /var/tmp/portage/sys-boot/raspberrypi-firmware-1.20230106/image
>>> Completed installing sys-boot/raspberrypi-firmware-1.20230106 into /var/tmp/portage/sys-boot/raspberrypi-firmware-1.20230106/image

 * Final size of build directory: 250668 KiB (244.7 MiB)
 * Final size of installed tree:   21792 KiB ( 21.2 MiB)

 * QA Notice: RESTRICT=binchecks prevented checks on these ELF files:
 * /boot/start4x.elf
 * /boot/start4.elf
 * /boot/start_db.elf
 * /boot/start.elf
 * /boot/start_x.elf
 * /boot/start4db.elf
 * /boot/start4cd.elf
 * /boot/start_cd.elf
 * QA Notice: Unrecognized ELF file(s):
 * 
 *      UNKNOWN_TYPE;/boot/start4x.elf;;;;
 *      UNKNOWN_TYPE;/boot/start4.elf;;;;
 *      UNKNOWN_TYPE;/boot/start_db.elf;;;;
 *      UNKNOWN_TYPE;/boot/start.elf;;;;
 *      UNKNOWN_TYPE;/boot/start_x.elf;;;;
 *      UNKNOWN_TYPE;/boot/start4db.elf;;;;
 *      UNKNOWN_TYPE;/boot/start4cd.elf;;;;
 *      UNKNOWN_TYPE;/boot/start_cd.elf;;;;
 * 

>>> Installing (1 of 1) sys-boot/raspberrypi-firmware-1.20230106::gentoo
 * Please configure your ram setup by editing /boot/config.txt
 * 
 * (Note: Above message is only printed the first time package is
 * installed. Please look at /usr/share/doc/raspberrypi-firmware-1.20230106/README.gentoo*
 * for future reference)

>>> Recording sys-boot/raspberrypi-firmware in "world" favorites file...

>>> Completed (1 of 1) sys-boot/raspberrypi-firmware-1.20230106::gentoo

 * Messages for package sys-boot/raspberrypi-firmware-1.20230106:

 * Please configure your ram setup by editing /boot/config.txt
 * 
 * (Note: Above message is only printed the first time package is
 * installed. Please look at /usr/share/doc/raspberrypi-firmware-1.20230106/README.gentoo*
 * for future reference)

 * GNU info directory index is up-to-date.

 * IMPORTANT: 11 news items need reading for repository 'gentoo'.
 * Use eselect news read to view new items.

 # ls -l /boot/
合計 21752
-rw-r--r-- 1 root root   52476 Sep 11 15:10 bootcode.bin
-rw-r--r-- 1 root root     108 Sep 11 15:10 cmdline.txt
-rw-r--r-- 1 root root    1784 Sep 11 15:10 config.txt
-rw-r--r-- 1 root root    7265 Sep 11 15:10 fixup.dat
-rw-r--r-- 1 root root    5398 Sep 11 15:10 fixup4.dat
-rw-r--r-- 1 root root    3170 Sep 11 15:10 fixup4cd.dat
-rw-r--r-- 1 root root    8382 Sep 11 15:10 fixup4db.dat
-rw-r--r-- 1 root root    8386 Sep 11 15:10 fixup4x.dat
-rw-r--r-- 1 root root    3170 Sep 11 15:10 fixup_cd.dat
-rw-r--r-- 1 root root   10229 Sep 11 15:10 fixup_db.dat
-rw-r--r-- 1 root root   10229 Sep 11 15:10 fixup_x.dat
-rw-r--r-- 1 root root 2975104 Sep 11 15:10 start.elf
-rw-r--r-- 1 root root 2250848 Sep 11 15:10 start4.elf
-rw-r--r-- 1 root root  805436 Sep 11 15:10 start4cd.elf
-rw-r--r-- 1 root root 3747240 Sep 11 15:10 start4db.elf
-rw-r--r-- 1 root root 2998344 Sep 11 15:10 start4x.elf
-rw-r--r-- 1 root root  805436 Sep 11 15:10 start_cd.elf
-rw-r--r-- 1 root root 4819144 Sep 11 15:10 start_db.elf
-rw-r--r-- 1 root root 3721992 Sep 11 15:10 start_x.elf
# cp -v /boot/config.txt /mnt/boot
'/boot/config.txt' -> '/mnt/boot/config.txt'
 # cp -v /boot/cmdline.txt /mnt/boot
'/boot/cmdline.txt' -> '/mnt/boot/cmdline.txt'
 # blkid /dev/sdc2
/dev/sdc2: UUID="44bb979e-22eb-48d3-8c0b-ecaef2f512b3" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="3780bab7-02"
 # nano /mnt/boot/cmdline.txt 
# cat /mnt/boot/cmdline.txt 
console=serial0,115200 console=tty1 root=UUID=44bb979e-22eb-48d3-8c0b-ecaef2f512b3 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait\

/mnt/root/etcfstab

#LABEL=boot             /boot           ext4            defaults        1 2
UUID=06D3-2456          /boot           vfat            defaults        1 2

#LABEL= root                                    /               xfs             defaults                0 1
UUID=44bb979e-22eb-48d3-8c0b-ecaef2f512b3       /               ext4            defaults                0 1