Skip to contentSkip to conversation

CI: Set up for an arm64 runner

PATCH Superseded Simon Glass 4 participants 24 messages Nov 12, 2024 – Nov 15, 2024 Remote processor (remoteproc)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover CI: Set up for an arm64 runner

All gitlab runners are currently amd64 machines. This series attempts to create a docker image which can also support arm64 so that sandbox tests can be run on it.

The TARGET_... environment variables for grub could perhaps be adjusted, using the new variables, but I have not done that for now.

Currently this builds OK on amd64 but fails when built on arm64, in grub on arm64-efi:

2022.6 gcc -DHAVE_CONFIG_H -I. -I../../.. -D_FILE_OFFSET_BITS=64
-MT argp-pvh.o -MD -MP -MF $depbase.Tpo -c -o argp-pvh.o argp-pvh.c &&\
2022.6 mv -f $depbase.Tpo $depbase.Po
2023.0 gcc: internal compiler error: Segmentation fault signal terminated program cc1 2023.0 Please submit a full bug report,
2023.0 with preprocessed source if appropriate.
2023.0 See <file:///usr/share/doc/gcc-11/README.Bugs> for instructions. 2023.0 make[4]: *** [Makefile:1714: argp-pvh.o] Error 4

Perhaps this doesn't matter, though, at least for now.

Changes in v3:
- Move ARGs to the top
- Revise documentation to explain a common error and building on arm64
- Use grub-efi and linux-image-generic for both archs
- Add patch to install toolchains on arm64 host
- Drop patches which remove grub and tracing for arm64

Changes in v2:
- Drop message about EFI_LOADER
- Use '\0' instead of 0
- Update docs also
- Add comments to the ARG variables
- Swap order so that amd64 is the exception

Simon Glass (9):
sandbox: efi_loader: Correct use of addresses as pointers
test: Adjust print_ut test to use unsigned char
docker: Support building for multiple architectures
docker: Adjust packages for arm64
docker: Drop coreboot for arm64
docker: Fix LegacyKeyValueFormat warning with PYTHONPATH
docker: Install toolchains on arm64 host
CI: Add platform variable
WIP: CI: Update for arm64

 .gitlab-ci.yml                        | 11 ++--
 arch/sandbox/cpu/cache.c              |  8 ++-
 doc/build/docker.rst                  | 25 ++++++++--
 drivers/remoteproc/rproc-elf-loader.c | 18 ++++---
 lib/efi_loader/efi_image_loader.c     |  3 +-
 test/print_ut.c                       |  8 +--
 tools/docker/Dockerfile               | 72 +++++++++++++++++++--------
 7 files changed, 104 insertions(+), 41 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 1/9 sandbox: efi_loader: Correct use of addresses as pointers

The cache-flush function is incorrect which causes a crash in the remoteproc tests with arm64.

Fix both problems by using map_sysmem() to convert an address to a pointer and map_to_sysmem() to convert a pointer to an address.

Also update the image-loader's cache-flushing logic.

Fixes 3286d223fd7 ("sandbox: implement invalidate_icache_all()")

---

(no changes since v2)

Changes in v2:
- Drop message about EFI_LOADER

 arch/sandbox/cpu/cache.c              |  8 +++++++-
 drivers/remoteproc/rproc-elf-loader.c | 18 +++++++++++-------
 lib/efi_loader/efi_image_loader.c     |  3 ++-
 3 files changed, 20 insertions(+), 9 deletions(-)
arch/sandbox/cpu/cache.c +7 -1
index c8a5e64214b..96b3da47e8e 100644
@@ -4,12 +4,18 @@
  */
 
 #include <cpu_func.h>
+#include <mapmem.h>
 #include <asm/state.h>
 
 void flush_cache(unsigned long addr, unsigned long size)
 {
+	void *ptr;
+
+	ptr = map_sysmem(addr, size);
+
 	/* Clang uses (char *) parameters, GCC (void *) */
-	__builtin___clear_cache((void *)addr, (void *)(addr + size));
+	__builtin___clear_cache(map_sysmem(addr, size), ptr + size);
+	unmap_sysmem(ptr);
 }
 
 void invalidate_icache_all(void)
drivers/remoteproc/rproc-elf-loader.c +11 -7
index ab1836b3f07..0b3941b7798 100644
@@ -6,6 +6,7 @@
 #include <dm.h>
 #include <elf.h>
 #include <log.h>
+#include <mapmem.h>
 #include <remoteproc.h>
 #include <asm/cache.h>
 #include <dm/device_compat.h>
@@ -180,6 +181,7 @@ int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size)
 	for (i = 0; i < ehdr->e_phnum; i++, phdr++) {
 		void *dst = (void *)(uintptr_t)phdr->p_paddr;
 		void *src = (void *)addr + phdr->p_offset;
+		ulong dst_addr;
 
 		if (phdr->p_type != PT_LOAD)
 			continue;
@@ -195,10 +197,11 @@ int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size)
 		if (phdr->p_filesz != phdr->p_memsz)
 			memset(dst + phdr->p_filesz, 0x00,
 			       phdr->p_memsz - phdr->p_filesz);
-		flush_cache(rounddown((unsigned long)dst, ARCH_DMA_MINALIGN),
-			    roundup((unsigned long)dst + phdr->p_filesz,
+		dst_addr = map_to_sysmem(dst);
+		flush_cache(rounddown(dst_addr, ARCH_DMA_MINALIGN),
+			    roundup(dst_addr + phdr->p_filesz,
 				    ARCH_DMA_MINALIGN) -
-			    rounddown((unsigned long)dst, ARCH_DMA_MINALIGN));
+			    rounddown(dst_addr, ARCH_DMA_MINALIGN));
 	}
 
 	return 0;
@@ -377,6 +380,7 @@ int rproc_elf32_load_rsc_table(struct udevice *dev, ulong fw_addr,
 	const struct dm_rproc_ops *ops;
 	Elf32_Shdr *shdr;
 	void *src, *dst;
+	ulong dst_addr;
 
 	shdr = rproc_elf32_find_rsc_table(dev, fw_addr, fw_size);
 	if (!shdr)
@@ -398,10 +402,10 @@ int rproc_elf32_load_rsc_table(struct udevice *dev, ulong fw_addr,
 		(ulong)dst, *rsc_size);
 
 	memcpy(dst, src, *rsc_size);
-	flush_cache(rounddown((unsigned long)dst, ARCH_DMA_MINALIGN),
-		    roundup((unsigned long)dst + *rsc_size,
-			    ARCH_DMA_MINALIGN) -
-		    rounddown((unsigned long)dst, ARCH_DMA_MINALIGN));
+	dst_addr = map_to_sysmem(dst);
+	flush_cache(rounddown(dst_addr, ARCH_DMA_MINALIGN),
+		    roundup(dst_addr + *rsc_size, ARCH_DMA_MINALIGN) -
+		    rounddown(dst_addr, ARCH_DMA_MINALIGN));
 
 	return 0;
 }
lib/efi_loader/efi_image_loader.c +2 -1
index 0ddf69a0918..bb58cf1badb 100644
@@ -13,6 +13,7 @@
 #include <efi_loader.h>
 #include <log.h>
 #include <malloc.h>
+#include <mapmem.h>
 #include <pe.h>
 #include <sort.h>
 #include <crypto/mscode.h>
@@ -977,7 +978,7 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle,
 	}
 
 	/* Flush cache */
-	flush_cache((ulong)efi_reloc,
+	flush_cache(map_to_sysmem(efi_reloc),
 		    ALIGN(virt_size, EFI_CACHELINE_SIZE));
 
 	/*
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v3 1/9] sandbox: efi_loader: Correct use of addresses as pointers

Quoted 2 lines · Simon Glass

The cache-flush function is incorrect which causes a crash in the remoteproc tests with arm64.

We should throw out all these sandbox virtual addresses where they are not needed.

Just add the missing conversion to drivers/remoteproc/rproc-elf-loader.c.

And change flush_cache() on all architectures to use void *.

Best regards

Heinrich

Quoted 123 lines

Fix both problems by using map_sysmem() to convert an address to a pointer and map_to_sysmem() to convert a pointer to an address.

Also update the image-loader's cache-flushing logic.

Fixes 3286d223fd7 ("sandbox: implement invalidate_icache_all()")

---

(no changes since v2)

Changes in v2:
- Drop message about EFI_LOADER

  arch/sandbox/cpu/cache.c              |  8 +++++++-
  drivers/remoteproc/rproc-elf-loader.c | 18 +++++++++++-------
  lib/efi_loader/efi_image_loader.c     |  3 ++-
  3 files changed, 20 insertions(+), 9 deletions(-)
arch/sandbox/cpu/cache.c +7 -1
index c8a5e64214b..96b3da47e8e 100644
@@ -4,12 +4,18 @@
   */
 
  #include <cpu_func.h>
+#include <mapmem.h>
  #include <asm/state.h>
 
  void flush_cache(unsigned long addr, unsigned long size)
  {
+	void *ptr;
+
+	ptr = map_sysmem(addr, size);
+
  	/* Clang uses (char *) parameters, GCC (void *) */
-	__builtin___clear_cache((void *)addr, (void *)(addr + size));
+	__builtin___clear_cache(map_sysmem(addr, size), ptr + size);
+	unmap_sysmem(ptr);
  }
 
  void invalidate_icache_all(void)
drivers/remoteproc/rproc-elf-loader.c +11 -7
index ab1836b3f07..0b3941b7798 100644
@@ -6,6 +6,7 @@
  #include <dm.h>
  #include <elf.h>
  #include <log.h>
+#include <mapmem.h>
  #include <remoteproc.h>
  #include <asm/cache.h>
  #include <dm/device_compat.h>
@@ -180,6 +181,7 @@ int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size)
  	for (i = 0; i < ehdr->e_phnum; i++, phdr++) {
  		void *dst = (void *)(uintptr_t)phdr->p_paddr;
  		void *src = (void *)addr + phdr->p_offset;
+		ulong dst_addr;
 
  		if (phdr->p_type != PT_LOAD)
  			continue;
@@ -195,10 +197,11 @@ int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size)
  		if (phdr->p_filesz != phdr->p_memsz)
  			memset(dst + phdr->p_filesz, 0x00,
  			       phdr->p_memsz - phdr->p_filesz);
