[PATCH 1/6] ARM: lib32: semihosting: prepare for more general use

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Jun 10 23:59:18 PDT 2024


So far, we limited semihosting support to 32-bit ARM, but it's also
usable on ARM64 and even RISC-V. Move the common code to
drivers/firmware, so it can be shared by all architectures.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/arm/Kconfig                              |  1 +
 arch/arm/cpu/Makefile                         |  2 ++
 .../semihosting-trap_32.S}                    |  2 +-
 arch/arm/include/asm/semihosting.h            | 15 +-----------
 arch/arm/lib32/Makefile                       |  1 -
 drivers/firmware/Kconfig                      |  3 +++
 drivers/firmware/Makefile                     |  1 +
 .../lib32 => drivers/firmware}/semihosting.c  |  0
 fs/Kconfig                                    |  2 +-
 include/asm-generic/semihosting.h             | 23 +++++++++++++++++++
 10 files changed, 33 insertions(+), 17 deletions(-)
 rename arch/arm/{lib32/semihosting-trap.S => cpu/semihosting-trap_32.S} (84%)
 rename {arch/arm/lib32 => drivers/firmware}/semihosting.c (100%)
 create mode 100644 include/asm-generic/semihosting.h

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index be18b609c782..26547cd3ba71 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -373,6 +373,7 @@ config ARM_UNWIND
 config ARM_SEMIHOSTING
 	bool "enable ARM semihosting support"
 	depends on !CPU_V8
+	select SEMIHOSTING
 	help
 	  This option enables ARM semihosting support in barebox. ARM
 	  semihosting is a communication discipline that allows code
diff --git a/arch/arm/cpu/Makefile b/arch/arm/cpu/Makefile
index 28161cd7d714..999cc375da1c 100644
--- a/arch/arm/cpu/Makefile
+++ b/arch/arm/cpu/Makefile
@@ -23,6 +23,8 @@ obj-pbl-y += setupc_$(S64_32).o cache_$(S64_32).o
 
 obj-$(CONFIG_ARM_PSCI_CLIENT) += psci-client.o
 
+obj-$(CONFIG_ARM_SEMIHOSTING) += semihosting-trap_$(S64_32).o
+
 #
 # Any variants can be called as start-armxyz.S
 #
diff --git a/arch/arm/lib32/semihosting-trap.S b/arch/arm/cpu/semihosting-trap_32.S
similarity index 84%
rename from arch/arm/lib32/semihosting-trap.S
rename to arch/arm/cpu/semihosting-trap_32.S
index f7960d7cea96..069cdaa1dd38 100644
--- a/arch/arm/lib32/semihosting-trap.S
+++ b/arch/arm/cpu/semihosting-trap_32.S
@@ -2,7 +2,7 @@
 /* SPDX-FileCopyrightText: 2015 Zodiac Inflight Innovations */
 
 /*
- * semihosting-trap.S -- Assembly code needed to make a semihosting call
+ * semihosting-trap_32.S -- Assembly code needed to make a semihosting call
  *
  * Author: Andrey Smirnov <andrew.smirnov at gmail.com>
  */
diff --git a/arch/arm/include/asm/semihosting.h b/arch/arm/include/asm/semihosting.h
index 9e1606c4aeaa..c18aa1a5fef5 100644
--- a/arch/arm/include/asm/semihosting.h
+++ b/arch/arm/include/asm/semihosting.h
@@ -3,19 +3,6 @@
 #ifndef __ASM_ARM_SEMIHOSTING_H
 #define __ASM_ARM_SEMIHOSTING_H
 
-int semihosting_open(const char *fname, int flags);
-int semihosting_close(int fd);
-int semihosting_writec(char c);
-int semihosting_write0(const char *str);
-ssize_t semihosting_write(int fd, const void *buf, size_t count);
-ssize_t semihosting_read(int fd, void *buf, size_t count);
-int semihosting_readc(void);
-int semihosting_isatty(int fd);
-int semihosting_seek(int fd, loff_t pos);
-int semihosting_flen(int fd);
-int semihosting_remove(const char *fname);
-int semihosting_rename(const char *fname1, const char *fname2);
-int semihosting_errno(void);
-int semihosting_system(const char *command);
+#include <asm-generic/semihosting.h>
 
 #endif
