Skip to contentSkip to conversation

common: remove !SANDBOX dependency for target tools

PATCH Applied Ahmad Fatoum 2 participants 5 messages Sep 17, 2021 – Oct 2, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/4 common: remove !SANDBOX dependency for target tools

d4aa01503348 ("common: add dependency !SANDBOX on target tools") and later commits disabled building the target tools with sandbox, because the build failed when they were enabled.

This has been fixed since then. Remove the limitation, so target tools can be cross-compiled when using the ARCH=sandbox.

---
v1 -> v2:
- no change

---
 common/Kconfig | 3 ---
 1 file changed, 3 deletions(-)
common/Kconfig +0 -3
index a9feae2ae866..222a438ee545 100644
@@ -740,7 +740,6 @@ config IMD_TARGET
 
 config KERNEL_INSTALL_TARGET
 	bool
-	depends on !SANDBOX
 	prompt "Build kernel-install utility for the target"
 	help
 	  Enable this to compile the kernel-install script using the cross
@@ -983,7 +982,6 @@ config DEFAULT_ENVIRONMENT_PATH
 
 config BAREBOXENV_TARGET
 	bool
-	depends on !SANDBOX
 	prompt "build bareboxenv tool for target"
 	help
 	  'bareboxenv' is a tool to access the barebox environment from a running Linux
@@ -992,7 +990,6 @@ config BAREBOXENV_TARGET
 config BAREBOXCRC32_TARGET
 	bool
 	prompt "build bareboxcrc32 tool for target"
-	depends on !SANDBOX
 	help
 	  'bareboxcrc32' is a userspacetool to generate the crc32 checksums the same way
 	  barebox does. Say yes here to build it for the target.
Signature · 7 lines
2.30.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH v2 2/4 common: add new menu for target tools

We have four target tools and will add 3 more in a follow up commit. Add a new menu to collect them.

---
v1 -> v2:
- no change

---
 common/Kconfig  | 26 --------------------------
 scripts/Kconfig | 30 ++++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 26 deletions(-)
common/Kconfig +0 -26
index 222a438ee545..9dab7532e15e 100644
@@ -734,18 +734,6 @@ config IMD
 	select CRC32
 	bool "barebox metadata support"
 
-config IMD_TARGET
-	bool "build bareboximd target tool"
-	depends on IMD
-
-config KERNEL_INSTALL_TARGET
-	bool
-	prompt "Build kernel-install utility for the target"
-	help
-	  Enable this to compile the kernel-install script using the cross
-	  compiler. The utility for the target will be under
-	  scripts/kernel-install-target
-
 choice
 	prompt "console support"
 	default CONSOLE_FULL
@@ -980,20 +968,6 @@ config DEFAULT_ENVIRONMENT_PATH
 	  be taken. Relative paths will be relative to the barebox top-level
 	  directory, but absolute paths are fine as well.
 
-config BAREBOXENV_TARGET
-	bool
-	prompt "build bareboxenv tool for target"
-	help
-	  'bareboxenv' is a tool to access the barebox environment from a running Linux
-	  system. Say yes here to build it for the target.
-
-config BAREBOXCRC32_TARGET
-	bool
-	prompt "build bareboxcrc32 tool for target"
-	help
-	  'bareboxcrc32' is a userspacetool to generate the crc32 checksums the same way
-	  barebox does. Say yes here to build it for the target.
-
 config HAS_SCHED
 	bool
 
scripts/Kconfig +30 -0
index b903486ecd8f..f7ed775fbc66 100644
@@ -40,3 +40,33 @@ config OMAP4_HOSTTOOL_USBBOOT
 	  You need libusb-1.0 to compile this tool.
 
 endmenu