-		flush_cache(rounddown((unsigned long)dst, ARCH_DMA_MINALIGN),
-			    roundup((unsigned long)dst + phdr->p_filesz,
+		dst_addr = map_to_sysmem(dst);
+		flush_cache(rounddown(dst_addr, ARCH_DMA_MINALIGN),
+			    roundup(dst_addr + phdr->p_filesz,
  				    ARCH_DMA_MINALIGN) -
-			    rounddown((unsigned long)dst, ARCH_DMA_MINALIGN));
+			    rounddown(dst_addr, ARCH_DMA_MINALIGN));
  	}
 
  	return 0;
@@ -377,6 +380,7 @@ int rproc_elf32_load_rsc_table(struct udevice *dev, ulong fw_addr,
  	const struct dm_rproc_ops *ops;
  	Elf32_Shdr *shdr;
  	void *src, *dst;
+	ulong dst_addr;
 
  	shdr = rproc_elf32_find_rsc_table(dev, fw_addr, fw_size);
  	if (!shdr)
@@ -398,10 +402,10 @@ int rproc_elf32_load_rsc_table(struct udevice *dev, ulong fw_addr,
  		(ulong)dst, *rsc_size);
 
  	memcpy(dst, src, *rsc_size);
-	flush_cache(rounddown((unsigned long)dst, ARCH_DMA_MINALIGN),
-		    roundup((unsigned long)dst + *rsc_size,
-			    ARCH_DMA_MINALIGN) -
-		    rounddown((unsigned long)dst, ARCH_DMA_MINALIGN));
+	dst_addr = map_to_sysmem(dst);
+	flush_cache(rounddown(dst_addr, ARCH_DMA_MINALIGN),
+		    roundup(dst_addr + *rsc_size, ARCH_DMA_MINALIGN) -
+		    rounddown(dst_addr, ARCH_DMA_MINALIGN));
 
  	return 0;
  }
lib/efi_loader/efi_image_loader.c +2 -1
index 0ddf69a0918..bb58cf1badb 100644
@@ -13,6 +13,7 @@
  #include <efi_loader.h>
  #include <log.h>
  #include <malloc.h>
+#include <mapmem.h>
  #include <pe.h>
  #include <sort.h>
  #include <crypto/mscode.h>
@@ -977,7 +978,7 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle,
  	}
 
  	/* Flush cache */
