diff options
Diffstat (limited to 'scripts/Kconfig.mk')
| -rw-r--r-- | scripts/Kconfig.mk | 205 |
1 files changed, 0 insertions, 205 deletions
diff --git a/scripts/Kconfig.mk b/scripts/Kconfig.mk deleted file mode 100644 index 3db7a2f..0000000 --- a/scripts/Kconfig.mk +++ /dev/null @@ -1,205 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later -# Copyright (C) 2026 Richard Qin -# -# scripts/Kconfig.mk — Kernel Configuration Infrastructure -# -# This file is the heart of the LumeOS build-time configuration system. -# It mirrors the role of Linux's Kconfig + auto.conf pipeline: -# -# 1. Developer edits `$(O)/.config` (or runs `make O=... defconfig`) -# 2. This file reads that configuration and applies missing defaults, -# validates constraints, and exports two things: -# a) KCPPFLAGS — a set of -DCONFIG_xxx=value flags for the compiler -# b) $(BUILD)/generated/autoconf.h — the same values as C #defines -# -# Design Principles (matching Linux conventions): -# - Every CONFIG_ symbol has a default defined HERE, so an empty output -# directory still builds a sane kernel. -# - Boolean options use 'y' / 'n'. Numeric options are plain integers. -# - The generated autoconf.h uses the exact same names so that -# `#ifdef CONFIG_DEBUG` works identically in Makefile and C. -# ====================================================================== - -# ------------------------------------------------------------------ -# §1 Read user configuration (if it exists) -# ------------------------------------------------------------------ -KCONFIG_CONFIG ?= $(BUILD)/.config --include $(KCONFIG_CONFIG) - -# ------------------------------------------------------------------ -# §2 Provide defaults for every CONFIG_ symbol -# -# ?= means "set only if not already set (by .config or CLI)". -# This is the single source of truth for default values. -# ------------------------------------------------------------------ - -# --- Platform ------------------------------------------------------- -CONFIG_ARCH ?= riscv - -# --- CPU / SMP ------------------------------------------------------ -CONFIG_NR_CPUS ?= 8 - -# --- Scheduler ------------------------------------------------------ -CONFIG_HZ ?= 100 -CONFIG_NR_PRIORITIES ?= 32 - -# --- Memory Management ---------------------------------------------- -CONFIG_PAGE_SIZE ?= 4096 -CONFIG_MAX_ORDER ?= 11 -CONFIG_KERNEL_STACK_SIZE ?= 8192 - -# --- Security / Hardening ------------------------------------------- -CONFIG_KASLR ?= y -CONFIG_KASLR_POLICY_ID ?= 0 -CONFIG_KASLR_LOG_LEVEL ?= 1 -CONFIG_STACK_CANARY ?= y -CONFIG_KERNEL_COMPRESSED ?= y - -# --- Debug ----------------------------------------------------------- -CONFIG_DEBUG ?= y -CONFIG_DEBUG_LOCKS ?= y -CONFIG_SELFTEST ?= y -CONFIG_KLOG ?= y - -# --- Initramfs ------------------------------------------------------ -# Source for the initramfs image. Accepted forms (auto-detected by -# scripts/gen_initramfs.sh): -# - a listing file (gen_init_cpio format) → built into a cpio -# - a directory → packed recursively -# - a *.cpio file → used as-is -# Override on the command line or pin in .config: -# make all CONFIG_INITRAMFS_SOURCE=/path/to/rootfs -CONFIG_INITRAMFS_SOURCE ?= usr/default_cpio_list -CONFIG_INITRAMFS_ROOT_UID ?= 0 -CONFIG_INITRAMFS_ROOT_GID ?= 0 - -# ------------------------------------------------------------------ -# §3 Derived constants (computed from CONFIG_ symbols) -# -# These follow Linux's pattern of expressing dependent values -# so that C code never has to do its own derivation at runtime. -# ------------------------------------------------------------------ - -# Default priority = middle of the range -CONFIG_DEFAULT_PRIORITY = $(shell echo $$(( $(CONFIG_NR_PRIORITIES) / 2 ))) - -# Idle priority = lowest = NR_PRIORITIES - 1 -CONFIG_IDLE_PRIORITY = $(shell echo $$(( $(CONFIG_NR_PRIORITIES) - 1 ))) - -# Default time slice in ticks: 100ms worth of ticks -# (same as Linux CFS's sysctl_sched_min_granularity default) -CONFIG_DEFAULT_TIMESLICE = $(shell echo $$(( $(CONFIG_HZ) / 10 ))) - -# ------------------------------------------------------------------ -# §4 Export to C/C++ via -D flags -# -# KCPPFLAGS is appended to CFLAGS/CXXFLAGS in the main Makefile. -# Every CONFIG_xxx=<value> becomes -DCONFIG_xxx=<value>. -# Boolean 'y' options become -DCONFIG_xxx=1. -# ------------------------------------------------------------------ -KCPPFLAGS := - -# Numeric options — pass through as-is -KCPPFLAGS += -DCONFIG_NR_CPUS=$(CONFIG_NR_CPUS) -KCPPFLAGS += -DCONFIG_HZ=$(CONFIG_HZ) -KCPPFLAGS += -DCONFIG_NR_PRIORITIES=$(CONFIG_NR_PRIORITIES) -KCPPFLAGS += -DCONFIG_DEFAULT_PRIORITY=$(CONFIG_DEFAULT_PRIORITY) -KCPPFLAGS += -DCONFIG_IDLE_PRIORITY=$(CONFIG_IDLE_PRIORITY) -KCPPFLAGS += -DCONFIG_DEFAULT_TIMESLICE=$(CONFIG_DEFAULT_TIMESLICE) -KCPPFLAGS += -DCONFIG_PAGE_SIZE=$(CONFIG_PAGE_SIZE) -KCPPFLAGS += -DCONFIG_MAX_ORDER=$(CONFIG_MAX_ORDER) -KCPPFLAGS += -DCONFIG_KERNEL_STACK_SIZE=$(CONFIG_KERNEL_STACK_SIZE) - -# Boolean options — translate 'y' → 1 -ifeq ($(CONFIG_KASLR),y) -KCPPFLAGS += -DCONFIG_KASLR=1 -endif -KCPPFLAGS += -DCONFIG_KASLR_POLICY_ID=$(CONFIG_KASLR_POLICY_ID) -KCPPFLAGS += -DCONFIG_KASLR_LOG_LEVEL=$(CONFIG_KASLR_LOG_LEVEL) -ifeq ($(CONFIG_STACK_CANARY),y) -KCPPFLAGS += -DCONFIG_STACK_CANARY=1 -endif -ifeq ($(CONFIG_DEBUG),y) -KCPPFLAGS += -DCONFIG_DEBUG=1 -endif -ifeq ($(CONFIG_DEBUG_LOCKS),y) -KCPPFLAGS += -DCONFIG_DEBUG_LOCKS=1 -endif -ifeq ($(CONFIG_SELFTEST),y) -KCPPFLAGS += -DCONFIG_SELFTEST=1 -endif -ifeq ($(CONFIG_KLOG),y) -KCPPFLAGS += -DCONFIG_KLOG=1 -endif -ifeq ($(CONFIG_KERNEL_COMPRESSED),y) -KCPPFLAGS += -DCONFIG_KERNEL_COMPRESSED=1 -endif - -# ------------------------------------------------------------------ -# §5 Generate autoconf.h (analogous to Linux's include/generated/autoconf.h) -# -# This header is auto-generated at build time so that C code can -# #include <generated/autoconf.h> and see CONFIG_xxx macros without -# relying on -D flags alone. This is important for IDE integration. -# ------------------------------------------------------------------ -AUTOCONF_H := $(BUILD)/generated/autoconf.h - -# ------------------------------------------------------------------ -# §6 Utility targets -# ------------------------------------------------------------------ - -# 'make defconfig' — reset .config to the arch default -.PHONY: defconfig savedefconfig showconfig - -defconfig: - @echo " DEFCFG arch/$(CONFIG_ARCH)/defconfig → $(KCONFIG_CONFIG)" - @mkdir -p $(dir $(KCONFIG_CONFIG)) - @cp arch/$(CONFIG_ARCH)/defconfig $(KCONFIG_CONFIG) - -# 'make savedefconfig' — save current effective config -savedefconfig: - @echo " SAVE $(KCONFIG_CONFIG)" - @mkdir -p $(dir $(KCONFIG_CONFIG)) - @echo "# LumeOS Kernel Configuration (saved $$(date +%Y-%m-%d))" > $(KCONFIG_CONFIG) - @echo "CONFIG_ARCH = $(CONFIG_ARCH)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_NR_CPUS = $(CONFIG_NR_CPUS)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_HZ = $(CONFIG_HZ)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_NR_PRIORITIES = $(CONFIG_NR_PRIORITIES)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_PAGE_SIZE = $(CONFIG_PAGE_SIZE)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_MAX_ORDER = $(CONFIG_MAX_ORDER)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_KERNEL_STACK_SIZE = $(CONFIG_KERNEL_STACK_SIZE)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_KASLR = $(CONFIG_KASLR)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_KASLR_POLICY_ID = $(CONFIG_KASLR_POLICY_ID)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_KASLR_LOG_LEVEL = $(CONFIG_KASLR_LOG_LEVEL)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_STACK_CANARY = $(CONFIG_STACK_CANARY)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_DEBUG = $(CONFIG_DEBUG)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_DEBUG_LOCKS = $(CONFIG_DEBUG_LOCKS)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_SELFTEST = $(CONFIG_SELFTEST)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_KLOG = $(CONFIG_KLOG)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_KERNEL_COMPRESSED = $(CONFIG_KERNEL_COMPRESSED)" >> $(KCONFIG_CONFIG) - -# 'make showconfig' — print effective configuration -showconfig: - @echo "========================================" - @echo " LumeOS Effective Configuration" - @echo "========================================" - @echo " ARCH = $(CONFIG_ARCH)" - @echo " NR_CPUS = $(CONFIG_NR_CPUS)" - @echo " HZ = $(CONFIG_HZ)" - @echo " NR_PRIORITIES = $(CONFIG_NR_PRIORITIES)" - @echo " DEFAULT_PRIORITY = $(CONFIG_DEFAULT_PRIORITY)" - @echo " IDLE_PRIORITY = $(CONFIG_IDLE_PRIORITY)" - @echo " DEFAULT_TIMESLICE = $(CONFIG_DEFAULT_TIMESLICE)" - @echo " PAGE_SIZE = $(CONFIG_PAGE_SIZE)" - @echo " MAX_ORDER = $(CONFIG_MAX_ORDER)" - @echo " KERNEL_STACK_SIZE = $(CONFIG_KERNEL_STACK_SIZE)" - @echo " KASLR = $(CONFIG_KASLR)" - @echo " KASLR_POLICY_ID = $(CONFIG_KASLR_POLICY_ID)" - @echo " KASLR_LOG_LEVEL = $(CONFIG_KASLR_LOG_LEVEL)" - @echo " STACK_CANARY = $(CONFIG_STACK_CANARY)" - @echo " DEBUG = $(CONFIG_DEBUG)" - @echo " DEBUG_LOCKS = $(CONFIG_DEBUG_LOCKS)" - @echo " SELFTEST = $(CONFIG_SELFTEST)" - @echo " KLOG = $(CONFIG_KLOG)" - @echo " KERNEL_COMPRESSED = $(CONFIG_KERNEL_COMPRESSED)" - @echo "========================================" |
