From patchwork Tue Aug 7 21:44:23 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Sealey X-Patchwork-Id: 1288431 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 7C7C83FC23 for ; Tue, 7 Aug 2012 21:48:13 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1SyrZt-0006YK-54; Tue, 07 Aug 2012 21:44:37 +0000 Received: from mail-ob0-f177.google.com ([209.85.214.177]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1SyrZq-0006Y6-2U for linux-arm-kernel@lists.infradead.org; Tue, 07 Aug 2012 21:44:35 +0000 Received: by obbta17 with SMTP id ta17so133498obb.36 for ; Tue, 07 Aug 2012 14:44:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:x-gm-message-state; bh=+DLrYsoSCUbt26PIKYSWa6nTaWA3obaDNtLvUKBLDI8=; b=ZRkyCO+3zDtHLSKPokIQeGqINJbEGeRsKwZtQ9dWP4XZo5n14U9SRf96s7j3SN34ht FyjkmWfWwlfQ9aaoNXGlgzxwbBzfLcMSaGT6FAWtmdCqux7bVdF/sMJnnYPBBM2RNv18 VguT5SZzUjLFp0541Dz/Lt2Fmvgr2kB6e9n/9zFnC8SFaRXDAvVzLEcUB3NkeWZfmTsc KHIqMPvrpBQMZqjCa2Fc0JGhAqbOqspi+jHm6joJVVDKUmmbXGjcryFqzImLEQf3xxMI eNg9QF0eFoyplFiEe83iBCmCF8l3TZKJyFv/+86QZ+Sq5Td405vIGBk6m3GIIgxf7S2J g2rA== Received: by 10.182.110.37 with SMTP id hx5mr26774189obb.48.1344375871811; Tue, 07 Aug 2012 14:44:31 -0700 (PDT) Received: from shinji.genesi-usa.com ([199.193.222.22]) by mx.google.com with ESMTPS id kf5sm2806626obc.7.2012.08.07.14.44.30 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 07 Aug 2012 14:44:30 -0700 (PDT) From: Matt Sealey To: Linux ARM Kernel Mailing List Subject: [PATCH] ARM: print an early warning if the ATAG_CORE/OF_DT_MAGIC vet did not pass Date: Tue, 7 Aug 2012 16:44:23 -0500 Message-Id: <1344375863-29947-1-git-send-email-matt@genesi-usa.com> X-Mailer: git-send-email 1.7.9.5 X-Gm-Message-State: ALoCoQlvs2pxIsSN5J4afLi4NUnv5WRqxPXxY+wgDsHnox0C3VVd8rtXinUEJhAVEPZRgDOnrL0a X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.214.177 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Steev Klimaszewski , Shawn Guo , Linux Kernel Mailing List , Matt Sealey X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org When booting and passing either corrupted or missing device trees or ATAGs, the __vet_atags function in kernel/head-common.S will set r2 to 0, thus causing what might be seen as strange behavior. What happens is setup_machine_fdt is passed __atags_pointer which is NULL in the above situation, and it will immediately exit with NULL return value for the machine_desc. On NULL machine_desc, the implication is that it was not a device tree, and it falls back to setup_machine_tags. This function will also return NULL, and the list of supported boards will be printed out. Only much, much later in the kernel is any message reporting lack of ATAG_CORE or any other indicator present since they all rely on there being a valid pointer to get to them. The following situations where this may happen are suggested: 1) Modification of the device tree blob is performed in the bootloader, and the tree is being corrupted for some reason. 2) Something is overwriting the device tree magic (kernel decompression, perhaps) which is possibly more common. 3) Something is overwriting the ATAG_CORE magic (as above) 4) DTB address passed to bootloader is invalid 5) Bootloader actually does boot setting r2 to 0 which either means it is ridiculously old or horrifically broken. Several reads of Documentation/arm/Booting lead me to believe that passing tags in r2 is OPTIONAL, HIGHLY RECOMMENDED for old bootloaders, and MANDATORY for new bootloaders. The kernel can't tell which is in use, so 0 might actually be valid. However, later it says that a bootloader must (lowercase) set r2 to "physical address of tagged list in system RAM, or physical address of device tree block (dtb) in system RAM." So it is not possible to define a behavior or print a definitive warning, and since we cannot fix these problems in the kernel we can at least provide more information about their occurrence at runtime rather than getting to the point where it seems something even more strange has happened. The pointer is lost at this point, though, so all we can do is report the event. Therefore, print a warning at the earliest opportunity to catch the r2=0 case and reduce frustration with developers attempting to port to device tree or port new bootloaders, hopefully without worrying people with old bootloaders complying with the existing documentation. Of course since this is very early in boot, DEBUG_LL needs to be enabled and a valid UART for the booting board needs to be configured for it to show any result, but this is true of all the above warnings anyway, otherwise all you get is Starting Kernel.... and a blinking terminal prompt. Signed-off-by: Matt Sealey Tested-by: Steev Klimaszewski --- arch/arm/kernel/setup.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index a81dcec..f788d44 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -942,6 +942,18 @@ void __init setup_arch(char **cmdline_p) struct machine_desc *mdesc; setup_processor(); + + if (__atags_pointer == 0L) { + early_print( + "Warning: ATAG_CORE/OF_DT_MAGIC pass failed or __atags_pointer NULL\n" + " Either r2 was NULL or __vet_atags set r2 to NULL on boot. This can be because\n" + " the bootloader is broken, the ATAGs or Device Tree have been overwritten by\n" + " other data during the boot process, the wrong address was supplied for the\n" + " Device Tree blob, or NULL was explicitly passed for some reason. Please check\n" + " into the situation as it is not usual to be able to boot a board with no ATAGs\n" + " or Device Tree.\n"); + } + mdesc = setup_machine_fdt(__atags_pointer); if (!mdesc) mdesc = setup_machine_tags(machine_arch_type);