PROJECTS

Raspberry PI4

Minimal Debian Buster image for Raspberry Pi 4.

Minimal image

Below is minimal Buster image for RPI4. Download it, uncompress and write it to SDcard. Image is for 8GiB card. If your card is bigger than that, you can use fdisk /dev/mmcblk0 to remove the second partition and recreate it same start sector but highest possible end sector and after boot resize2fs /dev/mmcblk0p2 to expand the filesystem. In case your card is smaller, bad luck.

Debian Buster (aarch64) 2020-02-29.img.gz

The image contains very stripped and cleaned down Buster image with sane minimal set of packages. It also runs sleek, very trimmed down kernel with only minimal set of features. Features are built in to core image, not as modules. The only module is brcmfmac (ie. Pi's wifi). It didn't work as builtin.

Generally image is suitable for server use. If you need graphical UI, probably there exists better options. Personally I like to strip down everything possible to minimal to save every clock cycle I have. If you feel same, this image is for you.

Features included are basically :

Kernel building

Generally, please follow process and instructions for RPI3. Below are short instructions more or less specific to RPI4.

Instructions below are for image above. Process for other images are probably the same, but image's name used for booting is probably different. For example Raspbian uses name kernel8.img. Name used here is kernel8-p4.img and defined in /boot/config.txt.

In case you are using ready prepared image downloaded above, it already contains sources. Of course sources are probable old, but I'd suggest to first experiment with these without pulling newer version from repository. If you pull newer version, upstream sources might have changed and example config below does not fit perfect any more. When you have succeeded and booted with your own once, it's easier to begin experiment freely.

Steps

If you are using image other than above, first clone sources from official Raspberry Pi git. I haven't tested against stock kernel. Might work, might not.

But you are using the provided image, it already had sources and minimal config on places just waiting for make -j4. In this case skip directly to building. Of course you can git pull it to sync it to current.

rpi4:/usr/src$ git clone --depth=1 https://github.com/raspberrypi/linux rpi-linux
Cloning into 'rpi-linux'...
remote: Enumerating objects: 66210, done.
remote: Counting objects: 100% (66210/66210), done.
remote: Compressing objects: 100% (61674/61674), done.
remote: Total 66210 (delta 5235), reused 16512 (delta 3610), pack-reused 0
Receiving objects: 100% (66210/66210), 177.89 MiB | 3.93 MiB/s, done.
Resolving deltas: 100% (5235/5235), done.
Checking out files: 100% (62367/62367), done.
	

Pick up minimal config from here and check it if you want to feel sure.

rpi4:/usr/src$ cd rpi-linux/
rpi4:/usr/src/rpi-linux$ wget -qO .config http://sub.nanona.fi/rpi4/minimal_kernel_config_4.19

rpi4:/usr/src/rpi-linux$ md5sum .config 
07ad42cc380a1484811e4dc2695dcdbc  .config

rpi4:/usr/src/rpi-linux$ ls -l .config 
-rw-r--r-- 1 juhar juhar 67881 helmi  28 10:54 .config
	

Do menuconfig once, and exit from dialog.

rpi4:/usr/src/rpi-linux$ make menuconfig
  HOSTCC  scripts/basic/fixdep
  UPD     scripts/kconfig/.mconf-cfg
  HOSTCC  scripts/kconfig/mconf.o
  YACC    scripts/kconfig/zconf.tab.c
  LEX     scripts/kconfig/zconf.lex.c
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTCC  scripts/kconfig/lxdialog/checklist.o
  HOSTCC  scripts/kconfig/lxdialog/inputbox.o
  HOSTCC  scripts/kconfig/lxdialog/menubox.o
  HOSTCC  scripts/kconfig/lxdialog/textbox.o
  HOSTCC  scripts/kconfig/lxdialog/util.o
  HOSTCC  scripts/kconfig/lxdialog/yesno.o
  HOSTLD  scripts/kconfig/mconf
scripts/kconfig/mconf  Kconfig


*** End of the configuration.
*** Execute 'make' to start the build or try 'make help'.
	

Build it.

rpi4:/usr/src/rpi-linux$ make -j4
  HOSTCC  scripts/kconfig/conf.o
  HOSTLD  scripts/kconfig/conf
scripts/kconfig/conf  --syncconfig Kconfig
  WRAP    arch/arm64/include/generated/uapi/asm/errno.h
  WRAP    arch/arm64/include/generated/uapi/asm/ioctl.h
  WRAP    arch/arm64/include/generated/uapi/asm/ioctls.h
  WRAP    arch/arm64/include/generated/uapi/asm/ipcbuf.h
  WRAP    arch/arm64/include/generated/uapi/asm/kvm_para.h
  WRAP    arch/arm64/include/generated/uapi/asm/mman.h
  WRAP    arch/arm64/include/generated/uapi/asm/msgbuf.h
  WRAP    arch/arm64/include/generated/uapi/asm/poll.h
  WRAP    arch/arm64/include/generated/uapi/asm/resource.h
  WRAP    arch/arm64/include/generated/uapi/asm/sembuf.h
  WRAP    arch/arm64/include/generated/uapi/asm/shmbuf.h
  WRAP    arch/arm64/include/generated/uapi/asm/socket.h
  UPD     include/generated/uapi/linux/version.h
  WRAP    arch/arm64/include/generated/uapi/asm/sockios.h
  WRAP    arch/arm64/include/generated/uapi/asm/swab.h
  WRAP    arch/arm64/include/generated/uapi/asm/termbits.h
...
  LD [M]  net/netfilter/xt_nat.ko
  LD [M]  net/netfilter/xt_pkttype.ko
  LD [M]  net/netfilter/xt_quota.ko
  LD [M]  net/netfilter/xt_state.ko
  LD [M]  net/netfilter/xt_tcpmss.ko
  LD [M]  net/netfilter/xt_tcpudp.ko
rpi4:/usr/src/rpi-linux$ 
	

Install modules.

rpi4:/usr/src/rpi-linux$ sudo make modules_install
  INSTALL arch/arm64/crypto/aes-arm64.ko
  INSTALL arch/arm64/crypto/aes-neon-blk.ko
  INSTALL arch/arm64/crypto/aes-neon-bs.ko
  INSTALL crypto/cryptd.ko
  INSTALL crypto/crypto_simd.ko
  INSTALL drivers/block/nbd.ko
  INSTALL drivers/input/evdev.ko
  INSTALL drivers/input/ff-memless.ko
  INSTALL drivers/input/input-polldev.ko
  INSTALL drivers/input/matrix-keymap.ko
  INSTALL drivers/net/dummy.ko
  INSTALL drivers/net/wireless/broadcom/brcm80211/brcmfmac/brcmfmac.ko
  INSTALL drivers/net/wireless/broadcom/brcm80211/brcmutil/brcmutil.ko
  INSTALL fs/binfmt_misc.ko
  INSTALL fs/fuse/fuse.ko
  INSTALL net/ipv4/netfilter/ip_tables.ko
  INSTALL net/ipv4/netfilter/ipt_MASQUERADE.ko
  INSTALL net/ipv4/netfilter/ipt_REJECT.ko
  INSTALL net/ipv4/netfilter/iptable_filter.ko
  INSTALL net/ipv4/netfilter/iptable_nat.ko
  INSTALL net/ipv4/netfilter/nf_defrag_ipv4.ko
  INSTALL net/ipv4/netfilter/nf_log_ipv4.ko
  INSTALL net/ipv4/netfilter/nf_nat_ipv4.ko
  INSTALL net/ipv4/netfilter/nf_reject_ipv4.ko
  INSTALL net/ipv6/netfilter/ip6_tables.ko
  INSTALL net/ipv6/netfilter/ip6t_MASQUERADE.ko
  INSTALL net/ipv6/netfilter/ip6t_NPT.ko
  INSTALL net/ipv6/netfilter/ip6t_REJECT.ko
  INSTALL net/ipv6/netfilter/ip6table_filter.ko
  INSTALL net/ipv6/netfilter/ip6table_nat.ko
  INSTALL net/ipv6/netfilter/nf_defrag_ipv6.ko
  INSTALL net/ipv6/netfilter/nf_log_ipv6.ko
  INSTALL net/ipv6/netfilter/nf_nat_ipv6.ko
  INSTALL net/ipv6/netfilter/nf_reject_ipv6.ko
  INSTALL net/netfilter/nf_conntrack.ko
  INSTALL net/netfilter/nf_log_common.ko
  INSTALL net/netfilter/nf_nat.ko
  INSTALL net/netfilter/x_tables.ko
  INSTALL net/netfilter/xt_LOG.ko
  INSTALL net/netfilter/xt_addrtype.ko
  INSTALL net/netfilter/xt_comment.ko
  INSTALL net/netfilter/xt_hashlimit.ko
  INSTALL net/netfilter/xt_iprange.ko
  INSTALL net/netfilter/xt_length.ko
  INSTALL net/netfilter/xt_limit.ko
  INSTALL net/netfilter/xt_mac.ko
  INSTALL net/netfilter/xt_nat.ko
  INSTALL net/netfilter/xt_pkttype.ko
  INSTALL net/netfilter/xt_quota.ko
  INSTALL net/netfilter/xt_state.ko
  INSTALL net/netfilter/xt_tcpmss.ko
  INSTALL net/netfilter/xt_tcpudp.ko
  DEPMOD  4.19.106-minimal1+
	

...and finally kernel...

rpi4:/usr/src/rpi-linux$ sudo cp arch/arm64/boot/Image /boot/kernel8-p4.img 
	

After installing the core image, sync and reboot. It should come up with with kernel you compiled.

rpi4:/usr/src/rpi-linux$ sync
rpi4:/usr/src/rpi-linux$ sudo /sbin/reboot 
	

Once you have done that, you have the baseline and you can start adding features you need to your own custom kernel. Strong suggestion is to keep backup of this initial working kernel and also bump up revision number on make menuconfig's Local version under General setup -menu. By this way you don't overwrite working kernel's /lib/modules/4.19.106-minimal1+ module directory with notworking one.

Image internals

Packages on image

adduser                       add and remove users and groups
apt                           commandline package manager
apt-utils                     package management related utility programs
base-files                    Debian base system miscellaneous files
base-passwd                   Debian base system master password and group f
bash                          GNU Bourne Again SHell
bc                            GNU bc arbitrary precision calculator language
binutils                      GNU assembler, linker and binary utilities
binutils-aarch64-linux-gnu    GNU binary utilities, for aarch64-linux-gnu ta
binutils-common:arm64         Common files for the GNU assembler, linker and
bison                         YACC-compatible parser generator
bsdmainutils                  collection of more utilities from FreeBSD
bsdutils                      basic utilities from 4.4BSD-Lite
build-essential               Informational list of build-essential packages
bzip2                         high-quality block-sorting file compressor - u
ca-certificates               Common CA certificates
console-setup                 console font and keymap setup program
console-setup-linux           Linux specific part of console-setup
coreutils                     GNU core utilities
cpio                          GNU cpio -- a program to manage archives of fi
cpp                           GNU C preprocessor (cpp)
cpp-8                         GNU C preprocessor
cron                          process scheduling daemon
dash                          POSIX-compliant shell
dbus                          simple interprocess messaging system (daemon a
debconf                       Debian configuration management system
debconf-i18n                  full internationalization support for debconf
debian-archive-keyring        GnuPG archive keys of the Debian archive
debianutils                   Miscellaneous utilities specific to Debian
deborphan                     program that can find unused packages, e.g. li
diffutils                     File comparison utilities
discover                      hardware identification system
discover-data                 Data lists for Discover hardware detection sys
dmidecode                     SMBIOS/DMI table decoder
dmsetup                       Linux Kernel Device Mapper userspace library
dpkg                          Debian package management system
dpkg-dev                      Debian package development tools
e2fsprogs                     ext2/ext3/ext4 file system utilities
fdisk                         collection of partitioning utilities
file                          Recognize the type of data in a file using ma
findutils                     utilities for finding files--find, xargs
flex                          fast lexical analyzer generator
g++                           GNU C++ compiler
g++-8                         GNU C++ compiler
gcc                           GNU C compiler
gcc-8                         GNU C compiler
gcc-8-base:arm64              GCC, the GNU Compiler Collection (base package
gdbm-l10n                     GNU dbm database routines (translation files) 
git                           fast, scalable, distributed revision control s
git-man                       fast, scalable, distributed revision control s
gpgv                          GNU privacy guard - signature verification too
grep                          GNU grep, egrep and fgrep
groff-base                    GNU troff text-formatting system (base system 
gzip                          GNU compression utilities
hostname                      utility to set/show the host name or domain na
htop                          interactive processes viewer
ifupdown                      high level tools to configure network interfac
init                          metapackage ensuring an init system is install
init-system-helpers           helper tools for all init systems
installation-report           system installation report
iproute2                      networking and traffic control tools
iptables                      administration tools for packet filtering and 
iputils-ping                  Tools to test the reachability of network host
isc-dhcp-client               DHCP client for automatically obtaining an IP 
isc-dhcp-common               common manpages relevant to all of the isc-dhc
joe                           user friendly full screen text editor
kbd                           Linux console font and keytable utilities
keyboard-configuration        system-wide keyboard preferences
kmod                          tools for managing Linux kernel modules
less                          pager program similar to more
locales                       GNU C Library: National Language (locale) data
login                         system login tools
logrotate                     Log rotation utility
lsb-base                      Linux Standard Base init script functionality
m4                            macro processing language
make                          utility for directing compilation
man-db                        on-line manual pager
mawk                          a pattern scanning and text processing languag
mlocate                       quickly find files on the filesystem based on 
mount                         tools for mounting and manipulating filesystem
nano                          small, friendly text editor inspired by Pico
ncdu                          ncurses disk usage viewer
ncurses-base                  basic terminal type definitions
ncurses-bin                   terminal-related programs and man pages
net-tools                     NET-3 networking toolkit
netbase                       Basic TCP/IP networking system
ntpdate                       client for setting system time from NTP server
openssh-client                secure shell (SSH) client, for secure access t
openssh-server                secure shell (SSH) server, for secure access f
openssh-sftp-server           secure shell (SSH) sftp server module, for SFT
openssl                       Secure Sockets Layer toolkit - cryptographic u
passwd                        change and administer password and group data
patch                         Apply a diff file to an original
pciutils                      Linux PCI Utilities
perl                          Larry Wall's Practical Extraction and Report L
perl-base                     minimal Perl system
perl-modules-5.28             Core Perl modules
procps                        /proc file system utilities
readline-common               GNU readline and history libraries, common fil
rsyslog                       reliable system and kernel logging daemon
saidar                        curses-based program which displays live syste
sed                           GNU stream editor for filtering/transforming t
sensible-utils                Utilities for sensible alternative selection
ssh                           secure shell client and server (metapackage)
sudo                          Provide limited super user privileges to speci
systemd                       system and service manager
systemd-sysv                  system and service manager - SysV links
sysvinit-utils                System-V-like utilities
tar                           GNU version of the tar archiving utility
tzdata                        time zone and daylight-saving time data
ucf                           Update Configuration File(s): preserve user ch
udev                          /dev/ and hotplug management daemon
usb.ids                       USB ID Repository
usbutils                      Linux USB utilities
util-linux                    miscellaneous system utilities
util-linux-locales            locales files for util-linux
vim-common                    Vi IMproved - Common files
vim-tiny                      Vi IMproved - enhanced vi editor - compact ver
wamerican                     American English dictionary words for /usr/sha
wget                          retrieves files from the web
whiptail                      Displays user-friendly dialog boxes from shell
wireless-tools                Tools for manipulating Linux Wireless Extensio
wpasupplicant                 client support for WPA and WPA2 (IEEE 802.11i)
xkb-data                      X Keyboard Extension (XKB) configuration data
xxd                           tool to make (or reverse) a hex dump
xz-utils                      XZ-format compression utilities
zlib1g:arm64                  compression library - runtime
	

/boot -partition

Boot partition contains these files. Probably all are not necessary, but I haven't bothered to clean these.

rpi4:~$ ls /boot/
armstub8-gic.bin          COPYING.linux  kernel8-p4.img    start_db.elf
bcm2710-rpi-3-b.dtb       fixup4cd.dat   LICENCE.broadcom  start.elf
bcm2710-rpi-3-b-plus.dtb  fixup4.dat     overlays          startup.sh
bcm2710-rpi-cm3.dtb       fixup4db.dat   RECOVERY.000      start_x.elf
bcm2711-rpi-4-b.dtb       fixup4x.dat    start4cd.elf      vl805.bin
bcm2837-rpi-3-b.dtb       fixup_cd.dat   start4db.elf      vl805.sig
bootcode.bin              fixup.dat      start4.elf
cmdline.txt               fixup_db.dat   start4x.elf
config.txt                fixup_x.dat    start_cd.elf
	

Configs are simplified as :

rpi4:~$ cat /boot/config.txt 
# For more options and information see
# http://www.raspberrypi.org/documentation/configuration/config-txt.md
# Some settings may impact device functionality. See link above for details

disable_overscan=1
dtparam=spi=on
dtparam=audio=on
dtoverlay=vc4-fkms-v3d
gpu_mem=32
start_x=0
arm_64bit=1

[pi4]
max_framebuffers=2
kernel=kernel8-p4.img
disable_overscan:1=1

[all]
	
rpi4:~$ cat /boot/cmdline.txt 
dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes usbhid.mousepoll=0 rootwait
	

If you are booting for external drive (and to do that change root to root=/dev/sda1), the rootwait is absolutety required so that boot process waits disks to spin up before trying to mount root from them.

/lib/firmware -directory

Required firmwares are manually added. These are required only for wireless to operate.

rpi4:~$ find /lib/firmware -type f
/lib/firmware/brcm/brcmfmac43455-sdio.bin
/lib/firmware/brcm/brcmfmac43455-sdio.clm_blob
/lib/firmware/brcm/brcmfmac43455-sdio.txt
/lib/firmware/regulatory.db
	

/etc/network/interfaces

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet static
	address 192.168.11.2
	netmask 255.255.255.0

#allow-hotplug wlan0
iface wlan0 inet dhcp
        wpa-ssid MY_SSID
        wpa-psk MY_SSID_PASS
        wpa-key-mgmt WPA-PSK
	

Notes & bugs