-	flush_cache((ulong)efi_reloc,
+	flush_cache(map_to_sysmem(efi_reloc),
  		    ALIGN(virt_size, EFI_CACHELINE_SIZE));
 
  	/*
#3 lore raw

Re: [PATCH v3 1/9] sandbox: efi_loader: Correct use of addresses as pointers

Quoted 7 lines · Heinrich Schuchardt
Quoted 2 lines · Simon Glass

The cache-flush function is incorrect which causes a crash in the remoteproc tests with arm64.

We should throw out all these sandbox virtual addresses where they are not needed.

Quoted 7 lines

Just add the missing conversion to drivers/remoteproc/rproc-elf-loader.c.

And change flush_cache() on all architectures to use void *.

Best regards

Heinrich

There are a number of places where the flush_cache invocation currently assumes that sandbox virtual addresses are used.

We will have to wait until the complete separation of CLI from the rest of U-Boot to clean this up.

Quoted 132 lines
Quoted 131 lines

Fix both problems by using map_sysmem() to convert an address to a pointer and map_to_sysmem() to convert a pointer to an address.

Also update the image-loader's cache-flushing logic.

Fixes 3286d223fd7 ("sandbox: implement invalidate_icache_all()")

---

(no changes since v2)

Changes in v2:
- Drop message about EFI_LOADER

  arch/sandbox/cpu/cache.c              |  8 +++++++- drivers/remoteproc/rproc-elf-loader.c | 18 +++++++++++------- lib/efi_loader/efi_image_loader.c     |  3 ++-

  3 files changed, 20 insertions(+), 9 deletions(-)
arch/sandbox/cpu/cache.c +7 -1
index c8a5e64214b..96b3da47e8e 100644
@@ -4,12 +4,18 @@
    */
 
   #include <cpu_func.h>
+#include <mapmem.h>
   #include <asm/state.h>
 
   void flush_cache(unsigned long addr, unsigned long size)
   {
+    void *ptr;
+
+    ptr = map_sysmem(addr, size);
+
       /* Clang uses (char *) parameters, GCC (void *) */
-    __builtin___clear_cache((void *)addr, (void *)(addr + size));
+    __builtin___clear_cache(map_sysmem(addr, size), ptr + size);
+    unmap_sysmem(ptr);
   }
 
   void invalidate_icache_all(void)
drivers/ renamed from drivers/remoteproc/rproc-elf-loader.c +0 -0

remoteproc/rproc-elf-loader.c
index ab1836b3f07..0b3941b7798 100644

drivers/remoteproc/rproc-elf-loader.c +2 -0
@@ -6,6 +6,7 @@
   #include <dm.h>
   #include <elf.h>
   #include <log.h>
+#include <mapmem.h>
   #include <remoteproc.h>
   #include <asm/cache.h>
   #include <dm/device_compat.h>
@@ -180,6 +181,7 @@ int rproc_elf32_load_image(struct udevice *dev,
 unsigned long addr, ulong size)
       for (i = 0; i < ehdr->e_phnum; i++, phdr++) {
           void *dst = (void *)(uintptr_t)phdr->p_paddr;
           void *src = (void *)addr + phdr->p_offset;
+        ulong dst_addr;
 
           if (phdr->p_type != PT_LOAD)

              continue;

drivers/remoteproc/rproc-elf-loader.c +3 -2
@@ -195,10 +197,11 @@ int rproc_elf32_load_image(struct udevice *dev,
 unsigned long addr, ulong size)
           if (phdr->p_filesz != phdr->p_memsz)
               memset(dst + phdr->p_filesz, 0x00,
                      phdr->p_memsz - phdr->p_filesz);
-        flush_cache(rounddown((unsigned long)dst, ARCH_DMA_MINALIGN),
-                roundup((unsigned long)dst + phdr->p_filesz,
+        dst_addr = map_to_sysmem(dst);
+        flush_cache(rounddown(dst_addr, ARCH_DMA_MINALIGN),
+                roundup(dst_addr + phdr->p_filesz,

                      ARCH_DMA_MINALIGN) -
-                rounddown((unsigned long)dst, ARCH_DMA_MINALIGN)); +                rounddown(dst_addr, ARCH_DMA_MINALIGN)); }

      return 0;

drivers/remoteproc/rproc-elf-loader.c +1 -0
@@ -377,6 +380,7 @@ int rproc_elf32_load_rsc_table(struct udevice
 *dev, ulong fw_addr,
       const struct dm_rproc_ops *ops;
       Elf32_Shdr *shdr;
       void *src, *dst;
+    ulong dst_addr;
 
       shdr = rproc_elf32_find_rsc_table(dev, fw_addr, fw_size);

      if (!shdr)

drivers/remoteproc/rproc-elf-loader.c +4 -4
@@ -398,10 +402,10 @@ int rproc_elf32_load_rsc_table(struct udevice
 *dev, ulong fw_addr,
           (ulong)dst, *rsc_size);
 
       memcpy(dst, src, *rsc_size);
-    flush_cache(rounddown((unsigned long)dst, ARCH_DMA_MINALIGN),
-            roundup((unsigned long)dst + *rsc_size,
-                ARCH_DMA_MINALIGN) -
-            rounddown((unsigned long)dst, ARCH_DMA_MINALIGN));
+    dst_addr = map_to_sysmem(dst);
+    flush_cache(rounddown(dst_addr, ARCH_DMA_MINALIGN),
+            roundup(dst_addr + *rsc_size, ARCH_DMA_MINALIGN) -
+            rounddown(dst_addr, ARCH_DMA_MINALIGN));
 
       return 0;

  }

lib/efi_loader/ renamed from lib/efi_loader/efi_image_loader.c +0 -0

efi_image_loader.c
index 0ddf69a0918..bb58cf1badb 100644

lib/efi_loader/efi_image_loader.c +2 -1
@@ -13,6 +13,7 @@
   #include <efi_loader.h>
   #include <log.h>
   #include <malloc.h>
+#include <mapmem.h>
   #include <pe.h>
   #include <sort.h>
   #include <crypto/mscode.h>
@@ -977,7 +978,7 @@ efi_status_t efi_load_pe(struct
 efi_loaded_image_obj *handle,
       }
 
       /* Flush cache */
-    flush_cache((ulong)efi_reloc,
+    flush_cache(map_to_sysmem(efi_reloc),
               ALIGN(virt_size, EFI_CACHELINE_SIZE));
 

      /*

#4 lore raw

Re: [PATCH v3 1/9] sandbox: efi_loader: Correct use of addresses as pointers

In reply to Heinrich Schuchardt

Hi Heinrich,

Quoted 11 lines · Heinrich Schuchardt
Quoted 2 lines · Simon Glass

The cache-flush function is incorrect which causes a crash in the remoteproc tests with arm64.

We should throw out all these sandbox virtual addresses where they are not needed.

Just add the missing conversion to drivers/remoteproc/rproc-elf-loader.c.

And change flush_cache() on all architectures to use void *.

No, that is not the right approach. U-Boot uses addresses throughout (ulong), except when a pointer is strictly needed.

Regards,
Simon

#5 lore raw

Re: [PATCH v3 1/9] sandbox: efi_loader: Correct use of addresses as pointers

In reply to Simon Glass

Hi Simon,

Quoted 118 lines · Simon Glass

The cache-flush function is incorrect which causes a crash in the remoteproc tests with arm64.

Fix both problems by using map_sysmem() to convert an address to a pointer and map_to_sysmem() to convert a pointer to an address.

Also update the image-loader's cache-flushing logic.

Fixes 3286d223fd7 ("sandbox: implement invalidate_icache_all()")

---

(no changes since v2)

Changes in v2:
- Drop message about EFI_LOADER

 arch/sandbox/cpu/cache.c              |  8 +++++++-
 drivers/remoteproc/rproc-elf-loader.c | 18 +++++++++++-------
 lib/efi_loader/efi_image_loader.c     |  3 ++-
 3 files changed, 20 insertions(+), 9 deletions(-)
arch/sandbox/cpu/cache.c +7 -1
index c8a5e64214b..96b3da47e8e 100644
@@ -4,12 +4,18 @@
  */
 
 #include <cpu_func.h>
+#include <mapmem.h>
 #include <asm/state.h>
 
 void flush_cache(unsigned long addr, unsigned long size)
 {
+       void *ptr;
+
+       ptr = map_sysmem(addr, size);
+
        /* Clang uses (char *) parameters, GCC (void *) */
-       __builtin___clear_cache((void *)addr, (void *)(addr + size));
+       __builtin___clear_cache(map_sysmem(addr, size), ptr + size);
+       unmap_sysmem(ptr);
 }
 
 void invalidate_icache_all(void)
drivers/remoteproc/rproc-elf-loader.c +11 -7
index ab1836b3f07..0b3941b7798 100644
@@ -6,6 +6,7 @@
 #include <dm.h>
 #include <elf.h>
 #include <log.h>
+#include <mapmem.h>
 #include <remoteproc.h>
 #include <asm/cache.h>
 #include <dm/device_compat.h>
@@ -180,6 +181,7 @@ int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size)
        for (i = 0; i < ehdr->e_phnum; i++, phdr++) {
                void *dst = (void *)(uintptr_t)phdr->p_paddr;
                void *src = (void *)addr + phdr->p_offset;
+               ulong dst_addr;
 
                if (phdr->p_type != PT_LOAD)
                        continue;
@@ -195,10 +197,11 @@ int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size)
                if (phdr->p_filesz != phdr->p_memsz)
                        memset(dst + phdr->p_filesz, 0x00,
                               phdr->p_memsz - phdr->p_filesz);
-               flush_cache(rounddown((unsigned long)dst, ARCH_DMA_MINALIGN),
-                           roundup((unsigned long)dst + phdr->p_filesz,
+               dst_addr = map_to_sysmem(dst);
+               flush_cache(rounddown(dst_addr, ARCH_DMA_MINALIGN),
+                           roundup(dst_addr + phdr->p_filesz,
                                    ARCH_DMA_MINALIGN) -
-                           rounddown((unsigned long)dst, ARCH_DMA_MINALIGN));
+                           rounddown(dst_addr, ARCH_DMA_MINALIGN));
        }
 
        return 0;
@@ -377,6 +380,7 @@ int rproc_elf32_load_rsc_table(struct udevice *dev, ulong fw_addr,
        const struct dm_rproc_ops *ops;
        Elf32_Shdr *shdr;
        void *src, *dst;
+       ulong dst_addr;
 
        shdr = rproc_elf32_find_rsc_table(dev, fw_addr, fw_size);
        if (!shdr)
@@ -398,10 +402,10 @@ int rproc_elf32_load_rsc_table(struct udevice *dev, ulong fw_addr,
                (ulong)dst, *rsc_size);
 
        memcpy(dst, src, *rsc_size);
-       flush_cache(rounddown((unsigned long)dst, ARCH_DMA_MINALIGN),
-                   roundup((unsigned long)dst + *rsc_size,
-                           ARCH_DMA_MINALIGN) -
-                   rounddown((unsigned long)dst, ARCH_DMA_MINALIGN));
+       dst_addr = map_to_sysmem(dst);
+       flush_cache(rounddown(dst_addr, ARCH_DMA_MINALIGN),
+                   roundup(dst_addr + *rsc_size, ARCH_DMA_MINALIGN) -
+                   rounddown(dst_addr, ARCH_DMA_MINALIGN));
 
        return 0;
 }
lib/efi_loader/efi_image_loader.c +1 -0
index 0ddf69a0918..bb58cf1badb 100644
@@ -13,6 +13,7 @@
 #include <efi_loader.h>
 #include <log.h>
 #include <malloc.h>
+#include <mapmem.h>
 #include <pe.h>
 #include <sort.h>
 #include <crypto/mscode.h>

lib/efi_loader/efi_image_loader.c efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, · line 981

Quoted 5 lines
lib/efi_loader/efi_image_loader.c +1 -1
@@ -977,7 +978,7 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle,
        }
 
        /* Flush cache */
-       flush_cache((ulong)efi_reloc,
+       flush_cache(map_to_sysmem(efi_reloc),

Shouldn't we now umap that address on the err: tag?

Thanks
/Ilias

Quoted 6 lines
lib/efi_loader/efi_image_loader.c +0 -1
                    ALIGN(virt_size, EFI_CACHELINE_SIZE));
 
        /*
--

2.34.1

#6 lore raw

Re: [PATCH v3 1/9] sandbox: efi_loader: Correct use of addresses as pointers

Hi Ilias,

Quoted 124 lines · Ilias Apalodimas

Hi Simon,

Quoted 120 lines · Simon Glass

The cache-flush function is incorrect which causes a crash in the remoteproc tests with arm64.

Fix both problems by using map_sysmem() to convert an address to a pointer and map_to_sysmem() to convert a pointer to an address.

Also update the image-loader's cache-flushing logic.

Fixes 3286d223fd7 ("sandbox: implement invalidate_icache_all()")

---

(no changes since v2)

Changes in v2:
- Drop message about EFI_LOADER

 arch/sandbox/cpu/cache.c              |  8 +++++++-
 drivers/remoteproc/rproc-elf-loader.c | 18 +++++++++++-------
 lib/efi_loader/efi_image_loader.c     |  3 ++-
 3 files changed, 20 insertions(+), 9 deletions(-)
arch/sandbox/cpu/cache.c +7 -1
index c8a5e64214b..96b3da47e8e 100644
@@ -4,12 +4,18 @@
  */
 
 #include <cpu_func.h>
+#include <mapmem.h>
 #include <asm/state.h>
 
 void flush_cache(unsigned long addr, unsigned long size)
 {
+       void *ptr;
+
+       ptr = map_sysmem(addr, size);
+
        /* Clang uses (char *) parameters, GCC (void *) */
-       __builtin___clear_cache((void *)addr, (void *)(addr + size));
+       __builtin___clear_cache(map_sysmem(addr, size), ptr + size);
+       unmap_sysmem(ptr);
 }
 
 void invalidate_icache_all(void)
drivers/remoteproc/rproc-elf-loader.c +11 -7
index ab1836b3f07..0b3941b7798 100644
@@ -6,6 +6,7 @@
 #include <dm.h>
 #include <elf.h>
 #include <log.h>
+#include <mapmem.h>
 #include <remoteproc.h>
 #include <asm/cache.h>
 #include <dm/device_compat.h>
@@ -180,6 +181,7 @@ int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size)
        for (i = 0; i < ehdr->e_phnum; i++, phdr++) {
                void *dst = (void *)(uintptr_t)phdr->p_paddr;
                void *src = (void *)addr + phdr->p_offset;
+               ulong dst_addr;
 
                if (phdr->p_type != PT_LOAD)
                        continue;
@@ -195,10 +197,11 @@ int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size)
                if (phdr->p_filesz != phdr->p_memsz)
                        memset(dst + phdr->p_filesz, 0x00,
                               phdr->p_memsz - phdr->p_filesz);
-               flush_cache(rounddown((unsigned long)dst, ARCH_DMA_MINALIGN),
-                           roundup((unsigned long)dst + phdr->p_filesz,
+               dst_addr = map_to_sysmem(dst);
+               flush_cache(rounddown(dst_addr, ARCH_DMA_MINALIGN),
+                           roundup(dst_addr + phdr->p_filesz,
                                    ARCH_DMA_MINALIGN) -
-                           rounddown((unsigned long)dst, ARCH_DMA_MINALIGN));
+                           rounddown(dst_addr, ARCH_DMA_MINALIGN));
        }
 
        return 0;
@@ -377,6 +380,7 @@ int rproc_elf32_load_rsc_table(struct udevice *dev, ulong fw_addr,
        const struct dm_rproc_ops *ops;
        Elf32_Shdr *shdr;
        void *src, *dst;
+       ulong dst_addr;
 
        shdr = rproc_elf32_find_rsc_table(dev, fw_addr, fw_size);
        if (!shdr)
@@ -398,10 +402,10 @@ int rproc_elf32_load_rsc_table(struct udevice *dev, ulong fw_addr,
                (ulong)dst, *rsc_size);
 
        memcpy(dst, src, *rsc_size);
-       flush_cache(rounddown((unsigned long)dst, ARCH_DMA_MINALIGN),
-                   roundup((unsigned long)dst + *rsc_size,
-                           ARCH_DMA_MINALIGN) -
-                   rounddown((unsigned long)dst, ARCH_DMA_MINALIGN));
+       dst_addr = map_to_sysmem(dst);
+       flush_cache(rounddown(dst_addr, ARCH_DMA_MINALIGN),
+                   roundup(dst_addr + *rsc_size, ARCH_DMA_MINALIGN) -
+                   rounddown(dst_addr, ARCH_DMA_MINALIGN));
 
        return 0;
 }
lib/efi_loader/efi_image_loader.c +1 -0
index 0ddf69a0918..bb58cf1badb 100644
@@ -13,6 +13,7 @@
 #include <efi_loader.h>
 #include <log.h>
 #include <malloc.h>
+#include <mapmem.h>
 #include <pe.h>
 #include <sort.h>
 #include <crypto/mscode.h>
@@ -977,7 +978,7 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle,
        }
 
Quoted 5 lines

lib/efi_loader/efi_image_loader.c efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, · line 981

Quoted 3 lines
lib/efi_loader/efi_image_loader.c +1 -1
        /* Flush cache */
