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 1BB30C433EF for ; Thu, 10 Mar 2022 20:53:20 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 703DC83B2D; Thu, 10 Mar 2022 21:52:48 +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="OqUXyCEB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B257883B0A; Thu, 10 Mar 2022 21:51:49 +0100 (CET) Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on0617.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0e::617]) (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 97DBE83AEF for ; Thu, 10 Mar 2022 21:51:34 +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=BOLE5YHVVCjqVwa94UxBd1VHRFKU0TCUqUOIy6KmXHg9C2p1oXSWjiNdaPplsUWJN7zofvHfRYgLEQgcMP4PGPebj5OADdbgxpGy5KDv+sl+bumDJG0J/qzPtb3rblIxQAx3bAPCN4bDNLISQG55EhDH/XjS2qUEvbP79QguaUuVNNKP6gcemvJnueLsAFSe/Jvc/jZazh8Ted0abkWZhJov7qBkl0FGZL8ehbaObto3gUnLBYtnprgAGIhtb+EihPkpcTzWvL7ciR/Ew78skvxv6xzYHA1OjW3RU717JbZP4WPVA2pPwcwHaf5MyvKrjlGEOGaT4ACC2BxEu1Elgw== 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=qIhElLHTYFUAtUo3DH+ZSjPjN9H5Wp8O0LpLm5J5hfQ=; b=XBvethbyOixErX5lgaqw0emW4Nk1A/BcEvIh8kHhKEx2r21+UMC4ub10di3BunXYqG9bHteZvHcMwoDGck6Wi44OtDOjUJPILQGD3Cs0i6VI9NgU3ScjTIohul/5o2NAvUJGHuFNTvKK0l8e7RIa5zUqU1ERqP+WTYFYHXX0cmuvGulbTRVvZJnwV19Yj6Uz2TjO7NDbXiTB42YIhWBMPI9QyGPCAw+iOeRozCFDAB8WC8el4r6sqdEHOiwko1oSqYIexJGd6hYPNYWXkVk97TIpQjTERmbODuyOPldsT4wuESD1o68jtj7sA5E0e5L3lCm/Bt804h+tlXdUQlbL3Q== 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=qIhElLHTYFUAtUo3DH+ZSjPjN9H5Wp8O0LpLm5J5hfQ=; b=OqUXyCEBLPCQUkGmeX4LoI8p5TMly9+dipHqKhFQvmkfT3TBcCprQRQ6ajZmgqizj3Z5zELU8aIXh5ceyQejix4XcZSu5+2/Hy9x9o2g5rJQeBmU9eJEPWP2M8Lz2voY02wkFSrfNpy//czLeqSt2FVpPubx1XivHdz23LVdcCG5Gj+QkLJSXm/vkiyJfXEKmL/WRv+b0RSsNb//NLEoiptwzflTeHeM1Cf6YbIuSW6Cf3Tuk1vuVKOkf4pF83UZhgn/4rx5os2qLBx5p5hkbwyFblS/Vy8j+VxuaVxD5TSoAjApSOuIugHb5lTUkGyqcrYbyTD+JUi3VPYktBXIiA== 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 AM5PR03MB3105.eurprd03.prod.outlook.com (2603:10a6:206:24::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Thu, 10 Mar 2022 20:51:33 +0000 Received: from DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::9860:b15b:f166:5896]) by DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::9860:b15b:f166:5896%3]) with mapi id 15.20.5061.022; Thu, 10 Mar 2022 20:51:33 +0000 From: Sean Anderson To: Tom Rini Cc: Liviu Dudau , u-boot@lists.denx.de, Simon Glass , Linus Walleij , Andre Przywara , Sean Anderson Subject: [PATCH v2 11/28] spl: Add semihosting boot method Date: Thu, 10 Mar 2022 15:50:41 -0500 Message-Id: <20220310205059.499269-12-sean.anderson@seco.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220310205059.499269-1-sean.anderson@seco.com> References: <20220310205059.499269-1-sean.anderson@seco.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: BL1PR13CA0433.namprd13.prod.outlook.com (2603:10b6:208:2c3::18) 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: 37d716a4-a907-478d-298a-08da02d7c27d X-MS-TrafficTypeDiagnostic: AM5PR03MB3105: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: jK7NSrkToVI4mXAS469nBWt+oKzGLRd686FU1tCbiXaCtOSSijROgFyvWawjhz6OPpXRCgU8UCWXtYdRB6v8vBeBx81B4kxu0OuP/44nSGh38RusyI23qyXxrey0EmsQYhnijfiTAiVATYNz05mwtnGwld9HWsWZWxnRXBhdxwEX6su7Z+Qu+C8rHVO+yUsc1hC/q4FsuLB+wqv/+BPdVflvMY/Nvf0CPBODeNSF0tIqIabZMEsqGVrun1Tsm+6nXro20hI9XpfJU2Y64fBeDFuvxBEqqiLaVXwMBuo1iA4nJpVQXGtkfS/tB83RMDCv9DOLUDAOotrYmUv0nTt/8hinlOf4j19kV9vuFZl9pNO7HYtEUotAba4W24D03aQt+IMRQoVd1t3A8YHc+7D89uRXqqbV0wBPi7RVN1ELdcns28QNaA0Azsh/+sxZcYEx3M25nrvDdT0Scg8Hr/qnaKAypBhlqn9xt71o8svKx5i6frpJgK3E4SfpxuwDzXHQ0tKlNETODPRQsKtJ9X6etXlMeDSnLW7OEp1dyN0nYPGCyVImsXwpB13rMQh/Rq2w6yAwFUauOrs0Dp+NtGOnM1Xe50U7mWKJF9FesGltn3dXGhlrfefswIyTJjXGVD2KsG1+7WEwvnuWqfXLIjriWYasrm7tqePbQYPhxl6nUWfZjzEpPPl1qSErtImjcXE8AZC6iEvbh27+65IeonP1kg== 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)(44832011)(8676002)(54906003)(6916009)(8936002)(316002)(5660300002)(66476007)(6486002)(86362001)(66946007)(2906002)(66556008)(508600001)(107886003)(83380400001)(36756003)(4326008)(2616005)(52116002)(38100700002)(1076003)(6512007)(6666004)(38350700002)(26005)(6506007)(186003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?BQ9uPlHxAa9DJ1PcZaXQI8V+rKHPLn8Z6hY48j+ImSQ+ETGnKTpJ99wCtxUQ?= =?us-ascii?Q?QgTKQH/XQmD0ZGA512BxUXWfNsQFWmrjrUeIw9hTQn3l5hLni7wmlNk6LJw1?= =?us-ascii?Q?TbZaeTuytNfuAYPkfu382DPm8D7NdwKxqV/2vkNFhFllNOlL+3I0YBSI+trT?= =?us-ascii?Q?Q6bogK3GuzQHxoiwXb1Bj3yWC6h8F6vg6y4YzYGjkBVoT/Tc6tAzfXH82aC1?= =?us-ascii?Q?7eiM06HT3zOQ5pYQtRUbKVZIFr/C/dNwJWtOa3Vec2g+RI0NmbIMUDiukLYp?= =?us-ascii?Q?TJzmEkH3r/36e4ejBZmheAbLXKvhKNGzlb8pJqFtliMP8p3ZGtvRNzgonNAY?= =?us-ascii?Q?3iuw8gC3Pe8MLT8OmAGevUqWCNoVwjDbg8w/5w/+LIWh6xHvrdQ2wEGgFOX+?= =?us-ascii?Q?rWHLPDgso0C0rv82yDF6FYroEIXrEKH/SID6EPvIcTM9yTk4JJzLYZzaa2IP?= =?us-ascii?Q?XRLHeNzSzysjGzAixz1pL0vysjNPTkhh3HFZry9ylqNwur5IApH0hjmhgIQ9?= =?us-ascii?Q?oGfnKSergOHMAt9dKr6XNYgroojeM55ClA2+glPfye7TD7UuF5/pQAQJwzct?= =?us-ascii?Q?pPKvsC4XQuZZbR99/YCz/mcgDI4P01IbJQdzfdrnZl6+ZczyVSZ56JB+xUo+?= =?us-ascii?Q?s6uUjSykGwrQMWq50/gXbnqAlOWz91kZdHwYOs/QfNKhsrLORV1X79bAhNWi?= =?us-ascii?Q?1bWw+wMAlzwl15eSe29CY5Xx9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= =?us-ascii?Q?LRRxBYlcfH0Qw11nnGGrJa4=3D?= X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: 37d716a4-a907-478d-298a-08da02d7c27d X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4523.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2022 20:51:33.1334 (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: ByHzRjZTHLlpc9AWHqpYEhrYblf4qpSgQIcF+NrB3k+JPCk/bKhVhAJm8ahgl+J2/jgIqUfT6earwdtYqyKI3g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR03MB3105 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 --- Changes in v2: - Make CONFIG_SPL_SEMIHOSTING depend on SPL - Compile arch/arm/lib/semihosting.o in 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 974555f900..209232aac2 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