mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH master 1/3] envfs: fix defaultenv_append_directory macro definition
@ 2023-08-17  7:39 Ahmad Fatoum
  2023-08-17  7:39 ` [PATCH master 2/3] test: arm: make multi_v8_defconfig.yaml a symlink to virt@ Ahmad Fatoum
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2023-08-17  7:39 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

defaultenv_append_directory is called as if it were a function and the
trailing semicolon can break parse of if-else statements. Wrap in do { }
while (0) to avoid this.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 include/envfs.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/envfs.h b/include/envfs.h
index d4e2c6110e65..abe0ffb96397 100644
--- a/include/envfs.h
+++ b/include/envfs.h
@@ -139,13 +139,13 @@ static inline int defaultenv_load(const char *dir, unsigned flags)
  * from the filename.
  */
 #define defaultenv_append_directory(name)			\
-	{							\
+	do {							\
 		extern char __bbenv_##name##_start[];		\
 		extern char __bbenv_##name##_end[];		\
 		defaultenv_append(__bbenv_##name##_start,	\
 				__bbenv_##name##_end -		\
 				__bbenv_##name##_start,		\
 				__stringify(name));		\
-	}
+	} while (0)
 
 #endif /* _ENVFS_H */
-- 
2.39.2




^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH master 2/3] test: arm: make multi_v8_defconfig.yaml a symlink to virt@
  2023-08-17  7:39 [PATCH master 1/3] envfs: fix defaultenv_append_directory macro definition Ahmad Fatoum
@ 2023-08-17  7:39 ` Ahmad Fatoum
  2023-08-17  7:39 ` [PATCH master 3/3] sandbox: store stickypage in runtime dir Ahmad Fatoum
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2023-08-17  7:39 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

multi_v8_defconfig builds images for Virt, ZynqMP, Rockchip and i.MX.
Convention is for unadorned Labgrid environment file to be a symlink to
a file with a more telling name.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 test/arm/multi_v8_defconfig.yaml      | 23 +----------------------
 test/arm/virt@multi_v8_defconfig.yaml | 22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+), 22 deletions(-)
 mode change 100644 => 120000 test/arm/multi_v8_defconfig.yaml
 create mode 100644 test/arm/virt@multi_v8_defconfig.yaml

diff --git a/test/arm/multi_v8_defconfig.yaml b/test/arm/multi_v8_defconfig.yaml
deleted file mode 100644
index d8f8ab5cbff3..000000000000
--- a/test/arm/multi_v8_defconfig.yaml
+++ /dev/null
@@ -1,22 +0,0 @@
-targets:
-  main:
-    drivers:
-      QEMUDriver:
-        qemu_bin: qemu-system-aarch64
-        machine: virt,highmem=off
-        cpu: cortex-a57
-        memory: 1024M
-        kernel: barebox-dt-2nd.img
-        extra_args: ''
-      BareboxDriver:
-        prompt: 'barebox@[^:]+:[^ ]+ '
-        bootstring: 'commandline:'
-      BareboxTestStrategy: {}
-    features:
-      - virtio-mmio
-    runner:
-      tuxmake_arch: arm64
-images:
-  barebox-dt-2nd.img: !template "$LG_BUILDDIR/images/barebox-dt-2nd.img"
-imports:
-  -  ../strategy.py
diff --git a/test/arm/multi_v8_defconfig.yaml b/test/arm/multi_v8_defconfig.yaml
new file mode 120000
index 000000000000..cbf4d40e3f0a
--- /dev/null
+++ b/test/arm/multi_v8_defconfig.yaml
@@ -0,0 +1 @@
+virt@multi_v8_defconfig.yaml
\ No newline at end of file
diff --git a/test/arm/virt@multi_v8_defconfig.yaml b/test/arm/virt@multi_v8_defconfig.yaml
new file mode 100644
index 000000000000..d8f8ab5cbff3
--- /dev/null
+++ b/test/arm/virt@multi_v8_defconfig.yaml
@@ -0,0 +1,22 @@
+targets:
+  main:
+    drivers:
+      QEMUDriver:
+        qemu_bin: qemu-system-aarch64
+        machine: virt,highmem=off
+        cpu: cortex-a57
+        memory: 1024M
+        kernel: barebox-dt-2nd.img
+        extra_args: ''
+      BareboxDriver:
+        prompt: 'barebox@[^:]+:[^ ]+ '
+        bootstring: 'commandline:'
+      BareboxTestStrategy: {}
+    features:
+      - virtio-mmio
+    runner:
+      tuxmake_arch: arm64
+images:
+  barebox-dt-2nd.img: !template "$LG_BUILDDIR/images/barebox-dt-2nd.img"
+imports:
+  -  ../strategy.py
-- 
2.39.2




^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH master 3/3] sandbox: store stickypage in runtime dir
  2023-08-17  7:39 [PATCH master 1/3] envfs: fix defaultenv_append_directory macro definition Ahmad Fatoum
  2023-08-17  7:39 ` [PATCH master 2/3] test: arm: make multi_v8_defconfig.yaml a symlink to virt@ Ahmad Fatoum
