From patchwork Mon Jun 25 09:05:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 167010 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from hemlock.osuosl.org (hemlock.osuosl.org [140.211.166.133]) by ozlabs.org (Postfix) with ESMTP id A0397B6FB6 for ; Mon, 25 Jun 2012 19:06:05 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id E829CA009A; Mon, 25 Jun 2012 09:06:03 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id a6xUqIt5J8iW; Mon, 25 Jun 2012 09:05:58 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id 036AFA0083; Mon, 25 Jun 2012 09:05:58 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (whitealder.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id A7CBD8F753 for ; Mon, 25 Jun 2012 09:05:56 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 988BC8B21B for ; Mon, 25 Jun 2012 09:05:56 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XAvGYRTv058D for ; Mon, 25 Jun 2012 09:05:51 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail.free-electrons.com (mail.free-electrons.com [88.190.12.23]) by whitealder.osuosl.org (Postfix) with ESMTP id 7F2AE8B688 for ; Mon, 25 Jun 2012 09:05:50 +0000 (UTC) Received: by mail.free-electrons.com (Postfix, from userid 106) id 46627176; Mon, 25 Jun 2012 11:05:37 +0200 (CEST) Received: from localhost (col31-4-88-188-83-94.fbx.proxad.net [88.188.83.94]) by mail.free-electrons.com (Postfix) with ESMTPSA id 62C6B12A; Mon, 25 Jun 2012 11:05:28 +0200 (CEST) From: Maxime Ripard To: buildroot@busybox.net Date: Mon, 25 Jun 2012 11:05:21 +0200 Message-Id: <1340615122-6006-1-git-send-email-maxime.ripard@free-electrons.com> X-Mailer: git-send-email 1.7.9.5 Cc: brian@crystalfontz.com Subject: [Buildroot] [PATCH] Add some support for device tree kernels with appended trees X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: buildroot-bounces@busybox.net This is a refactoring of the previous basic device tree options available for microblaze. The previous option only made it possible for microblaze targets to give a path to an external device tree, and build a simpleImage with it. This involved using a custom target name as simpleImages are built with the simpleImage.dt_name. This is also the case on powerpc with cuImages. This patch extends the previous mechanism by adding simpleImage and cuImage to the image name list and no longer rely on custom image name. A field is also added to specify either the device tree name if it is already present in the kernel or a path to a custom one. Finally, this patch also support generating kernel images with appended device trees, including regenerating uboot images to update the header. If the appending feature is not used, the generated dtb file is copied into output/images. Signed-off-by: Maxime Ripard Cc: Stephan Hoffmann --- linux/Config.in | 55 ++++++++++++++++++++++++++++++++++++------ linux/linux.mk | 71 ++++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 103 insertions(+), 23 deletions(-) diff --git a/linux/Config.in b/linux/Config.in index 4562b1b..5618629 100644 --- a/linux/Config.in +++ b/linux/Config.in @@ -124,24 +124,53 @@ config BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE help Path to the kernel configuration file +config BR2_LINUX_KERNEL_DTS_SUPPORT + bool "Device Tree Support" + +config BR2_LINUX_KERNEL_APPENDED_DTB + bool "Append the Device Tree binary to the kernel" + depends on BR2_LINUX_KERNEL_DTS_SUPPORT + +choice + prompt "Device Tree choice" + depends on BR2_LINUX_KERNEL_DTS_SUPPORT + default BR2_LINUX_KERNEL_USE_DEFAULT_DTS + +config BR2_LINUX_KERNEL_USE_DEFAULT_DTS + bool "Using a device tree present in the kernel" + +config BR2_LINUX_KERNEL_USE_CUSTOM_DTS + bool "Using a custom device tree file" + +endchoice + config BR2_LINUX_KERNEL_DTS_FILE - string "Device Tree dts file location" - depends on BR2_microblaze - help - Path from where the dts file has to be copied - The final "custom target" name depends on the - dts file name: - .dts --> simpleImage. + string "DTS name" + depends on BR2_LINUX_KERNEL_USE_DEFAULT_DTS + help + Name of the default device tree, without the + trailing .dts + +config BR2_LINUX_KERNEL_CUSTOM_DTS_FILE + string "Device tree file path" + depends on BR2_LINUX_KERNEL_USE_CUSTOM_DTS + help + Path to the kernel configuration file + # # Binary format # +config BR2_LINUX_KERNEL_UBOOT_IMAGE + bool + choice prompt "Kernel binary format" config BR2_LINUX_KERNEL_UIMAGE bool "uImage" depends on BR2_arm || BR2_armeb || BR2_bfin || BR2_powerpc || BR2_avr32 || BR2_sh || BR2_sh64 + select BR2_LINUX_KERNEL_UBOOT_IMAGE config BR2_LINUX_KERNEL_BZIMAGE bool "bzImage" @@ -151,6 +180,18 @@ config BR2_LINUX_KERNEL_ZIMAGE bool "zImage" depends on BR2_arm || BR2_armeb || BR2_powerpc || BR2_sparc || BR2_sh || BR2_sh64 || BR2_xtensa +config BR2_LINUX_KERNEL_CUIMAGE + bool "cuImage" + depends on BR2_LINUX_KERNEL_DTS_SUPPORT + depends on BR2_powerpc + select BR2_LINUX_KERNEL_UBOOT_IMAGE + +config BR2_LINUX_KERNEL_SIMPLEIMAGE + bool "simpleImage" + depends on BR2_LINUX_KERNEL_DTS_SUPPORT + depends on BR2_microblaze + select BR2_LINUX_KERNEL_UBOOT_IMAGE + config BR2_LINUX_KERNEL_VMLINUX_BIN bool "vmlinux.bin" depends on BR2_mips || BR2_mipsel || BR2_sh || BR2_sh64 diff --git a/linux/linux.mk b/linux/linux.mk index 34f8623..3eb5e6d 100644 --- a/linux/linux.mk +++ b/linux/linux.mk @@ -34,6 +34,10 @@ LINUX_PATCHES = $(call qstrip,$(BR2_LINUX_KERNEL_PATCH)) LINUX_INSTALL_IMAGES = YES LINUX_DEPENDENCIES += host-module-init-tools +ifeq ($(BR2_LINUX_KERNEL_UBOOT_IMAGE),y) + LINUX_DEPENDENCIES+=host-uboot-tools +endif + LINUX_MAKE_FLAGS = \ HOSTCC="$(HOSTCC)" \ HOSTCFLAGS="$(HOSTCFLAGS)" \ @@ -46,6 +50,12 @@ LINUX_MAKE_FLAGS = \ # going to be installed in the target filesystem. LINUX_VERSION_PROBED = $(shell $(MAKE) $(LINUX_MAKE_FLAGS) -C $(LINUX_DIR) --no-print-directory -s kernelrelease) +ifeq ($(BR2_LINUX_KERNEL_USE_DEFAULT_DTS),y) +KERNEL_DTS_NAME = $(BR2_LINUX_KERNEL_DTS_FILE) +else ifeq ($(BR2_LINUX_KERNEL_USE_CUSTOM_DTS),y) +KERNEL_DTS_NAME = $(basename $(notdir $(BR2_LINUX_KERNEL_CUSTOM_DTS_FILE))) +endif + ifeq ($(BR2_LINUX_KERNEL_IMAGE_TARGET_CUSTOM),y) LINUX_IMAGE_NAME=$(call qstrip,$(BR2_LINUX_KERNEL_IMAGE_TARGET_NAME)) else @@ -56,11 +66,14 @@ LINUX_IMAGE_NAME=vmImage else LINUX_IMAGE_NAME=uImage endif -LINUX_DEPENDENCIES+=host-uboot-tools else ifeq ($(BR2_LINUX_KERNEL_BZIMAGE),y) LINUX_IMAGE_NAME=bzImage else ifeq ($(BR2_LINUX_KERNEL_ZIMAGE),y) LINUX_IMAGE_NAME=zImage +else ifeq ($(BR2_LINUX_KERNEL_CUIMAGE),y) +LINUX_IMAGE_NAME=cuImage.$(KERNEL_DTS_NAME) +else ifeq ($(BR2_LINUX_KERNEL_SIMPLEIMAGE),y) +LINUX_IMAGE_NAME=simpleImage.$(KERNEL_DTS_NAME) else ifeq ($(BR2_LINUX_KERNEL_VMLINUX_BIN),y) LINUX_IMAGE_NAME=vmlinux.bin else ifeq ($(BR2_LINUX_KERNEL_VMLINUX),y) @@ -117,19 +130,6 @@ endef LINUX_POST_PATCH_HOOKS += LINUX_APPLY_PATCHES -ifeq ($(KERNEL_ARCH),microblaze) -# on microblaze, we always want mkimage -LINUX_DEPENDENCIES+=host-uboot-tools - -define LINUX_COPY_DTS - if test -f "$(BR2_LINUX_KERNEL_DTS_FILE)" ; then \ - cp $(BR2_LINUX_KERNEL_DTS_FILE) $(@D)/arch/microblaze/boot/dts ; \ - else \ - echo "Cannot copy dts file!" ; \ - fi -endef -endif - ifeq ($(BR2_LINUX_KERNEL_USE_DEFCONFIG),y) KERNEL_SOURCE_CONFIG = $(KERNEL_ARCH_PATH)/configs/$(call qstrip,$(BR2_LINUX_KERNEL_DEFCONFIG))_defconfig else ifeq ($(BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG),y) @@ -140,11 +140,12 @@ define LINUX_CONFIGURE_CMDS cp $(KERNEL_SOURCE_CONFIG) $(KERNEL_ARCH_PATH)/configs/buildroot_defconfig $(TARGET_MAKE_ENV) $(MAKE1) $(LINUX_MAKE_FLAGS) -C $(@D) buildroot_defconfig rm $(KERNEL_ARCH_PATH)/configs/buildroot_defconfig + $(if $(BR2_LINUX_KERNEL_DTS_SUPPORT), + $(if $(BR2_LINUX_KERNEL_USE_CUSTOM_DTS), + cp $(BR2_LINUX_KERNEL_CUSTOM_DTS_FILE) $(KERNEL_ARCH_PATH)/boot/dts/)) $(if $(BR2_ARM_EABI), $(call KCONFIG_ENABLE_OPT,CONFIG_AEABI,$(@D)/.config), $(call KCONFIG_DISABLE_OPT,CONFIG_AEABI,$(@D)/.config)) - $(if $(BR2_microblaze), - $(call LINUX_COPY_DTS)) # As the kernel gets compiled before root filesystems are # built, we create a fake cpio file. It'll be # replaced later by the real cpio archive, and the kernel will be @@ -164,9 +165,35 @@ define LINUX_CONFIGURE_CMDS $(call KCONFIG_SET_OPT,CONFIG_UEVENT_HELPER_PATH,\"/sbin/mdev\",$(@D)/.config)) $(if $(BR2_PACKAGE_SYSTEMD), $(call KCONFIG_ENABLE_OPT,CONFIG_CGROUPS,$(@D)/.config)) + $(if $(BR2_LINUX_KERNEL_APPENDED_DTB), + $(call KCONFIG_ENABLE_OPT,CONFIG_ARM_APPENDED_DTB,$(@D)/.config)) yes '' | $(TARGET_MAKE_ENV) $(MAKE1) $(LINUX_MAKE_FLAGS) -C $(@D) oldconfig endef +ifeq ($(BR2_LINUX_KERNEL_DTS_SUPPORT),y) +define LINUX_BUILD_DTB + $(TARGET_MAKE_ENV) $(MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) $(KERNEL_DTS_NAME).dtb +endef +endif + +ifeq ($(BR2_LINUX_KERNEL_APPENDED_DTB),y) +ifeq ($(BR2_LINUX_KERNEL_UBOOT_IMAGE),y) +define LINUX_APPEND_DTB + cat $(KERNEL_ARCH_PATH)/boot/zImage $(KERNEL_ARCH_PATH)/boot/$(KERNEL_DTS_NAME).dtb > $(KERNEL_ARCH_PATH)/boot/zImage_dtb + mv $(KERNEL_ARCH_PATH)/boot/zImage_dtb $(KERNEL_ARCH_PATH)/boot/zImage + LOAD=`$(MKIMAGE) -l $(LINUX_IMAGE_PATH) | sed -n 's/Load Address: \([0-9]*\)/\1/p'`; \ + ENTRY=`$(MKIMAGE) -l $(LINUX_IMAGE_PATH) | sed -n 's/Entry Point: \([0-9]*\)/\1/p'`; \ + $(MKIMAGE) -A $(KERNEL_ARCH) -O linux -T kernel -C none -a $${LOAD} -e $${ENTRY} -n 'Linux Buildroot' \ + -d $(KERNEL_ARCH_PATH)/boot/zImage $(KERNEL_ARCH_PATH)/boot/$(KERNEL_IMAGE_NAME) +endef +else +define LINUX_APPEND_DTB + cat $(KERNEL_ARCH_PATH)/boot/zImage $(KERNEL_ARCH_PATH)/boot/$(KERNEL_DTS_NAME).dtb > $(KERNEL_ARCH_PATH)/boot/zImage_dtb + mv $(KERNEL_ARCH_PATH)/boot/zImage_dtb $(KERNEL_ARCH_PATH)/boot/zImage +endef +endif +endif + # Compilation. We make sure the kernel gets rebuilt when the # configuration has changed. define LINUX_BUILD_CMDS @@ -174,6 +201,9 @@ define LINUX_BUILD_CMDS @if grep -q "CONFIG_MODULES=y" $(@D)/.config; then \ $(TARGET_MAKE_ENV) $(MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) modules ; \ fi + $(if $(BR2_LINUX_KERNEL_DTS_SUPPORT), + $(LINUX_BUILD_DTB) + $(LINUX_APPEND_DTB)) endef @@ -183,12 +213,21 @@ define LINUX_INSTALL_KERNEL_IMAGE_TO_TARGET endef endif +ifeq ($(BR2_LINUX_KERNEL_DTS_SUPPORT),y) +ifneq ($(BR2_LINUX_KERNEL_UBOOT_IMAGE),y) +define LINUX_INSTALL_DTB + cp $(KERNEL_ARCH_PATH/boot/$(KERNEL_DTS_NAME).dtb $(BINARIES_DIR)/ +endef +endif +endif + define LINUX_INSTALL_IMAGES_CMDS cp $(LINUX_IMAGE_PATH) $(BINARIES_DIR) endef define LINUX_INSTALL_TARGET_CMDS $(LINUX_INSTALL_KERNEL_IMAGE_TO_TARGET) + $(LINUX_INSTALL_DTB) # Install modules and remove symbolic links pointing to build # directories, not relevant on the target @if grep -q "CONFIG_MODULES=y" $(@D)/.config; then \