+
+menu "Target Tools"
+
+config IMD_TARGET
+	bool "build bareboximd target tool"
+	depends on IMD
+
+config KERNEL_INSTALL_TARGET
+	bool
+	prompt "Build kernel-install utility for the target"
+	help
+	  Enable this to compile the kernel-install script using the cross
+	  compiler. The utility for the target will be under
+	  scripts/kernel-install-target
+
+config BAREBOXENV_TARGET
+	bool
+	prompt "build bareboxenv tool for target"
+	help
+	  'bareboxenv' is a tool to access the barebox environment from a running Linux
+	  system. Say yes here to build it for the target.
+
+config BAREBOXCRC32_TARGET
+	bool
+	prompt "build bareboxcrc32 tool for target"
+	help
+	  'bareboxcrc32' is a userspacetool to generate the crc32 checksums the same way
+	  barebox does. Say yes here to build it for the target.
+
+endmenu
Signature · 7 lines
2.30.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH v2 3/4 scripts: omap3-usb-loader: make proper use of pkg-config --cflags

In reply to Ahmad Fatoum

pkg-config --cflags libusb-1.0 should ensure <libusb.h> would be found. Command's output is used to compile omap3-usb-loader.c, but because the file does #include <libusb-1.0/libusb.h>, it will probably not find the header in the directory added to search path by pkg-config and depend on other directories in the search path. Fix this. We already expect users to have proper pkg-config files, so linking works, so it's not too much to ask to expect the pkg-config file that should already exist to yield proper --cflags as well.

---
v1 -> v2:
- new alternate commit after Trent's feedback

---
 scripts/omap3-usb-loader.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/omap3-usb-loader.c +1 -1
index 599a93856ac3..0f352c8453fc 100644
@@ -28,7 +28,7 @@
 #include <errno.h>
 #include <libgen.h>		/* for basename */
 
