-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexternal.mk
More file actions
153 lines (145 loc) · 8.68 KB
/
Copy pathexternal.mk
File metadata and controls
153 lines (145 loc) · 8.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
################################################################################
#
# external.mk for the MISTER BR2_EXTERNAL tree
#
# Pulls in every package .mk under package/*/*.mk. P3.1 added the Realtek
# Wi-Fi kernel-module packages; v9 narrowed the SELECTED set (defconfig) to the
# three 802.11ac chips with no mainline USB driver -- rtl8812au, rtl8814au-morrownr
# and rtl8821au-morrownr -- and moved 8188eu/8188fu/8821cu/8822bu onto in-kernel
# drivers (rtl8xxxu/rtw88; the now-deselected packages stay in the tree as a
# selectable fallback). P3.2 added xone (Xbox One/Series accessory driver) the
# same way (see PLAN.md §6, TASKS.md class D/E). This is the standard Buildroot
# br2-external idiom, so new packages need no change here — just add
# package/<name>/<name>.mk.
#
################################################################################
include $(sort $(wildcard $(BR2_EXTERNAL_MISTER_PATH)/package/*/*.mk))
################################################################################
#
# P1.10 — stage-2 half of the two-stage initramfs build (A1, PLAN.md §5,
# docs/decisions/0002-initramfs.md).
#
# Stage 1 (configs/mister_initramfs_defconfig, driven by the top-level Makefile's
# `initramfs` target) produces output-initramfs/images/rootfs.cpio. This block is
# what makes the MAIN build's kernel swallow it: it injects CONFIG_INITRAMFS_SOURCE
# into the kernel .config at kconfig-fixup time, which is the same mechanism
# Buildroot itself uses for BR2_TARGET_ROOTFS_INITRAMFS (linux/linux.mk:412-419) —
# we just point it at a different, much smaller cpio.
#
# WHY HERE AND NOT IN THE DEFCONFIG. The obvious alternative is
# BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES in configs/fragments/de10nano.fragment. Do
# not: package/pkg-kconfig.mk:19-20 makes `make linux-update-defconfig` and
# `make linux-savedefconfig` HARD-FAIL ("Unable to perform when fragment files are
# set") as soon as any fragment is configured — and those are precisely the commands
# P1.3 uses to regenerate board/mister/de10nano/linux.config. Doing it here keeps
# that workflow intact and keeps an absolute build path out of a committed defconfig.
#
# Ordering is safe: Buildroot's Makefile includes linux/linux.mk (line 553) before
# $(BR2_EXTERNAL_MKS) (line 564), and LINUX_KCONFIG_FIXUP_CMDS is expanded lazily
# inside the .stamp_kconfig_fixup_done recipe, so appending to it here works.
# $(sep) is Buildroot's newline (support/misc/utils.mk:103) — a bare `+=` would
# splice our first command onto the tail of linux.mk's last one.
#
################################################################################
# WHY THE ARCH TEST — added with the DE25-Nano target (D2.1).
#
# BR2_LINUX_KERNEL=y alone was the right condition while every output directory
# in this tree built for the same armv7 board. It no longer is:
# the de25nano fragment stack (configs/fragments/de25nano.fragment) builds an AARCH64 kernel for a different
# board (Agilex 5), in output-de25/, and this hook keys on the *symbol*, not on
# which defconfig or which O= is in play — so without a second test it would
# fire there too and try to embed $(MISTER_INITRAMFS_CPIO) into that kernel.
#
# Two things would go wrong, one loudly and one not:
# 1. LOUDLY, and only by luck: the fixup hard-fails if the cpio is absent, so
# a DE25 build in a tree that had never run `make initramfs` would die with
# an error message telling the developer to build a stage-1 initramfs their
# board does not have and does not want.
# 2. QUIETLY, which is the real hazard: in a tree that HAS run `make
# initramfs` (i.e. any tree that has built the DE10 image — so, every
# developer's, and CI's), the cpio exists and the fixup succeeds. The
# aarch64 kernel then ships an armv7 BusyBox as its initramfs, boots, runs
# /init, and fails at the first exec with a message about the *binary*
# rather than about the build. A green build that produces that is worse
# than no build.
#
# THE TEST IS ON THE ARCHITECTURE, not on a board name or a defconfig name, and
# that is the point: the thing that makes this hook wrong for the DE25 is not
# "it is the DE25", it is that the cpio is armv7 userspace. Every output dir
# this hook is *meant* for -- the main DE10 image, the kernel-only stack
# and the rt variant built on it -- is BR2_arm=y, and every one of them wants the
# cpio. So `BR2_arm` names the actual precondition and needs no maintenance when
# a fourth armv7 variant or a second aarch64 board appears.
#
# Considered and rejected: a BR2_EXTERNAL Config.in symbol (e.g. a
# "BR2_PACKAGE_MISTER_EMBED_STAGE1_INITRAMFS" bool) would be more explicit, but
# it would have to be added to configs/fragments/de10nano.fragment (the board
# layer both DE10 stacks share) to keep them building — a toolchain-family
# edit that changes the DE10's toolchain-fingerprint cache key, for zero
# behavioural difference.
# Revisit if a third board ever needs a stage-1 cpio of its own architecture.
ifeq ($(BR2_LINUX_KERNEL)$(BR2_arm),yy)
# Overridable so CI can build the two stages in separate workspaces.
MISTER_INITRAMFS_CPIO ?= $(BR2_EXTERNAL_MISTER_PATH)/output-initramfs/images/rootfs.cpio
define MISTER_LINUX_INITRAMFS_FIXUP
@if [ ! -f "$(MISTER_INITRAMFS_CPIO)" ]; then \
echo "*** MISTER: stage-1 initramfs cpio not found:"; \
echo "*** $(MISTER_INITRAMFS_CPIO)"; \
echo "*** The kernel cannot be built without it — U-Boot never loads an"; \
echo "*** initrd (A3), so the cpio must be INSIDE the zImage. Build it with:"; \
echo "*** make initramfs"; \
echo "*** (the top-level 'make all' does this for you)."; \
exit 1; \
fi
@$(call MESSAGE,"Embedding stage-1 initramfs: $(MISTER_INITRAMFS_CPIO)")
$(call KCONFIG_ENABLE_OPT,CONFIG_BLK_DEV_INITRD)
$(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_SOURCE,"$(MISTER_INITRAMFS_CPIO)")
$(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_ROOT_UID,0)
$(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_ROOT_GID,0)
$(call KCONFIG_ENABLE_OPT,CONFIG_RD_GZIP)
$(call KCONFIG_ENABLE_OPT,CONFIG_INITRAMFS_COMPRESSION_GZIP)
endef
# CONFIG_INITRAMFS_COMPRESSION_* is set explicitly rather than left to kconfig. The
# choice in usr/Kconfig carries NO `default`, so it silently resolves to its first
# visible entry — today that happens to be GZIP, but "whatever is listed first
# upstream" is not something a boot path should depend on. We ship an UNCOMPRESSED
# cpio (BR2_TARGET_ROOTFS_CPIO_NONE in stage 1) and let the kernel gzip it here:
# compressing it twice would be pointless, and gzip beats leaving it raw for the
# LZ4-compressed zImage to squeeze (LZ4 optimises for decode speed, not ratio).
LINUX_KCONFIG_FIXUP_CMDS += $(sep)$(MISTER_LINUX_INITRAMFS_FIXUP)
endif # BR2_LINUX_KERNEL && BR2_arm
################################################################################
#
# dhcpcd: pin the hook set so it cannot depend on the BUILD HOST.
#
# dhcpcd's own ./configure decides which dhcpcd-hooks to install by probing the
# machine it runs on -- `which ntpd`, `which chronyd`,
# /usr/lib/systemd/systemd-timesyncd, `which ypbind` -- unless it is handed the
# list explicitly (configure: `if ! $HOOKSET` around the probes; HOOKSET is
# only set by --with-hooks). Buildroot's package/dhcpcd/dhcpcd.mk passes no
# --with-hooks, so the TARGET image inherited the host's daemons: a GitHub
# runner (ntpd/chronyd on PATH) shipped 50-ntp.conf, a developer box with
# systemd-timesyncd and no ntpd shipped 50-timesyncd.conf instead -- and the
# build was green either way. Found 2026-09-02 by diffing a CI image against a
# local one (docs/init-parity.md, dhcpcd row).
#
# This appends to the package's own CONFIG_OPTS -- legal because Buildroot
# includes BR2_EXTERNAL .mk files after package/*/*.mk (work/buildroot/
# Makefile: package includes first, then $(BR2_EXTERNAL_MKS)) and the
# DHCPCD_CONFIGURE_CMDS `define` expands $(DHCPCD_CONFIG_OPTS) when the recipe
# RUNS, not when the .mk is parsed. No Buildroot patch, no dhcpcd patch.
#
# The values reproduce the canonical (CI-built) image exactly: the base hooks
# 01-test/20-resolv.conf/30-hostname are unconditional in hooks/Makefile;
# `ntp.conf` selects 50-ntp.conf (we ship classic ntpd, BR2_PACKAGE_NTP, so
# DHCP-offered NTP servers land in /etc/ntp.conf as on stock); `yp.conf` keeps
# the 50-yp.conf EXAMPLE hook under /usr/share/dhcpcd/hooks, which CI also
# shipped. Names are hook stems: configure's find_hook() matches
# [0-9][0-9]-<stem>[.conf], so "ntp.conf" is right and "50-ntp.conf" silently
# matches nothing (verified against dhcpcd 10.2.4's configure).
# scripts/check-linux-img.sh asserts the resulting hook set, fail-closed.
#
################################################################################
ifeq ($(BR2_PACKAGE_DHCPCD),y)
DHCPCD_CONFIG_OPTS += --with-hooks=ntp.conf --with-eghooks=yp.conf
endif