From patchwork Wed Oct 16 15:48:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Draszik?= X-Patchwork-Id: 1178049 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=andred.net Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 46tdxL3JlJz9sCJ for ; Thu, 17 Oct 2019 04:06:30 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 32C70C21DAF; Wed, 16 Oct 2019 17:06:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 19AF2C21DAF; Wed, 16 Oct 2019 17:06:26 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id AD325C21C51; Wed, 16 Oct 2019 15:49:02 +0000 (UTC) Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by lists.denx.de (Postfix) with ESMTPS id 2C610C21BE5 for ; Wed, 16 Oct 2019 15:49:02 +0000 (UTC) Received: by mail-wr1-f67.google.com with SMTP id r5so28604308wrm.12 for ; Wed, 16 Oct 2019 08:49:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Hkl/2IaBq57Tj64yafXbCAeSJRwzgHFjaFw/pZnY7mE=; b=MDztmhTEZz7U6IiUGnzgWty2vJ7VRaL/WNK/doa81onFQyoQyP83EcgzcMNMLaGXOg CoZlBostu56Kdy2Qf8pIBtMykKWBv0/rhbYBfhapN/q6wuOgZSAsufEXKyvfAxBGMeCX tUaTIDNvfIOgfS9MnQe6boa0tHUJbOZNHn8y5jdnPmN0+Kb/9y9i4ZcPG+8DSeIgizVX KBDLwHrTua6JCutsT3j9dtaSwjwmUiVWp3+3rwZbqqy2LgBs7OqAzCNimWmDdeV4UMCM YzuBj8kI/KgPBctD8V6edMKBNsWr1Bur4aB8BRXbkdDxMXoEUcSmLBgN0oSK/WCPlQ0I B93Q== X-Gm-Message-State: APjAAAWhsqIQUP6sQu9Mz8P/Jt7hgMlTaLonUR4OA5t+uqGkAwLiX7Cy a7hxu6dbdW/A7MgpHNk1qdBmtbrYG2g= X-Google-Smtp-Source: APXvYqybr7RevcUwZsh6SepWnJF29Os2VGiPBpH/hS7CkdxOMFoKkfX+o6mpoVxUuQyz1eY7kGqmkA== X-Received: by 2002:a5d:4685:: with SMTP id u5mr3501848wrq.264.1571240941445; Wed, 16 Oct 2019 08:49:01 -0700 (PDT) Received: from 1aq-andre.garage.tyco.com ([77.107.218.170]) by smtp.gmail.com with ESMTPSA id z9sm6806972wrv.1.2019.10.16.08.49.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2019 08:49:00 -0700 (PDT) From: =?utf-8?q?Andr=C3=A9_Draszik?= To: u-boot@lists.denx.de Date: Wed, 16 Oct 2019 16:48:55 +0100 Message-Id: <20191016154855.40276-1-git@andred.net> X-Mailer: git-send-email 2.23.0.rc1 MIME-Version: 1.0 X-Mailman-Approved-At: Wed, 16 Oct 2019 17:06:24 +0000 Cc: =?utf-8?q?Andr=C3=A9_Draszik?= , "NXP i.MX U-Boot Team" , Albert Aribaud Subject: [U-Boot] [PATCH] imx: spl: inject 'u-boot, spl-boot-device' for next-stage X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This implements the 'spl_perform_fixups' hook for i.MX-based boards and injects the /chosen/u-boot,spl-boot-device with a string representation corresponding to the boot device used. The intended usage is for the full U-Boot stage to evaluate this in scripts and then adapt its boot-order as needed. This change is heavily based on commit e5f2ecc75001 ("rockchip: rk3399: inject 'u-boot, spl-boot-device' for next-stage") A string representation of the boot device was chosen here (as opposed to an ofpath in the rockchip commit), so as to make this less hardware dependent. Signed-off-by: André Draszik Cc: Stefano Babic Cc: Fabio Estevam Cc: "NXP i.MX U-Boot Team" Cc: Albert Aribaud --- arch/arm/mach-imx/spl.c | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/arch/arm/mach-imx/spl.c b/arch/arm/mach-imx/spl.c index f025c4b301..42ca719cd8 100644 --- a/arch/arm/mach-imx/spl.c +++ b/arch/arm/mach-imx/spl.c @@ -176,6 +176,55 @@ u32 spl_boot_device(void) } #endif /* CONFIG_MX7 || CONFIG_IMX8M || CONFIG_IMX8 */ +static const char *imx_decode_boot_device(u32 boot_device) +{ + int i; + static const struct { + u32 boot_device; + const char *ofpath; + } spl_boot_devices_tbl[] = { + { BOOT_DEVICE_MMC1, "mmc1" }, + { BOOT_DEVICE_MMC2, "mmc2" }, + { BOOT_DEVICE_SPI, "spi" }, + { BOOT_DEVICE_NAND, "nand" }, + }; + + for (i = 0; i < ARRAY_SIZE(spl_boot_devices_tbl); ++i) + if (spl_boot_devices_tbl[i].boot_device == boot_device) + return spl_boot_devices_tbl[i].ofpath; + + return NULL; +} + +void spl_perform_fixups(struct spl_image_info *spl_image) +{ + void *blob = spl_image->fdt_addr; + const char *boot_ofpath; + int chosen; + + /* + * Inject the ofpath of the device the full U-Boot (or Linux in + * Falcon-mode) was booted from into the FDT, if a FDT has been + * loaded at the same time. + */ + if (!blob) + return; + boot_ofpath = imx_decode_boot_device(spl_image->boot_device); + if (!boot_ofpath) { + pr_err("%s: could not map boot_device to ofpath\n", __func__); + return; + } + + chosen = fdt_find_or_add_subnode(blob, 0, "chosen"); + if (chosen < 0) { + pr_err("%s: could not find/create '/chosen'\n", __func__); + return; + } + fdt_setprop_string(blob, chosen, + "u-boot,spl-boot-device", boot_ofpath); +} + + #ifdef CONFIG_SPL_USB_GADGET int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name) {