-       flush_cache((ulong)efi_reloc,
+       flush_cache(map_to_sysmem(efi_reloc),

Shouldn't we now umap that address on the err: tag?

This address should be in sandbox's DRAM, so there is no mapping created. The mapping is needed for things that are not in the emulated DRAM, such as stack variables.

Quoted 9 lines

Thanks
/Ilias

Quoted 6 lines
lib/efi_loader/efi_image_loader.c +0 -1
                    ALIGN(virt_size, EFI_CACHELINE_SIZE));
 
        /*
--

2.34.1

Regards,
Simon

#7 lore raw

Re: [PATCH v3 1/9] sandbox: efi_loader: Correct use of addresses as pointers

Quoted 142 lines · Simon Glass

Hi Ilias,

Quoted 50 lines · Ilias Apalodimas

Hi Simon,

Quoted 46 lines · Simon Glass

The cache-flush function is incorrect which causes a crash in the remoteproc tests with arm64.

Fix both problems by using map_sysmem() to convert an address to a pointer and map_to_sysmem() to convert a pointer to an address.

Also update the image-loader's cache-flushing logic.

Fixes 3286d223fd7 ("sandbox: implement invalidate_icache_all()")

---

(no changes since v2)

Changes in v2:
- Drop message about EFI_LOADER

 arch/sandbox/cpu/cache.c              |  8 +++++++-
 drivers/remoteproc/rproc-elf-loader.c | 18 +++++++++++-------
 lib/efi_loader/efi_image_loader.c     |  3 ++-
 3 files changed, 20 insertions(+), 9 deletions(-)
arch/sandbox/cpu/cache.c +7 -1
index c8a5e64214b..96b3da47e8e 100644
@@ -4,12 +4,18 @@
  */
 
 #include <cpu_func.h>
+#include <mapmem.h>
 #include <asm/state.h>
 
 void flush_cache(unsigned long addr, unsigned long size)
 {
+       void *ptr;
+
+       ptr = map_sysmem(addr, size);
+
        /* Clang uses (char *) parameters, GCC (void *) */
-       __builtin___clear_cache((void *)addr, (void *)(addr + size));
+       __builtin___clear_cache(map_sysmem(addr, size), ptr + size);
+       unmap_sysmem(ptr);
 }
 
Quoted 2 lines

Review

Quoted 2 lines
arch/sandbox/cpu/cache.c +0 -0
 void invalidate_icache_all(void)
(quoted diff) +0 -0

b/drivers/remoteproc/rproc-elf-loader.c

Quoted 4 lines
Quoted 4 lines

index ab1836b3f07..0b3941b7798 100644

drivers/remoteproc/rproc-elf-loader.c +0 -0
@@ -6,6 +6,7 @@
Quoted 8 lines

drivers/remoteproc/rproc-elf-loader.c int rproc_elf32_load_image(struct udevice *dev,

Quoted 8 lines
drivers/remoteproc/rproc-elf-loader.c +1 -0
 #include <dm.h>
 #include <elf.h>
 #include <log.h>
+#include <mapmem.h>
 #include <remoteproc.h>
 #include <asm/cache.h>
 #include <dm/device_compat.h>
@@ -180,6 +181,7 @@ int rproc_elf32_load_image(struct udevice *dev,

unsigned long addr, ulong size)

Quoted 8 lines

drivers/remoteproc/rproc-elf-loader.c int rproc_elf32_load_image(struct udevice *dev,

Quoted 8 lines
drivers/remoteproc/rproc-elf-loader.c +1 -0
        for (i = 0; i < ehdr->e_phnum; i++, phdr++) {
                void *dst = (void *)(uintptr_t)phdr->p_paddr;
                void *src = (void *)addr + phdr->p_offset;
+               ulong dst_addr;
 
                if (phdr->p_type != PT_LOAD)
                        continue;
@@ -195,10 +197,11 @@ int rproc_elf32_load_image(struct udevice *dev,

unsigned long addr, ulong size)

Quoted 4 lines

drivers/remoteproc/rproc-elf-loader.c int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size)

Quoted 4 lines
drivers/remoteproc/rproc-elf-loader.c +0 -1
                if (phdr->p_filesz != phdr->p_memsz)
                        memset(dst + phdr->p_filesz, 0x00,
                               phdr->p_memsz - phdr->p_filesz);
-               flush_cache(rounddown((unsigned long)dst,

ARCH_DMA_MINALIGN),

Quoted 1 line

drivers/remoteproc/rproc-elf-loader.c int rproc_elf32_load_image(struct udevice *dev, · line 199

Quoted 1 line
drivers/remoteproc/rproc-elf-loader.c +0 -1
-                           roundup((unsigned long)dst +

phdr->p_filesz,

Quoted 5 lines

drivers/remoteproc/rproc-elf-loader.c int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size)

Quoted 5 lines
drivers/remoteproc/rproc-elf-loader.c +3 -1
+               dst_addr = map_to_sysmem(dst);
+               flush_cache(rounddown(dst_addr, ARCH_DMA_MINALIGN),
+                           roundup(dst_addr + phdr->p_filesz,
                                    ARCH_DMA_MINALIGN) -
-                           rounddown((unsigned long)dst,

ARCH_DMA_MINALIGN));

Quoted 5 lines

drivers/remoteproc/rproc-elf-loader.c int rproc_elf32_load_rsc_table(struct udevice

Quoted 5 lines
drivers/remoteproc/rproc-elf-loader.c +1 -0
+                           rounddown(dst_addr, ARCH_DMA_MINALIGN));
        }
 
        return 0;
@@ -377,6 +380,7 @@ int rproc_elf32_load_rsc_table(struct udevice

*dev, ulong fw_addr,

Quoted 8 lines

drivers/remoteproc/rproc-elf-loader.c int rproc_elf32_load_rsc_table(struct udevice

Quoted 8 lines
drivers/remoteproc/rproc-elf-loader.c +1 -0
        const struct dm_rproc_ops *ops;
        Elf32_Shdr *shdr;
        void *src, *dst;
+       ulong dst_addr;
 
        shdr = rproc_elf32_find_rsc_table(dev, fw_addr, fw_size);
        if (!shdr)
@@ -398,10 +402,10 @@ int rproc_elf32_load_rsc_table(struct udevice

*dev, ulong fw_addr,

Quoted 12 lines
Quoted 12 lines
drivers/remoteproc/rproc-elf-loader.c +4 -4
                (ulong)dst, *rsc_size);
 
        memcpy(dst, src, *rsc_size);
-       flush_cache(rounddown((unsigned long)dst, ARCH_DMA_MINALIGN),
-                   roundup((unsigned long)dst + *rsc_size,
-                           ARCH_DMA_MINALIGN) -
-                   rounddown((unsigned long)dst, ARCH_DMA_MINALIGN));
+       dst_addr = map_to_sysmem(dst);
+       flush_cache(rounddown(dst_addr, ARCH_DMA_MINALIGN),
+                   roundup(dst_addr + *rsc_size, ARCH_DMA_MINALIGN) -
+                   rounddown(dst_addr, ARCH_DMA_MINALIGN));
 
Quoted 3 lines

Review

Quoted 3 lines
drivers/remoteproc/rproc-elf-loader.c +0 -0
        return 0;
 }
(quoted diff) +0 -0

b/lib/efi_loader/efi_image_loader.c

Quoted 4 lines
Quoted 4 lines

index 0ddf69a0918..bb58cf1badb 100644

lib/efi_loader/efi_image_loader.c +0 -0
@@ -13,6 +13,7 @@
Quoted 8 lines

lib/efi_loader/efi_image_loader.c efi_status_t efi_load_pe(struct

Quoted 8 lines
lib/efi_loader/efi_image_loader.c +1 -0
 #include <efi_loader.h>
 #include <log.h>
 #include <malloc.h>
+#include <mapmem.h>
 #include <pe.h>
 #include <sort.h>
 #include <crypto/mscode.h>
@@ -977,7 +978,7 @@ efi_status_t efi_load_pe(struct

efi_loaded_image_obj *handle,

Quoted 6 lines
Quoted 5 lines
lib/efi_loader/efi_image_loader.c +1 -1
        }
 
        /* Flush cache */
-       flush_cache((ulong)efi_reloc,
+       flush_cache(map_to_sysmem(efi_reloc),
Quoted 6 lines
Quoted 1 line

Shouldn't we now umap that address on the err: tag?

This address should be in sandbox's DRAM, so there is no mapping created. The mapping is needed for things that are not in the emulated DRAM, such as stack variables.

Isn't there a ref counter that gets increased for these though? Why would we not want to decrease it properly?

Thanks
/Ilias

Quoted 14 lines
Quoted 10 lines

Thanks
/Ilias

Quoted 6 lines
lib/efi_loader/efi_image_loader.c +0 -1
                    ALIGN(virt_size, EFI_CACHELINE_SIZE));
 
        /*
--

2.34.1

Regards,
Simon

#8 lore raw

Re: [PATCH v3 1/9] sandbox: efi_loader: Correct use of addresses as pointers

Quoted 148 lines · Ilias Apalodimas
Quoted 144 lines · Simon Glass

Hi Ilias,

Quoted 50 lines · Ilias Apalodimas

Hi Simon,

Quoted 46 lines · Simon Glass

The cache-flush function is incorrect which causes a crash in the remoteproc tests with arm64.

Fix both problems by using map_sysmem() to convert an address to a pointer and map_to_sysmem() to convert a pointer to an address.

Also update the image-loader's cache-flushing logic.

Fixes 3286d223fd7 ("sandbox: implement invalidate_icache_all()")

---

(no changes since v2)

Changes in v2:
- Drop message about EFI_LOADER

 arch/sandbox/cpu/cache.c              |  8 +++++++-
 drivers/remoteproc/rproc-elf-loader.c | 18 +++++++++++-------
 lib/efi_loader/efi_image_loader.c     |  3 ++-
 3 files changed, 20 insertions(+), 9 deletions(-)
arch/sandbox/cpu/cache.c +7 -1
index c8a5e64214b..96b3da47e8e 100644
@@ -4,12 +4,18 @@
  */
 
 #include <cpu_func.h>
+#include <mapmem.h>
 #include <asm/state.h>
 
 void flush_cache(unsigned long addr, unsigned long size)
 {
+       void *ptr;
+
+       ptr = map_sysmem(addr, size);
+
        /* Clang uses (char *) parameters, GCC (void *) */
-       __builtin___clear_cache((void *)addr, (void *)(addr + size));
+       __builtin___clear_cache(map_sysmem(addr, size), ptr + size);
+       unmap_sysmem(ptr);
 }
 
Quoted 2 lines

Review

Quoted 2 lines
arch/sandbox/cpu/cache.c +0 -0
 void invalidate_icache_all(void)
(quoted diff) +0 -0

b/drivers/remoteproc/rproc-elf-loader.c

Quoted 4 lines
Quoted 4 lines

index ab1836b3f07..0b3941b7798 100644

drivers/remoteproc/rproc-elf-loader.c +0 -0
@@ -6,6 +6,7 @@
Quoted 8 lines

drivers/remoteproc/rproc-elf-loader.c int rproc_elf32_load_image(struct udevice *dev,

Quoted 8 lines
drivers/remoteproc/rproc-elf-loader.c +1 -0
 #include <dm.h>
 #include <elf.h>
 #include <log.h>
+#include <mapmem.h>
 #include <remoteproc.h>
 #include <asm/cache.h>
 #include <dm/device_compat.h>
@@ -180,6 +181,7 @@ int rproc_elf32_load_image(struct udevice *dev,

unsigned long addr, ulong size)

Quoted 8 lines

drivers/remoteproc/rproc-elf-loader.c int rproc_elf32_load_image(struct udevice *dev,

Quoted 8 lines
drivers/remoteproc/rproc-elf-loader.c +1 -0
        for (i = 0; i < ehdr->e_phnum; i++, phdr++) {
                void *dst = (void *)(uintptr_t)phdr->p_paddr;
                void *src = (void *)addr + phdr->p_offset;
+               ulong dst_addr;
 
                if (phdr->p_type != PT_LOAD)
                        continue;
@@ -195,10 +197,11 @@ int rproc_elf32_load_image(struct udevice *dev,

unsigned long addr, ulong size)

Quoted 4 lines

drivers/remoteproc/rproc-elf-loader.c int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size)

Quoted 4 lines
drivers/remoteproc/rproc-elf-loader.c +0 -1
                if (phdr->p_filesz != phdr->p_memsz)
                        memset(dst + phdr->p_filesz, 0x00,
                               phdr->p_memsz - phdr->p_filesz);
-               flush_cache(rounddown((unsigned long)dst,

ARCH_DMA_MINALIGN),

Quoted 1 line

drivers/remoteproc/rproc-elf-loader.c int rproc_elf32_load_image(struct udevice *dev, · line 199

Quoted 1 line
drivers/remoteproc/rproc-elf-loader.c +0 -1
-                           roundup((unsigned long)dst +

phdr->p_filesz,

Quoted 5 lines

drivers/remoteproc/rproc-elf-loader.c int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size)

Quoted 5 lines
drivers/remoteproc/rproc-elf-loader.c +3 -1
+               dst_addr = map_to_sysmem(dst);
+               flush_cache(rounddown(dst_addr, ARCH_DMA_MINALIGN),
+                           roundup(dst_addr + phdr->p_filesz,
                                    ARCH_DMA_MINALIGN) -
-                           rounddown((unsigned long)dst,

ARCH_DMA_MINALIGN));

Quoted 5 lines

drivers/remoteproc/rproc-elf-loader.c int rproc_elf32_load_rsc_table(struct udevice

Quoted 5 lines
drivers/remoteproc/rproc-elf-loader.c +1 -0
+                           rounddown(dst_addr, ARCH_DMA_MINALIGN));
        }
 
        return 0;
@@ -377,6 +380,7 @@ int rproc_elf32_load_rsc_table(struct udevice

*dev, ulong fw_addr,

Quoted 8 lines

drivers/remoteproc/rproc-elf-loader.c int rproc_elf32_load_rsc_table(struct udevice

Quoted 8 lines
drivers/remoteproc/rproc-elf-loader.c +1 -0
        const struct dm_rproc_ops *ops;
        Elf32_Shdr *shdr;
        void *src, *dst;
+       ulong dst_addr;
 
        shdr = rproc_elf32_find_rsc_table(dev, fw_addr, fw_size);
        if (!shdr)
@@ -398,10 +402,10 @@ int rproc_elf32_load_rsc_table(struct udevice

*dev, ulong fw_addr,

Quoted 12 lines
Quoted 12 lines
drivers/remoteproc/rproc-elf-loader.c +4 -4
                (ulong)dst, *rsc_size);
 
        memcpy(dst, src, *rsc_size);
-       flush_cache(rounddown((unsigned long)dst, ARCH_DMA_MINALIGN),
-                   roundup((unsigned long)dst + *rsc_size,
-                           ARCH_DMA_MINALIGN) -
-                   rounddown((unsigned long)dst, ARCH_DMA_MINALIGN));
+       dst_addr = map_to_sysmem(dst);
+       flush_cache(rounddown(dst_addr, ARCH_DMA_MINALIGN),
+                   roundup(dst_addr + *rsc_size, ARCH_DMA_MINALIGN) -
+                   rounddown(dst_addr, ARCH_DMA_MINALIGN));
 
Quoted 3 lines

Review

Quoted 3 lines
drivers/remoteproc/rproc-elf-loader.c +0 -0
        return 0;
 }
(quoted diff) +0 -0

b/lib/efi_loader/efi_image_loader.c

Quoted 4 lines
Quoted 4 lines

index 0ddf69a0918..bb58cf1badb 100644

lib/efi_loader/efi_image_loader.c +0 -0
@@ -13,6 +13,7 @@
Quoted 8 lines

lib/efi_loader/efi_image_loader.c efi_status_t efi_load_pe(struct

Quoted 8 lines
lib/efi_loader/efi_image_loader.c +1 -0
 #include <efi_loader.h>
 #include <log.h>
 #include <malloc.h>
+#include <mapmem.h>
 #include <pe.h>
 #include <sort.h>
 #include <crypto/mscode.h>
@@ -977,7 +978,7 @@ efi_status_t efi_load_pe(struct

efi_loaded_image_obj *handle,

Quoted 7 lines

lib/efi_loader/efi_image_loader.c efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, · line 981

Quoted 5 lines
lib/efi_loader/efi_image_loader.c +1 -1
        }
 
        /* Flush cache */
-       flush_cache((ulong)efi_reloc,
+       flush_cache(map_to_sysmem(efi_reloc),

Shouldn't we now umap that address on the err: tag?

Quoted 8 lines
Quoted 4 lines

This address should be in sandbox's DRAM, so there is no mapping created. The mapping is needed for things that are not in the emulated DRAM, such as stack variables.

Isn't there a ref counter that gets increased for these though? Why would we not want to decrease it properly?

Ah scratch that, the refcnt is not for the sandbox DRAM. But in any case, I don't like seeing that magic of people knowing what they should unmap or not.
I would prefer calling the unmap call unconditionally, since the function deals with sandbox memory correctly already

Thanks
/Ilias

Quoted 20 lines

Thanks
/Ilias

Quoted 14 lines
Quoted 10 lines

Thanks
/Ilias

Quoted 6 lines
lib/efi_loader/efi_image_loader.c +0 -1
                    ALIGN(virt_size, EFI_CACHELINE_SIZE));
 
        /*
--

2.34.1

Regards,
Simon

#9 lore raw

Re: [PATCH v3 1/9] sandbox: efi_loader: Correct use of addresses as pointers

Hi Ilias,

Quoted 148 lines · Ilias Apalodimas
Quoted 144 lines · Ilias Apalodimas
Quoted 138 lines · Simon Glass

Hi Ilias,

Quoted 124 lines · Ilias Apalodimas

Hi Simon,

Quoted 120 lines · Simon Glass

The cache-flush function is incorrect which causes a crash in the remoteproc tests with arm64.

Fix both problems by using map_sysmem() to convert an address to a pointer and map_to_sysmem() to convert a pointer to an address.

Also update the image-loader's cache-flushing logic.

Fixes 3286d223fd7 ("sandbox: implement invalidate_icache_all()")

---

(no changes since v2)

Changes in v2:
- Drop message about EFI_LOADER

 arch/sandbox/cpu/cache.c              |  8 +++++++-
 drivers/remoteproc/rproc-elf-loader.c | 18 +++++++++++-------
 lib/efi_loader/efi_image_loader.c     |  3 ++-
 3 files changed, 20 insertions(+), 9 deletions(-)
arch/sandbox/cpu/cache.c +7 -1
index c8a5e64214b..96b3da47e8e 100644
@@ -4,12 +4,18 @@
  */
 
 #include <cpu_func.h>
+#include <mapmem.h>
 #include <asm/state.h>
 
 void flush_cache(unsigned long addr, unsigned long size)
 {
+       void *ptr;
+
+       ptr = map_sysmem(addr, size);
+
        /* Clang uses (char *) parameters, GCC (void *) */
-       __builtin___clear_cache((void *)addr, (void *)(addr + size));
+       __builtin___clear_cache(map_sysmem(addr, size), ptr + size);
+       unmap_sysmem(ptr);
 }
 
 void invalidate_icache_all(void)
drivers/remoteproc/rproc-elf-loader.c +11 -7
index ab1836b3f07..0b3941b7798 100644
@@ -6,6 +6,7 @@
 #include <dm.h>
 #include <elf.h>
 #include <log.h>
+#include <mapmem.h>
 #include <remoteproc.h>
 #include <asm/cache.h>
 #include <dm/device_compat.h>
@@ -180,6 +181,7 @@ int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size)
        for (i = 0; i < ehdr->e_phnum; i++, phdr++) {
                void *dst = (void *)(uintptr_t)phdr->p_paddr;
                void *src = (void *)addr + phdr->p_offset;
+               ulong dst_addr;
 
                if (phdr->p_type != PT_LOAD)
                        continue;
@@ -195,10 +197,11 @@ int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size)
                if (phdr->p_filesz != phdr->p_memsz)
                        memset(dst + phdr->p_filesz, 0x00,
                               phdr->p_memsz - phdr->p_filesz);
-               flush_cache(rounddown((unsigned long)dst, ARCH_DMA_MINALIGN),
-                           roundup((unsigned long)dst + phdr->p_filesz,
+               dst_addr = map_to_sysmem(dst);
+               flush_cache(rounddown(dst_addr, ARCH_DMA_MINALIGN),
+                           roundup(dst_addr + phdr->p_filesz,
                                    ARCH_DMA_MINALIGN) -
-                           rounddown((unsigned long)dst, ARCH_DMA_MINALIGN));
+                           rounddown(dst_addr, ARCH_DMA_MINALIGN));
        }
 
        return 0;
@@ -377,6 +380,7 @@ int rproc_elf32_load_rsc_table(struct udevice *dev, ulong fw_addr,
        const struct dm_rproc_ops *ops;
        Elf32_Shdr *shdr;
        void *src, *dst;
+       ulong dst_addr;
 
        shdr = rproc_elf32_find_rsc_table(dev, fw_addr, fw_size);
        if (!shdr)
@@ -398,10 +402,10 @@ int rproc_elf32_load_rsc_table(struct udevice *dev, ulong fw_addr,
                (ulong)dst, *rsc_size);
 
        memcpy(dst, src, *rsc_size);
-       flush_cache(rounddown((unsigned long)dst, ARCH_DMA_MINALIGN),
-                   roundup((unsigned long)dst + *rsc_size,
-                           ARCH_DMA_MINALIGN) -
-                   rounddown((unsigned long)dst, ARCH_DMA_MINALIGN));
+       dst_addr = map_to_sysmem(dst);
+       flush_cache(rounddown(dst_addr, ARCH_DMA_MINALIGN),
+                   roundup(dst_addr + *rsc_size, ARCH_DMA_MINALIGN) -
+                   rounddown(dst_addr, ARCH_DMA_MINALIGN));
 
        return 0;
 }
lib/efi_loader/efi_image_loader.c +1 -0
index 0ddf69a0918..bb58cf1badb 100644
@@ -13,6 +13,7 @@
 #include <efi_loader.h>
 #include <log.h>
 #include <malloc.h>
+#include <mapmem.h>
 #include <pe.h>
 #include <sort.h>
 #include <crypto/mscode.h>
@@ -977,7 +978,7 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle,
        }
 
Quoted 5 lines

lib/efi_loader/efi_image_loader.c efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, · line 981

Quoted 3 lines
lib/efi_loader/efi_image_loader.c +1 -1
        /* Flush cache */
-       flush_cache((ulong)efi_reloc,
+       flush_cache(map_to_sysmem(efi_reloc),

Shouldn't we now umap that address on the err: tag?

This address should be in sandbox's DRAM, so there is no mapping created. The mapping is needed for things that are not in the emulated DRAM, such as stack variables.

Quoted 6 lines
Quoted 2 lines

Isn't there a ref counter that gets increased for these though? Why would we not want to decrease it properly?

Ah scratch that, the refcnt is not for the sandbox DRAM. But in any case, I don't like seeing that magic of people knowing what they should unmap or not. I would prefer calling the unmap call unconditionally, since the function deals with sandbox memory correctly already

Yes, that's OK with me and is clearer, as you say.

Regards,
Simon

Reviewed-by
#10 lore raw

Re: [PATCH v3 1/9] sandbox: efi_loader: Correct use of addresses as pointers

Quoted 153 lines · Simon Glass

Hi Ilias,

Quoted 148 lines · Ilias Apalodimas
Quoted 144 lines · Ilias Apalodimas
Quoted 138 lines · Simon Glass

Hi Ilias,

Quoted 124 lines · Ilias Apalodimas

Hi Simon,

Quoted 120 lines · Simon Glass

The cache-flush function is incorrect which causes a crash in the remoteproc tests with arm64.

Fix both problems by using map_sysmem() to convert an address to a pointer and map_to_sysmem() to convert a pointer to an address.

Also update the image-loader's cache-flushing logic.

Fixes 3286d223fd7 ("sandbox: implement invalidate_icache_all()")

---

(no changes since v2)

Changes in v2:
- Drop message about EFI_LOADER

 arch/sandbox/cpu/cache.c              |  8 +++++++-
 drivers/remoteproc/rproc-elf-loader.c | 18 +++++++++++-------
 lib/efi_loader/efi_image_loader.c     |  3 ++-
 3 files changed, 20 insertions(+), 9 deletions(-)
arch/sandbox/cpu/cache.c +7 -1
index c8a5e64214b..96b3da47e8e 100644
@@ -4,12 +4,18 @@
  */
 
 #include <cpu_func.h>
+#include <mapmem.h>
 #include <asm/state.h>
 
 void flush_cache(unsigned long addr, unsigned long size)
 {
+       void *ptr;
+
+       ptr = map_sysmem(addr, size);
+
        /* Clang uses (char *) parameters, GCC (void *) */
-       __builtin___clear_cache((void *)addr, (void *)(addr + size));
+       __builtin___clear_cache(map_sysmem(addr, size), ptr + size);
+       unmap_sysmem(ptr);
 }
 
 void invalidate_icache_all(void)
drivers/remoteproc/rproc-elf-loader.c +11 -7
index ab1836b3f07..0b3941b7798 100644
@@ -6,6 +6,7 @@
 #include <dm.h>
 #include <elf.h>
 #include <log.h>
+#include <mapmem.h>
 #include <remoteproc.h>
 #include <asm/cache.h>
 #include <dm/device_compat.h>
@@ -180,6 +181,7 @@ int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size)
        for (i = 0; i < ehdr->e_phnum; i++, phdr++) {
                void *dst = (void *)(uintptr_t)phdr->p_paddr;
                void *src = (void *)addr + phdr->p_offset;
+               ulong dst_addr;
 
                if (phdr->p_type != PT_LOAD)
                        continue;
@@ -195,10 +197,11 @@ int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size)
                if (phdr->p_filesz != phdr->p_memsz)
                        memset(dst + phdr->p_filesz, 0x00,
                               phdr->p_memsz - phdr->p_filesz);
-               flush_cache(rounddown((unsigned long)dst, ARCH_DMA_MINALIGN),
-                           roundup((unsigned long)dst + phdr->p_filesz,
+               dst_addr = map_to_sysmem(dst);
+               flush_cache(rounddown(dst_addr, ARCH_DMA_MINALIGN),
+                           roundup(dst_addr + phdr->p_filesz,
                                    ARCH_DMA_MINALIGN) -
-                           rounddown((unsigned long)dst, ARCH_DMA_MINALIGN));
+                           rounddown(dst_addr, ARCH_DMA_MINALIGN));
        }
 
        return 0;
@@ -377,6 +380,7 @@ int rproc_elf32_load_rsc_table(struct udevice *dev, ulong fw_addr,
        const struct dm_rproc_ops *ops;
        Elf32_Shdr *shdr;
        void *src, *dst;
+       ulong dst_addr;
 
        shdr = rproc_elf32_find_rsc_table(dev, fw_addr, fw_size);
        if (!shdr)
@@ -398,10 +402,10 @@ int rproc_elf32_load_rsc_table(struct udevice *dev, ulong fw_addr,
                (ulong)dst, *rsc_size);
 
        memcpy(dst, src, *rsc_size);
-       flush_cache(rounddown((unsigned long)dst, ARCH_DMA_MINALIGN),
-                   roundup((unsigned long)dst + *rsc_size,
-                           ARCH_DMA_MINALIGN) -
-                   rounddown((unsigned long)dst, ARCH_DMA_MINALIGN));
+       dst_addr = map_to_sysmem(dst);
+       flush_cache(rounddown(dst_addr, ARCH_DMA_MINALIGN),
+                   roundup(dst_addr + *rsc_size, ARCH_DMA_MINALIGN) -
+                   rounddown(dst_addr, ARCH_DMA_MINALIGN));
 
        return 0;
 }
lib/efi_loader/efi_image_loader.c +1 -0
index 0ddf69a0918..bb58cf1badb 100644
@@ -13,6 +13,7 @@
 #include <efi_loader.h>
 #include <log.h>
 #include <malloc.h>
+#include <mapmem.h>
 #include <pe.h>
 #include <sort.h>
 #include <crypto/mscode.h>
@@ -977,7 +978,7 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle,
        }
 
Quoted 5 lines

lib/efi_loader/efi_image_loader.c efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, · line 981

Quoted 3 lines
lib/efi_loader/efi_image_loader.c +1 -1
        /* Flush cache */
-       flush_cache((ulong)efi_reloc,
+       flush_cache(map_to_sysmem(efi_reloc),

Shouldn't we now umap that address on the err: tag?

This address should be in sandbox's DRAM, so there is no mapping created. The mapping is needed for things that are not in the emulated DRAM, such as stack variables.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Isn't there a ref counter that gets increased for these though? Why would we not want to decrease it properly?

Ah scratch that, the refcnt is not for the sandbox DRAM. But in any case, I don't like seeing that magic of people knowing what they should unmap or not. I would prefer calling the unmap call unconditionally, since the function deals with sandbox memory correctly already

Yes, that's OK with me and is clearer, as you say.

Thanks Simon, with the unmap call added

Quoted 3 lines

Regards,
Simon

#11 lore raw

PATCH v3 2/9 test: Adjust print_ut test to use unsigned char

In reply to Simon Glass

Since char is unsigned on arm64, this test currently fails. It seems better to use unsigned anyway, since 0xff is written into the string at the start. Update the terminator-assert to use a character instead of a byte.

---

(no changes since v2)

Changes in v2:
- Use '\0' instead of 0

 test/print_ut.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
test/print_ut.c +4 -4
index f5e607b21a3..7ab79e4617f 100644
@@ -242,7 +242,7 @@ PRINT_TEST(print_display_buffer, UTF_CONSOLE);
 
 static int print_hexdump_line(struct unit_test_state *uts)
 {
-	char *linebuf;
+	u8 *linebuf;
 	u8 *buf;
 	int i;
 
@@ -255,10 +255,10 @@ static int print_hexdump_line(struct unit_test_state *uts)
 	linebuf = map_sysmem(0x400, BUF_SIZE);
 	memset(linebuf, '\xff', BUF_SIZE);
 	ut_asserteq(-ENOSPC, hexdump_line(0, buf, 1, 0x10, 0, linebuf, 75));
-	ut_asserteq(-1, linebuf[0]);
+	ut_asserteq(0xff, linebuf[0]);
 	ut_asserteq(0x10, hexdump_line(0, buf, 1, 0x10, 0, linebuf, 76));
-	ut_asserteq(0, linebuf[75]);
-	ut_asserteq(-1, linebuf[76]);
+	ut_asserteq('\0', linebuf[75]);
+	ut_asserteq(0xff, linebuf[76]);
 
 	unmap_sysmem(buf);
 
Signature · 1 line
2.34.1
#12 lore raw

PATCH v3 3/9 docker: Support building for multiple architectures

In reply to Simon Glass

Add instructions on how to build the file for multiple architectures. Add a message indicating what is happening.

Update the documentation as well. Drop the 'sudo' since these should not be needed if Docker is correctly configured.

---

Changes in v3:
- Move ARGs to the top
- Revise documentation to explain a common error and building on arm64

Changes in v2:
- Update docs also
- Add comments to the ARG variables

 doc/build/docker.rst    | 25 ++++++++++++++++++++++---
 tools/docker/Dockerfile | 12 ++++++++++++
 2 files changed, 34 insertions(+), 3 deletions(-)
doc/build/docker.rst +22 -3
index 45659b3b89d..b8fd12ead71 100644
@@ -1,14 +1,33 @@
 GitLab CI / U-Boot runner container
 ===================================
 
-In order to have a reproducible and portable build environment for CI we use a container for building in.  This means that developers can also reproduce the CI environment, to a large degree at least, locally.  This file is located in the tools/docker directory.  To build the image yourself
+In order to have a reproducible and portable build environment for CI we use a container for building in.  This means that developers can also reproduce the CI environment, to a large degree at least, locally.  This file is located in the tools/docker directory.
+
+The docker image supports both amd64 and arm64. Ensure that the
+'docker-buildx' Debian package is installed (or the equivalent on another
+distribution).
+
+You will need a multi-platform container, otherwise this error is shown::
+
+    ERROR: Multi-platform build is not supported for the docker driver.
+    Switch to a different driver, or turn on the containerd image store, and try again.
+
+You can add one with::
+
+    docker buildx create --name multiarch --driver docker-container --use
+
+Building is supported on both amd64 (i.e. 64-bit x86) and arm64 machines. While
+both amd64 and arm64 happen in parallel, the non-native part will take
+considerably longer as it must use QEMU to emulate the foreign code.
+
+To build the image yourself::
 
 .. code-block:: bash
 
-    sudo docker build -t your-namespace:your-tag .
+    docker buildx build --platform linux/arm64/v8,linux/amd64 -t your-namespace:your-tag .
 
 Or to use an existing container
 
 .. code-block:: bash
 
-    sudo docker pull trini/u-boot-gitlab-ci-runner:jammy-20240227-14Mar2024
+    docker pull trini/u-boot-gitlab-ci-runner:jammy-20240227-14Mar2024
tools/docker/Dockerfile +12 -0
index 967ac89fbde..7f4b17ab0a4 100644
@@ -2,13 +2,25 @@
 # This Dockerfile is used to build an image containing basic stuff to be used
 # to build U-Boot and run our test suites.
 
+# Build with (for example):
+# docker buildx build --platform linux/arm64/v8,linux/amd64 --tag sjg20/u-boot-gitlab-ci-runner-multiarch:jammy-20240808-03Nov2024 .
+
 FROM ubuntu:jammy-20240808
 LABEL org.opencontainers.image.authors="Tom Rini <[email protected]>"
 LABEL org.opencontainers.image.description=" This image is for building U-Boot inside a container"
 
+# Used by docker to set the target platform: valid values are linux/arm64/v8
+# and linux/amd64
+ARG TARGETPLATFORM
+
+# Used by docker to set the build platform: the only valid value is linux/amd64
+ARG BUILDPLATFORM
+
 # Make sure apt is happy
 ENV DEBIAN_FRONTEND=noninteractive
 
+RUN echo "Building on $BUILDPLATFORM, for target $TARGETPLATFORM"
+
 # Add LLVM repository
 RUN apt-get update && apt-get install -y gnupg2 wget xz-utils && rm -rf /var/lib/apt/lists/*
 RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
Signature · 1 line
2.34.1
#13 lore raw

Re: [PATCH v3 3/9] docker: Support building for multiple architectures

Quoted 5 lines · Simon Glass

Add instructions on how to build the file for multiple architectures. Add a message indicating what is happening.

Update the documentation as well. Drop the 'sudo' since these should not be needed if Docker is correctly configured.

Please, explain what you mean by correctly configured.

By default Ubuntu requires sudo to execute docker.

https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user
teaches us:

"The docker group grants root-level privileges to the user. For details on how this impacts security in your system, see Docker Daemon Attack Surface."

So adding a user to the docker group may not be the best idea.

Installing Docker in rootless mode is possible
(https://docs.docker.com/engine/security/rootless/) but as said it is not necessarily the distro default.

Best regards

Heinrich

Quoted 87 lines

---

Changes in v3:
- Move ARGs to the top
- Revise documentation to explain a common error and building on arm64

Changes in v2:
- Update docs also
- Add comments to the ARG variables

  doc/build/docker.rst    | 25 ++++++++++++++++++++++---
  tools/docker/Dockerfile | 12 ++++++++++++
  2 files changed, 34 insertions(+), 3 deletions(-)
doc/build/docker.rst +22 -3
index 45659b3b89d..b8fd12ead71 100644
@@ -1,14 +1,33 @@
  GitLab CI / U-Boot runner container
  ===================================
 
-In order to have a reproducible and portable build environment for CI we use a container for building in.  This means that developers can also reproduce the CI environment, to a large degree at least, locally.  This file is located in the tools/docker directory.  To build the image yourself
+In order to have a reproducible and portable build environment for CI we use a container for building in.  This means that developers can also reproduce the CI environment, to a large degree at least, locally.  This file is located in the tools/docker directory.
+
+The docker image supports both amd64 and arm64. Ensure that the
+'docker-buildx' Debian package is installed (or the equivalent on another
+distribution).
+
+You will need a multi-platform container, otherwise this error is shown::
+
+    ERROR: Multi-platform build is not supported for the docker driver.
+    Switch to a different driver, or turn on the containerd image store, and try again.
+
+You can add one with::
+
+    docker buildx create --name multiarch --driver docker-container --use
+
+Building is supported on both amd64 (i.e. 64-bit x86) and arm64 machines. While
+both amd64 and arm64 happen in parallel, the non-native part will take
+considerably longer as it must use QEMU to emulate the foreign code.
+
+To build the image yourself::
 
  .. code-block:: bash
 
-    sudo docker build -t your-namespace:your-tag .
+    docker buildx build --platform linux/arm64/v8,linux/amd64 -t your-namespace:your-tag .
 
  Or to use an existing container
 
  .. code-block:: bash
 
-    sudo docker pull trini/u-boot-gitlab-ci-runner:jammy-20240227-14Mar2024
+    docker pull trini/u-boot-gitlab-ci-runner:jammy-20240227-14Mar2024
tools/docker/Dockerfile +12 -0
index 967ac89fbde..7f4b17ab0a4 100644
@@ -2,13 +2,25 @@
  # This Dockerfile is used to build an image containing basic stuff to be used
  # to build U-Boot and run our test suites.
 
+# Build with (for example):
+# docker buildx build --platform linux/arm64/v8,linux/amd64 --tag sjg20/u-boot-gitlab-ci-runner-multiarch:jammy-20240808-03Nov2024 .
+
  FROM ubuntu:jammy-20240808
  LABEL org.opencontainers.image.authors="Tom Rini <[email protected]>"
  LABEL org.opencontainers.image.description=" This image is for building U-Boot inside a container"
 
+# Used by docker to set the target platform: valid values are linux/arm64/v8
+# and linux/amd64
+ARG TARGETPLATFORM
+
+# Used by docker to set the build platform: the only valid value is linux/amd64
+ARG BUILDPLATFORM
+
  # Make sure apt is happy
  ENV DEBIAN_FRONTEND=noninteractive
 
+RUN echo "Building on $BUILDPLATFORM, for target $TARGETPLATFORM"
+
  # Add LLVM repository
  RUN apt-get update && apt-get install -y gnupg2 wget xz-utils && rm -rf /var/lib/apt/lists/*
  RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
#14 lore raw

Re: [PATCH v3 3/9] docker: Support building for multiple architectures

Quoted 18 lines · Heinrich Schuchardt
Quoted 5 lines · Simon Glass

Add instructions on how to build the file for multiple architectures. Add a message indicating what is happening.

Update the documentation as well. Drop the 'sudo' since these should not be needed if Docker is correctly configured.

Please, explain what you mean by correctly configured.

By default Ubuntu requires sudo to execute docker.

https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user
teaches us:

"The docker group grants root-level privileges to the user. For details on how this impacts security in your system, see Docker Daemon Attack Surface."

Quoted 5 lines

So adding a user to the docker group may not be the best idea.

Installing Docker in rootless mode is possible
(https://docs.docker.com/engine/security/rootless/) but as said it is not necessarily the distro default.

Yes, please drop this patch as we expect to handle things in the broadest possible way, so not assuming that the user is in the docker group.

Signature · 1 line
Tom
#15 lore raw

PATCH v3 4/9 docker: Adjust packages for arm64

In reply to Simon Glass

The package names are slightly different for arm64 and we don't seem to have a linux-image-kvm package. Provide some extra ones for x86

---

Changes in v3:
- Use grub-efi and linux-image-generic for both archs

Changes in v2:
- Swap order so that amd64 is the exception

 tools/docker/Dockerfile | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
tools/docker/Dockerfile +7 -5
index 7f4b17ab0a4..fd4835e9562 100644
@@ -44,7 +44,10 @@ RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_
 RUN wget -O - https://github.com/foss-xtensa/toolchain/releases/download/2020.07/x86_64-2020.07-xtensa-dc233c-elf.tar.gz | tar -C /opt -xz
 
 # Update and install things from apt now
-RUN apt-get update && apt-get install -y \
+RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
+		EXTRA_PACKAGES="grub-efi-ia32-bin libc6-i386"; \
+	fi; \
+	apt-get update && apt-get install -y \
 	automake \
 	autopoint \
 	bc \
@@ -70,13 +73,11 @@ RUN apt-get update && apt-get install -y \
 	gnu-efi \
 	gnutls-dev \
 	graphviz \
-	grub-efi-amd64-bin \
-	grub-efi-ia32-bin \
+	grub-efi \
 	help2man \
 	iasl \
 	imagemagick \
 	iputils-ping \
-	libc6-i386 \
 	libconfuse-dev \
 	libgit2-dev \
 	libjson-glib-dev \
@@ -94,7 +95,7 @@ RUN apt-get update && apt-get install -y \
 	libtool \
 	libudev-dev \
 	libusb-1.0-0-dev \
-	linux-image-kvm \
+	linux-image-generic \
 	lzma-alone \
 	lzop \
 	mount \
@@ -131,6 +132,7 @@ RUN apt-get update && apt-get install -y \
 	xilinx-bootgen \
 	xxd \
 	zip \
+	${EXTRA_PACKAGES} \
 	&& rm -rf /var/lib/apt/lists/*
 
 # Make kernels readable for libguestfs tools to work correctly
Signature · 1 line
2.34.1
#17 lore raw

PATCH v3 5/9 docker: Drop coreboot for arm64

In reply to Simon Glass

This isn't needed for sandbox builds and coreboot isn't much used on arm64, nor does U-Boot have a build that supports running from coreboot on any ARM target.

So drop it.

---

(no changes since v1)

 tools/docker/Dockerfile | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/docker/Dockerfile +4 -2
index fd4835e9562..048a57c5b16 100644
@@ -258,7 +258,8 @@ RUN mkdir /tmp/trace && \
     rm -rf /tmp/trace
 
 # Build coreboot
-RUN wget -O - https://coreboot.org/releases/coreboot-24.08.tar.xz | tar -C /tmp -xJ && \
+RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
+    wget -O - https://coreboot.org/releases/coreboot-24.08.tar.xz | tar -C /tmp -xJ && \
     cd /tmp/coreboot-24.08 && \
     make crossgcc-i386 CPUS=$(nproc) && \
     make -C payloads/coreinfo olddefconfig && \
@@ -269,7 +270,8 @@ RUN wget -O - https://coreboot.org/releases/coreboot-24.08.tar.xz | tar -C /tmp
     make olddefconfig && \
     make -j $(nproc) && \
     sudo mkdir /opt/coreboot && \
-    sudo cp build/coreboot.rom build/cbfstool /opt/coreboot/
+    sudo cp build/coreboot.rom build/cbfstool /opt/coreboot/; \
+    fi
 
 # Create our user/group
 RUN echo uboot ALL=NOPASSWD: ALL > /etc/sudoers.d/uboot
Signature · 1 line
2.34.1
#18 lore raw

PATCH v3 6/9 docker: Fix LegacyKeyValueFormat warning with PYTHONPATH

In reply to Simon Glass

Fix a warning due to the syntax used for PYTHONPATH:

LegacyKeyValueFormat: "ENV key=value" should be used instead of
legacy "ENV key value" format (line 304)

---

(no changes since v1)

 tools/docker/Dockerfile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/docker/Dockerfile +1 -1
index 048a57c5b16..aa97dadbd64 100644
@@ -301,4 +301,4 @@ RUN /bin/echo -e "\nx86 = i386" >> ~/.buildman;
 
 # Add mkbootimg tool
 RUN git clone https://android.googlesource.com/platform/system/tools/mkbootimg /home/uboot/mkbootimg
-ENV PYTHONPATH "${PYTHONPATH}:/home/uboot/mkbootimg"
+ENV PYTHONPATH="${PYTHONPATH}:/home/uboot/mkbootimg"
Signature · 1 line
2.34.1
#19 lore raw

PATCH v3 7/9 docker: Install toolchains on arm64 host

In reply to Simon Glass

Refactor the code to support downloading toolchains for arm64 as well as x86_64

There doesn't seem to be an xtensa toolchain for arm64 at the same location, so download that only on x86

---

Changes in v3:
- Add patch to install toolchains on arm64 host

 tools/docker/Dockerfile | 40 ++++++++++++++++++++++++++--------------
 1 file changed, 26 insertions(+), 14 deletions(-)
tools/docker/Dockerfile +26 -14
index aa97dadbd64..4ca1d3fb013 100644
@@ -19,6 +19,15 @@ ARG BUILDPLATFORM
 # Make sure apt is happy
 ENV DEBIAN_FRONTEND=noninteractive
 
+# Set architectures to build for (leaving out ARM which is an exception)
+ENV ARCHS="aarch64 arc i386 m68k mips microblaze nios2 powerpc riscv64 riscv32 sh2"
+
+# Mirror containing the toolchains
+ENV MIRROR=https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin
+
+# Toolchain version
+ENV TCVER=13.2.0
+
 RUN echo "Building on $BUILDPLATFORM, for target $TARGETPLATFORM"
 
 # Add LLVM repository
@@ -26,22 +35,25 @@ RUN apt-get update && apt-get install -y gnupg2 wget xz-utils && rm -rf /var/lib
 RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
 RUN echo deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main | tee /etc/apt/sources.list.d/llvm.list
 
-# Manually install the kernel.org "Crosstool" based toolchains for gcc-13.2.0
-RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-aarch64-linux.tar.xz | tar -C /opt -xJ
-RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-arc-linux.tar.xz | tar -C /opt -xJ
-RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-arm-linux-gnueabi.tar.xz | tar -C /opt -xJ
-RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-i386-linux.tar.xz | tar -C /opt -xJ
-RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-m68k-linux.tar.xz | tar -C /opt -xJ
-RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-mips-linux.tar.xz | tar -C /opt -xJ
-RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-microblaze-linux.tar.xz | tar -C /opt -xJ
-RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-nios2-linux.tar.xz | tar -C /opt -xJ
-RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-powerpc-linux.tar.xz | tar -C /opt -xJ
-RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-riscv64-linux.tar.xz | tar -C /opt -xJ
-RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-riscv32-linux.tar.xz | tar -C /opt -xJ
-RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-sh2-linux.tar.xz | tar -C /opt -xJ
+# Create a list of URLs to process, then pass them into a 'while read' loop
+RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then HOSTARCH=x86_64; else HOSTARCH=arm64; fi; ( \
+	# Manually install the kernel.org "Crosstool"-based toolchains
+	for arch in $ARCHS; do \
+		echo $MIRROR/$HOSTARCH/$TCVER/${HOSTARCH}-gcc-$TCVER-nolibc-${arch}-linux.tar.xz; \
+	done; \
+	\
+	# Deal with ARM, which has a 'gnueabi' suffix
+	echo $MIRROR/${HOSTARCH}/$TCVER/${HOSTARCH}-gcc-$TCVER-nolibc-arm-linux-gnueabi.tar.xz; \
+	\
+	) | while read url; do \
+		# Read the URL and unpack it into /opt
+		wget -O - $url | tar -C /opt -xJ; \
+	done
 
 # Manually install other toolchains
-RUN wget -O - https://github.com/foss-xtensa/toolchain/releases/download/2020.07/x86_64-2020.07-xtensa-dc233c-elf.tar.gz | tar -C /opt -xz
+RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
+		wget -O - https://github.com/foss-xtensa/toolchain/releases/download/2020.07/x86_64-2020.07-xtensa-dc233c-elf.tar.gz | tar -C /opt -xz; \
+	fi
 
 # Update and install things from apt now
 RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
Signature · 1 line
2.34.1
Reviewed-by on v3 7/9
#20 lore raw

Re: [PATCH v3 7/9] docker: Install toolchains on arm64 host

Quoted 7 lines · Simon Glass

Refactor the code to support downloading toolchains for arm64 as well as x86_64

There doesn't seem to be an xtensa toolchain for arm64 at the same location, so download that only on x86

Signature · 1 line
Tom
#21 lore raw

PATCH v3 8/9 CI: Add platform variable

In reply to Simon Glass

Add a list of possible platforms that can be used by gitlab runners.

---

Changes in v3:
- Drop patches which remove grub and tracing for arm64

 .gitlab-ci.yml | 1 +
 1 file changed, 1 insertion(+)
.gitlab-ci.yml +1 -0
index 0aeda53bc2d..e152060b046 100644
@@ -3,6 +3,7 @@
 variables:
   DEFAULT_TAG: ""
   MIRROR_DOCKER: docker.io
+  PLATFORM: linux/amd64,linux/arm64
 
 default:
   tags:
Signature · 1 line
2.34.1
Reviewed-by on v3 8/9
#22 lore raw

Re: [PATCH v3 8/9] CI: Add platform variable

Quoted 26 lines · Simon Glass

Add a list of possible platforms that can be used by gitlab runners.

---

Changes in v3:
- Drop patches which remove grub and tracing for arm64

 .gitlab-ci.yml | 1 +
 1 file changed, 1 insertion(+)
.gitlab-ci.yml +1 -1
index 0aeda53bc2d..e152060b046 100644
@@ -3,6 +3,7 @@
 variables:
   DEFAULT_TAG: ""
   MIRROR_DOCKER: docker.io
+  PLATFORM: linux/amd64,linux/arm64
 
 default:
   tags:
--
Quoted 2 lines

2.34.1

#23 lore raw

PATCH v3 9/9 WIP: CI: Update for arm64

In reply to Simon Glass

Do not apply.

This is an unfinished attempt to update gitlab to run on an arm64 host.

For now it just adjusts grub and selects the multiarch image

---

(no changes since v1)

 .gitlab-ci.yml | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
.gitlab-ci.yml +7 -3
index e152060b046..9a513cad102 100644
@@ -11,7 +11,7 @@ default:
 
 # Grab our configured image.  The source for this is found
 # in the u-boot tree at tools/docker/Dockerfile
-image: ${MIRROR_DOCKER}/trini/u-boot-gitlab-ci-runner:jammy-20240808-21Aug2024
+image: ${MIRROR_DOCKER}/sjg20/u-boot-gitlab-ci-runner-multiarch:jammy-20240808-08Nov2024
 
 # We run some tests in different order, to catch some failures quicker.
 stages:
@@ -33,8 +33,12 @@ stages:
     - ln -s conf.qemu_arm64_na /tmp/uboot-test-hooks/bin/travis-ci/conf.qemu_arm64_lwip_na
     - ln -s travis-ci /tmp/uboot-test-hooks/bin/`hostname`
     - ln -s travis-ci /tmp/uboot-test-hooks/py/`hostname`
-    - grub-mkimage --prefix="" -o ~/grub_x86.efi -O i386-efi normal  echo lsefimmap lsefi lsefisystab efinet tftp minicmd
-    - grub-mkimage --prefix="" -o ~/grub_x64.efi -O x86_64-efi normal  echo lsefimmap lsefi lsefisystab efinet tftp minicmd
+    - if [ $PLATFORM = "linux/amd64" ]; then
+        grub-mkimage --prefix="" -o ~/grub_x86.efi -O i386-efi normal  echo lsefimmap lsefi lsefisystab efinet tftp minicmd;
+        grub-mkimage --prefix="" -o ~/grub_x64.efi -O x86_64-efi normal  echo lsefimmap lsefi lsefisystab efinet tftp minicmd;
+      else
+        grub-mkimage --prefix="" -o ~/grub_x86.efi -O arm64-efi normal  echo lsefimmap lsefi lsefisystab efinet tftp minicmd;
+      fi
     - if [[ "${TEST_PY_BD}" == "qemu-riscv32_spl" ]]; then
         wget -O - https://github.com/riscv-software-src/opensbi/releases/download/v1.3.1/opensbi-1.3.1-rv-bin.tar.xz | tar -C /tmp -xJ;
         export OPENSBI=/tmp/opensbi-1.3.1-rv-bin/share/opensbi/ilp32/generic/firmware/fw_dynamic.bin;
Signature · 1 line
2.34.1