penguin/monok8s

k8s image for Mono Gateway Dev Kit

patches/mono-ask.mk

raw ยท 3910 bytes

# mono-ask.mk
# Custom wrapper to build the NXP ASK for the monok8s Alpine/musl ecosystem

# Define default paths and cross-compilers
KDIR?= /src/linux
ASK_DIR?= $(CURDIR)
ARCH?= arm64
GNU_CROSS?= aarch64-linux-gnu-
MUSL_HOST?= aarch64-linux-musl

STAMPS_DIR := $(ASK_DIR)/sources/.stamps
FMLIB_DIR  := $(ASK_DIR)/sources/fmlib
FMC_BASE   := $(ASK_DIR)/sources/fmc
FMC_DIR    := $(FMC_BASE)/source

SYSROOT_PATH := /opt/aarch64-linux-musl-cross/aarch64-linux-musl

.PHONY: prepare-kernel build-kernel modules userspace dist

prepare-preloaded-sources:
	@echo "--> Initializing dummy git repos and building preloaded fmlib/fmc..."
	mkdir -p $(STAMPS_DIR)
	
	git config --global user.email "monok8s@localhost"
	git config --global user.name "monok8s authors"
	git config --global --add safe.directory '*'
	
	# Inject libmnl.pc into the vendor's isolated sysroot to satisfy pkg-config
	mkdir -p $(ASK_DIR)/sources/sysroot/lib/pkgconfig
	cp -a $(SYSROOT_PATH)/lib/pkgconfig/libmnl.pc $(ASK_DIR)/sources/sysroot/lib/pkgconfig/
	
	# Handle fmlib: Initialize dummy repo, patch, and build
	cd $(FMLIB_DIR) && git init -q && git add -A && git commit -q -m "base"
	cd $(FMLIB_DIR) && git apply $(ASK_DIR)/patches/fmlib/01-mono-ask-extensions.patch
	$(MAKE) -C $(FMLIB_DIR) CROSS_COMPILE=$(MUSL_HOST)- KERNEL_SRC=$(KDIR) libfm-arm.a
	ln -sf libfm-arm.a $(FMLIB_DIR)/libfm.a
	touch $(STAMPS_DIR)/fmlib
	
	# Handle fmc: Initialize dummy repo, patch, and build
	cd $(FMC_BASE) && git init -q && git add -A && git commit -q -m "base"
	cd $(FMC_BASE) && git apply $(ASK_DIR)/patches/fmc/01-mono-ask-extensions.patch
	$(MAKE) -C $(FMC_DIR) CC="$(MUSL_HOST)-gcc -static" CXX="$(MUSL_HOST)-g++ -static" AR=$(MUSL_HOST)-ar \
		MACHINE=ls1046 \
		FMD_USPACE_HEADER_PATH=$(FMLIB_DIR)/include/fmd \
		FMD_USPACE_LIB_PATH=$(FMLIB_DIR) \
		LIBXML2_HEADER_PATH=$(SYSROOT_PATH)/include/libxml2 \
		TCLAP_HEADER_PATH=$(SYSROOT_PATH)/include
	touch $(STAMPS_DIR)/fmc

# 1. Patch the kernel and merge our custom Kubernetes configuration
prepare-kernel:
	@echo "--> Patching the Linux kernel with NXP DPAA extensions..."
	cd $(KDIR) && patch -p1 < $(ASK_DIR)/patches/kernel/002-mono-gateway-ask-kernel_linux_6_12.patch
	@echo "--> Merging NXP defconfig with Kubernetes extra config..."
	cp $(ASK_DIR)/config/kernel/defconfig $(KDIR)/.config
	cd $(KDIR) && ./scripts/kconfig/merge_config.sh -m .config /src/kernel-extra.config
	$(MAKE) -C $(KDIR) ARCH=$(ARCH) CROSS_COMPILE=$(GNU_CROSS) olddefconfig
	/src/ensure-kconfig.sh $(KDIR)/.config /src/kernel-extra.config

# 2. Build the kernel tree (mandatory before out-of-tree modules can be built)
build-kernel: prepare-kernel
	@echo "--> Building the Linux kernel natively..."
	# Replace "dtbs" with the exact path to your target dtb
	$(MAKE) -C $(KDIR) ARCH=$(ARCH) CROSS_COMPILE=$(GNU_CROSS) -j$$(nproc) \
		Image modules freescale/mono-gateway-dk-sdk.dtb

# 3. Build the ASK out-of-tree modules using the vendor Makefile
modules: build-kernel
	@echo "--> Building ASK out-of-tree modules..."
	$(MAKE) -f Makefile modules KDIR=$(KDIR) CROSS_COMPILE=$(GNU_CROSS) ARCH=$(ARCH)

# 4. Build the ASK userspace daemons using the musl cross-compiler
userspace: prepare-preloaded-sources
	@echo "--> Building ASK sources and libraries..."
	$(MAKE) -f Makefile sources KDIR=$(KDIR) CROSS_COMPILE=$(MUSL_HOST)- ARCH=$(ARCH) HOST=$(MUSL_HOST)
	
	@echo "--> Stripping -Werror from vendor Makefiles for modern GCC compatibility..."
	sed -i 's/-Werror//g' $(ASK_DIR)/cmm/Makefile
	sed -i 's/-Werror//g' $(ASK_DIR)/dpa_app/Makefile
	
	@echo "--> Building ASK userspace executables statically..."
	$(MAKE) -f Makefile userspace KDIR=$(KDIR) CROSS_COMPILE=$(MUSL_HOST)- ARCH=$(ARCH) HOST=$(MUSL_HOST) CC='"$(MUSL_HOST)-gcc -static"' CXX='"$(MUSL_HOST)-g++ -static"'

# 5. Extract artifacts
dist:
	@echo "--> Staging artifacts..."
	$(MAKE) -f Makefile dist KDIR=$(KDIR) CROSS_COMPILE=$(GNU_CROSS) ARCH=$(ARCH)