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: 995622 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) 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=baylibre.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="I7ZWv4Oo"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 42s46r3jXFz9sBh for ; Sat, 10 Nov 2018 02:38:12 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 2A01FC22592; Fri, 9 Nov 2018 15:36:01 +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_DNSWL_NONE, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID 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 4DAEEC225B6; Fri, 9 Nov 2018 15:27:32 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 69C55C225B9; Fri, 9 Nov 2018 15:27:26 +0000 (UTC) Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by lists.denx.de (Postfix) with ESMTPS id 55A1BC225AB for ; Fri, 9 Nov 2018 15:27:20 +0000 (UTC) Received: by mail-wm1-f65.google.com with SMTP id s10-v6so2381724wmc.5 for ; Fri, 09 Nov 2018 07:27:20 -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=emz39lpyO9U72XKfku1c5TKUspVczJsQ1YI1xiun5RJw/soZsTTT5dRyAwcanG0HeQ sFt7cOT63BfT2IMXcDyTQa4dGlmW8UWQNRtxZ00A/0Wx0jGvUGWiHYhlntGIkZzwHs0Y wbpusoxrMBRWGX9tGXIavX9P2W2I6XfunaNxTpfFNvdgLS2f4HddblzJGUynnxUWA87G wK8DRZ2Nr3kOzSKP1DTc5kUnLiGn9LntMLL2v1FLtXqMiDDG7a/vmeFKGvJII5uraXcb iWkgg23dU25GyBnmGOPtg+5kx3/Ljym64t5tDtJb+SWzIir9W7WN83vtP6dCztk4lUqU HTuw== X-Gm-Message-State: AGRZ1gKYZfb9qgM2RgZmsEQX5yy9fQPEHHOajjC8dJr4kSuhHjHzSx20 uJQeUrtBZBxtFc2uiIJPPwsvYV4IA6Q= 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 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> Cc: linux-amlogic@lists.infradead.org, Jerome Brunet , trini@konsulko.com Subject: [U-Boot] [PATCH u-boot 19/19] ARM: meson: Add boot device discovery 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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) \