Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1146059pxb; Thu, 4 Mar 2021 04:40:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJzsfgdRcdSeiZwfq+kWELzqRC2YGpyKsYwCXCncUkgjy3jEDUP7RxpOdS/mTMwVydnSHBN7 X-Received: by 2002:a17:907:119b:: with SMTP id uz27mr3944976ejb.464.1614861656708; Thu, 04 Mar 2021 04:40:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614861656; cv=none; d=google.com; s=arc-20160816; b=NNCY5bqFD8IcWdVrABjgRtNcBFoYbzZouTYiHCTdMmBI61NG5IXyvWREt3B4HVT0Xj eOkb4l1PGD0wbspjWOtAjFFzT+Fn3fIusWM9TSc8dy4f9jodlPYdWLs521aVpWN0Gupc CEyQbNcUQrVw+lk6LR87Tfw0R0exCipqrXiKx0Rgb0X2IVoKeM6i9+6yNzmElffgyuU9 hQUw/Gl8wiLN983WdLlGX0KlMQdVdDbTeXfAneNqmYCJe7Ok2TuPrQW5JhgxCM+GV2Mf p5MpVVPXiN1i21I76VR3yEI5K+Q/t/S98pe24VW9oKorGK5cbM+FXXK1XlYLCxkxGCNe PhkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=pHyvpak9GXRX9r8//NpWalfSTnWXEBrCT+0qjL0q54E=; b=Mg+QN5aRYpRKqC17PGce0G+/SvzoFlK4RkU4OyvgRC2olwWusNVDNAcj1f7veTmHF6 vc8jszF4P3nZa94OaBZGsHzW4hatgt5AJsbfGQRqp611tw2NQhFZq77SfbWvHsXF/jic Owl1yPStrPyL4DYZ/dd3QhY8YV1ek/lRXfeVlymXtYdbC5ww93DPayXerGQ/LGiJ87o3 s8/TDAiYqNRgrGQWImRXrXmexzP/Ip3YrokoGElbZw1TwggeqrT5M5x/q1tlxP98agGU QXwICdUGPx9a18JOlo0G+bsPkg2+tlGvkbjiYlvJSLQ9MBEhlImdrUzr8ZCeNuyNpY6u im2A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ka12si17982696ejc.323.2021.03.04.04.40.33; Thu, 04 Mar 2021 04:40:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230401AbhCCX7h (ORCPT + 99 others); Wed, 3 Mar 2021 18:59:37 -0500 Received: from aposti.net ([89.234.176.197]:37442 "EHLO aposti.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1387802AbhCCTea (ORCPT ); Wed, 3 Mar 2021 14:34:30 -0500 From: Paul Cercueil To: Thomas Bogendoerfer Cc: Rob Herring , od@zcrc.me, linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Paul Cercueil Subject: [PATCH] MIPS: boot/compressed: Copy DTB to aligned address Date: Wed, 3 Mar 2021 19:33:05 +0000 Message-Id: <20210303193305.924384-1-paul@crapouillou.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since 5.12-rc1, the Device Tree blob must now be properly aligned. Therefore, the decompress routine must be careful to copy the blob at the next aligned address after the kernel image. This commit fixes the kernel sometimes not booting with a Device Tree blob appended to it. Fixes: c4d5e638d6e9 ("scripts/dtc: Update to upstream version v1.6.0-51-g183df9e9c2b9") Signed-off-by: Paul Cercueil --- arch/mips/boot/compressed/decompress.c | 8 ++++++++ arch/mips/kernel/vmlinux.lds.S | 2 ++ 2 files changed, 10 insertions(+) diff --git a/arch/mips/boot/compressed/decompress.c b/arch/mips/boot/compressed/decompress.c index e3946b06e840..3d70d15ada28 100644 --- a/arch/mips/boot/compressed/decompress.c +++ b/arch/mips/boot/compressed/decompress.c @@ -14,6 +14,7 @@ #include #include +#include /* * These two variables specify the free mem region @@ -120,6 +121,13 @@ void decompress_kernel(unsigned long boot_heap_start) /* last four bytes is always image size in little endian */ image_size = get_unaligned_le32((void *)&__image_end - 4); + /* The device tree's address must be properly aligned */ + image_size = ALIGN(image_size, STRUCT_ALIGNMENT); + + puts("Copy device tree to address "); + puthex(VMLINUX_LOAD_ADDRESS_ULL + image_size); + puts("\n"); + /* copy dtb to where the booted kernel will expect it */ memcpy((void *)VMLINUX_LOAD_ADDRESS_ULL + image_size, __appended_dtb, dtb_size); diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S index c1c345be04ff..4b4e39b7c79b 100644 --- a/arch/mips/kernel/vmlinux.lds.S +++ b/arch/mips/kernel/vmlinux.lds.S @@ -145,6 +145,7 @@ SECTIONS } #ifdef CONFIG_MIPS_ELF_APPENDED_DTB + STRUCT_ALIGN(); .appended_dtb : AT(ADDR(.appended_dtb) - LOAD_OFFSET) { *(.appended_dtb) KEEP(*(.appended_dtb)) @@ -172,6 +173,7 @@ SECTIONS #endif #ifdef CONFIG_MIPS_RAW_APPENDED_DTB + STRUCT_ALIGN(); __appended_dtb = .; /* leave space for appended DTB */ . += 0x100000; -- 2.30.1