From 1502f614b260b229899764ef111dcb08674a08a5 Mon Sep 17 00:00:00 2001 From: weishanshan1084 Date: Mon, 29 Apr 2024 14:07:25 +0800 Subject: [PATCH] support ubuntu and debian rootfs Signed-off-by: weishanshan1084 --- Makefile | 2 + package/Makefile.in | 4 + package/skeleton-custom/skeleton-custom.mk | 32 +++++++- system/Config.in | 74 +++++++++++++++++++ .../pkg-toolchain-external.mk | 28 +++++++ 5 files changed, 139 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 91973cca..855a8750 100644 --- a/Makefile +++ b/Makefile @@ -725,6 +725,7 @@ target-finalize: $(PACKAGES) $(TARGET_DIR) host-finalize @$(call MESSAGE,"Finalizing target directory") $(call per-package-rsync,$(sort $(PACKAGES)),target,$(TARGET_DIR),copy) $(foreach hook,$(TARGET_FINALIZE_HOOKS),$($(hook))$(sep)) +ifeq ($(BR2_ROOTFS_SKELETON_DEFAULT),y) rm -rf $(TARGET_DIR)/usr/include $(TARGET_DIR)/usr/share/aclocal \ $(TARGET_DIR)/usr/lib/pkgconfig $(TARGET_DIR)/usr/share/pkgconfig \ $(TARGET_DIR)/usr/lib/cmake $(TARGET_DIR)/usr/share/cmake \ @@ -766,6 +767,7 @@ endif echo "PRETTY_NAME=\"Buildroot $(BR2_VERSION)\"" \ ) > $(TARGET_DIR)/usr/lib/os-release ln -sf ../usr/lib/os-release $(TARGET_DIR)/etc +endif # BR2_ROOTFS_SKELETON_DEFAULT @$(call MESSAGE,"Sanitizing RPATH in target tree") PARALLEL_JOBS=$(PARALLEL_JOBS) \ diff --git a/package/Makefile.in b/package/Makefile.in index 3e276d23..3ac7d694 100644 --- a/package/Makefile.in +++ b/package/Makefile.in @@ -149,6 +149,10 @@ endif TARGET_LDFLAGS = $(call qstrip,$(BR2_TARGET_LDFLAGS)) +ifeq ($(BR2_ROOTFS_SKELETON_UBUNTU)$(BR2_ROOTFS_SKELETON_DEBIAN),y) +TARGET_LDFLAGS += -Wl,-rpath-link=$(STAGING_DIR)/usr/lib/aarch64-linux-gnu +endif + # By design, _FORTIFY_SOURCE requires gcc optimization to be enabled. # Therefore, we need to pass _FORTIFY_SOURCE and the optimization level # through the same mechanism, i.e currently through CFLAGS. Passing diff --git a/package/skeleton-custom/skeleton-custom.mk b/package/skeleton-custom/skeleton-custom.mk index b05c834b..18c95204 100644 --- a/package/skeleton-custom/skeleton-custom.mk +++ b/package/skeleton-custom/skeleton-custom.mk @@ -15,6 +15,36 @@ SKELETON_CUSTOM_PROVIDES = skeleton SKELETON_CUSTOM_INSTALL_STAGING = YES +ifeq ($(BR2_ROOTFS_SKELETON_UBUNTU)$(BR2_ROOTFS_SKELETON_DEBIAN),y) +define SKELETON_CUSTOM_BUILD_CMDS + $(foreach s, $(call qstrip,$(BR2_ROOTFS_POST_CUSTOM_SKELETON_SCRIPT)), \ + @$(call MESSAGE,"Executing post-skeleton-custom script $(s)")$(sep) \ + $(EXTRA_ENV) $(s) $(@D) $(call qstrip,$(BR2_ROOTFS_POST_SCRIPT_ARGS))$(sep)) +endef + +define SKELETON_CUSTOM_INSTALL_TARGET_CMDS + $(call SYSTEM_RSYNC,$(@D),$(TARGET_DIR)) + $(INSTALL) -m 0644 support/misc/target-dir-warning.txt \ + $(TARGET_DIR_WARNING_FILE) + cd $(TARGET_DIR)/var && rm run && ln -sf ../run run && rm lock && ln -sf ../run/lock lock +endef + +define SKELETON_CUSTOM_INSTALL_STAGING_CMDS + $(call SYSTEM_RSYNC,$(@D),$(STAGING_DIR)) + cd $(STAGING_DIR)/var && rm run && ln -sf ../run run && rm lock && ln -sf ../run/lock lock +endef + +define SKELETON_CUSTOM_REMOVE_PERMISSION_FOR_SSH_FILES + if [ -d $(TARGET_DIR)/etc/ssh ]; then \ + chmod go-r $(TARGET_DIR)/etc/ssh/ssh_host_ecdsa_key; \ + chmod go-r $(TARGET_DIR)/etc/ssh/ssh_host_ed25519_key; \ + chmod go-r $(TARGET_DIR)/etc/ssh/ssh_host_rsa_key; \ + fi +endef +SKELETON_CUSTOM_POST_INSTALL_TARGET_HOOKS += SKELETON_CUSTOM_REMOVE_PERMISSION_FOR_SSH_FILES + +else + SKELETON_CUSTOM_PATH = $(call qstrip,$(BR2_ROOTFS_SKELETON_CUSTOM_PATH)) ifeq ($(BR2_PACKAGE_SKELETON_CUSTOM)$(BR_BUILDING),yy) @@ -57,5 +87,5 @@ define SKELETON_CUSTOM_INSTALL_STAGING_CMDS $(call SYSTEM_USR_SYMLINKS_OR_DIRS,$(STAGING_DIR)) $(call SYSTEM_LIB_SYMLINK,$(STAGING_DIR)) endef - +endif # ifeq ($(BR2_ROOTFS_SKELETON_UBUNTU)$(BR2_ROOTFS_SKELETON_DEBIAN),y) $(eval $(generic-package)) diff --git a/system/Config.in b/system/Config.in index 33ca69b9..b6fc6c99 100644 --- a/system/Config.in +++ b/system/Config.in @@ -26,6 +26,76 @@ endchoice if BR2_ROOTFS_SKELETON_CUSTOM +choice + prompt "Choose Ubuntu or Debian" + default BR2_ROOTFS_SKELETON_UBUNTU + +config BR2_ROOTFS_SKELETON_UBUNTU + bool "custom target skeleton is ubuntu" + help + Custom target skeleton is ubuntu. + +if BR2_ROOTFS_SKELETON_UBUNTU + +choice + prompt "Choose Ubuntu version" + default BR2_ROOTFS_SKELETON_UBUNTU_JAMMY + +config BR2_ROOTFS_SKELETON_UBUNTU_JAMMY + bool "Ubuntu 22.04" + help + Ubuntu 22.04 LTS (Jammy Jellyfish) + +config BR2_ROOTFS_SKELETON_UBUNTU_FOCAL + bool "Ubuntu 20.04" + help + Ubuntu 20.04 LTS (Focal Fossa) + +endchoice + +endif + +config BR2_ROOTFS_SKELETON_DEBIAN + bool "custom target skeleton is debian" + help + Custom target skeleton is debian. + +endchoice + +config BR2_PACKAGE_ROOTFS_DESKTOP + bool "Ubuntu or Debian desktop" + help + Ubuntu or Debian desktop. + +config BR2_TARGET_GENERIC_HOSTNAME + string "System hostname" + default "buildroot" + help + Select system hostname to be stored in /etc/hostname. + + Leave empty to not create /etc/hostname, or to keep the + one from a custom skeleton. + +config BR2_ROOTFS_LINUX_HEADERS + bool "custom kernel headers" + help + Custom kernel headers for Ubuntu or Debian. + +config BR2_ROOTFS_POST_CUSTOM_SKELETON_SCRIPT + string "Custom scripts to run before using custom skeleton" + default "" + help + Specify a space-separated list of scripts to be run after the download + and unzip has finished and before Buildroot starts using the custom skeleton. + + This gives users the opportunity to do board/skeleton specific configuration, + add-ons and the like, so the generated files can be used directly + without further processing. + + These scripts are called with the build directory name + as first argument. Make sure the exit code of those scripts are 0, otherwise + make will stop after calling them. + config BR2_ROOTFS_SKELETON_CUSTOM_PATH string "custom target skeleton path" help @@ -605,6 +675,10 @@ config BR2_ROOTFS_USERS_TABLES See manual for details on the usage and syntax of these files. +config BR2_ROOTFS_CHOWN + bool "Install rootfs-chown service" + select BR2_PACKAGE_ROOTFS_CHOWN + config BR2_ROOTFS_OVERLAY string "Root filesystem overlay directories" default "" diff --git a/toolchain/toolchain-external/pkg-toolchain-external.mk b/toolchain/toolchain-external/pkg-toolchain-external.mk index ddf1d70a..a7ceccd6 100644 --- a/toolchain/toolchain-external/pkg-toolchain-external.mk +++ b/toolchain/toolchain-external/pkg-toolchain-external.mk @@ -453,6 +453,18 @@ define TOOLCHAIN_EXTERNAL_INSTALL_SYSROOT_LIBS $(call copy_toolchain_sysroot,$${SYSROOT_DIR},$${ARCH_SYSROOT_DIR},$${ARCH_SUBDIR},$${ARCH_LIB_DIR},$${SUPPORT_LIB_DIR}) endef +define TOOLCHAIN_EXTERNAL_FIX_SYMLINK_IN_STAGING + for link in $$(find $(STAGING_DIR) -type l); do \ + target=$$(readlink $${link}) ; \ + if [ "$${target}" == "$${target$(SHARP_SIGN)/}" ] ; then \ + continue ; \ + fi ; \ + relpath="$(call relpath_prefix,$${target$(SHARP_SIGN)/})" ; \ + echo "Fixing symlink $${link} from $${target} to $${relpath}$${target$(SHARP_SIGN)/}" ; \ + ln -sf $${relpath}$${target$(SHARP_SIGN)/} $${link} ; \ + done +endef + # Create a symlink from (usr/)$(ARCH_LIB_DIR) to lib. # Note: the skeleton package additionally creates lib32->lib or lib64->lib # (as appropriate) @@ -595,6 +607,15 @@ $(2)_TOOLCHAIN_WRAPPER_ARGS += $$(TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS) $(2)_BUILD_CMDS = $$(TOOLCHAIN_WRAPPER_BUILD) +ifeq ($(BR2_ROOTFS_SKELETON_CUSTOM),y) +define $(2)_INSTALL_STAGING_CMDS + $$(TOOLCHAIN_WRAPPER_INSTALL) + $$(TOOLCHAIN_EXTERNAL_FIX_SYMLINK_IN_STAGING) + $$(TOOLCHAIN_EXTERNAL_INSTALL_WRAPPER) + $$(TOOLCHAIN_EXTERNAL_INSTALL_GDBINIT) + $$(TOOLCHAIN_EXTERNAL_FIXUP_PRETTY_PRINTER_LOADER) +endef +else define $(2)_INSTALL_STAGING_CMDS $$(TOOLCHAIN_WRAPPER_INSTALL) $$(TOOLCHAIN_EXTERNAL_CREATE_STAGING_LIB_SYMLINK) @@ -603,10 +624,16 @@ define $(2)_INSTALL_STAGING_CMDS $$(TOOLCHAIN_EXTERNAL_INSTALL_GDBINIT) $$(TOOLCHAIN_EXTERNAL_FIXUP_PRETTY_PRINTER_LOADER) endef +endif # Even though we're installing things in both the staging, the host # and the target directory, we do everything within the # install-staging step, arbitrarily. +ifeq ($(BR2_ROOTFS_SKELETON_CUSTOM),y) +define $(2)_INSTALL_TARGET_CMDS + +endef +else define $(2)_INSTALL_TARGET_CMDS $$(TOOLCHAIN_EXTERNAL_CREATE_TARGET_LIB_SYMLINK) $$(TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LIBS) @@ -614,6 +641,7 @@ define $(2)_INSTALL_TARGET_CMDS $$(TOOLCHAIN_EXTERNAL_FIXUP_UCLIBCNG_LDSO) $$(TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LDD) endef +endif # Call the generic package infrastructure to generate the necessary # make targets