@ 2023-08-17  7:39 ` Ahmad Fatoum
  2023-08-17  9:33 ` [PATCH master 1/3] envfs: fix defaultenv_append_directory macro definition Marco Felsch
  2023-08-18  6:00 ` Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2023-08-17  7:39 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The stickypage is a hack to have a 4K hostfile persist over reboot. This
was so far done by compiling the stickypage separately and referencing
it from the device tree via the magic $build variable that expands to
the working directory.

This breaks a number of assumptions:
  - KBUILD_IMAGE: should only have a single entry, e.g.
    barebox-flash-images ends up with two files per one line

  - stickypage must be writable, which may fail if barebox is installed,
    e.g. in r/o Nix Store

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 .gitignore                                    |  2 -
 Makefile                                      |  2 +-
 arch/sandbox/Makefile                         |  9 +--
 arch/sandbox/board/.gitignore                 |  1 -
 arch/sandbox/board/Makefile                   |  7 +-
 arch/sandbox/board/hostfile.c                 | 22 ++++--
 arch/sandbox/board/stickypage.S               |  3 +
 arch/sandbox/dts/sandbox.dts                  |  3 +-
 .../sandbox/mach-sandbox/include/mach/linux.h |  2 +-
 arch/sandbox/os/common.c                      | 76 +++++++++++++++----
 10 files changed, 87 insertions(+), 40 deletions(-)

diff --git a/.gitignore b/.gitignore
index d2487d548376..3b9cd6a25aff 100644
--- a/.gitignore
+++ b/.gitignore
@@ -45,7 +45,6 @@ Module.symvers
 /TAGS
 /barebox*
 /System.map
-/stickypage.bin
 
 #
 # git files that we don't want to ignore even it they are dot-files
@@ -95,4 +94,3 @@ GTAGS
 /allrandom.config
 /allyes.config
 /compile_commands.json
-/stickypage.bin
diff --git a/Makefile b/Makefile
index 1efe90f41ce7..9777a4d0c5ec 100644
--- a/Makefile
+++ b/Makefile
@@ -1141,7 +1141,7 @@ endif # CONFIG_MODULES
 
 # Directories & files removed with 'make clean'
 CLEAN_DIRS  += $(MODVERDIR)
-CLEAN_FILES +=	barebox System.map stickypage.bin include/generated/barebox_default_env.h \
+CLEAN_FILES +=	barebox System.map include/generated/barebox_default_env.h \
                 .tmp_version .tmp_barebox* barebox.bin barebox.map \
 		.tmp_kallsyms* barebox.ldr compile_commands.json \
 		barebox-flash-image \
diff --git a/arch/sandbox/Makefile b/arch/sandbox/Makefile
index 04fa426b1a61..c2906c0b1c0c 100644
--- a/arch/sandbox/Makefile
+++ b/arch/sandbox/Makefile
@@ -31,7 +31,8 @@ KBUILD_CFLAGS += -Dmalloc=barebox_malloc -Dcalloc=barebox_calloc \
 		-Dclosedir=barebox_closedir -Dreadlink=barebox_readlink \
 		-Doptarg=barebox_optarg -Doptind=barebox_optind \
 		-Dsetjmp=barebox_setjmp -Dlongjmp=barebox_longjmp \
-		-Dputchar=barebox_putchar
+		-Dmkdir=barebox_mkdir -Ddirname=barebox_dirname \
+		-Dremove=barebox_remove -Dputchar=barebox_putchar
 
 machdirs := $(patsubst %,arch/sandbox/mach-%/,$(machine-y))
 
@@ -75,11 +76,7 @@ cmd_barebox__ = $(CC) -o $@ $(BAREBOX_LDFLAGS)
 
 common-y += $(BOARD) arch/sandbox/os/ arch/sandbox/lib/
 
-stickypage.bin:
-	@$(kecho) "  LN      stickypage.bin"
-	@ln -fs arch/sandbox/board/stickypage.bin stickypage.bin
-
-KBUILD_IMAGE := barebox stickypage.bin
+KBUILD_IMAGE := barebox
 
 common-$(CONFIG_OFTREE) += arch/sandbox/dts/
 
diff --git a/arch/sandbox/board/.gitignore b/arch/sandbox/board/.gitignore
index c0acd24b98b5..03987a700942 100644
--- a/arch/sandbox/board/.gitignore
+++ b/arch/sandbox/board/.gitignore
@@ -1,4 +1,3 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
 barebox.lds
-stickypage.bin
diff --git a/arch/sandbox/board/Makefile b/arch/sandbox/board/Makefile
index 11688c5aba45..b4bab02163fb 100644
--- a/arch/sandbox/board/Makefile
+++ b/arch/sandbox/board/Makefile
@@ -13,9 +13,4 @@ obj-$(CONFIG_LED) += led.o
 
 extra-y += barebox.lds
 
-extra-y += stickypage.bin
-
-OBJCOPYFLAGS_stickypage.bin = -O binary
-
-%.bin: %.o
-	$(call if_changed,objcopy)
+obj-y += stickypage.o
diff --git a/arch/sandbox/board/hostfile.c b/arch/sandbox/board/hostfile.c
index ca21703544af..225617fe910f 100644
--- a/arch/sandbox/board/hostfile.c
+++ b/arch/sandbox/board/hostfile.c
@@ -248,7 +248,20 @@ static int of_hostfile_map_fixup(struct device_node *root, void *ctx)
 	struct device_node *node;
 	int ret;
 
-	for_each_compatible_node_from(node, root, NULL, hostfile_dt_ids->compatible) {
+	for_each_compatible_node_from(node, root, NULL, "barebox,stickypage") {
+		char *filename;
+
+		filename = linux_get_stickypage_path();
+		if (!filename) {
+			pr_err("error allocating stickypage\n");
+			continue;
+		}
+
+		of_property_write_string(node, "barebox,filename", filename);
+		of_property_write_string(node, "compatible", "barebox,hostfile");
+	}
+
+	for_each_compatible_node_from(node, root, NULL, "barebox,hostfile") {
 		struct hf_info hf = {};
 		uint64_t reg[2] = {};
 
@@ -260,13 +273,6 @@ static int of_hostfile_map_fixup(struct device_node *root, void *ctx)
 			continue;
 		}
 
-		if (memcmp(hf.filename, "$build/", 7) == 0) {
-			char *fullpath = xasprintf("%s/%s", linux_get_builddir(),
-					           hf.filename + sizeof "$build/" - 1);
-
-			hf.filename = fullpath;
-		}
-
 		hf.is_blockdev = of_property_read_bool(node, "barebox,blockdev");
 		hf.is_cdev = of_property_read_bool(node, "barebox,cdev");
 		hf.is_readonly = of_property_read_bool(node, "barebox,read-only");
diff --git a/arch/sandbox/board/stickypage.S b/arch/sandbox/board/stickypage.S
index f1915ab986fd..1d3861c373f0 100644
--- a/arch/sandbox/board/stickypage.S
+++ b/arch/sandbox/board/stickypage.S
@@ -1,5 +1,8 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 
+.section .note.GNU-stack,"",%progbits
+.section .rodata.stickypage,"a"
+
 .globl stickypage;
 stickypage:
 
diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts
index 6a0ae77d65bd..f3fe6ce65c08 100644
--- a/arch/sandbox/dts/sandbox.dts
+++ b/arch/sandbox/dts/sandbox.dts
@@ -56,8 +56,7 @@ y {
 	};
 
 	stickypage: stickypage {
-		compatible = "barebox,hostfile", "syscon";
-		barebox,filename = "$build/stickypage.bin";
+		compatible = "barebox,stickypage", "syscon";
 		reg = <0 0 0 4096>;
 		barebox,cdev; /* no caching allowed */
 		barebox,feature-controller;
diff --git a/arch/sandbox/mach-sandbox/include/mach/linux.h b/arch/sandbox/mach-sandbox/include/mach/linux.h
index 028bc2fa9087..f4d91f08de8e 100644
--- a/arch/sandbox/mach-sandbox/include/mach/linux.h
+++ b/arch/sandbox/mach-sandbox/include/mach/linux.h
@@ -15,7 +15,7 @@ int linux_register_device(const char *name, void *start, void *end);
 int tap_alloc(const char *dev);
 uint64_t linux_get_time(void);
 int linux_open(const char *filename, int readwrite);
-const char *linux_get_builddir(void);
+char *linux_get_stickypage_path(void);
 int linux_open_hostfile(struct hf_info *hf);
 int linux_read(int fd, void *buf, size_t count);
 int linux_read_nonblock(int fd, void *buf, size_t count);
diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
index 2878eda29e08..3446074f99d0 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -75,6 +75,15 @@ static void cookmode(void)
 	tcsetattr(0, TCSANOW, &term_orig);
 }
 
+static char *stickypage_path;
+
+static void prepare_exit(void)
+{
+	cookmode();
+	if (stickypage_path)
+		remove(stickypage_path);
+}
+
 int linux_tstc(int fd)
 {
 	struct timeval tv = {
@@ -122,7 +131,7 @@ uint64_t linux_get_time(void)
 
 void __attribute__((noreturn)) linux_exit(void)
 {
-	cookmode();
+	prepare_exit();
 	exit(0);
 }
 
@@ -167,7 +176,7 @@ void linux_reexec(void)
 
 void linux_hang(void)
 {
-	cookmode();
+	prepare_exit();
 	/* falls through to generic hang() */
 }
 
@@ -329,19 +338,60 @@ static int add_image(const char *_str, char *devname_template, int *devname_numb
 	return ret;
 }
 
-const char *linux_get_builddir(void)
-{
-	static char path[4097];
-	int ret;
+extern uint8_t stickypage[4096];
 
-	if (!path[0]) {
-		ret = selfpath(path, sizeof(path));
-		if (ret < 0)
-			return NULL;
-		dirname(path);
+char *linux_get_stickypage_path(void)
+{
+	size_t nwritten;
+	ssize_t ret;
+	int fd;
+
+	ret = asprintf(&stickypage_path, "%s/barebox/stickypage.%lu",
+		       getenv("XDG_RUNTIME_DIR") ?: "/run", (long)getpid());
+	if (ret < 0)
+		goto err_asprintf;
+
+	ret = mkdir(dirname(stickypage_path), 0755);
+	if (ret < 0 && errno != EEXIST) {
+		perror("mkdir");
+		goto err_creat;
 	}
 
-	return path;
+	stickypage_path[strlen(stickypage_path)] = '/';
+
+	fd = open(stickypage_path, O_CREAT | O_WRONLY | O_TRUNC | O_EXCL, 0644);
+	if (fd < 0) {
+		if (errno == EEXIST)
+			return stickypage_path;
+
+		perror("open");
+		goto err_creat;
+	}
+
+	for (nwritten = 0; nwritten < sizeof(stickypage); ) {
+		ret = write(fd, &stickypage[nwritten], sizeof(stickypage) - nwritten);
+		if (ret < 0) {
+			if (errno == EINTR || errno == EAGAIN)
+				continue;
+			perror("write");
+			goto err_write;
+		}
+
+		nwritten += ret;
+	}
+
+	close(fd);
+
+	return stickypage_path;
+
+err_write:
+	close(fd);
+err_creat:
+	free(stickypage_path);
+err_asprintf:
+	stickypage_path = NULL;
+
+	return NULL;
 }
 
 int linux_open_hostfile(struct hf_info *hf)
@@ -469,7 +519,7 @@ int main(int argc, char *argv[])
 	char *aux;
 
 #ifdef CONFIG_ASAN
-	__sanitizer_set_death_callback(cookmode);
+	__sanitizer_set_death_callback(prepare_exit);
 #endif
 
 	while (1) {
-- 
2.39.2




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH master 1/3] envfs: fix defaultenv_append_directory macro definition
  2023-08-17  7:39 [PATCH master 1/3] envfs: fix defaultenv_append_directory macro definition Ahmad Fatoum
  2023-08-17  7:39 ` [PATCH master 2/3] test: arm: make multi_v8_defconfig.yaml a symlink to virt@ Ahmad Fatoum
  2023-08-17  7:39 ` [PATCH master 3/3] sandbox: store stickypage in runtime dir Ahmad Fatoum
@ 2023-08-17  9:33 ` Marco Felsch
  2023-08-18  6:00 ` Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Marco Felsch @ 2023-08-17  9:33 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On 23-08-17, Ahmad Fatoum wrote:
> defaultenv_append_directory is called as if it were a function and the
> trailing semicolon can break parse of if-else statements. Wrap in do { }
> while (0) to avoid this.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

Reviewed-by: Marco Felsch <m.felsch@pengutronix.de>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH master 1/3] envfs: fix defaultenv_append_directory macro definition
  2023-08-17  7:39 [PATCH master 1/3] envfs: fix defaultenv_append_directory macro definition Ahmad Fatoum
                   ` (2 preceding siblings ...)
  2023-08-17  9:33 ` [PATCH master 1/3] envfs: fix defaultenv_append_directory macro definition Marco Felsch
@ 2023-08-18  6:00 ` Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2023-08-18  6:00 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Thu, Aug 17, 2023 at 09:39:39AM +0200, Ahmad Fatoum wrote:
> defaultenv_append_directory is called as if it were a function and the
> trailing semicolon can break parse of if-else statements. Wrap in do { }
> while (0) to avoid this.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  include/envfs.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/include/envfs.h b/include/envfs.h
> index d4e2c6110e65..abe0ffb96397 100644
> --- a/include/envfs.h
> +++ b/include/envfs.h
> @@ -139,13 +139,13 @@ static inline int defaultenv_load(const char *dir, unsigned flags)
>   * from the filename.
>   */
>  #define defaultenv_append_directory(name)			\
> -	{							\
> +	do {							\
>  		extern char __bbenv_##name##_start[];		\
>  		extern char __bbenv_##name##_end[];		\
>  		defaultenv_append(__bbenv_##name##_start,	\
>  				__bbenv_##name##_end -		\
>  				__bbenv_##name##_start,		\
>  				__stringify(name));		\
> -	}
> +	} while (0)
>  
>  #endif /* _ENVFS_H */
> -- 
> 2.39.2
> 
> 
> 

-- 
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 |



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-08-18  6:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-17  7:39 [PATCH master 1/3] envfs: fix defaultenv_append_directory macro definition Ahmad Fatoum
2023-08-17  7:39 ` [PATCH master 2/3] test: arm: make multi_v8_defconfig.yaml a symlink to virt@ Ahmad Fatoum
2023-08-17  7:39 ` [PATCH master 3/3] sandbox: store stickypage in runtime dir Ahmad Fatoum
2023-08-17  9:33 ` [PATCH master 1/3] envfs: fix defaultenv_append_directory macro definition Marco Felsch
2023-08-18  6:00 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox