From patchwork Fri Nov 9 15:26:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 10676197 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 2C28C17D4 for ; Fri, 9 Nov 2018 15:27:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 181A528305 for ; Fri, 9 Nov 2018 15:27:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C8C82ED4C; Fri, 9 Nov 2018 15:27:52 +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 5B4FE2ED55 for ; Fri, 9 Nov 2018 15:27:51 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=DiI+DtwW3GDw6MkT3q9N6dWB358nHJTqtlpidw4KxpA=; b=ML+pT0jVYsUwrmbbkuxsN8Kc5K WyIrQjcwTCc2TvqNoXoz1vkmw6vVBbll4ljb7+LU86JtTPRUEjRdOhPlIVbxyc29DZ/ROu0XAFkHm oxIj/qsoMGW3SuCLTnaswfi2/MLYiLDF/h+L5U39B99iDpWoIhXsaLmen/RotiVI1bdFw3MrRbT1T wv1DeUDqCdUQF7yrEIOQ+Urvm9kS9+gS6p5WtI9osoCXmxy/Gdr0g2hhO+yltAhgBZ6M40wF2kGmW Mly10PqD8xj1O1GmLC1uX2KQfo8c1AIQ0I/u/fDFCLotPV8t0x0x4CYyvcM565pPXPQ0w2FM/PTrr Ga8OHt3A==; 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 1gL8hK-0003DI-B0; Fri, 09 Nov 2018 15:27:50 +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 1gL8gy-0002bu-63 for linux-amlogic@lists.infradead.org; Fri, 09 Nov 2018 15:27:30 +0000 Received: by mail-wm1-x344.google.com with SMTP id f19-v6so4018428wmb.0 for ; Fri, 09 Nov 2018 07:27:21 -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; bh=JixGkGWPQ2s1JmnJZ4/MIZbPLwOEdAmSp9W3XV6xFqk=; b=I7ZWv4OozLKk6uFJCbqqZcBInzxjWMFw9mApO6mMX5LPCduoVYUU8gSkc/p1BTd3Cu HQU1SfzApu7bcZRIlnMIyAYQ0r521K3Oym3GrNgsFyaXBfsLXuvGevbPND/DMLxbLLPF dmOBJgKMWerSFhEwNXctuFvaSK/N0r1TsKHwNjqAYN1d5WKyCgCetSMHS9Uqz3pipwer r996ln/J3JQMRFNSLq8fmgLME3xJHD9S5n8qypxUY5/qYB95FUbpywrX6NR1lBria0Aa EdK1xGhw3ylCYttihk1C3YLPuvMEbFwNgVohISYFCwlLd8n168Xi+gJlLDl0pyKqBkOg ioVQ== 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; bh=JixGkGWPQ2s1JmnJZ4/MIZbPLwOEdAmSp9W3XV6xFqk=; b=SdUciIGkkZXyxSerVG8+snF3UFCgC9xyKEEY0XLtB8ptdFtAKAX85T4lq+xPmG5uEI zV/sJK34SSJ4GtdqVV2ePc/hSafZKyDNLIGjLew4SF1ncidMwh3VEhNW8oKCE9aSLu7y r/jY4WF6NSk11Qo78Mj1woTdCcb/RVt4uZIUiKP7D4YFybYufBxo/R+y8I9IOPv9VWXa cMdITNl2JHhSpRIdpI8eiNCXq0blsCVYdvaMEA+K0C1JaKnMvCTkkGOSG5iYB9dt6vpH wJYII/o2JKv+/tUjQ6t/1HpCMIhyyIubY/ZVIrqQ3XDTgDZI3QsOa49vxExLy6SbtTI7 k0xA== X-Gm-Message-State: AGRZ1gJLry4XBicpdw+PBFvxg1sOaiBNPjDhmmJcej/bI7yYwW8BOd1P QmHmAtmgrUls6PswBtZnXzPodA== X-Google-Smtp-Source: AJdET5eCqcXBT+KWKnPIeRqPOFb9hMkKMs1ItOUXoum935tnaJThE9Wlm3W/WlcMNNi6MkqWitFfXQ== X-Received: by 2002:a1c:98ce:: with SMTP id a197-v6mr5314009wme.135.1541777239648; Fri, 09 Nov 2018 07:27:19 -0800 (PST) Received: from bender.baylibre.local ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id a127-v6sm1748545wmh.24.2018.11.09.07.27.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Nov 2018 07:27:18 -0800 (PST) From: Neil Armstrong To: u-boot@lists.denx.de Subject: [PATCH u-boot 19/19] ARM: meson: Add boot device discovery Date: Fri, 9 Nov 2018 16:26:58 +0100 Message-Id: <1541777218-472-20-git-send-email-narmstrong@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1541777218-472-1-git-send-email-narmstrong@baylibre.com> References: <1541777218-472-1-git-send-email-narmstrong@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181109_072728_233590_F718CF8B X-CRM114-Status: GOOD ( 19.59 ) 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 MIME-Version: 1.0 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 execution some specific FIP init code to run the loaded Arm Trusted Firmware BL2 and BL3 staged 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 28a38b7..d293f2a 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 0000000..a90fe55 --- /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 4bc9475..b781ba9 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 deddcc5..11077bc 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 014b25d..173905e 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 249e0d9..996bd28 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 f1397f8..e41552d 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 f961f43..40ac079 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) \