From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BC9F4C433F5 for ; Tue, 22 Mar 2022 21:02:29 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4222F83CC0; Tue, 22 Mar 2022 22:01:43 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=seco.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=seco.com header.i=@seco.com header.b="2Sgn5IL2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F341D80F78; Tue, 22 Mar 2022 22:00:37 +0100 (CET) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on0602.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0d::602]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C4A4183BA3 for ; Tue, 22 Mar 2022 22:00:18 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=seco.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sean.anderson@seco.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LbyZ1VFTBQ3D0Ew+RYf6TWIcBlqQgApPE1zEAH2MIk0u1ZkZPBN0O4QKSqITTs6LZaff9j2TEc0HD4Obb8n2y1PUdU/+KpRE3QOuEnDU6VpwpIoRT04+uZiRYdELi4w5mSGC1oADSwJW/RLVQTv7Z1OKExv8rqB3OAxXK2rvn6kwr8rPLj2PdDE8O9uGhe/BjYg9KeJLHV9OJz+sBDJQDpiiXiQcl5POHpLFXFKYKygILD1isrzXuj3ZosW2uqJAhtjaI5B+m8kK9dkRgVbHcUE9LKO05yYWIfu4CjwYzRN/FXEwo+yfx7y73/rdAXDKpgxFxIMEoE6VJUAvN8+Ewg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HjbScahy4Eu3IOQHaMc57VmW4CrityOajMaSDhAn+mg=; b=ZferTK6FT1PiiA8EomVS99aT3IdgEkJ12W0Xcifvpr9iS53D8hX3rchmAefkQzZlvBtqtt5a0XEeDpiEmC76T+ba0Uz7fv5E7HppgqFll38BIRBkdYh5Q/eXboa1YfGS3MI1JRtpGcP+Bk5curoQNoV/BeSXOdcAES3KFLRdcmHa+iu17+xFIWkd7cO87iDs1XWeeoyVxsFGSq1hqXYwAoH78XsqYugyjuSW4+GWpUqffN69k/QVWQ7/Wijgj59Fdm2QH2EUk1wFSCkCGEbW5lXX02IFE5LfQGI/+bmW3+lhufd4uRMEIxnZ3+oHxHEmZpG87fHI36wB891x25puBA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=seco.com; dmarc=pass action=none header.from=seco.com; dkim=pass header.d=seco.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seco.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HjbScahy4Eu3IOQHaMc57VmW4CrityOajMaSDhAn+mg=; b=2Sgn5IL2oGERgyAZ6qfsIKMybBzvYubDFeOrXA5k+c9WT0A0n2FBxz8Vj4dKLpt1exqnKZwjAfaDeZ3X1EggEqESQBel7koBt2xHahjBoYW7+bNf33GdbS0STNU/Xbto1zAy+3O08zonyR3vEkD+RMI4wnwLGMzWNOD7W9suMDU3CZC25dN4oFVzCtDu3yC1ngbNJpQpn3eotORbwSwqldZs06owT0/twPVTq+nE4GB7cFPNXJYI9xsEJq4dGAE6y7BKuHj+nxDMi833C4rMpNBODGoxC28+1eO2V+Vf5FhH52P1GgK2Cvl4jCFfnIgKQmN8MiNJl3jOwGm15Wl92g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=seco.com; Received: from DB7PR03MB4972.eurprd03.prod.outlook.com (2603:10a6:10:7d::22) by AM0PR03MB3938.eurprd03.prod.outlook.com (2603:10a6:208:6e::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.23; Tue, 22 Mar 2022 21:00:17 +0000 Received: from DB7PR03MB4972.eurprd03.prod.outlook.com ([fe80::2414:8ad5:9fd6:3bff]) by DB7PR03MB4972.eurprd03.prod.outlook.com ([fe80::2414:8ad5:9fd6:3bff%5]) with mapi id 15.20.5081.023; Tue, 22 Mar 2022 21:00:17 +0000 From: Sean Anderson To: Tom Rini Cc: Linus Walleij , Liviu Dudau , Andre Przywara , Simon Glass , u-boot@lists.denx.de, Sean Anderson Subject: [PATCH v3 11/29] spl: Add semihosting boot method Date: Tue, 22 Mar 2022 16:59:19 -0400 Message-Id: <20220322205938.1721846-12-sean.anderson@seco.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220322205938.1721846-1-sean.anderson@seco.com> References: <20220322205938.1721846-1-sean.anderson@seco.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: MN2PR20CA0012.namprd20.prod.outlook.com (2603:10b6:208:e8::25) To DB7PR03MB4972.eurprd03.prod.outlook.com (2603:10a6:10:7d::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b04817a8-4ef3-4d3e-d80c-08da0c46f7e1 X-MS-TrafficTypeDiagnostic: AM0PR03MB3938:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ld5kdSlBPRiJlnlCJeRBLofzJDQegzdSytIBg2Wlm9hINRb3RtTGLchLQl6DBDOc7oy0ajHpIuqH/WlorAxRaTJ67o4qERSd94xe6X1wUVKTpZPvFEhXPK8bfdbSCOPrAOOPYbxzdfXcboI5fgMXeVj47cT/RrTNfyTa4BWL/xzWRJ4mM8YRBgyYaB3NOBgmi7UpC9OaeGG1aymfDGYzx+XW6Y1iWJ361sTKMNKTBVqfMnpV4cJs1wuKZG9zBlh9dwEFbGcZq76imCp3UavmJT2kw2+9VR/dtGUmZOwth7eWU7jI7iTrq0rYaMNMOiHyQtPE2Wl2TkRbIPbnKjL92WKqB+IRrhfqYWuOEUJbJLzdLBN5EiI8uxjtCqPFj5Br79opP7BiwehNKJsKZ2ChVX5R4xs65q1QlJYHP+Xjd7ttPZqfwnJWupCiFEomwJOYDsPNP2ACAXXYalgvGSeFXwTQert+IROU4RagOjpRz5iSKw0JjR6r8WVBbhJBj/xBuaFTMMrmgqTcI0+idZT/cBebpyG7zEip2IQFUZYAFAcx2geuRc6fTD+l+TESJiFigI5qTaf6qGt+JVGDwsvY7OjUkxF7+TYYRKFzUB2I2XJU/HDlKiAiPfaDkjt83tVWOlB2IpivVGNdJjvawdfuigOQ0bDvY5Ej/8gv8YV7IC+ZdEfNYruZMcGZqNmOpdfCBVTDbavO2ZZO3FcJzaeQqg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR03MB4972.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(38100700002)(38350700002)(86362001)(2906002)(508600001)(66946007)(83380400001)(6486002)(8676002)(66556008)(66476007)(107886003)(4326008)(1076003)(5660300002)(2616005)(8936002)(54906003)(186003)(26005)(44832011)(52116002)(6916009)(36756003)(6506007)(6512007)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?v2e07JPRzphW3fMsGvayVdQtgzoP/mPumS7yOfW2TinUfhsX+Aadqs5ZpXP6?= =?us-ascii?Q?dKVvlQHsscBiWQuTZZRN9Itapxudai4QfrtwzhdQ+arQDdizy0xtnDP5Zias?= =?us-ascii?Q?gYCohrUnMT8NK3HR4JjAFhH1B527c62Q4KoUufR8lEqY3ADWGjCZUEdv0gAz?= =?us-ascii?Q?VE6zGwVWTCir8QY/bHsDEJeoodGap+zRNOWVs1nHPXawtY6qkPrisz+fLLtf?= =?us-ascii?Q?xNBwH/wUgb03nW7ea6+Y4pjLC1dNqlXqtOIK6s57zJ8JCWlWB63TQ4PEO8pL?= =?us-ascii?Q?h9FFosB+J1RhxcmHtaJSWePm5WhwtvDyn9QRwrssJNgDuZLo9/tIpE9Jtf/K?= =?us-ascii?Q?NAJ+sdVO12G0imaJOrfw3bS3npsZSqLnCwqkfovfUMGAN+xaGaJfN4GbwQe1?= =?us-ascii?Q?jNV9ZTSqI3TXINBSGorQfgDQ8wJ0xP+a5Y/gIfTvQeEjKT0PRi8i7njQpXU2?= =?us-ascii?Q?Jou+r12cg+OUirhMyUplcH59eFNYbKQ2YLA0I+t4cM6Gyrv8Q+TG1CyHvsqe?= =?us-ascii?Q?hALTceedph/044p+FMQZ4xZcy4K2BKu1MDvNgMZWI/bbCyd3KYs40qbCSqh3?= =?us-ascii?Q?CymHy1GSqpBrrtFDCenywOu+G+YYI2THZvWnIg9qKG3i2YLNqE/olbyx7hJR?= =?us-ascii?Q?X/eQjCxIBoguL76qnOsQmkKIK31tBN7s9zN0/8bOG1i7FNwnENBRPypalbjO?= =?us-ascii?Q?qfC4MZPY1gtTQoeAxQTD+RHri9az1+mE4jqmbb77bV+T5vPKy00YD0ATr6ZH?= =?us-ascii?Q?Bj9J+GOOcJNX2vP1E6fT3Sw0mA1WpyndG0C1DzghmjeR31czdYsZQd3jRX+Y?= =?us-ascii?Q?a/KkwYLGgrnZkWFzFt7BCiBqkpX12L5HSW21DQzgFcKVT3c9j8dYagnxBQdO?= =?us-ascii?Q?l/GjeTRUJdS2URANcsCR9ri5tfymtt7/wWy9gg0o9w1S594gYBcVS7oj9V66?= =?us-ascii?Q?NW4/Uk1lrY9Ss5Tj52v/QIdy6gdymwVmqkzyJsz/YbgOg8lOZWlPWEIKYsBl?= =?us-ascii?Q?U5txUrUJn6SpfIRMldR6HkRcBWFA2S0xKo+r0eoN+W2UiK6mpLWYy5B5BguR?= =?us-ascii?Q?ekPBOswp+mRipjvZ3a0SscP+JYt2qEtVisOkfRMLElrh5ocFkxsymW7b390j?= =?us-ascii?Q?xVQahPdq7dt8c7SP6kQ+9R1VYJ8OGiMIknS8Fdpd74PCLNT5EoWuX01JGtsc?= =?us-ascii?Q?QVys2qnaGxidiTk4DDseyf3Jucy69c/34/9BN2sOD03qwzvS/FBCfhsq3sjm?= =?us-ascii?Q?pirdeontzbuLMeOrw92pVgch/dXixPD41J/JAy36Mf6EB1VZ0N6ful8VXptn?= =?us-ascii?Q?2BguILtBI2feviYvKpD5cJsP6IUVfS6yA+j2x6YZ03zHlASNXFPu/nWMTHDJ?= =?us-ascii?Q?0p3NuwXalX317XlxwjV6o4hI3yHLkDWNmLxF3Rkioz6ljzW3p7LVlzjZf9DJ?= =?us-ascii?Q?P0iu91ffHgwry54b5g/YHgSynixm9CntesxemGcfBCaAs5+d8bE+nA=3D=3D?= X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: b04817a8-4ef3-4d3e-d80c-08da0c46f7e1 X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4972.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Mar 2022 21:00:17.3457 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bebe97c3-6438-442e-ade3-ff17aa50e733 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dnODfCVJ5Xg60i6mOM1jG90jN6YOyNgfy2b4u0btjmjzR8dfxgFI94o1pNCL3HPjS2okBojqAU6uR/3ZMBpqMA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR03MB3938 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean This adds a boot method for loading the next stage from the host. It is mostly modeled off of spl_load_image_ext. I am not really sure why/how spl_load_image_fat uses three different methods to load the image, but the simple case seems to work OK for now. To control the presence of this boot method, we add a config symbol. While we're at it, we update the original semihosting config symbol. I think semihosting has some advantages of other forms of JTAG boot. Common other ways to boot from JTAG include: - Implementing DDR initialization through JTAG (typically with dozens of lines of TCL) and then loading U-Boot. The DDR initialization typically uses hard-coded register writes, and is not easily adapted to different boards. BOOT_DEVICE_SMH allows booting with SPL, leveraging U-Boot's existing DDR initialization code. This is the method used by NXP's CodeWarrior IDE on Layerscape processors (see AN12270). - Loading a bootloader into SDRAM, waiting for it to initialize DDR, and then loading U-Boot. This is tricky, because the debugger must stop the boot after the bootloader has completed its work. Trying to load U-Boot too early can cause failure to boot. This is the method used by Xilinx with its Zynq(MP) processors. - Loading SPL with BOOT_DEVICE_RAM and breaking before SPL loads the image to load U-Boot at the appropriate place. This can be a bit tricky, because the load address is dependent on the header size. An elf with symbols must also be used in order to stop at the appropriate point. BOOT_DEVICE_SMH can be viewed as an extension of this process, where SPL automatically stops and tells the host where to place the image. Signed-off-by: Sean Anderson --- (no changes since v2) Changes in v2: - Compile arch/arm/lib/semihosting.o in SPL - Make CONFIG_SPL_SEMIHOSTING depend on SPL arch/arm/Kconfig | 26 +++++++++++-- arch/arm/include/asm/spl.h | 1 + arch/arm/lib/Makefile | 2 +- common/spl/Makefile | 1 + common/spl/spl_semihosting.c | 71 ++++++++++++++++++++++++++++++++++++ 5 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 common/spl/spl_semihosting.c diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 64acbda254..408d96ac8e 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -403,11 +403,29 @@ config ARM_SMCCC firmware (for example, PSCI) according to SMCCC. config SEMIHOSTING - bool "support boot from semihosting" + bool "Support ARM semihosting" help - In emulated environments, semihosting is a way for - the hosted environment to call out to the emulator to - retrieve files from the host machine. + Semihosting is a method for a target to communicate with a host + debugger. It uses special instructions which the debugger will trap + on and interpret. This allows U-Boot to read/write files, print to + the console, and execute arbitrary commands on the host system. + + Enabling this option will add support for reading and writing files + on the host system. If you don't have a debugger attached then trying + to do this will likely cause U-Boot to hang. Say 'n' if you are unsure. + +config SPL_SEMIHOSTING + bool "Support ARM semihosting in SPL" + depends on SPL + help + Semihosting is a method for a target to communicate with a host + debugger. It uses special instructions which the debugger will trap + on and interpret. This allows U-Boot to read/write files, print to + the console, and execute arbitrary commands on the host system. + + Enabling this option will add support for reading and writing files + on the host system. If you don't have a debugger attached then trying + to do this will likely cause U-Boot to hang. Say 'n' if you are unsure. config SYS_THUMB_BUILD bool "Build U-Boot using the Thumb instruction set" diff --git a/arch/arm/include/asm/spl.h b/arch/arm/include/asm/spl.h index e568af2561..b5790bd0bc 100644 --- a/arch/arm/include/asm/spl.h +++ b/arch/arm/include/asm/spl.h @@ -30,6 +30,7 @@ enum { BOOT_DEVICE_DFU, BOOT_DEVICE_XIP, BOOT_DEVICE_BOOTROM, + BOOT_DEVICE_SMH, BOOT_DEVICE_NONE }; #endif diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile index c48e1f622d..594fc1228a 100644 --- a/arch/arm/lib/Makefile +++ b/arch/arm/lib/Makefile @@ -46,7 +46,7 @@ else obj-$(CONFIG_$(SPL_TPL_)USE_ARCH_MEMSET) += memset.o obj-$(CONFIG_$(SPL_TPL_)USE_ARCH_MEMCPY) += memcpy.o endif -obj-$(CONFIG_SEMIHOSTING) += semihosting.o +obj-$(CONFIG_$(SPL_TPL_)SEMIHOSTING) += semihosting.o obj-y += bdinfo.o obj-y += sections.o diff --git a/common/spl/Makefile b/common/spl/Makefile index db8fd36a26..e71e7bee66 100644 --- a/common/spl/Makefile +++ b/common/spl/Makefile @@ -28,6 +28,7 @@ obj-$(CONFIG_$(SPL_TPL_)USB_STORAGE) += spl_usb.o obj-$(CONFIG_$(SPL_TPL_)FS_FAT) += spl_fat.o obj-$(CONFIG_$(SPL_TPL_)FS_EXT4) += spl_ext.o obj-$(CONFIG_$(SPL_TPL_)SATA) += spl_sata.o +obj-$(CONFIG_$(SPL_TPL_)SEMIHOSTING) += spl_semihosting.o obj-$(CONFIG_$(SPL_TPL_)DFU) += spl_dfu.o obj-$(CONFIG_$(SPL_TPL_)SPI_LOAD) += spl_spi.o obj-$(CONFIG_$(SPL_TPL_)RAM_SUPPORT) += spl_ram.o diff --git a/common/spl/spl_semihosting.c b/common/spl/spl_semihosting.c new file mode 100644 index 0000000000..df6aeb2951 --- /dev/null +++ b/common/spl/spl_semihosting.c @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2022 Sean Anderson + */ + +#include +#include +#include +#include +#include + +static int smh_read_full(long fd, void *memp, size_t len) +{ + long read; + + read = smh_read(fd, memp, len); + if (read < 0) + return read; + if (read != len) + return -EIO; + return 0; +} + +static int spl_smh_load_image(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev) +{ + const char *filename = CONFIG_SPL_FS_LOAD_PAYLOAD_NAME; + int ret; + long fd, len; + struct image_header *header = + spl_get_load_buffer(-sizeof(*header), sizeof(*header)); + + fd = smh_open(filename, MODE_READ | MODE_BINARY); + if (fd < 0) { + log_debug("could not open %s: %ld\n", filename, fd); + return fd; + } + + ret = smh_flen(fd); + if (ret < 0) { + log_debug("could not get length of image: %d\n", ret); + goto out; + } + len = ret; + + ret = smh_read_full(fd, header, sizeof(struct image_header)); + if (ret) { + log_debug("could not read image header: %d\n", ret); + goto out; + } + + ret = spl_parse_image_header(spl_image, bootdev, header); + if (ret) { + log_debug("failed to parse image header: %d\n", ret); + goto out; + } + + ret = smh_seek(fd, 0); + if (ret) { + log_debug("could not seek to start of image: %d\n", ret); + goto out; + } + + ret = smh_read_full(fd, (void *)spl_image->load_addr, len); + if (ret) + log_debug("could not read %s: %d\n", filename, ret); +out: + smh_close(fd); + return ret; +} +SPL_LOAD_IMAGE_METHOD("SEMIHOSTING", 0, BOOT_DEVICE_SMH, spl_smh_load_image); -- 2.25.1