From e09ec8e340260ace3d49d634fc869b7a9eb09186 Mon Sep 17 00:00:00 2001 From: Andre Przywara Date: Fri, 4 Mar 2022 16:30:12 +0000 Subject: vexpress64: config header: unify environment definition The definition of the standard environment variables (kernel_addr_r and friends) has been improved lately for the FVP model, but the Juno board is still using some custom scheme. Since we need to extend this to a third board soon, let's unify the definition: - Define the Juno addresses in the same generic way we do for the FVP model, and move the actual variable setting out of the board #ifdef's. - Add the missing addresses for a PXE file and a boot script. - Cleanup some stale comments on the way. As the FVP model doesn't have support for distro_boot quite yet, add a dummy definition for now, to be replaced with the real thing later. Signed-off-by: Andre Przywara --- include/configs/vexpress_aemv8.h | 83 ++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 38 deletions(-) (limited to 'include') diff --git a/include/configs/vexpress_aemv8.h b/include/configs/vexpress_aemv8.h index b956bd91478..f8731aad97d 100644 --- a/include/configs/vexpress_aemv8.h +++ b/include/configs/vexpress_aemv8.h @@ -99,8 +99,6 @@ #define CONFIG_PL011_CLOCK 24000000 #endif -/* Miscellaneous configurable options */ - /* Physical Memory Map */ #define PHYS_SDRAM_1 (V2M_BASE) /* SDRAM Bank #1 */ /* Top 16MB reserved for secure world use */ @@ -116,11 +114,7 @@ #define PHYS_SDRAM_2_SIZE 0x80000000 #endif -/* Enable memtest */ - -/* Initial environment variables */ -#ifdef CONFIG_TARGET_VEXPRESS64_JUNO -/* Copy the kernel and FDT to DRAM memory and boot */ +/* Copy the kernel, initrd and FDT from NOR flash to DRAM memory and boot. */ #define BOOTENV_DEV_AFS(devtypeu, devtypel, instance) \ "bootcmd_afs=" \ "afs load ${kernel_name} ${kernel_addr_r} ;"\ @@ -143,6 +137,10 @@ "booti ${kernel_addr_r} ${ramdisk_param} ${fdt_addr_r}\0" #define BOOTENV_DEV_NAME_AFS(devtypeu, devtypel, instance) "afs " +/* Boot sources for distro boot and load addresses, per board */ + +#ifdef CONFIG_TARGET_VEXPRESS64_JUNO /* Arm Juno board */ + #define BOOT_TARGET_DEVICES(func) \ func(USB, usb, 0) \ func(SATA, sata, 0) \ @@ -153,40 +151,49 @@ #include -/* - * Defines where the kernel and FDT exist in NOR flash and where it will - * be copied into DRAM - */ -#define CONFIG_EXTRA_ENV_SETTINGS \ - "kernel_name=norkern\0" \ - "kernel_alt_name=Image\0" \ - "kernel_addr_r=0x80080000\0" \ - "ramdisk_name=ramdisk.img\0" \ - "ramdisk_addr_r=0x88000000\0" \ - "fdtfile=board.dtb\0" \ - "fdt_alt_name=juno\0" \ - "fdt_addr_r=0x80000000\0" \ - BOOTENV - -#elif CONFIG_TARGET_VEXPRESS64_BASE_FVP - -#define VEXPRESS_KERNEL_ADDR 0x80080000 -#define VEXPRESS_FDT_ADDR 0x8fc00000 -#define VEXPRESS_BOOT_ADDR 0x8fd00000 -#define VEXPRESS_RAMDISK_ADDR 0x8fe00000 - -#define CONFIG_EXTRA_ENV_SETTINGS \ - "kernel_name=Image\0" \ - "kernel_addr_r=" __stringify(VEXPRESS_KERNEL_ADDR) "\0" \ - "ramdisk_name=ramdisk.img\0" \ - "ramdisk_addr_r=" __stringify(VEXPRESS_RAMDISK_ADDR) "\0" \ - "fdtfile=devtree.dtb\0" \ - "fdt_addr_r=" __stringify(VEXPRESS_FDT_ADDR) "\0" \ - "boot_name=boot.img\0" \ - "boot_addr_r=" __stringify(VEXPRESS_BOOT_ADDR) "\0" +#define VEXPRESS_KERNEL_ADDR 0x80080000 +#define VEXPRESS_PXEFILE_ADDR 0x8fb00000 +#define VEXPRESS_FDT_ADDR 0x8fc00000 +#define VEXPRESS_SCRIPT_ADDR 0x8fd00000 +#define VEXPRESS_RAMDISK_ADDR 0x8fe00000 + +#define EXTRA_ENV_NAMES \ + "kernel_name=norkern\0" \ + "kernel_alt_name=Image\0" \ + "ramdisk_name=ramdisk.img\0" \ + "fdtfile=board.dtb\0" \ + "fdt_alt_name=juno\0" + +#elif CONFIG_TARGET_VEXPRESS64_BASE_FVP /* ARMv8-A base model */ + +#define VEXPRESS_KERNEL_ADDR 0x80080000 +#define VEXPRESS_PXEFILE_ADDR 0x8fa00000 +#define VEXPRESS_SCRIPT_ADDR 0x8fb00000 +#define VEXPRESS_FDT_ADDR 0x8fc00000 +#define VEXPRESS_BOOT_ADDR 0x8fd00000 +#define VEXPRESS_RAMDISK_ADDR 0x8fe00000 + +#define EXTRA_ENV_NAMES \ + "kernel_name=Image\0" \ + "ramdisk_name=ramdisk.img\0" \ + "fdtfile=devtree.dtb\0" \ + "boot_name=boot.img\0" \ + "boot_addr_r=" __stringify(VEXPRESS_BOOT_ADDR) "\0" + +#define BOOTENV #endif +/* Default load addresses and names for the different payloads. */ +#define CONFIG_EXTRA_ENV_SETTINGS \ + "kernel_addr_r=" __stringify(VEXPRESS_KERNEL_ADDR) "\0" \ + "ramdisk_addr_r=" __stringify(VEXPRESS_RAMDISK_ADDR) "\0" \ + "pxefile_addr_r=" __stringify(VEXPRESS_PXEFILE_ADDR) "\0" \ + "fdt_addr_r=" __stringify(VEXPRESS_FDT_ADDR) "\0" \ + "scriptaddr=" __stringify(VEXPRESS_SCRIPT_ADDR) "\0" \ + EXTRA_ENV_NAMES \ + BOOTENV + /* Monitor Command Prompt */ #define CONFIG_SYS_CBSIZE 512 /* Console I/O Buffer Size */ #define CONFIG_SYS_MAXARGS 64 /* max command args */ -- cgit v1.2.3 From 8a0a8ff52c1681a3cde8568cb6e252b9a98fdf06 Mon Sep 17 00:00:00 2001 From: Andre Przywara Date: Fri, 4 Mar 2022 16:30:14 +0000 Subject: vexpress64: fvp: add distro_boot support So far the FVP model just supports booting through semihosting, so by loading files from the host the model is running on. This allows for quick booting of new kernels (or replacing DTBs), but prevents more featureful boots like using UEFI. Enable the distro_boot feature, and provide a list of possible boot sources that U-Boot should check: - For backwards compatibility we start with semihosting, which gets its commands migrated from CONFIG_BOOTCOMMAND into the distro_boot infrastructure. This is also slightly tweaked to fail graceful in case the required files could not be found. - Next we try to use a user provided script, that could be easily placed into memory using the model command line. - Since we gained virtio support with the enablement of OF_CONTROL, let's check virtio block devices next. This is where UEFI boot can be easily used, for instance by providing a distro installer .iso file through virtio-blk. - Networking is now provided by virtio as well, so enable the default PXE and DHCP boot flows, mostly because we can. Signed-off-by: Andre Przywara --- include/configs/vexpress_aemv8.h | 57 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/configs/vexpress_aemv8.h b/include/configs/vexpress_aemv8.h index f8731aad97d..74060c63490 100644 --- a/include/configs/vexpress_aemv8.h +++ b/include/configs/vexpress_aemv8.h @@ -137,6 +137,50 @@ "booti ${kernel_addr_r} ${ramdisk_param} ${fdt_addr_r}\0" #define BOOTENV_DEV_NAME_AFS(devtypeu, devtypel, instance) "afs " +/* Boot by executing a U-Boot script pre-loaded into DRAM. */ +#define BOOTENV_DEV_MEM(devtypeu, devtypel, instance) \ + "bootcmd_mem= " \ + "source ${scriptaddr}; " \ + "if test $? -eq 1; then " \ + " env import -t ${scriptaddr}; " \ + " if test -n $uenvcmd; then " \ + " echo Running uenvcmd ...; " \ + " run uenvcmd; " \ + " fi; " \ + "fi\0" +#define BOOTENV_DEV_NAME_MEM(devtypeu, devtypel, instance) "mem " + +#ifdef CONFIG_CMD_VIRTIO +#define FUNC_VIRTIO(func) func(VIRTIO, virtio, 0) +#else +#define FUNC_VIRTIO(func) +#endif + +/* + * Boot by loading an Android image, or kernel, initrd and FDT through + * semihosting into DRAM. + */ +#define BOOTENV_DEV_SMH(devtypeu, devtypel, instance) \ + "bootcmd_smh= " \ + "if smhload ${boot_name} ${boot_addr_r}; then" \ + " setenv bootargs;" \ + " abootimg addr ${boot_addr_r};" \ + " abootimg get dtb --index=0 fdt_addr_r;" \ + " bootm ${boot_addr_r} ${boot_addr_r} ${fdt_addr_r};" \ + "else" \ + " if smhload ${kernel_name} ${kernel_addr_r}; then" \ + " setenv fdt_high 0xffffffffffffffff;" \ + " setenv initrd_high 0xffffffffffffffff;" \ + " smhload ${fdtfile} ${fdt_addr_r};" \ + " smhload ${ramdisk_name} ${ramdisk_addr_r} ramdisk_end;" \ + " fdt addr ${fdt_addr_r};" \ + " fdt resize;" \ + " fdt chosen ${ramdisk_addr_r} ${ramdisk_end};" \ + " booti $kernel_addr_r - $fdt_addr_r;" \ + " fi;" \ + "fi\0" +#define BOOTENV_DEV_NAME_SMH(devtypeu, devtypel, instance) "smh " + /* Boot sources for distro boot and load addresses, per board */ #ifdef CONFIG_TARGET_VEXPRESS64_JUNO /* Arm Juno board */ @@ -149,8 +193,6 @@ func(DHCP, dhcp, na) \ func(AFS, afs, na) -#include - #define VEXPRESS_KERNEL_ADDR 0x80080000 #define VEXPRESS_PXEFILE_ADDR 0x8fb00000 #define VEXPRESS_FDT_ADDR 0x8fc00000 @@ -166,6 +208,13 @@ #elif CONFIG_TARGET_VEXPRESS64_BASE_FVP /* ARMv8-A base model */ +#define BOOT_TARGET_DEVICES(func) \ + func(SMH, smh, na) \ + func(MEM, mem, na) \ + FUNC_VIRTIO(func) \ + func(PXE, pxe, na) \ + func(DHCP, dhcp, na) + #define VEXPRESS_KERNEL_ADDR 0x80080000 #define VEXPRESS_PXEFILE_ADDR 0x8fa00000 #define VEXPRESS_SCRIPT_ADDR 0x8fb00000 @@ -180,10 +229,10 @@ "boot_name=boot.img\0" \ "boot_addr_r=" __stringify(VEXPRESS_BOOT_ADDR) "\0" -#define BOOTENV - #endif +#include + /* Default load addresses and names for the different payloads. */ #define CONFIG_EXTRA_ENV_SETTINGS \ "kernel_addr_r=" __stringify(VEXPRESS_KERNEL_ADDR) "\0" \ -- cgit v1.2.3 From 30cacb8123459328c46c25f65196bb4885dcdb05 Mon Sep 17 00:00:00 2001 From: Andre Przywara Date: Fri, 4 Mar 2022 16:30:16 +0000 Subject: vexpress64: generalise page table generation In preparation for the ARMv8-R64 FVP support, which has DRAM mapped at 0x0, generalise the page table generation, by using symbolic names for the address ranges instead of fixed numbers. We already define the base of the DRAM and MMIO regions, so just use those symbols in the page table description. Rename V2M_BASE to the more speaking V2M_DRAM_BASE on the way. On the VExpress memory map, the address space right after 4GB is of no particular interest to software, as the whole of DRAM is mapped at 32GB instead. The first 2 GB alias to the lower 2GB of DRAM mapped below 4GB, so we skip this part and map some more of the high DRAM, should anyone need it. Signed-off-by: Andre Przywara --- include/configs/vexpress_aemv8.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/configs/vexpress_aemv8.h b/include/configs/vexpress_aemv8.h index 74060c63490..e0f9bbeb16c 100644 --- a/include/configs/vexpress_aemv8.h +++ b/include/configs/vexpress_aemv8.h @@ -20,7 +20,7 @@ #define CONFIG_SYS_BOOTM_LEN (64 << 20) /* Increase max gunzip size */ /* CS register bases for the original memory map. */ -#define V2M_BASE 0x80000000 +#define V2M_DRAM_BASE 0x80000000 #define V2M_PA_BASE 0x00000000 #define V2M_PA_CS0 (V2M_PA_BASE + 0x00000000) @@ -100,7 +100,7 @@ #endif /* Physical Memory Map */ -#define PHYS_SDRAM_1 (V2M_BASE) /* SDRAM Bank #1 */ +#define PHYS_SDRAM_1 (V2M_DRAM_BASE) /* SDRAM Bank #1 */ /* Top 16MB reserved for secure world use */ #define DRAM_SEC_SIZE 0x01000000 #define PHYS_SDRAM_1_SIZE 0x80000000 - DRAM_SEC_SIZE -- cgit v1.2.3 From 8d78a6b67467145f7e02295ca5d4944251dbc645 Mon Sep 17 00:00:00 2001 From: Peter Hoyes Date: Fri, 4 Mar 2022 16:30:18 +0000 Subject: vexpress64: Add ARMv8R-64 board variant The ARMv8-R64 architecture introduces optional VMSA (paging based MMU) support in the EL1/0 translation regime, which makes that part mostly compatible to ARMv8-A. Add a new board variant to describe the "BASE-R64" FVP model, which inherits a lot from the existing v8-A FVP support. One major difference is that the memory map in "inverted": DRAM starts at 0x0, MMIO is at 2GB [1]. * Create new TARGET_VEXPRESS64_BASER_FVP target, sharing most of the exising configuration. * Implement inverted memory map in vexpress_aemv8.h * Create vexpress_aemv8r defconfig * Provide an MMU memory map for the BASER_FVP * Update vexpress64 documentation At the moment the boot-wrapper is the only supported secure firmware. As there is no official DT for the board yet, we rely on it being supplied by the boot-wrapper into U-Boot, so use OF_HAS_PRIOR_STAGE, and go with a dummy DT for now. [1] https://developer.arm.com/documentation/100964/1114/Base-Platform/Base---memory/BaseR-Platform-memory-map Signed-off-by: Peter Hoyes [Andre: rebase and add Linux kernel header] Signed-off-by: Andre Przywara [trini: Add MAINTAINERS entry for Peter] --- include/configs/vexpress_aemv8.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'include') diff --git a/include/configs/vexpress_aemv8.h b/include/configs/vexpress_aemv8.h index e0f9bbeb16c..efffea97c2e 100644 --- a/include/configs/vexpress_aemv8.h +++ b/include/configs/vexpress_aemv8.h @@ -20,8 +20,13 @@ #define CONFIG_SYS_BOOTM_LEN (64 << 20) /* Increase max gunzip size */ /* CS register bases for the original memory map. */ +#ifdef CONFIG_TARGET_VEXPRESS64_BASER_FVP +#define V2M_DRAM_BASE 0x00000000 +#define V2M_PA_BASE 0x80000000 +#else #define V2M_DRAM_BASE 0x80000000 #define V2M_PA_BASE 0x00000000 +#endif #define V2M_PA_CS0 (V2M_PA_BASE + 0x00000000) #define V2M_PA_CS1 (V2M_PA_BASE + 0x14000000) @@ -229,6 +234,24 @@ "boot_name=boot.img\0" \ "boot_addr_r=" __stringify(VEXPRESS_BOOT_ADDR) "\0" +#elif CONFIG_TARGET_VEXPRESS64_BASER_FVP /* ARMv8-R base model */ + +#define BOOT_TARGET_DEVICES(func) \ + func(MEM, mem, na) \ + FUNC_VIRTIO(func) \ + func(PXE, pxe, na) \ + func(DHCP, dhcp, na) + +#define VEXPRESS_KERNEL_ADDR 0x00200000 +#define VEXPRESS_PXEFILE_ADDR 0x0fb00000 +#define VEXPRESS_FDT_ADDR 0x0fc00000 +#define VEXPRESS_SCRIPT_ADDR 0x0fd00000 +#define VEXPRESS_RAMDISK_ADDR 0x0fe00000 + +#define EXTRA_ENV_NAMES \ + "kernel_name=Image\0" \ + "ramdisk_name=ramdisk.img\0" \ + "fdtfile=board.dtb\0" #endif #include -- cgit v1.2.3 From b10f724807312a996100c7c4b779d320ed40d573 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Tue, 22 Mar 2022 16:59:14 -0400 Subject: arm: smh: Export semihosting functions This exports semihosting functions for use in other files. The header is in include/ and not arm/include/asm because I anticipate that RISC-V may want to add their own implementation at some point. smh_len_fd has been renamed to smh_flen to more closely match the semihosting spec. Signed-off-by: Sean Anderson --- include/semihosting.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 include/semihosting.h (limited to 'include') diff --git a/include/semihosting.h b/include/semihosting.h new file mode 100644 index 00000000000..38438630465 --- /dev/null +++ b/include/semihosting.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2022 Sean Anderson + */ + +#ifndef _SEMIHOSTING_H +#define _SEMIHOSTING_H + +long smh_open(const char *fname, char *modestr); +long smh_read(long fd, void *memp, size_t len); +long smh_close(long fd); +long smh_flen(long fd); + +#endif /* _SEMIHOSTING_H */ -- cgit v1.2.3 From eff77c3a24ff6623f3767816ca54b8124f0e69a7 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Tue, 22 Mar 2022 16:59:15 -0400 Subject: arm: smh: Use numeric modes for smh_open There's no point in using string constants for smh_open if we are just going to have to parse them. Instead, use numeric modes. The user needs to be a bit careful with these, since they are much closer semantically to string modes used by fopen(3) than the numeric modes used with open(2). Signed-off-by: Sean Anderson --- include/semihosting.h | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/semihosting.h b/include/semihosting.h index 38438630465..cf54819192b 100644 --- a/include/semihosting.h +++ b/include/semihosting.h @@ -6,7 +6,30 @@ #ifndef _SEMIHOSTING_H #define _SEMIHOSTING_H -long smh_open(const char *fname, char *modestr); +/** + * enum smh_open_mode - Numeric file modes for use with smh_open() + * MODE_READ: 'r' + * MODE_BINARY: 'b' + * MODE_PLUS: '+' + * MODE_WRITE: 'w' + * MODE_APPEND: 'a' + * + * These modes represent the mode string used by fopen(3) in a form which can + * be passed to smh_open(). These do NOT correspond directly to %O_RDONLY, + * %O_CREAT, etc; see fopen(3) for details. In particular, @MODE_PLUS + * effectively results in adding %O_RDWR, and @MODE_WRITE will add %O_TRUNC. + * For compatibility, @MODE_BINARY should be added when opening non-text files + * (such as images). + */ +enum smh_open_mode { + MODE_READ = 0x0, + MODE_BINARY = 0x1, + MODE_PLUS = 0x2, + MODE_WRITE = 0x4, + MODE_APPEND = 0x8, +}; + +long smh_open(const char *fname, enum smh_open_mode mode); long smh_read(long fd, void *memp, size_t len); long smh_close(long fd); long smh_flen(long fd); -- cgit v1.2.3 From 79f6ad6a7b9c30bacb135b91a268fd9767bca79d Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Tue, 22 Mar 2022 16:59:17 -0400 Subject: arm: smh: Document functions in header This adds some documentation for semihosting functions in the header. Signed-off-by: Sean Anderson --- include/semihosting.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'include') diff --git a/include/semihosting.h b/include/semihosting.h index cf54819192b..d8337b6269b 100644 --- a/include/semihosting.h +++ b/include/semihosting.h @@ -29,9 +29,41 @@ enum smh_open_mode { MODE_APPEND = 0x8, }; +/** + * smh_open() - Open a file on the host + * @fname: The name of the file to open + * @mode: The mode to use when opening the file + * + * Return: Either a file descriptor or a negative error on failure + */ long smh_open(const char *fname, enum smh_open_mode mode); + +/** + * smh_read() - Read data from a file + * @fd: A file descriptor returned from smh_open() + * @memp: Pointer to a buffer of memory of at least @len bytes + * @len: The number of bytes to read + * + * Return: + * * The number of bytes read on success, with 0 indicating %EOF + * * A negative error on failure + */ long smh_read(long fd, void *memp, size_t len); + +/** + * smh_close() - Close an open file + * @fd: A file descriptor returned from smh_open() + * + * Return: 0 on success or negative error on failure + */ long smh_close(long fd); + +/** + * smh_flen() - Get the length of a file + * @fd: A file descriptor returned from smh_open() + * + * Return: The length of the file, in bytes, or a negative error on failure + */ long smh_flen(long fd); #endif /* _SEMIHOSTING_H */ -- cgit v1.2.3 From 12a05b3bcd85ff4aa930e7a1fb8795d5a6bfdf81 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Tue, 22 Mar 2022 16:59:18 -0400 Subject: arm: smh: Add some file manipulation commands In order to add filesystem support, we will need to be able to seek and write files. Add the appropriate helper functions. Signed-off-by: Sean Anderson --- include/semihosting.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'include') diff --git a/include/semihosting.h b/include/semihosting.h index d8337b6269b..b53c6504440 100644 --- a/include/semihosting.h +++ b/include/semihosting.h @@ -50,6 +50,17 @@ long smh_open(const char *fname, enum smh_open_mode mode); */ long smh_read(long fd, void *memp, size_t len); +/** + * smh_write() - Write data to a file + * @fd: A file descriptor returned from smh_open() + * @memp: Pointer to a buffer of memory of at least @len bytes + * @len: The number of bytes to read + * @written: Pointer which will be updated with the actual bytes written + * + * Return: 0 on success or negative error on failure + */ +long smh_write(long fd, const void *memp, size_t len, ulong *written); + /** * smh_close() - Close an open file * @fd: A file descriptor returned from smh_open() @@ -66,4 +77,13 @@ long smh_close(long fd); */ long smh_flen(long fd); +/** + * smh_seek() - Seek to a position in a file + * @fd: A file descriptor returned from smh_open() + * @pos: The offset (in bytes) to seek to + * + * Return: 0 on success or negative error on failure + */ +long smh_seek(long fd, long pos); + #endif /* _SEMIHOSTING_H */ -- cgit v1.2.3 From f676b45151c33986501e5f8f9bcc64f4a9511089 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Tue, 22 Mar 2022 16:59:20 -0400 Subject: fs: Add semihosting filesystem This adds a filesystem which is backed by the host's filesystem. It is modeled off of sandboxfs, which has very similar aims. Semihosting doesn't support listing directories (except with SYS_SYSTEM), so neither do we. it's possible to optimize a bit for the common case of reading a whole file by omitting a call to smh_seek, but this is left as a future optimization. Signed-off-by: Sean Anderson --- include/fs.h | 1 + include/semihostingfs.h | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 include/semihostingfs.h (limited to 'include') diff --git a/include/fs.h b/include/fs.h index b607b0028dc..e2beba36b98 100644 --- a/include/fs.h +++ b/include/fs.h @@ -18,6 +18,7 @@ struct cmd_tbl; #define FS_TYPE_BTRFS 5 #define FS_TYPE_SQUASHFS 6 #define FS_TYPE_EROFS 7 +#define FS_TYPE_SEMIHOSTING 8 struct blk_desc; diff --git a/include/semihostingfs.h b/include/semihostingfs.h new file mode 100644 index 00000000000..25ebdbbeff3 --- /dev/null +++ b/include/semihostingfs.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2022, Sean Anderson + * Copyright (c) 2012, Google Inc. + */ + +#ifndef __SEMIHOSTING_FS__ +#define __SEMIHOSTING_FS__ + +struct blk_desc; +struct disk_partition; + +int smh_fs_set_blk_dev(struct blk_desc *rbdd, struct disk_partition *info); +void smh_fs_close(void); +int smh_fs_size(const char *filename, loff_t *size); +int smh_fs_read(const char *filename, void *buf, loff_t offset, loff_t len, + loff_t *actread); +int smh_fs_write(const char *filename, void *buf, loff_t offset, + loff_t len, loff_t *actwrite); + +#endif -- cgit v1.2.3 From dcc4f9623e27b92a1e0b97326631b0d5841c49cb Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Tue, 22 Mar 2022 16:59:22 -0400 Subject: arm: smh: Remove smhload command This command's functionality is now completely implemented by the standard fs load command. Convert the vexpress64 boot command (which is the only user) and remove the implementation. Signed-off-by: Sean Anderson --- include/configs/vexpress_aemv8.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/configs/vexpress_aemv8.h b/include/configs/vexpress_aemv8.h index efffea97c2e..4f0ff239e68 100644 --- a/include/configs/vexpress_aemv8.h +++ b/include/configs/vexpress_aemv8.h @@ -167,20 +167,20 @@ */ #define BOOTENV_DEV_SMH(devtypeu, devtypel, instance) \ "bootcmd_smh= " \ - "if smhload ${boot_name} ${boot_addr_r}; then" \ + "if load hostfs - ${boot_addr_r} ${boot_name}; then" \ " setenv bootargs;" \ " abootimg addr ${boot_addr_r};" \ " abootimg get dtb --index=0 fdt_addr_r;" \ " bootm ${boot_addr_r} ${boot_addr_r} ${fdt_addr_r};" \ "else" \ - " if smhload ${kernel_name} ${kernel_addr_r}; then" \ + " if load hostfs - ${kernel_addr_r} ${kernel_name}; then" \ " setenv fdt_high 0xffffffffffffffff;" \ " setenv initrd_high 0xffffffffffffffff;" \ - " smhload ${fdtfile} ${fdt_addr_r};" \ - " smhload ${ramdisk_name} ${ramdisk_addr_r} ramdisk_end;" \ + " load hostfs - ${fdt_addr_r} ${fdtfile};" \ + " load hostfs - ${ramdisk_addr_r} ${ramdisk_name};" \ " fdt addr ${fdt_addr_r};" \ " fdt resize;" \ - " fdt chosen ${ramdisk_addr_r} ${ramdisk_end};" \ + " fdt chosen ${ramdisk_addr_r} ${filesize};" \ " booti $kernel_addr_r - $fdt_addr_r;" \ " fi;" \ "fi\0" -- cgit v1.2.3 From 3ea744e87359f95251ae7ec3c7a92f8b3293593b Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Tue, 22 Mar 2022 16:59:23 -0400 Subject: arm: smh: Add some functions for working with the host console This adds three wrappers around the semihosting commands for reading and writing to the host console. We use the more standard getc/putc/puts names instead of readc/writec/write0 for familiarity. Signed-off-by: Sean Anderson --- include/semihosting.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'include') diff --git a/include/semihosting.h b/include/semihosting.h index b53c6504440..6f3c29786ce 100644 --- a/include/semihosting.h +++ b/include/semihosting.h @@ -86,4 +86,23 @@ long smh_flen(long fd); */ long smh_seek(long fd, long pos); +/** + * smh_getc() - Read a character from stdin + * + * Return: The character read, or a negative error on failure + */ +int smh_getc(void); + +/** + * smh_putc() - Print a character on stdout + * @ch: The character to print + */ +void smh_putc(char ch); + +/** + * smh_write0() - Print a nul-terminated string on stdout + * @s: The string to print + */ +void smh_puts(const char *s); + #endif /* _SEMIHOSTING_H */ -- cgit v1.2.3 From 74d11d37e2d33c616748d5572fd5718944826d17 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Tue, 22 Mar 2022 16:59:24 -0400 Subject: serial: Add semihosting driver This adds a serial driver which uses semihosting calls to read and write to the host's console. For convenience, if CONFIG_DM_SERIAL is enabled, we will instantiate a serial driver. This allows users to enable this driver (which has no physical device) without modifying their device trees or board files. We also implement a non-DM driver for SPL, or for much faster output in U-Boot proper. There are three ways to print to the console: Method Baud ================== ===== smh_putc in a loop 170 smh_puts 1600 smh_write with :tt 20000 ================== ===== These speeds were measured using a 175 character message with a J-Link adapter. For reference, U-Boot typically prints around 2700 characters during boot on this board. There are two major factors affecting the speed of these functions. First, each breakpoint incurs a delay. Second, each debugger memory transaction incurs a delay. smh_putc has a breakpoint and memory transaction for every character. smh_puts has one breakpoint, but still has to use a transaction for every character. This is because we don't know the length up front, so OpenOCD has to check if each character is nul. smh_write has only one breakpoint and one memory transfer. DM serial drivers can only implement a putc interface, so we are stuck with the slowest API. Non-DM drivers can implement puts, which is vastly more efficient. When the driver starts up, we try to open :tt. Since this is an extension, this may fail. If it does, we fall back to smh_puts. We don't check :semihosting-features, since there are nonconforming implementations (OpenOCD) which don't implement it (but *do* implement :tt). Some semihosting implementations (QEMU) don't handle READC properly. To work around this, we try to use open/read (much like for stdin) if possible. There is no non-blocking I/O available, so we don't implement pending. This will cause __serial_tstc to always return true. If CONFIG_SERIAL_RX_BUFFER is enabled, _serial_tstc will try and read characters forever. To avoid this, we depend on this config being disabled. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- include/serial.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/serial.h b/include/serial.h index 19a8c0c67d2..2681d26c829 100644 --- a/include/serial.h +++ b/include/serial.h @@ -23,6 +23,7 @@ struct serial_device { void default_serial_puts(const char *s); extern struct serial_device serial_smc_device; +extern struct serial_device serial_smh_device; extern struct serial_device serial_scc_device; extern struct serial_device *default_serial_console(void); -- cgit v1.2.3 From 93c3d329707e0d8dc98e5f86938bbedbe15b5349 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Tue, 22 Mar 2022 17:16:05 -0400 Subject: ls1046ardb: Add support for JTAG boot This adds support for booting entirely from JTAG while using a hard-coded RCW. With these steps, it is not necessary to program a "good" RCW using CodeWarrior. The method here can be performed with any JTAG adapter supported by OpenOCD, including the on-board CMSIS-DAP (albeit very slowly). These steps require LS1046A support in OpenOCD, which was added in [1]. [1] https://sourceforge.net/p/openocd/code/ci/5b70c1f679755677c925b4e6dd2c3d8be4715717/ Signed-off-by: Sean Anderson [trini: Add reference to doc/board/nxp/ls1046ardb.rst] --- include/configs/ls1046ardb.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/configs/ls1046ardb.h b/include/configs/ls1046ardb.h index 04c3ad02c8f..df699bca34a 100644 --- a/include/configs/ls1046ardb.h +++ b/include/configs/ls1046ardb.h @@ -140,6 +140,8 @@ #endif #endif +#define CONFIG_SPL_FS_LOAD_PAYLOAD_NAME "u-boot.img" + #include #endif /* __LS1046ARDB_H__ */ -- cgit v1.2.3 From 385d69d76b4216c10083f908005983d0c62e159c Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Tue, 22 Mar 2022 16:59:30 -0400 Subject: arm: smh: Add option to detect semihosting These functions are intended to support detecting semihosting and falling back gracefully to alternative implementations. The test starts by making semihosting call. SYS_ERRNO is chosen because it should not mutate any state. If this semihosting call results in an exception (rather than being caught by the debugger), then the exception handler should call disable_semihosting() and resume execution after the call. Ideally, this would just be part of semihosting by default, and not a separate config. However, to reduce space ARM SPL doesn't include exception vectors by default. This means we can't detect if a semihosting call failed unless we enable them. To avoid forcing them to be enabled, we use a separate config option. It might also be possible to try and detect whether a debugger has enabled (by reading HDE from DSCR), but I wasn't able to figure out a way to do this from all ELs. This patch just introduces the generic code to handle detection. The next patch will implement it for arm64 (but not arm32). Signed-off-by: Sean Anderson --- include/semihosting.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'include') diff --git a/include/semihosting.h b/include/semihosting.h index 6f3c29786ce..9816233c508 100644 --- a/include/semihosting.h +++ b/include/semihosting.h @@ -6,6 +6,36 @@ #ifndef _SEMIHOSTING_H #define _SEMIHOSTING_H +#if CONFIG_IS_ENABLED(SEMIHOSTING_FALLBACK) +/** + * semihosting_enabled() - Determine whether semihosting is supported + * + * Semihosting-based drivers should call this function before making other + * semihosting calls. + * + * Return: %true if a debugger is attached which supports semihosting, %false + * otherwise + */ +bool semihosting_enabled(void); + +/** + * disable_semihosting() - Cause semihosting_enabled() to return false + * + * If U-Boot ever receives an unhandled exception caused by a semihosting trap, + * the trap handler should call this function. + */ +void disable_semihosting(void); +#else +static inline bool semihosting_enabled(void) +{ + return CONFIG_IS_ENABLED(SEMIHOSTING); +} + +static inline void disable_semihosting(void) +{ +} +#endif + /** * enum smh_open_mode - Numeric file modes for use with smh_open() * MODE_READ: 'r' -- cgit v1.2.3 From bbe310cdaf459b0ee69534584128ed6e057568db Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Tue, 22 Mar 2022 16:59:31 -0400 Subject: arm64: Catch non-emulated semihosting calls If a debugger is not attached to U-Boot, semihosting calls will raise a synchronous abort exception. Try to catch this and disable semihosting so we can e.g. use another uart if one is available. In the immediate case, we return an error, since it is not always possible to check for semihosting beforehand (debug uart, user-initiated load command, etc.) We handle all possible semihosting instructions, which is probably overkill. However, we do need to keep track of what instruction set we're using so that we don't suppress an actual error. A future enhancement could try to determine semihosting capability by inspecting the processor state. There's an example of this at [1] for RISC-V. The equivalent for ARM would inspect the monitor modei enable/select bits of the DSCR. However, as the article notes, an exception handler is still helpful in order to catch disconnected debuggers. [1] https://tomverbeure.github.io/2021/12/30/Semihosting-on-RISCV.html#avoiding-hangs-when-a-debugger-is-not-connected Signed-off-by: Sean Anderson --- include/semihosting.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'include') diff --git a/include/semihosting.h b/include/semihosting.h index 9816233c508..f1f73464e4f 100644 --- a/include/semihosting.h +++ b/include/semihosting.h @@ -6,6 +6,17 @@ #ifndef _SEMIHOSTING_H #define _SEMIHOSTING_H +/* + * These are the encoded instructions used to indicate a semihosting trap. They + * are named like SMH_ISA_INSN, where ISA is the instruction set (e.g. + * AArch64), and INSN is the mneumonic for the instruction. + */ +#define SMH_A64_HLT 0xD45E0000 +#define SMH_A32_SVC 0xEF123456 +#define SMH_A32_HLT 0xE10F0070 +#define SMH_T32_SVC 0xDFAB +#define SMH_T32_HLT 0xBABC + #if CONFIG_IS_ENABLED(SEMIHOSTING_FALLBACK) /** * semihosting_enabled() - Determine whether semihosting is supported -- cgit v1.2.3 From 7a763471894feb58d5a1bdf78ea7014c7a952264 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Tue, 22 Mar 2022 16:59:34 -0400 Subject: serial: dm: Add support for puts Some serial drivers can be vastly more efficient when printing multiple characters at once. Non-DM serial has had a puts option for these sorts of drivers; implement it for DM serial as well. Because we have to add carriage returns, we can't just pass the whole string directly to the serial driver. Instead, we print up to the newline, then print a carriage return, and then continue on. This is less efficient, but it is better than printing each character individually. It also avoids having to allocate memory just to add a few characters. Drivers may perform short writes (such as filling a FIFO) and return the number of characters written in len. We loop over them in the same way that _serial_putc loops over putc. This results in around sizeof(void *) growth for all boards with DM_SERIAL. The full implementation takes around 140 bytes. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- include/serial.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'include') diff --git a/include/serial.h b/include/serial.h index 2681d26c829..8c2e7adbc32 100644 --- a/include/serial.h +++ b/include/serial.h @@ -195,6 +195,24 @@ struct dm_serial_ops { * @return 0 if OK, -ve on error */ int (*putc)(struct udevice *dev, const char ch); + /** + * puts() - Write a string + * + * This writes a string. This function should be implemented only if + * writing multiple characters at once is more performant than just + * calling putc() in a loop. + * + * If the whole string cannot be written at once, then this function + * should return the number of characters written. Returning a negative + * error code implies that no characters were written. If this function + * returns 0, then it will be called again with the same arguments. + * + * @dev: Device pointer + * @s: The string to write + * @len: The length of the string to write. + * @return The number of characters written on success, or -ve on error + */ + ssize_t (*puts)(struct udevice *dev, const char *s, size_t len); /** * pending() - Check if input/output characters are waiting * -- cgit v1.2.3