Skip to contentSkip to conversation

common/spl: use memmove() in load_simple_fit()

PATCH In review Rasmus Villemoes 4 participants 4 messages Aug 19, 2025 – Jan 27

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common/spl: use memmove() in load_simple_fit()

I had trouble booting some am335x boards (both beagleboneblack and a custom board). SPL would start just fine, and apparently load U-Boot proper, but it would hang when jumping to U-Boot.

While debugging, I stumbled on this memcpy() which from code inspection very much looked to have overlapping src and dst, and indeed a simple printf revealed

calling memcpy(0x8087bf68, 0x8087bf80, 0xf7f8)

Now, it will always be with src > dst, our memcpy() implementations "most likely" do forward-copying, and in the end it turned out that this wasn't the culprit after all [*].

But to avoid me or others barking up the wrong tree in the future, and because this use of memcpy() is technically undefined, use memmove() instead.

[*] That was 358d1cc232c ("spl: Align FDT load address"), which has since been fixed in master but not the v2025.07 I worked of by 52caad0d14a ("ARM: Align image end to 8 bytes to fit DT alignment").

---
 common/spl/spl_fit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/spl/spl_fit.c +1 -1
index 25f3c822a49..746c3d2fa28 100644
@@ -353,7 +353,7 @@ static int load_simple_fit(struct spl_load_info *info, ulong fit_offset,
 		}
 		length = loadEnd - CONFIG_SYS_LOAD_ADDR;
 	} else {
-		memcpy(load_ptr, src, length);
+		memmove(load_ptr, src, length);
 	}
 
 	if (image_info) {
Signature · 1 line
2.50.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 33 lines · Rasmus Villemoes

I had trouble booting some am335x boards (both beagleboneblack and a custom board). SPL would start just fine, and apparently load U-Boot proper, but it would hang when jumping to U-Boot.

While debugging, I stumbled on this memcpy() which from code inspection very much looked to have overlapping src and dst, and indeed a simple printf revealed

   calling memcpy(0x8087bf68, 0x8087bf80, 0xf7f8)

Now, it will always be with src > dst, our memcpy() implementations "most likely" do forward-copying, and in the end it turned out that this wasn't the culprit after all [*].

But to avoid me or others barking up the wrong tree in the future, and because this use of memcpy() is technically undefined, use memmove() instead.

[*] That was 358d1cc232c ("spl: Align FDT load address"), which has since been fixed in master but not the v2025.07 I worked of by 52caad0d14a ("ARM: Align image end to 8 bytes to fit DT alignment").

---
  common/spl/spl_fit.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
common/spl/spl_fit.c +0 -0
index 25f3c822a49..746c3d2fa28 100644

common/spl/spl_fit.c static int load_simple_fit(struct spl_load_info *info, ulong fit_offset, · line 359

Quoted 8 lines
common/spl/spl_fit.c +1 -1
@@ -353,7 +353,7 @@ static int load_simple_fit(struct spl_load_info *info, ulong fit_offset,
  		}
  		length = loadEnd - CONFIG_SYS_LOAD_ADDR;
  	} else {
-		memcpy(load_ptr, src, length);
+		memmove(load_ptr, src, length);
  	}
 
  	if (image_info) {
#2 lore raw
In reply to Rasmus Villemoes
Quoted 10 lines · Rasmus Villemoes

I had trouble booting some am335x boards (both beagleboneblack and a custom board). SPL would start just fine, and apparently load U-Boot proper, but it would hang when jumping to U-Boot.

While debugging, I stumbled on this memcpy() which from code inspection very much looked to have overlapping src and dst, and indeed a simple printf revealed

[...]

Applied to u-boot/next, thanks!

[1/1] common/spl: use memmove() in load_simple_fit()

      commit: 122c25c00a238b55ac6745eb961c5ea66b45be8c
Signature · 1 line
Tom
#3 lore raw
In reply to Rasmus Villemoes

Hi Rasmus,

Quoted 43 lines · Rasmus Villemoes

I had trouble booting some am335x boards (both beagleboneblack and a custom board). SPL would start just fine, and apparently load U-Boot proper, but it would hang when jumping to U-Boot.

While debugging, I stumbled on this memcpy() which from code inspection very much looked to have overlapping src and dst, and indeed a simple printf revealed

calling memcpy(0x8087bf68, 0x8087bf80, 0xf7f8)

Now, it will always be with src > dst, our memcpy() implementations "most likely" do forward-copying, and in the end it turned out that this wasn't the culprit after all [*].

But to avoid me or others barking up the wrong tree in the future, and because this use of memcpy() is technically undefined, use memmove() instead.

[*] That was 358d1cc232c ("spl: Align FDT load address"), which has since been fixed in master but not the v2025.07 I worked of by 52caad0d14a ("ARM: Align image end to 8 bytes to fit DT alignment").

---
 common/spl/spl_fit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/spl/spl_fit.c +1 -2
index 25f3c822a49..746c3d2fa28 100644
@@ -353,7 +353,7 @@ static int load_simple_fit(struct spl_load_info *info, ulong fit_offset,
                }
                length = loadEnd - CONFIG_SYS_LOAD_ADDR;
        } else {
-               memcpy(load_ptr, src, length);
+               memmove(load_ptr, src, length);
        }
 
        if (image_info) {
--
Quoted 2 lines

2.50.1

I just hit this too, thanks for the fix!

- Simon