diff --git a/arch/arm/lib32/Makefile b/arch/arm/lib32/Makefile
index d54fb7644c39..511a029062e6 100644
--- a/arch/arm/lib32/Makefile
+++ b/arch/arm/lib32/Makefile
@@ -23,7 +23,6 @@ pbl-y	+= runtime-offset.o
 obj-$(CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS)	+= memcpy.o
 obj-$(CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS)	+= memset.o
 obj-$(CONFIG_ARM_UNWIND) += unwind.o
-obj-$(CONFIG_ARM_SEMIHOSTING) += semihosting-trap.o semihosting.o
 obj-$(CONFIG_MODULES) += module.o
 obj-$(CONFIG_ARM_MODULE_PLTS) += module-plts.o
 extra-y += barebox.lds
diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig
index 3252b61bc764..89c8bdeda3f0 100644
--- a/drivers/firmware/Kconfig
+++ b/drivers/firmware/Kconfig
@@ -1,6 +1,9 @@
 # SPDX-License-Identifier: GPL-2.0-only
 menu "Firmware Drivers"
 
+config SEMIHOSTING
+	bool
+
 config FIRMWARE_ALTERA_SERIAL
 	bool "Altera SPI programming"
 	depends on OFDEVICE
diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile
index 4eabf42fd639..d0ebe663ea55 100644
--- a/drivers/firmware/Makefile
+++ b/drivers/firmware/Makefile
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_SEMIHOSTING) += semihosting.o
 obj-$(CONFIG_FIRMWARE_ALTERA_SERIAL) += altera_serial.o
 obj-$(CONFIG_FIRMWARE_ALTERA_SOCFPGA) += socfpga.o socfpga_sdr.o
 obj-$(CONFIG_FIRMWARE_ZYNQMP_FPGA) += zynqmp-fpga.o
diff --git a/arch/arm/lib32/semihosting.c b/drivers/firmware/semihosting.c
similarity index 100%
rename from arch/arm/lib32/semihosting.c
rename to drivers/firmware/semihosting.c
diff --git a/fs/Kconfig b/fs/Kconfig
index a3ba84b6aefd..e02cb939a5cf 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -113,7 +113,7 @@ config FS_UIMAGEFS
 	prompt "uImage FS support"
 
 config FS_SMHFS
-	depends on ARM_SEMIHOSTING
+	depends on SEMIHOSTING
 	select FS_LEGACY
 	bool
 	prompt "Semihosting FS support"
diff --git a/include/asm-generic/semihosting.h b/include/asm-generic/semihosting.h
new file mode 100644
index 000000000000..d337c33ff486
--- /dev/null
+++ b/include/asm-generic/semihosting.h
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __ASM_GENERIC_SEMIHOSTING_H
+#define __ASM_GENERIC_SEMIHOSTING_H
+
+#include <linux/types.h>
+
+int semihosting_open(const char *fname, int flags);
+int semihosting_close(int fd);
+int semihosting_writec(char c);
+int semihosting_write0(const char *str);
+ssize_t semihosting_write(int fd, const void *buf, size_t count);
+ssize_t semihosting_read(int fd, void *buf, size_t count);
+int semihosting_readc(void);
+int semihosting_isatty(int fd);
+int semihosting_seek(int fd, loff_t pos);
+int semihosting_flen(int fd);
+int semihosting_remove(const char *fname);
+int semihosting_rename(const char *fname1, const char *fname2);
+int semihosting_errno(void);
+int semihosting_system(const char *command);
+
+#endif
-- 
2.39.2




More information about the barebox mailing list