-#include <libusb-1.0/libusb.h>		/* the main event */
+#include <libusb.h>		/* the main event */
 
 /* Device specific defines (OMAP)
  * Primary source: http://www.ti.com/lit/pdf/sprugn4
Signature · 7 lines
2.30.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

PATCH v2 4/4 scripts: allow building USB loader tools for target as well

In reply to Ahmad Fatoum

We currently build the USB loader tools only for the host (build) system, but it can be useful to cross compile them as well for the target.

We already have some target tools, but support for those is easier, because they don't link against libraries. We use pkg-config to get cc and ld flags, but we always assume that pkg-config is for the host system and there is no well-defined way to request pkg-config for the target system.

Support this by introducing a new CROSS_PKG_CONFIG. This will be consulted only for target tools and default to $(CROSS_COMPILE)pkgconfig.

Users can override it as necessary, for example, with Yocto, pkg-config will be for the cross environment, so target tools can now be built with:

export ARCH=sandbox CROSS_COMPILE=aarch64-linux-gnu- export CROSS_PKG_CONFIG=pkg-config scripts make targettools_defconfig
make scripts

---
v1 -> v2:
- add kwboot target tool (Enrico)
- fix CONFIG_CONFIG_ option (Enrico)
- remove unneeded CONFIG_COMPILE_HOSTTOOLS in targettools_defconfig
- use correct target Kconfig symbol in Makefile

---
 Documentation/user/barebox.rst             | 45 ++++++++++++++++++++++
 Makefile                                   |  9 ++++-
 arch/sandbox/configs/targettools_defconfig |  9 +++++
 scripts/.gitignore                         |  3 ++
 scripts/Kconfig                            | 35 +++++++++++++++++
 scripts/Makefile                           | 10 ++++-
 scripts/imx/.gitignore                     |  1 +
 scripts/imx/Makefile                       | 10 +++++
 scripts/imx/imx-target.c                   |  1 +
 scripts/imx/imx-usb-loader-target.c        |  1 +
 scripts/kwboot-target.c                    |  1 +
 scripts/omap3-usb-loader-target.c          |  1 +
 scripts/omap4_usbboot-target.c             |  1 +
 13 files changed, 125 insertions(+), 2 deletions(-)
 create mode 100644 arch/sandbox/configs/targettools_defconfig
 create mode 100644 scripts/imx/imx-target.c
 create mode 100644 scripts/imx/imx-usb-loader-target.c
 create mode 100644 scripts/kwboot-target.c
 create mode 100644 scripts/omap3-usb-loader-target.c
 create mode 100644 scripts/omap4_usbboot-target.c
Documentation/user/barebox.rst +45 -0
index 503f0b979777..b6b7a57af300 100644
@@ -262,3 +262,48 @@ the usage for a particular command. barebox has tab completion which will comple
 your command. Arguments to commands are also completed depending on the command. If
 a command expects a file argument only files will be offered as completion. Other
 commands will only complete devices or devicetree nodes.
+
+Building barebox tools
+----------------------
+
+The normal barebox build results in one or more barebox images (cf. :ref:`multi_image`)
+and a number of tools built from its ``scripts/`` directory.
+
+Most tools are used for the barebox build itself: e.g. the device tree compiler,
+the Kconfig machinery and the different image formatting tools that wrap barebox,
+so it may be loaded by the boot ROM of the relevant SoCs.
+
+In addition to these barebox also builds host and target tools that are useful
+outside of barebox build: e.g. to manipulate the environment or to load an
+image over a boot ROM's USB recovery protocol.
+
+There are two ``ARCH=sandbox`` to make this more straight forward:
+
+Host Tools
+^^^^^^^^^^
+
+The ``hosttools_defconfig`` will compile standalone host tools for the
+host (build) system. To build the USB loaders, ``pkg-config`` needs to know
+about ``libusb-1.0``.
+
+.. code-block:: console
+
+  export ARCH=sandbox
+  make hosttools_defconfig
+  make scripts
+
+Target Tools
+^^^^^^^^^^^^
+
+The ``targettools_defconfig`` will cross-compile standalone target tools for the
+target system.  To build the USB loaders, ``CROSS_PKG_CONFIG`` needs to know
+about ``libusb-1.0``. This config won't built any host tools, so it's ok to
+set ``CROSS_PKG_CONFIG=pkg-config`` if ``pkg-config`` is primed for target
+use. The default is ``CROSS_PKG_CONFIG=$(CROSS_COMPILE)pkg-config``. Example:
+
+.. code-block:: console
+
+  export ARCH=sandbox CROSS_COMPILE=aarch64-linux-gnu-
+  export CROSS_PKG_CONFIG=pkg-config
+  make targettools_defconfig
+  make scripts
Makefile +8 -1
index 74e4893f02c8..bb00cfbe08ed 100644
@@ -362,6 +362,8 @@ endif
 
 KCONFIG_CONFIG	?= .config
 
+CROSS_PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
+
 export KCONFIG_CONFIG
 
 # SHELL used by kbuild
@@ -1126,11 +1128,16 @@ CLEAN_DIRS  += $(MODVERDIR)
 CLEAN_FILES +=	barebox System.map stickypage.bin include/generated/barebox_default_env.h \
                 .tmp_version .tmp_barebox* barebox.bin barebox.map \
 		.tmp_kallsyms* barebox.ldr compile_commands.json \
-		scripts/bareboxenv-target barebox-flash-image \
+		barebox-flash-image \
 		barebox.srec barebox.s5p barebox.ubl barebox.zynq \
 		barebox.uimage barebox.spi barebox.kwb barebox.kwbuart \
 		barebox.efi barebox.canon-a1100.bin
 
+CLEAN_FILES +=	scripts/bareboxenv-target scripts/kernel-install-target \
+		scripts/bareboxcrc32-target scripts/bareboximd-target \
+		scripts/omap3-usb-loader-target scripts/omap4_usbboot-target \
+		scripts/imx-usb-loader-target scripts/kwboot-target
+
 # Directories & files removed with 'make mrproper'
 MRPROPER_DIRS  += include/config usr/include include/generated Documentation/commands
 MRPROPER_FILES += .config .config.old .version .old_version \
arch/sandbox/configs/targettools_defconfig new file +9 -0
new file mode 100644
index 000000000000..d06074790c02
@@ -0,0 +1,9 @@
+CONFIG_IMD=y
+CONFIG_IMD_TARGET=y
+CONFIG_KERNEL_INSTALL_TARGET=y
+CONFIG_BAREBOXENV_TARGET=y
+CONFIG_BAREBOXCRC32_TARGET=y
+CONFIG_MVEBU_KWBOOT_TARGET=y
+CONFIG_ARCH_IMX_USBLOADER_TARGET=y
+CONFIG_OMAP3_USB_LOADER_TARGET=y
+CONFIG_OMAP4_USBBOOT_TARGET=y
scripts/.gitignore +3 -0
index 9577d568edd0..cf645ec74661 100644
@@ -8,6 +8,7 @@ bareboximd
 kallsyms
 kwbimage
 kwboot
+kwboot-target
 gen_netx_image
 omap_signGP
 mk-omap-image
@@ -27,7 +28,9 @@ mxsboot
 mxs-usb-loader
 /omap3-usb-loader
 omap4_usbboot
+omap4_usbboot-target
 omap3-usb-loader
+omap3-usb-loader-target
 mips-relocs
 rsatoc
 stm32image
scripts/Kconfig +35 -0
index f7ed775fbc66..a490aaa44ebb 100644
@@ -69,4 +69,39 @@ config BAREBOXCRC32_TARGET
 	  'bareboxcrc32' is a userspacetool to generate the crc32 checksums the same way
 	  barebox does. Say yes here to build it for the target.
 
+config HAS_TARGET_LIBUSB_1_0
+	def_bool $(success,$(CROSS_PKG_CONFIG) --exists libusb-1.0)
+	help
+	  Ensure $(CROSS_PKG_CONFIG) is set to a valid pkg-config
+	  binary that knows about libusb-1.0 compiled for the
+	  target architecture.
+
+config MVEBU_KWBOOT_TARGET
+	bool "kwboot target tool"
+	help
+	  Say Y here to build the kwboot tool for the target
+	  to bootstrap over UART.
+
+config ARCH_IMX_USBLOADER_TARGET
+	depends on HAS_TARGET_LIBUSB_1_0
+	bool "imx-usb-loader for target"
+	help
+	  Say Y here to build the imx-usb-loader tool for the target.
+	  The cross toolchain needs libusb-1.0 to compile this tool.
+
+config OMAP3_USB_LOADER_TARGET
+	bool "omap3 USB loader for target"
+	depends on HAS_TARGET_LIBUSB_1_0
+	help
+	  Say Y here to build the omap3 usb loader tool for the target.
+	  The cross toolchain needs libusb-1.0 to compile this tool.
+
+
+config OMAP4_USBBOOT_TARGET
+	bool "omap4 usbboot for target"
+	depends on HAS_TARGET_LIBUSB_1_0
+	help
+	  Say Y here to build the omap4 usb loader tool for the target.
+	  The cross toolchain needs libusb-1.0 to compile this tool.
+
 endmenu
scripts/Makefile +9 -1
index eb0f5c5805bb..1527b07d4723 100644
@@ -41,8 +41,16 @@ userprogs-always-$(CONFIG_BAREBOXENV_TARGET)		+= bareboxenv-target
 userprogs-always-$(CONFIG_KERNEL_INSTALL_TARGET)	+= kernel-install-target
 userprogs-always-$(CONFIG_BAREBOXCRC32_TARGET)		+= bareboxcrc32-target
 userprogs-always-$(CONFIG_IMD_TARGET)			+= bareboximd-target
+userprogs-always-$(CONFIG_OMAP3_USB_LOADER_TARGET)	+= omap3-usb-loader-target
+userprogs-always-$(CONFIG_OMAP4_USBBOOT_TARGET)		+= omap4_usbboot-target
+userprogs-always-$(CONFIG_MVEBU_KWBOOT_TARGET)		+= kwboot-target
 
-userccflags += -I $(srctree)/$(src)/include
+omap3-usb-loader-target-userccflags += `$(CROSS_PKG_CONFIG) --cflags libusb-1.0`
+omap3-usb-loader-target-userldlibs += `$(CROSS_PKG_CONFIG) --libs libusb-1.0`
+omap4_usbboot-target-userccflags += `$(CROSS_PKG_CONFIG) --cflags libusb-1.0`
+omap4_usbboot-target-userldlibs += -lpthread `$(CROSS_PKG_CONFIG) --libs libusb-1.0`
+
+userccflags += -I $(srctree)/$(src)/include -isystem $(srctree)/scripts/include
 
 subdir-y			+= mod
 subdir-y			+= imx
scripts/imx/.gitignore +1 -0
index 84e6f2b40617..341aec9ee435 100644
@@ -1,2 +1,3 @@
 imx-usb-loader
+imx-usb-loader-target
 imx-image
scripts/imx/Makefile +10 -0
index 029f9ca9f8af..a7f487a0452c 100644
@@ -4,13 +4,23 @@ hostprogs-always-$(CONFIG_ARCH_IMX_USBLOADER)	+= imx-usb-loader
 HOSTCFLAGS_imx-usb-loader.o = `pkg-config --cflags libusb-1.0`
 HOSTLDLIBS_imx-usb-loader  = `pkg-config --libs libusb-1.0`
 
+imx-usb-loader-target-userccflags += `$(CROSS_PKG_CONFIG) --cflags libusb-1.0`
+imx-usb-loader-target-userldlibs += `$(CROSS_PKG_CONFIG) --libs libusb-1.0`
+
 HOSTCFLAGS_imx.o = -I$(srctree)/arch/arm/mach-imx/include
+imx-target-userccflags += -I$(srctree)/arch/arm/mach-imx/include
 HOSTCFLAGS_imx-image.o = -I$(srctree) -I$(srctree)/arch/arm/mach-imx/include
 HOSTCFLAGS_imx-usb-loader.o += -I$(srctree) -I$(srctree)/arch/arm/mach-imx/include
+imx-usb-loader-target-userccflags += -I$(srctree) -I$(srctree)/arch/arm/mach-imx/include
 ifdef CONFIG_ARCH_IMX_IMXIMAGE_SSL_SUPPORT
 HOSTCFLAGS_imx-image.o += -DIMXIMAGE_SSL_SUPPORT
 HOSTLDLIBS_imx-image  = `pkg-config --libs openssl`
 endif
 
 imx-usb-loader-objs := imx-usb-loader.o imx.o
+imx-usb-loader-target-objs := imx-usb-loader-target.o imx-target.o
 imx-image-objs := imx-image.o imx.o
+
+userprogs-always-$(CONFIG_ARCH_IMX_USBLOADER_TARGET)	+= imx-usb-loader-target
+
+userccflags += -I $(srctree)/$(src)/include -isystem $(srctree)/scripts/include
scripts/imx/imx-target.c new file +1 -0
new file mode 100644
index 000000000000..4062eed6f60f
@@ -0,0 +1 @@
+#include "imx.c"
scripts/imx/imx-usb-loader-target.c new file +1 -0
new file mode 100644
index 000000000000..f2050aec1791
@@ -0,0 +1 @@
+#include "imx-usb-loader.c"
scripts/kwboot-target.c new file +1 -0
new file mode 100644
index 000000000000..68cde2d24ca2
@@ -0,0 +1 @@
+#include "kwboot.c"
scripts/omap3-usb-loader-target.c new file +1 -0
new file mode 100644
index 000000000000..c99c261a0253
@@ -0,0 +1 @@
+#include "omap3-usb-loader.c"
scripts/omap4_usbboot-target.c new file +1 -0
new file mode 100644
index 000000000000..3dd606533749
@@ -0,0 +1 @@
+#include "omap4_usbboot.c"
Signature · 7 lines
2.30.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#4 lore raw
In reply to Ahmad Fatoum
Quoted 7 lines · Ahmad Fatoum

d4aa01503348 ("common: add dependency !SANDBOX on target tools") and later commits disabled building the target tools with sandbox, because the build failed when they were enabled.

This has been fixed since then. Remove the limitation, so target tools can be cross-compiled when using the ARCH=sandbox.

Quoted 7 lines

---
v1 -> v2:
- no change

---
 common/Kconfig | 3 ---
 1 file changed, 3 deletions(-)

Applied, thanks

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox