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 1D97FC433EF for ; Thu, 3 Mar 2022 20:46:35 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B1D7283D43; Thu, 3 Mar 2022 21:45:09 +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="DdnoFE3E"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2F64F811D8; Thu, 3 Mar 2022 21:44:45 +0100 (CET) Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-am5eur02on060b.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe07::60b]) (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 72A7D83CAF for ; Thu, 3 Mar 2022 21:44:31 +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=mvRwlTEuZloGj0qBGyWPiVcu4Py+DZGYZqIgnYaRtMO0YxQqSU6FMypvsorqz/gkkOQQmgRWIT8rikhtqhQI/h5nTiI5CkjPqdy2Xbz1py2AdET58v905lBCtv+P42T0S11cHobhXkLMiOCKgfdHvk63B100pAwcV19BOvyJ4fvisXmKpelPj0GwDSY3sJzh/h0anlCY9XDGKQ0imW3cFcgctbsjemjJ731Snrycn2+1xdxhNZiVqzFsn4V+WGojIVRjoDcJQdF03lhBC8QbrhocHfYZCVtiiFZcZV3pO1g05UanmjxhXX0CRhnrzkBvsFuXDJs1R5xw6smYyxBNwQ== 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=R4t8XHypC7XtVqJy5CBfZZBZOodaxmSJmQf4VPidM5Q=; b=GtsajEsfJ9OjakWt7niasXxBmP0X8rB2T0NF6dlkvURUKpatJ8/VnH9m1AahtRZM8uga6J1/d7Qe+30Jtb08iCTBpWuU0K1ix1LV3BRfY4oIhH36kOConXDQcVJRD7yW2Gy5AX84lle5CfCyzm4NED2nUw2dpxUhpkPjVu+hopfrH+Nn4TsYQJbPwQY1V12HfLe2F6yybKiXNDVWDqshpYGbN21MQERkPJhsOgvPhhEt0k4xDx2VuZ9ROomyFJXEMDnYNhHqnufJcdJmOjvIbJNWHwkzxY6p4eOX89I8z+RPeMrvrR0KkNMVQAnF/wgp/F4oFjmHReqpwLhfoOjM0w== 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=R4t8XHypC7XtVqJy5CBfZZBZOodaxmSJmQf4VPidM5Q=; b=DdnoFE3ENekQ/GDkPpz7n5JXeWTIV9vJrrQjGOOBd58Go+tMZalmaj5nouPrLeqCF/M8sOlYKfgMS44dB78kTIOMhyKuOK/E4ztUuhtz80DZzZQpjQnk4c1WP/4zJ5eHenMqkPK3wr/Xh0x40KPnaJ+GXKlgHlwCPIcrZ0jxIeEP9P8EEu7y+413wOanhcazJBqJyqC2p+1ZEKhZMQl49zqFLSL4f3kOXL3Wvnw8nv1HCek0O97orVP34/fMdSsJ9cHISkQ1ldIDHMptCXpRU1hKwZ8a62RjXiZ+K18Jfwa3GbjSZpqIfJOZr0TlyVuld9HEjpxPxN7ogRjjpR2R7Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=seco.com; Received: from DB7PR03MB4523.eurprd03.prod.outlook.com (2603:10a6:10:19::27) by AM6PR03MB3573.eurprd03.prod.outlook.com (2603:10a6:209:2f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.26; Thu, 3 Mar 2022 20:44:30 +0000 Received: from DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::9130:93ae:6e27:e9a]) by DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::9130:93ae:6e27:e9a%4]) with mapi id 15.20.5038.014; Thu, 3 Mar 2022 20:44:29 +0000 From: Sean Anderson To: Simon Glass Cc: Linus Walleij , Tom Rini , u-boot@lists.denx.de, Sean Anderson Subject: [PATCH 10/17] spl: Add semihosting boot method Date: Thu, 3 Mar 2022 15:43:53 -0500 Message-Id: <20220303204400.2787389-11-sean.anderson@seco.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220303204400.2787389-1-sean.anderson@seco.com> References: <20220303204400.2787389-1-sean.anderson@seco.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: MN2PR16CA0013.namprd16.prod.outlook.com (2603:10b6:208:134::26) To DB7PR03MB4523.eurprd03.prod.outlook.com (2603:10a6:10:19::27) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6accd380-1cac-4aa4-fd1c-08d9fd569d47 X-MS-TrafficTypeDiagnostic: AM6PR03MB3573: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: Hfh/pr/+mGyk4i+8ld2epA+7oocb+K0gRtjoeghDuoJLtki8BXYuilaGw1wDjQAdnF/AFwDyCS1kI6pZZNKwyv5MWjDp8Drpg+NMpVDaN02HvOmTdQoe1oaPtj+OkLAjf8HHvLbj0biL3k4jkYk6YblIhNho5kOcmJtwj2aaObzJVGRjMoSyXK9oB4E9xXlQDP1jaU9fENWjeOau7lW7z7frcpamx2vFCMQ8nGRXq0I8Ol7BXAjX3SgcBDHZdFgj2ocSPdikxnrkZB1pns4k+touJLesSfaD1Yv18SeUZN8s+4Y9fbEk9WBtSe8qx0I/YwcjqZqOgRNSARyd35jJ59x3O6E/THjbpALpsiyQASFgTo8YJWU3JUDLJ5MeWAbbDAr3g3U9UWMS89TRHLXxsWFTpHdDMlj01kA9j9LvunP/n+V5E2PLmRbd2orYDwvP4AMvlJd2n08mUkSaP59eEkQGq8/KM5XpJBfxpEwvkBzUK1SOwCNzrQ8paCjEaMBwopNl/e7hY2Bmx1bsz94hmKM4wffxUE9eXY1MM600gcHc3Ikg9BaIDrCG48ObP8DqaBE1E1rwnlUIiUYfZ519BTTXee8qDlbXYxqdEqjKzy4yduxSyl1TBxRTPYwa9I+jIDB/lMLSMoogbgidoOQrHpNlptnlCBcBIjRLTO1g+aDlzFz+LO7sRj1KDYD0ubW6xWCqbWO604Q9X0TDzk/6kQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR03MB4523.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(6916009)(36756003)(54906003)(1076003)(2616005)(83380400001)(316002)(38100700002)(38350700002)(186003)(26005)(107886003)(4326008)(6506007)(6666004)(508600001)(6512007)(2906002)(52116002)(86362001)(5660300002)(6486002)(8676002)(44832011)(66476007)(66946007)(66556008)(8936002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?11+Z+vdY5NckANp/AGuaDUHT4tcxthTuxUChYjKDx52cKkLB5q/u6+aZaHjb?= =?us-ascii?Q?JaFrG8731TpL7fnfhSX9hjpY1r0SzRZGw6iK4TcgMm+usmXaUuvGtGF/Ld4v?= =?us-ascii?Q?14dlM1W8MHOegQPH243Phn7g5J5Q6/zxzk3omGB9jVQtaGyW5hjuIyfvic6q?= =?us-ascii?Q?Qgi7sQeAUXeolqEPaZsxnIdxfYKi5+STQZDcHQrS1vAD+nOtyZh5z6+Ft9eM?= =?us-ascii?Q?4/GWsXODGtbTetx4+Nd7pd8t24XoRYWPAKl6FIHytS8TEBU3NZucQUZFwKYs?= =?us-ascii?Q?H9cPNTKRvLsHFUeFXfiGDcz6Yy44PvVPQ3Mc74eb6C6HJ0M6HyqC6Vr9vIqt?= =?us-ascii?Q?jLHZdFGSLkkFrfnZP21aVsdbrmdyI+kKfMb+Piz/w1CM7lfkQRpzBvLLgPV6?= =?us-ascii?Q?xHtaE//kfhRpcwvkYTjt6WjH7F89SI9Wj1lP71iR1KLrKccZ08L0FZ3ZLk6X?= =?us-ascii?Q?Y/xEBqZuk6LudeE93p2Xc5RyUDkYWmQnketq6Ja6A9oeHqF0hgWCa+OUrNao?= =?us-ascii?Q?b2jzA8fD05AfPnVa5zJ1xRNV5WwGp6zzCS3m4VlD4cdWGTj3jCO664ZGF4Ef?= =?us-ascii?Q?pyTIQCIxINGcjpsi9I9MABW1J9yHvoCxUzkMvfZZiZqNssdUsmK0s1eiV71I?= =?us-ascii?Q?+8v7LRzI0nQzllNjsPDLeLc1Y48CPvFMTqhR3Pqi5QjgJuacviC0Qbd1RFND?= =?us-ascii?Q?hrNbT+N/z+NqFCE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ii?Q?Oiodilpa/DbBrCOKy17C30U=3D?= X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6accd380-1cac-4aa4-fd1c-08d9fd569d47 X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4523.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Mar 2022 20:44:29.8641 (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: asoYiUV2/6NjptIlqP/ctXjm83TlQg6fIPZmy6/HDVgiXTadb0IoF0kyBLLEYJQHY6Gletk5sQyf1EWum/LQJw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR03MB3573 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 --- arch/arm/Kconfig | 25 +++++++++++-- arch/arm/include/asm/spl.h | 1 + common/spl/Makefile | 1 + common/spl/spl_semihosting.c | 71 ++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 common/spl/spl_semihosting.c diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 391a77c2b4..5cacb292b5 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -403,11 +403,28 @@ 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" + 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/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