From patchwork Thu Nov 22 09:07:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 10693727 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 58F0F5A4 for ; Thu, 22 Nov 2018 09:08:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C6B52C09D for ; Thu, 22 Nov 2018 09:08:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 40AED2C0DA; Thu, 22 Nov 2018 09:08:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A6E3E2C09D for ; Thu, 22 Nov 2018 09:08:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=y1ho6x7kJpmB9AJaIJBKZNLXQYNmNEy6+BtBvg6g4oY=; b=ECfYmtwNwZc/np uWOnPyhDX1CWs5FvlOym//SkT/XB9SaTiyKodfSo/T7gWHP2TvXHGvEqn3xQoFMmEDUNE1BWCAV1X LKxX6RMONBUYAg/wZQleEsAHkkZeIOYex5y/bh+M34sYmQHoAVL9cWGFEyeRKgeAsJgopvIlikhWV 2LpSaWuyZ+c6/FJryEQ0VeVmUjpqwwHd4wywtjr9XtfaPeHbyTRhTl8+2rqDM6f+rSKdgNRf+30H4 flXMCXcjpZmjt6eKMO9cBcrbW1UjpOdVTB0GmyU/61kmqvXNlxo/ur7+ljJSl4hY9sqt5fSSvQSet RamPYN6+2vpS7iMma6IQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gPkyW-0000RR-7H; Thu, 22 Nov 2018 09:08:40 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gPky4-00085p-Ig for linux-amlogic@lists.infradead.org; Thu, 22 Nov 2018 09:08:15 +0000 Received: by mail-wm1-x344.google.com with SMTP id p2-v6so8270632wmc.2 for ; Thu, 22 Nov 2018 01:08:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mzqWE1ulueHbBikPKzjCPDx0TDT0Wp/5yaGaTD9E8bg=; b=vFZWXq0w30Rfcr6ZJAgzwlcB+ROzu/uYv0W5+amLj4mPGoR9+QOP+xbTlOu1hvgrVr 2uYxo1JeL2xJXkU6YURP6iMR1mkBIYY27De84J62tXd15ZaVYxTvyndd6UV3qglWqMui JKFsgO7jRdO/KZTjjdfKb/wp0hthddTZTM2zDwoR9F1aXJABjCYumGwRKKGa6QYDavEw PRudk9oPQDX4W0f7HkxHgNBN/CUgsJs8oCkloMiekS5mNsQTMbnAV2k/x1J4EAsXv/48 9dKf+BV9nUjMtkh+IekWrz3uzrF4d0eLdeHutDvF06WgfrtfDoQAlX/UbDtOEXhHZaz6 5h2w== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=mzqWE1ulueHbBikPKzjCPDx0TDT0Wp/5yaGaTD9E8bg=; b=IDMmOnTc8v4KprT4L6LwhK8R5509soBWR/4azdopKIi1w9w2ENIYqUIa0z8MV2b40P NQNCIHXRcPCw8EjjSVRWQj+XfR7nn+NlygqfL1C0m5eJH0NZSfX/WbGEJxLV9MC8cqwB sb9X57c9XMjQv2w+bunxN76wKUDTDIlxpZ9YQ2Fh9CHauk9Gu0TLWdOZOTNAotYeH0yR hmacZdjgmuac/TweQK5XETP8XCulMd2ubt4mA4VQPc2sw1vD6TDefT1IPo2AgtpXA9Hj tAU7eAoRvYvl7DW43RWky2b1EvgAUU1bK9VT894261H6ACDA89IH2W9fZ6/SsKsAAmh4 8UZQ== X-Gm-Message-State: AGRZ1gKTZDfDusYythXKXH3wiYCUgcdUKGzniT+S/lM6PeeZQP4VhKiv tYhLnvf7kY8NOurUIIFYCRKauQ== X-Google-Smtp-Source: AFSGD/Vn+hpSNbP9wd/8K5kKFpJF5ALjjvPtN+T9XG9Ukoo/7b5QwKRV3jQXRkA6R7ROuBGtelgisA== X-Received: by 2002:a1c:6e09:: with SMTP id j9mr9148944wmc.105.1542877684012; Thu, 22 Nov 2018 01:08:04 -0800 (PST) Received: from bender.baylibre.local (lmontsouris-657-1-212-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id y9sm13856434wrq.55.2018.11.22.01.08.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 22 Nov 2018 01:08:02 -0800 (PST) From: Neil Armstrong To: u-boot@lists.denx.de Subject: [PATCH u-boot v2 19/19] ARM: meson: Add boot device discovery Date: Thu, 22 Nov 2018 10:07:40 +0100 Message-Id: <20181122090740.29739-20-narmstrong@baylibre.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181122090740.29739-1-narmstrong@baylibre.com> References: <20181122090740.29739-1-narmstrong@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181122_010813_027454_852DCBD2 X-CRM114-Status: GOOD ( 19.06 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-amlogic@lists.infradead.org, Jerome Brunet , trini@konsulko.com, Neil Armstrong Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The Amlogic Meson SoCs ROM supports a boot over USB with a custom protocol. When no other boot medium are available (or by forcing the USB mode), the ROM sets the primary USB port as device mode and waits for a Host to enumerate. When enumerated, a custom protocol described at [1] permits writing to memory and execute some specific FIP init code to run the loaded Arm Trusted Firmware BL2 and BL3 stages before running the BL33 stage. In this mode, we can load different binaries that can be used by U-boot like a script image file. This adds support for a custom USB boot stage only available when the boot mode is USB and the script file at a pre-defined address is valid. This support was heavily copied from the Sunxi Allwinner FEL U-Boot support. The tool pyamlboot described at [2], permits using this boot mode on boards exposing the first USB port, either as OTG or Host port. [1] https://github.com/superna9999/pyamlboot/blob/master/PROTOCOL.md [2] https://github.com/superna9999/pyamlboot/blob/master/README.md Signed-off-by: Jerome Brunet Signed-off-by: Neil Armstrong --- arch/arm/include/asm/arch-meson/axg.h | 1 + arch/arm/include/asm/arch-meson/boot.h | 20 ++++++++++++ arch/arm/include/asm/arch-meson/gx.h | 1 + arch/arm/mach-meson/Kconfig | 1 + arch/arm/mach-meson/board-axg.c | 6 ++++ arch/arm/mach-meson/board-common.c | 45 ++++++++++++++++++++++++++ arch/arm/mach-meson/board-gx.c | 6 ++++ include/configs/meson64.h | 13 ++++++++ 8 files changed, 93 insertions(+) create mode 100644 arch/arm/include/asm/arch-meson/boot.h diff --git a/arch/arm/include/asm/arch-meson/axg.h b/arch/arm/include/asm/arch-meson/axg.h index 28a38b791d..d293f2a839 100644 --- a/arch/arm/include/asm/arch-meson/axg.h +++ b/arch/arm/include/asm/arch-meson/axg.h @@ -20,6 +20,7 @@ #define AXG_AO_SEC_GP_CFG4 AXG_AO_ADDR(0x94) #define AXG_AO_SEC_GP_CFG5 AXG_AO_ADDR(0x95) +#define AXG_AO_BOOT_DEVICE 0xF #define AXG_AO_MEM_SIZE_MASK 0xFFFF0000 #define AXG_AO_MEM_SIZE_SHIFT 16 #define AXG_AO_BL31_RSVMEM_SIZE_MASK 0xFFFF0000 diff --git a/arch/arm/include/asm/arch-meson/boot.h b/arch/arm/include/asm/arch-meson/boot.h new file mode 100644 index 0000000000..a90fe55081 --- /dev/null +++ b/arch/arm/include/asm/arch-meson/boot.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2016 BayLibre, SAS + * Author: Neil Armstrong + */ + +#ifndef __MESON_BOOT_H__ +#define __MESON_BOOT_H__ + +/* Boot device */ +#define BOOT_DEVICE_RESERVED 0 +#define BOOT_DEVICE_EMMC 1 +#define BOOT_DEVICE_NAND 2 +#define BOOT_DEVICE_SPI 3 +#define BOOT_DEVICE_SD 4 +#define BOOT_DEVICE_USB 5 + +int meson_get_boot_device(void); + +#endif /* __MESON_BOOT_H__ */ diff --git a/arch/arm/include/asm/arch-meson/gx.h b/arch/arm/include/asm/arch-meson/gx.h index 4bc9475d35..b781ba9475 100644 --- a/arch/arm/include/asm/arch-meson/gx.h +++ b/arch/arm/include/asm/arch-meson/gx.h @@ -21,6 +21,7 @@ #define GX_AO_SEC_GP_CFG4 GX_AO_ADDR(0x94) #define GX_AO_SEC_GP_CFG5 GX_AO_ADDR(0x95) +#define GX_AO_BOOT_DEVICE 0xF #define GX_AO_MEM_SIZE_MASK 0xFFFF0000 #define GX_AO_MEM_SIZE_SHIFT 16 #define GX_AO_BL31_RSVMEM_SIZE_MASK 0xFFFF0000 diff --git a/arch/arm/mach-meson/Kconfig b/arch/arm/mach-meson/Kconfig index deddcc5ab0..11077bc6cc 100644 --- a/arch/arm/mach-meson/Kconfig +++ b/arch/arm/mach-meson/Kconfig @@ -8,6 +8,7 @@ config MESON64_COMMON select DM_SERIAL select SYSCON select REGMAP + select BOARD_LATE_INIT imply CMD_DM config MESON_GX diff --git a/arch/arm/mach-meson/board-axg.c b/arch/arm/mach-meson/board-axg.c index 014b25d61a..173905e762 100644 --- a/arch/arm/mach-meson/board-axg.c +++ b/arch/arm/mach-meson/board-axg.c @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -15,6 +16,11 @@ DECLARE_GLOBAL_DATA_PTR; +int meson_get_boot_device(void) +{ + return readl(AXG_AO_SEC_GP_CFG0) & AXG_AO_BOOT_DEVICE; +} + /* Configure the reserved memory zones exported by the secure registers * into EFI and DTB reserved memory entries. */ diff --git a/arch/arm/mach-meson/board-common.c b/arch/arm/mach-meson/board-common.c index 8c4f3074fb..8c41301674 100644 --- a/arch/arm/mach-meson/board-common.c +++ b/arch/arm/mach-meson/board-common.c @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -66,6 +67,50 @@ void meson_board_add_reserved_memory(void *fdt, u64 start, u64 size) } } +static void meson_set_boot_source(void) +{ + const char *source; + + switch (meson_get_boot_device()) { + case BOOT_DEVICE_EMMC: + source = "emmc"; + break; + + case BOOT_DEVICE_NAND: + source = "nand"; + break; + + case BOOT_DEVICE_SPI: + source = "spi"; + break; + + case BOOT_DEVICE_SD: + source = "sd"; + break; + + case BOOT_DEVICE_USB: + source = "usb"; + break; + + default: + source = "unknown"; + } + + env_set("boot_source", source); +} + +__weak int meson_board_late_init(void) +{ + return 0; +} + +int board_late_init(void) +{ + meson_set_boot_source(); + + return meson_board_late_init(); +} + void reset_cpu(ulong addr) { psci_system_reset(); diff --git a/arch/arm/mach-meson/board-gx.c b/arch/arm/mach-meson/board-gx.c index f1397f87c5..e41552db52 100644 --- a/arch/arm/mach-meson/board-gx.c +++ b/arch/arm/mach-meson/board-gx.c @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -15,6 +16,11 @@ DECLARE_GLOBAL_DATA_PTR; +int meson_get_boot_device(void) +{ + return readl(GX_AO_SEC_GP_CFG0) & GX_AO_BOOT_DEVICE; +} + /* Configure the reserved memory zones exported by the secure registers * into EFI and DTB reserved memory entries. */ diff --git a/include/configs/meson64.h b/include/configs/meson64.h index f961f43871..40ac079dfc 100644 --- a/include/configs/meson64.h +++ b/include/configs/meson64.h @@ -28,6 +28,18 @@ #define CONFIG_SYS_LOAD_ADDR CONFIG_SYS_TEXT_BASE #define CONFIG_SYS_BOOTM_LEN (64 << 20) /* 64 MiB */ +/* ROM USB boot support, auto-execute boot.scr at scriptaddr */ +#define BOOTENV_DEV_ROMUSB(devtypeu, devtypel, instance) \ + "bootcmd_romusb=" \ + "if test \"${boot_source}\" = \"usb\" && " \ + "test -n \"${scriptaddr}\"; then " \ + "echo '(ROM USB boot)'; " \ + "source ${scriptaddr}; " \ + "fi\0" + +#define BOOTENV_DEV_NAME_ROMUSB(devtypeu, devtypel, instance) \ + "romusb " + #ifdef CONFIG_CMD_USB #define BOOT_TARGET_DEVICES_USB(func) func(USB, usb, 0) #else @@ -36,6 +48,7 @@ #ifndef BOOT_TARGET_DEVICES #define BOOT_TARGET_DEVICES(func) \ + func(ROMUSB, romusb, na) \ func(MMC, mmc, 0) \ func(MMC, mmc, 1) \ func(MMC, mmc, 2) \