From d32c1d496394986056e98c0786828a0307626964 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Tue, 16 Jul 2019 02:25:13 +0200 Subject: [PATCH] raspi build, config modules, cli options --- .gitignore | 1 + Makefile | 60 +++++++++++++++++++++++++------------- config.example | 7 +++++ modules/default.mk | 27 +++++++++++++++++ modules/display_ws5inch.mk | 34 +++++++++++++++++++++ 5 files changed, 109 insertions(+), 20 deletions(-) create mode 100644 config.example create mode 100644 modules/default.mk create mode 100644 modules/display_ws5inch.mk diff --git a/.gitignore b/.gitignore index 4853b85..2c4d42b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,6 @@ part_boot.img part_root.img rpi_boot.img rpi_root.img +config.mk .*.swp .*.swo diff --git a/Makefile b/Makefile index 03a66ae..da5d3e4 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,11 @@ - DEFAULT: _target + +nul_:= +comma_:=, +space_:=${nul_} ${nul_} + .PHONY: clean .FORCE -.PHONY: _qemu _bootstrap _install _copy _config _bootloader _squash +.PHONY: _qemu _bootstrap _install _copy _config_raspi _config _bootloader _squash .PHONY: _target _partition _format _mount _sparse _umount _partcopy _mbr ARCH := amd64 @@ -18,6 +22,11 @@ endef PACKAGES := ${PACKAGES} apt btrfs-tools busybox-static bzip2 ca-certificates cron debian-archive-keyring deborphan firmware-linux-free gzip htop ifupdown init iputils-ping irqbalance isc-dhcp-client less make net-tools nmap ntpdate openssh-client psmisc rsync sshfs sudo systemd traceroute unzip vim wget wireless-tools wpasupplicant xz-utils zip +config.mk: + cp "config.example" "$@" + +include config.mk + ifdef disk VOLUME := ${disk} PBOOT := ${disk}1 @@ -87,7 +96,7 @@ define SOURCES = deb http://raspbian.raspberrypi.org/raspbian stretch main non-free firmware rpi deb http://archive.raspberrypi.org/debian stretch main endef -PACKAGES := ${PACKAGES} firmware-brcm8011 libraspberrypi-bin libraspberrypi0 pi-bluetooth raspberrypi-bootloader raspberrypi-kernel +PACKAGES := ${PACKAGES} firmware-brcm80211 libraspberrypi-bin libraspberrypi0 pi-bluetooth raspberrypi-bootloader raspberrypi-kernel _target: _umount _partcopy _config _install @@ -98,7 +107,8 @@ _sparse: _format: _sparse _mount: _format _copy: _install _mount -_config: _copy _mount +_config_raspi: _copy _mount +_config: _copy _mount _config_raspi _umount: _mount _config _partition: _partcopy: _partition _umount @@ -109,6 +119,11 @@ _target: endif +include modules/default.mk +ifdef modules +include $(addsuffix .mk, $(addprefix modules/, $(subst ${comma_},${space},${modules}))) +endif + ifeq "${ARCH}" "amd64" PACKAGES := ${PACKAGES} linux-image-amd64 else ifeq "${ARCH}" "i386" @@ -125,18 +140,21 @@ cfg_root/: sys_root/ _install btrfs sub snap "$<" "$@" || mkdir -p "$@" chmod 755 "$@" +rpi_root/: + btrfs subvol create "$@" || mkdir -p "$@" + chmod 755 "$@" + img_mount/: - mkdir -p "$@" + mkdir -p -m 755 "$@" chmod 755 "$@" hdd_mount/: - mkdir -p "$@" - chmod 755 "$@" + mkdir -p -m 755 "$@" _qemu: ${SYSROOT}/usr/bin/qemu-arm-static ${SYSROOT}/usr/bin/qemu-arm-static: /usr/bin/qemu-arm-static ${SYSROOT} - mkdir -p "$${SYSROOT}"/usr/bin - chmod 755 "$${SYSROOT}/usr" "$${SYSROOT}/usr/bin" + mkdir -p -m 755 "$${SYSROOT}"/usr/bin + chmod 755 "$${SYSROOT}"/usr cp -p "$<" "$@" _bootstrap: ${SYSROOT}/bin/sh @@ -150,12 +168,12 @@ _aptkeys: ${SYSROOT}/etc/apt/trusted.gpg.d/ _norecommends: ${SYSROOT}/etc/apt/apt.conf.d/10norecommends ${SYSROOT}/etc/apt/apt.conf.d/10norecommends: ${SYSROOT} - mkdir -p "$(dir $@)" + mkdir -p -m 755 "$(dir $@)" printf 'APT::Install-Recommends "false";\n' >"$@" chmod 644 "$@" ${SYSROOT}/etc/apt/trusted.gpg.d/: ${SYSROOT} - mkdir -p "$@" + mkdir -p -m 755 "$@" cp keys/*.gpg "$@" _install: ${SYSROOT} _aptkeys _norecommends @@ -173,10 +191,16 @@ _install: ${SYSROOT} _aptkeys _norecommends _copy: ${SYSROOT} ${CFGROOT} cp -au "$${SYSROOT}/." "$${CFGROOT}/" -.PHONY: _main_config -_config: _main_config -_main_config: ${CFGROOT} cfg_seed/ - cp -au cfg_seed/. "$${CFGROOT}" +_config_raspi: ${CFGROOT}/boot/cmdline.txt +${CFGROOT}/boot/cmdline.txt: ${CFGROOT} + printf 'dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet' >"$@" + +.PHONY: _common_config +_config: _common_config +_common_config: ${CFGROOT} cfg_seed/ + ln -sf /dev/null "$${CFGROOT}/etc/systemd/network/99-default.link" + printf 'LABEL=FSROOT / ext4 auto,nofail,rw 0 0\nLABEL=BOOT /boot vfat auto,nofail,ro 0 0\n' \ + >"$${CFGROOT}/etc/fstab" ${SQUASH}: ${CFGROOT} -rm "$${SQUASH}" @@ -243,8 +267,6 @@ _grub_efi64: ${CFGROOT} grub-mkimage -p / -O x86_64-efi fat part_gpt normal linux all_video >"$${CFGROOT}/boot/EFI/BOOT/BOOTX64.EFI" _bootloader: ${CFGROOT} _grub_efi32 _grub_efi64 _syslinux_bios #_syslinux_efi32 _syslinux_efi64 - # cp -L "$${CFGROOT}/vmlinuz" "$${CFGROOT}/initrd.img" "$${CFGROOT}/boot/" - # cp -r cfg_syslinux/. "$${CFGROOT}/" printf 'UI menu.c32\nDEFAULT stretch\nTIMEOUT 30\n' >"$${CFGROOT}/boot/bootmenu.cfg" printf 'set timeout=3\ndefault=stretch\n\n' >"$${CFGROOT}/boot/grub.cfg" k="$$(printf ' %s' "$${CFGROOT}/boot/"vmlinuz-*)"; k="$${k##*/}"; \ @@ -276,10 +298,8 @@ _partcopy: ${VOLUME} ${PROOT} ${PBOOT} _mount: ${PBOOT} ${PROOT} ${CFG_ROOT} mount -t ext4 "$${PROOT}" "$${CFGROOT}" chmod 755 "$${CFGROOT}" - mkdir -p "$${CFGROOT}/boot" - chmod 755 "$${CFGROOT}/boot" + mkdir -p -m 755 "$${CFGROOT}/boot" mount -t vfat "$${PBOOT}" "$${CFGROOT}/boot" - chmod 755 "$${CFGROOT}/boot" _umount: ${CFGROOT} -umount "$${CFGROOT}/boot" diff --git a/config.example b/config.example new file mode 100644 index 0000000..bcb984a --- /dev/null +++ b/config.example @@ -0,0 +1,7 @@ +# image=disk.img squash=rootfs.squash raspi=raspi.img +# modules= + +# packages=chromium,gimp +# rootpass=topsecret +# wifi=MyWiFi +# wifipass=P4ssW0rD diff --git a/modules/default.mk b/modules/default.mk new file mode 100644 index 0000000..f52cd60 --- /dev/null +++ b/modules/default.mk @@ -0,0 +1,27 @@ +ifdef packages +PACKAGES := ${PACKAGES} $(subst ${comma_},${space},${packages}) +endif + +ifdef rootpass +export rootpass +.PHONY: _rootpass +_config: _rootpass +_rootpass: ${CFGROOT} + chroot "$${CFGROOT}" usermod -p "$$(openssl passwd -salt "x$${RANDOM}" "$${rootpass}")" root +endif + +ifdef wifi +export wifi +_config: ${CFGROOT}/etc/network/interfaces.d/wifi + +ifdef wifipass +export wifipass +${CFGROOT}/etc/network/interfaces.d/wifi: ${CFGROOT} + printf 'auto wlan0\nallow-hotplug wlan0\n\niface wlan0 inet dhcp\n' >$@ + printf ' wpa-ssid "%s"\n wpa-psk "%s"\n' "$$wifi" "$$wifipass" >>$@ +else +${CFGROOT}/etc/network/interfaces.d/wifi: ${CFGROOT} + printf 'auto wlan0\nallow-hotplug wlan0\n\niface wlan0 inet dhcp\n' >$@ + printf ' wireless-ssid "%s"\n' "$$wifi" >>$@ +endif +endif diff --git a/modules/display_ws5inch.mk b/modules/display_ws5inch.mk new file mode 100644 index 0000000..d948c5d --- /dev/null +++ b/modules/display_ws5inch.mk @@ -0,0 +1,34 @@ +define display_ws5inch_boot = + +# Waveshare 5 Inch Display +hdmi_group=2 +hdmi_mode=87 +hdmi_cvt=800 480 60 6 0 0 0 +hdmi_drive=1 +dtparam=i2c_arm=on +dtparam=spi=on +enable_uart=1 +dtoverlay=ads7846,cs=1,penirq=25,penirq_pull=2,speed=50000,keep_vref_on=0,swapxy=0,pmax=255,xohms=150,xmin=200,xmax=3900,ymin=200,ymax=3900 +endef + +define display_ws5inch_cfg = +Section "InputClass" + Identifier "evdev touchscreen catchall" + MatchIsTouchscreen "on" + Option "Calibration" "200 3950 250 4000" + MatchDevicePath "/dev/input/event*" + Driver "evdev" +EndSection +endef + +export display_ws5inch_boot display_ws5inch_cfg + +PACKAGES := ${PACKAGES} xserver-xorg-input-evdev xinput xinput-calibrator + +.PHONY: _display_ws5inch +_config: _display_ws5inch +_display_ws5inch: ${CFGROOT} _copy _mount + printf %s "$${display_ws5inch_boot}" >>"$${CFGROOT}/boot/config.txt" + mkdir -p "$${CFGROOT}/usr/share/X11/xorg.conf.d/" + printf %s "$${display_ws5inch_cfg}" >"$${CFGROOT}/usr/share/X11/xorg.conf.d/45-evdev.conf" + #-chroot "$${CFGROOT}" adduser local input -- 2.39.2