Skip to contentSkip to conversation

common/memsize.c: Fix get_ram_size() original data restore

PATCH In review Stefan Eichenberger 5 participants 16 messages Mar 14, 2025 – Mar 2

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common/memsize.c: Fix get_ram_size() original data restore

From: Stefan Eichenberger <[email protected]>

The get_ram_size() function fails to restore the original RAM data when the data cache is enabled. This issue was observed on an AM625 R5 SPL with 512MB of RAM and is a regression that became visible with commit bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled").

Observed boot failure messages:
Warning: Did not detect image signing certificate. Skipping authentication to prevent boot failure. This will fail on Security Enforcing(HS-SE) devices Authentication passed
Starting ATF on ARM64 core...

The system then hangs. This indicates that without a data cache flush, data in the cache is not coherent with RAM, preventing the system from booting. This was verified by printing the content of this address when the issue occurs.

Add a data cache flush after each restore operation to resolve this issue.

Fixes bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled")
Fixes 1c64b98c1ec4 ("common/memsize.c: Fix get_ram_size() when cache is enabled")
---
 common/memsize.c | 8 ++++++++
 1 file changed, 8 insertions(+)
common/memsize.c +8 -0
index 86109579c95..8fa1b0e2a00 100644
@@ -82,6 +82,8 @@ long get_ram_size(long *base, long maxsize)
 			addr  = base + cnt;
 			sync();
 			*addr = save[--i];
+			if (dcache_en)
+				dcache_flush_invalidate(addr);
 		}
 		return (0);
 	}
@@ -90,6 +92,8 @@ long get_ram_size(long *base, long maxsize)
 		addr = base + cnt;	/* pointer arith! */
 		val = *addr;
 		*addr = save[--i];
+		if (dcache_en)
+			dcache_flush_invalidate(addr);
 		if (val != ~cnt) {
 			size = cnt * sizeof(long);
 			/*
@@ -101,6 +105,8 @@ long get_ram_size(long *base, long maxsize)
 			     cnt <<= 1) {
 				addr  = base + cnt;
 				*addr = save[--i];
+				if (dcache_en)
+					dcache_flush_invalidate(addr);
 			}
 			/* warning: don't restore save_base in this case,
 			 * it is already done in the loop because
@@ -112,6 +118,8 @@ long get_ram_size(long *base, long maxsize)
 		}
 	}
 	*base = save_base;
+	if (dcache_en)
+		dcache_flush_invalidate(base);
 
 	return (maxsize);
 }
Signature · 1 line
2.45.2
#1 lore raw

Hello Tom,

Quoted 18 lines · Stefan Eichenberger

From: Stefan Eichenberger <[email protected]>

The get_ram_size() function fails to restore the original RAM data when the data cache is enabled. This issue was observed on an AM625 R5 SPL with 512MB of RAM and is a regression that became visible with commit bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled").

Observed boot failure messages:
Warning: Did not detect image signing certificate. Skipping authentication to prevent boot failure. This will fail on Security Enforcing(HS-SE) devices Authentication passed
Starting ATF on ARM64 core...

The system then hangs. This indicates that without a data cache flush, data in the cache is not coherent with RAM, preventing the system from booting. This was verified by printing the content of this address when the issue occurs.

Quoted 6 lines

Add a data cache flush after each restore operation to resolve this issue.

Fixes bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled")
Fixes 1c64b98c1ec4 ("common/memsize.c: Fix get_ram_size() when cache is enabled")

This patch is for master, and it is hopefully fixing the last remaining issue that is preventing our board to boot with current U-Boot.

Thanks,
Francesco

#2 lore raw
In reply to Stefan Eichenberger
Quoted 21 lines · Stefan Eichenberger

From: Stefan Eichenberger <[email protected]>

The get_ram_size() function fails to restore the original RAM data when the data cache is enabled. This issue was observed on an AM625 R5 SPL with 512MB of RAM and is a regression that became visible with commit bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled").

Observed boot failure messages:
Warning: Did not detect image signing certificate. Skipping authentication to prevent boot failure. This will fail on Security Enforcing(HS-SE) devices Authentication passed
Starting ATF on ARM64 core...

The system then hangs. This indicates that without a data cache flush, data in the cache is not coherent with RAM, preventing the system from booting. This was verified by printing the content of this address when the issue occurs.

Add a data cache flush after each restore operation to resolve this issue.

Quoted 6 lines
Fixes bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled")
Fixes 1c64b98c1ec4 ("common/memsize.c: Fix get_ram_size() when cache is enabled")
---
 common/memsize.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Ugh. Is there not a chance the problem being that we need a dcache_flush_all() in the K3 ddr code somewhere? I'm just trying to see how we got here and I notice now that yes, this does look like it finishes what 1c64b98c1ec4 started but in hindsight was that showing something else needing to be fixed?

Signature · 1 line
Tom
#3 lore raw

Hi Tom,

Quoted 30 lines · Tom Rini
Quoted 21 lines · Stefan Eichenberger

From: Stefan Eichenberger <[email protected]>

The get_ram_size() function fails to restore the original RAM data when the data cache is enabled. This issue was observed on an AM625 R5 SPL with 512MB of RAM and is a regression that became visible with commit bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled").

Observed boot failure messages:
Warning: Did not detect image signing certificate. Skipping authentication to prevent boot failure. This will fail on Security Enforcing(HS-SE) devices Authentication passed
Starting ATF on ARM64 core...

The system then hangs. This indicates that without a data cache flush, data in the cache is not coherent with RAM, preventing the system from booting. This was verified by printing the content of this address when the issue occurs.

Add a data cache flush after each restore operation to resolve this issue.

Quoted 6 lines
Fixes bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled")
Fixes 1c64b98c1ec4 ("common/memsize.c: Fix get_ram_size() when cache is enabled")
---
 common/memsize.c | 8 ++++++++
 1 file changed, 8 insertions(+)
Quoted 5 lines

Ugh. Is there not a chance the problem being that we need a dcache_flush_all() in the K3 ddr code somewhere? I'm just trying to see how we got here and I notice now that yes, this does look like it finishes what 1c64b98c1ec4 started but in hindsight was that showing something else needing to be fixed?

I am also not entirely satisfied with the current fix. I rechecked with U-Boot v2024.10, where we did not observe the issue. This difference is due to the cache always being disabled when get_ram_size() is called. This explains why it was working before commit bc07851897bd ("board: ti:
Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled").

I think my previous fix introduced this second call to get_ram_size() when adding:
void spl_perform_fixups(struct spl_image_info *spl_image)

{
	fixup_memory_node(spl_image);
}

Doing some more tests now shows that probably only adding the following would have been sufficient:
gd->bd->bi_dram[0].size = gd->ram_size;

If confirmed through further testing, this patch may be unnecessary.

Regards,
Stefan

#4 lore raw
In reply to Stefan Eichenberger

Hello Tom,

Quoted 18 lines · Stefan Eichenberger

From: Stefan Eichenberger <[email protected]>

The get_ram_size() function fails to restore the original RAM data when the data cache is enabled. This issue was observed on an AM625 R5 SPL with 512MB of RAM and is a regression that became visible with commit bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled").

Observed boot failure messages:
Warning: Did not detect image signing certificate. Skipping authentication to prevent boot failure. This will fail on Security Enforcing(HS-SE) devices Authentication passed
Starting ATF on ARM64 core...

The system then hangs. This indicates that without a data cache flush, data in the cache is not coherent with RAM, preventing the system from booting. This was verified by printing the content of this address when the issue occurs.

Quoted 6 lines

Add a data cache flush after each restore operation to resolve this issue.

Fixes bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled")
Fixes 1c64b98c1ec4 ("common/memsize.c: Fix get_ram_size() when cache is enabled")

Tom, can we merge this?
This is the last bit to solve the regression reported here,
https://lore.kernel.org/all/20260224152405.GD340942@francesco-nb/

Thanks,
Francesco

#5 lore raw
Quoted 24 lines · Francesco Dolcini

Hello Tom,

Quoted 21 lines · Stefan Eichenberger

From: Stefan Eichenberger <[email protected]>

The get_ram_size() function fails to restore the original RAM data when the data cache is enabled. This issue was observed on an AM625 R5 SPL with 512MB of RAM and is a regression that became visible with commit bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled").

Observed boot failure messages:
Warning: Did not detect image signing certificate. Skipping authentication to prevent boot failure. This will fail on Security Enforcing(HS-SE) devices Authentication passed
Starting ATF on ARM64 core...

The system then hangs. This indicates that without a data cache flush, data in the cache is not coherent with RAM, preventing the system from booting. This was verified by printing the content of this address when the issue occurs.

Add a data cache flush after each restore operation to resolve this issue.

Quoted 7 lines
Quoted 3 lines
Fixes bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled")
Fixes 1c64b98c1ec4 ("common/memsize.c: Fix get_ram_size() when cache is enabled")

Tom, can we merge this?
This is the last bit to solve the regression reported here,
https://lore.kernel.org/all/20260224152405.GD340942@francesco-nb/

I wasn't happy with this at the time, and Stefan's last email in the thread left me with the impression more investigation was needed and likely something else was the root cause.

Signature · 1 line
Tom
#6 lore raw

+Emanuele

Hello Tom,

Quoted 29 lines · Tom Rini
Quoted 28 lines · Francesco Dolcini

Hello Tom,

Quoted 24 lines · Stefan Eichenberger

From: Stefan Eichenberger <[email protected]>

The get_ram_size() function fails to restore the original RAM data when the data cache is enabled. This issue was observed on an AM625 R5 SPL with 512MB of RAM and is a regression that became visible with commit bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled").

Observed boot failure messages:
Warning: Did not detect image signing certificate. Skipping authentication to prevent boot failure. This will fail on Security Enforcing(HS-SE) devices Authentication passed
Starting ATF on ARM64 core...

The system then hangs. This indicates that without a data cache flush, data in the cache is not coherent with RAM, preventing the system from booting. This was verified by printing the content of this address when the issue occurs.

Add a data cache flush after each restore operation to resolve this issue.

Fixes bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled")
Fixes 1c64b98c1ec4 ("common/memsize.c: Fix get_ram_size() when cache is enabled")
Quoted 7 lines
Quoted 3 lines

Tom, can we merge this?
This is the last bit to solve the regression reported here,
https://lore.kernel.org/all/20260224152405.GD340942@francesco-nb/

I wasn't happy with this at the time, and Stefan's last email in the thread left me with the impression more investigation was needed and likely something else was the root cause.

I believe that this patch is needed.

On AM62 what is happening is the following.

We have a cortex-R5 that is the first core booting (there is also a cortex-m4, but it's not relevant for this discussion).

It runs from internal memory and it configures the DDR ram

We load to DDR memory various pieces of firmware (TFA, U-Boot for the cortex A53, ...)

We do execute get_ram_size(), that read/write the memory, and it is supposed to restore it back the original content

However when we have the cache enabled, we might miss to write back the original memory content, where the other pieces of firmware are.

And after that we start the cortex A53, running in DDR, and there the memory content might not be correct, because there is no cache coherency between the cortex-A and the cortex-R. And because of that we have crashes.

Stefan: any comment here? Can you help?

Francesco

#8 lore raw
In reply to Stefan Eichenberger
Quoted 78 lines · Stefan Eichenberger

Hi Francesco and Tom,

Quoted 60 lines · Francesco Dolcini

+Emanuele

Hello Tom,

Quoted 29 lines · Tom Rini
Quoted 28 lines · Francesco Dolcini

Hello Tom,

Quoted 24 lines · Stefan Eichenberger

From: Stefan Eichenberger <[email protected]>

The get_ram_size() function fails to restore the original RAM data when the data cache is enabled. This issue was observed on an AM625 R5 SPL with 512MB of RAM and is a regression that became visible with commit bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled").

Observed boot failure messages:
Warning: Did not detect image signing certificate. Skipping authentication to prevent boot failure. This will fail on Security Enforcing(HS-SE) devices Authentication passed
Starting ATF on ARM64 core...

The system then hangs. This indicates that without a data cache flush, data in the cache is not coherent with RAM, preventing the system from booting. This was verified by printing the content of this address when the issue occurs.

Add a data cache flush after each restore operation to resolve this issue.

Fixes bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled")
Fixes 1c64b98c1ec4 ("common/memsize.c: Fix get_ram_size() when cache is enabled")
Quoted 7 lines
Quoted 3 lines

Tom, can we merge this?
This is the last bit to solve the regression reported here,
https://lore.kernel.org/all/20260224152405.GD340942@francesco-nb/

I wasn't happy with this at the time, and Stefan's last email in the thread left me with the impression more investigation was needed and likely something else was the root cause.

I believe that this patch is needed.

On AM62 what is happening is the following.

We have a cortex-R5 that is the first core booting (there is also a cortex-m4, but it's not relevant for this discussion).

It runs from internal memory and it configures the DDR ram

We load to DDR memory various pieces of firmware (TFA, U-Boot for the cortex A53, ...)

We do execute get_ram_size(), that read/write the memory, and it is supposed to restore it back the original content

However when we have the cache enabled, we might miss to write back the original memory content, where the other pieces of firmware are.

Quoted 6 lines

And after that we start the cortex A53, running in DDR, and there the memory content might not be correct, because there is no cache coherency between the cortex-A and the cortex-R. And because of that we have crashes.

Stefan: any comment here? Can you help?

I think what you wrote summarises the issue well. If I recall correctly, I "fixed" the issue last time by simply calling get_ram_size() once before enabling the cache. This was in commit 4164289db882e. The SPL then informs U-Boot of the memory size via fdt fixup. However, something has probably changed now (possibly in the R5 SPL), meaning the cache is enabled earlier, so the cache is enabled again when get_ram_size() is called.

Quoted 3 lines

For the AMP use case, either "get_ram_size" should not be called once the cache is enabled, or a similar patch to the one I proposed is required.

I would lean towards the former if at all possible.

Signature · 1 line
Tom
#7 lore raw
In reply to Francesco Dolcini

Hi Francesco and Tom,

Quoted 60 lines · Francesco Dolcini

+Emanuele

Hello Tom,

Quoted 29 lines · Tom Rini
Quoted 28 lines · Francesco Dolcini

Hello Tom,

Quoted 24 lines · Stefan Eichenberger

From: Stefan Eichenberger <[email protected]>

The get_ram_size() function fails to restore the original RAM data when the data cache is enabled. This issue was observed on an AM625 R5 SPL with 512MB of RAM and is a regression that became visible with commit bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled").

Observed boot failure messages:
Warning: Did not detect image signing certificate. Skipping authentication to prevent boot failure. This will fail on Security Enforcing(HS-SE) devices Authentication passed
Starting ATF on ARM64 core...

The system then hangs. This indicates that without a data cache flush, data in the cache is not coherent with RAM, preventing the system from booting. This was verified by printing the content of this address when the issue occurs.

Add a data cache flush after each restore operation to resolve this issue.

Fixes bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled")
Fixes 1c64b98c1ec4 ("common/memsize.c: Fix get_ram_size() when cache is enabled")
Quoted 7 lines
Quoted 3 lines

Tom, can we merge this?
This is the last bit to solve the regression reported here,
https://lore.kernel.org/all/20260224152405.GD340942@francesco-nb/

I wasn't happy with this at the time, and Stefan's last email in the thread left me with the impression more investigation was needed and likely something else was the root cause.

I believe that this patch is needed.

On AM62 what is happening is the following.

We have a cortex-R5 that is the first core booting (there is also a cortex-m4, but it's not relevant for this discussion).

It runs from internal memory and it configures the DDR ram

We load to DDR memory various pieces of firmware (TFA, U-Boot for the cortex A53, ...)

We do execute get_ram_size(), that read/write the memory, and it is supposed to restore it back the original content

However when we have the cache enabled, we might miss to write back the original memory content, where the other pieces of firmware are.

Quoted 6 lines

And after that we start the cortex A53, running in DDR, and there the memory content might not be correct, because there is no cache coherency between the cortex-A and the cortex-R. And because of that we have crashes.

Stefan: any comment here? Can you help?

I think what you wrote summarises the issue well. If I recall correctly, I "fixed" the issue last time by simply calling get_ram_size() once before enabling the cache. This was in commit 4164289db882e. The SPL then informs U-Boot of the memory size via fdt fixup. However, something has probably changed now (possibly in the R5 SPL), meaning the cache is enabled earlier, so the cache is enabled again when get_ram_size() is called.

For the AMP use case, either "get_ram_size" should not be called once the cache is enabled, or a similar patch to the one I proposed is required.

Regards,
Stefan

#9 lore raw
In reply to Tom Rini
Quoted 79 lines · Tom Rini
Quoted 78 lines · Stefan Eichenberger

Hi Francesco and Tom,

Quoted 60 lines · Francesco Dolcini

+Emanuele

Hello Tom,

Quoted 29 lines · Tom Rini
Quoted 28 lines · Francesco Dolcini

Hello Tom,

Quoted 24 lines · Stefan Eichenberger

From: Stefan Eichenberger <[email protected]>

The get_ram_size() function fails to restore the original RAM data when the data cache is enabled. This issue was observed on an AM625 R5 SPL with 512MB of RAM and is a regression that became visible with commit bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled").

Observed boot failure messages:
Warning: Did not detect image signing certificate. Skipping authentication to prevent boot failure. This will fail on Security Enforcing(HS-SE) devices Authentication passed
Starting ATF on ARM64 core...

The system then hangs. This indicates that without a data cache flush, data in the cache is not coherent with RAM, preventing the system from booting. This was verified by printing the content of this address when the issue occurs.

Add a data cache flush after each restore operation to resolve this issue.

Fixes bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled")
Fixes 1c64b98c1ec4 ("common/memsize.c: Fix get_ram_size() when cache is enabled")
Quoted 7 lines
Quoted 3 lines

Tom, can we merge this?
This is the last bit to solve the regression reported here,
https://lore.kernel.org/all/20260224152405.GD340942@francesco-nb/

I wasn't happy with this at the time, and Stefan's last email in the thread left me with the impression more investigation was needed and likely something else was the root cause.

I believe that this patch is needed.

On AM62 what is happening is the following.

We have a cortex-R5 that is the first core booting (there is also a cortex-m4, but it's not relevant for this discussion).

It runs from internal memory and it configures the DDR ram

We load to DDR memory various pieces of firmware (TFA, U-Boot for the cortex A53, ...)

We do execute get_ram_size(), that read/write the memory, and it is supposed to restore it back the original content

However when we have the cache enabled, we might miss to write back the original memory content, where the other pieces of firmware are.

Quoted 6 lines

And after that we start the cortex A53, running in DDR, and there the memory content might not be correct, because there is no cache coherency between the cortex-A and the cortex-R. And because of that we have crashes.

Stefan: any comment here? Can you help?

I think what you wrote summarises the issue well. If I recall correctly, I "fixed" the issue last time by simply calling get_ram_size() once before enabling the cache. This was in commit 4164289db882e. The SPL then informs U-Boot of the memory size via fdt fixup. However, something has probably changed now (possibly in the R5 SPL), meaning the cache is enabled earlier, so the cache is enabled again when get_ram_size() is called.

Quoted 6 lines
Quoted 3 lines

For the AMP use case, either "get_ram_size" should not be called once the cache is enabled, or a similar patch to the one I proposed is required.

I would lean towards the former if at all possible.

Just trying to understand, what is the reasoning behind ensuring get_ram_size is not called if cache is not enabled? Wasn't get_ram_size written with the possibility of cache being enabled (existence of dcache_en logic); then this patch is a valid fix right?

In parallel, I do agree we need to have a code analysis w.r.t dram_init, we are making certain cache and dram calls spuriously making this confusing.

Signature · 2 lines
Thanking You
Neha Malcom Francis
#10 lore raw
Quoted 89 lines · Neha
Quoted 79 lines · Tom Rini
Quoted 78 lines · Stefan Eichenberger

Hi Francesco and Tom,

Quoted 60 lines · Francesco Dolcini

+Emanuele

Hello Tom,

Quoted 29 lines · Tom Rini
Quoted 28 lines · Francesco Dolcini

Hello Tom,

Quoted 24 lines · Stefan Eichenberger

From: Stefan Eichenberger <[email protected]>

The get_ram_size() function fails to restore the original RAM data when the data cache is enabled. This issue was observed on an AM625 R5 SPL with 512MB of RAM and is a regression that became visible with commit bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled").

Observed boot failure messages:
Warning: Did not detect image signing certificate. Skipping authentication to prevent boot failure. This will fail on Security Enforcing(HS-SE) devices Authentication passed
Starting ATF on ARM64 core...

The system then hangs. This indicates that without a data cache flush, data in the cache is not coherent with RAM, preventing the system from booting. This was verified by printing the content of this address when the issue occurs.

Add a data cache flush after each restore operation to resolve this issue.

Fixes bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled")
Fixes 1c64b98c1ec4 ("common/memsize.c: Fix get_ram_size() when cache is enabled")
Quoted 7 lines
Quoted 3 lines

Tom, can we merge this?
This is the last bit to solve the regression reported here,
https://lore.kernel.org/all/20260224152405.GD340942@francesco-nb/

I wasn't happy with this at the time, and Stefan's last email in the thread left me with the impression more investigation was needed and likely something else was the root cause.

I believe that this patch is needed.

On AM62 what is happening is the following.

We have a cortex-R5 that is the first core booting (there is also a cortex-m4, but it's not relevant for this discussion).

It runs from internal memory and it configures the DDR ram

We load to DDR memory various pieces of firmware (TFA, U-Boot for the cortex A53, ...)

We do execute get_ram_size(), that read/write the memory, and it is supposed to restore it back the original content

However when we have the cache enabled, we might miss to write back the original memory content, where the other pieces of firmware are.

Quoted 6 lines

And after that we start the cortex A53, running in DDR, and there the memory content might not be correct, because there is no cache coherency between the cortex-A and the cortex-R. And because of that we have crashes.

Stefan: any comment here? Can you help?

I think what you wrote summarises the issue well. If I recall correctly, I "fixed" the issue last time by simply calling get_ram_size() once before enabling the cache. This was in commit 4164289db882e. The SPL then informs U-Boot of the memory size via fdt fixup. However, something has probably changed now (possibly in the R5 SPL), meaning the cache is enabled earlier, so the cache is enabled again when get_ram_size() is called.

Quoted 6 lines
Quoted 3 lines

For the AMP use case, either "get_ram_size" should not be called once the cache is enabled, or a similar patch to the one I proposed is required.

I would lean towards the former if at all possible.

Quoted 8 lines

Just trying to understand, what is the reasoning behind ensuring get_ram_size is not called if cache is not enabled? Wasn't get_ram_size written with the possibility of cache being enabled (existence of dcache_en logic); then this patch is a valid fix right?

In parallel, I do agree we need to have a code analysis w.r.t dram_init, we are making certain cache and dram calls spuriously making this confusing.

Hello Tom,
I agree with Francis.

When I proposed commit 1c64b98c1ec4 ("common/memsize.c: Fix get_ram_size() when cache is enabled"), I was not considering the presence of other actors (other cores, DMA engines, etc.).

That patch fixes what I had overlooked at the time. We need to restore the actual RAM contents, not only what is perceived by the core executing get_ram_size().

To me this patch sounds intrinsically correct.

Thank you and kind regards,
Emanuele

#13 lore raw
In reply to Francis, Neha
Quoted 76 lines · Neha
Quoted 75 lines · Tom Rini
Quoted 73 lines · Stefan Eichenberger
Quoted 54 lines · Francesco Dolcini
Quoted 27 lines · Tom Rini
Quoted 26 lines · Francesco Dolcini
Quoted 24 lines · Stefan Eichenberger

From: Stefan Eichenberger <[email protected]>

The get_ram_size() function fails to restore the original RAM data when the data cache is enabled. This issue was observed on an AM625 R5 SPL with 512MB of RAM and is a regression that became visible with commit bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled").

Observed boot failure messages:
Warning: Did not detect image signing certificate. Skipping authentication to prevent boot failure. This will fail on Security Enforcing(HS-SE) devices Authentication passed
Starting ATF on ARM64 core...

The system then hangs. This indicates that without a data cache flush, data in the cache is not coherent with RAM, preventing the system from booting. This was verified by printing the content of this address when the issue occurs.

Add a data cache flush after each restore operation to resolve this issue.

Fixes bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled")
Fixes 1c64b98c1ec4 ("common/memsize.c: Fix get_ram_size() when cache is enabled")
Quoted 7 lines
Quoted 3 lines

Tom, can we merge this?
This is the last bit to solve the regression reported here,
https://lore.kernel.org/all/20260224152405.GD340942@francesco-nb/

I wasn't happy with this at the time, and Stefan's last email in the thread left me with the impression more investigation was needed and likely something else was the root cause.

I believe that this patch is needed.

On AM62 what is happening is the following.

We have a cortex-R5 that is the first core booting (there is also a cortex-m4, but it's not relevant for this discussion).

It runs from internal memory and it configures the DDR ram

We load to DDR memory various pieces of firmware (TFA, U-Boot for the cortex A53, ...)

We do execute get_ram_size(), that read/write the memory, and it is supposed to restore it back the original content

However when we have the cache enabled, we might miss to write back the original memory content, where the other pieces of firmware are.

Quoted 6 lines

And after that we start the cortex A53, running in DDR, and there the memory content might not be correct, because there is no cache coherency between the cortex-A and the cortex-R. And because of that we have crashes.

Stefan: any comment here? Can you help?

I think what you wrote summarises the issue well. If I recall correctly, I "fixed" the issue last time by simply calling get_ram_size() once before enabling the cache. This was in commit 4164289db882e. The SPL then informs U-Boot of the memory size via fdt fixup. However, something has probably changed now (possibly in the R5 SPL), meaning the cache is enabled earlier, so the cache is enabled again when get_ram_size() is called.

For the AMP use case, either "get_ram_size" should not be called once the cache is enabled, or a similar patch to the one I proposed is required.

Quoted 6 lines
Quoted 2 lines

I would lean towards the former if at all possible.

Just trying to understand, what is the reasoning behind ensuring get_ram_size is not called if cache is not enabled? Wasn't get_ram_size written with the possibility of cache being enabled (existence of dcache_en logic); then this patch is a valid fix right?

Yes, I am also confused about this.

Right now get_ram_size works well if cache is enabled ... apart this issue in which the memory state is correct only from the CPU core that called the function (or that we have some kind of HW cache coherency in place, but this is not the case for AM62 A53/R5 cores).

If I have to solve the issue outside of get_ram_size(), I can either disable the cache before calling it, or flush the whole cache to the DDR just afterward.

IOW, to me the patch is conceptually correct and I would apply it.

Francesco

#11 lore raw
In reply to Emanuele Ghidoli
Quoted 108 lines · Emanuele Ghidoli
Quoted 89 lines · Neha
Quoted 79 lines · Tom Rini
Quoted 78 lines · Stefan Eichenberger

Hi Francesco and Tom,

Quoted 60 lines · Francesco Dolcini

+Emanuele

Hello Tom,

Quoted 29 lines · Tom Rini
Quoted 28 lines · Francesco Dolcini

Hello Tom,

Quoted 24 lines · Stefan Eichenberger

From: Stefan Eichenberger <[email protected]>

The get_ram_size() function fails to restore the original RAM data when the data cache is enabled. This issue was observed on an AM625 R5 SPL with 512MB of RAM and is a regression that became visible with commit bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled").

Observed boot failure messages:
Warning: Did not detect image signing certificate. Skipping authentication to prevent boot failure. This will fail on Security Enforcing(HS-SE) devices Authentication passed
Starting ATF on ARM64 core...

The system then hangs. This indicates that without a data cache flush, data in the cache is not coherent with RAM, preventing the system from booting. This was verified by printing the content of this address when the issue occurs.

Add a data cache flush after each restore operation to resolve this issue.

Fixes bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled")
Fixes 1c64b98c1ec4 ("common/memsize.c: Fix get_ram_size() when cache is enabled")
Quoted 7 lines
Quoted 3 lines

Tom, can we merge this?
This is the last bit to solve the regression reported here,
https://lore.kernel.org/all/20260224152405.GD340942@francesco-nb/

I wasn't happy with this at the time, and Stefan's last email in the thread left me with the impression more investigation was needed and likely something else was the root cause.

I believe that this patch is needed.

On AM62 what is happening is the following.

We have a cortex-R5 that is the first core booting (there is also a cortex-m4, but it's not relevant for this discussion).

It runs from internal memory and it configures the DDR ram

We load to DDR memory various pieces of firmware (TFA, U-Boot for the cortex A53, ...)

We do execute get_ram_size(), that read/write the memory, and it is supposed to restore it back the original content

However when we have the cache enabled, we might miss to write back the original memory content, where the other pieces of firmware are.

Quoted 6 lines

And after that we start the cortex A53, running in DDR, and there the memory content might not be correct, because there is no cache coherency between the cortex-A and the cortex-R. And because of that we have crashes.

Stefan: any comment here? Can you help?

I think what you wrote summarises the issue well. If I recall correctly, I "fixed" the issue last time by simply calling get_ram_size() once before enabling the cache. This was in commit 4164289db882e. The SPL then informs U-Boot of the memory size via fdt fixup. However, something has probably changed now (possibly in the R5 SPL), meaning the cache is enabled earlier, so the cache is enabled again when get_ram_size() is called.

Quoted 6 lines
Quoted 3 lines

For the AMP use case, either "get_ram_size" should not be called once the cache is enabled, or a similar patch to the one I proposed is required.

I would lean towards the former if at all possible.

Quoted 8 lines

Just trying to understand, what is the reasoning behind ensuring get_ram_size is not called if cache is not enabled? Wasn't get_ram_size written with the possibility of cache being enabled (existence of dcache_en logic); then this patch is a valid fix right?

In parallel, I do agree we need to have a code analysis w.r.t dram_init, we are making certain cache and dram calls spuriously making this confusing.

Hello Tom,
I agree with Francis.

When I proposed commit 1c64b98c1ec4 ("common/memsize.c: Fix get_ram_size() when cache is enabled"), I was not considering the presence of other actors (other cores, DMA engines, etc.).

Quoted 5 lines

That patch fixes what I had overlooked at the time. We need to restore the actual RAM contents, not only what is perceived by the core executing get_ram_size().

To me this patch sounds intrinsically correct.

Alright. Can I please get some Reviewed / Tested by tags? Thanks.

Signature · 1 line
Tom
Tested-by on v1 1/1
#14 lore raw
In reply to Stefan Eichenberger
Quoted 18 lines · Stefan Eichenberger

From: Stefan Eichenberger <[email protected]>

The get_ram_size() function fails to restore the original RAM data when the data cache is enabled. This issue was observed on an AM625 R5 SPL with 512MB of RAM and is a regression that became visible with commit bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled").

Observed boot failure messages:
Warning: Did not detect image signing certificate. Skipping authentication to prevent boot failure. This will fail on Security Enforcing(HS-SE) devices Authentication passed
Starting ATF on ARM64 core...

The system then hangs. This indicates that without a data cache flush, data in the cache is not coherent with RAM, preventing the system from booting. This was verified by printing the content of this address when the issue occurs.

Quoted 6 lines

Add a data cache flush after each restore operation to resolve this issue.

Fixes bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled")
Fixes 1c64b98c1ec4 ("common/memsize.c: Fix get_ram_size() when cache is enabled")
Reviewed-by
#12 lore raw
In reply to Tom Rini
Quoted 109 lines · Tom Rini
Quoted 108 lines · Emanuele Ghidoli
Quoted 89 lines · Neha
Quoted 79 lines · Tom Rini
Quoted 78 lines · Stefan Eichenberger

Hi Francesco and Tom,

Quoted 60 lines · Francesco Dolcini

+Emanuele

Hello Tom,

Quoted 29 lines · Tom Rini
Quoted 28 lines · Francesco Dolcini

Hello Tom,

Quoted 24 lines · Stefan Eichenberger

From: Stefan Eichenberger <[email protected]>

The get_ram_size() function fails to restore the original RAM data when the data cache is enabled. This issue was observed on an AM625 R5 SPL with 512MB of RAM and is a regression that became visible with commit bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled").

Observed boot failure messages:
Warning: Did not detect image signing certificate. Skipping authentication to prevent boot failure. This will fail on Security Enforcing(HS-SE) devices Authentication passed
Starting ATF on ARM64 core...

The system then hangs. This indicates that without a data cache flush, data in the cache is not coherent with RAM, preventing the system from booting. This was verified by printing the content of this address when the issue occurs.

Add a data cache flush after each restore operation to resolve this issue.

Fixes bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled")
Fixes 1c64b98c1ec4 ("common/memsize.c: Fix get_ram_size() when cache is enabled")
Quoted 7 lines
Quoted 3 lines

Tom, can we merge this?
This is the last bit to solve the regression reported here,
https://lore.kernel.org/all/20260224152405.GD340942@francesco-nb/

I wasn't happy with this at the time, and Stefan's last email in the thread left me with the impression more investigation was needed and likely something else was the root cause.

I believe that this patch is needed.

On AM62 what is happening is the following.

We have a cortex-R5 that is the first core booting (there is also a cortex-m4, but it's not relevant for this discussion).

It runs from internal memory and it configures the DDR ram

We load to DDR memory various pieces of firmware (TFA, U-Boot for the cortex A53, ...)

We do execute get_ram_size(), that read/write the memory, and it is supposed to restore it back the original content

However when we have the cache enabled, we might miss to write back the original memory content, where the other pieces of firmware are.

Quoted 6 lines

And after that we start the cortex A53, running in DDR, and there the memory content might not be correct, because there is no cache coherency between the cortex-A and the cortex-R. And because of that we have crashes.

Stefan: any comment here? Can you help?

I think what you wrote summarises the issue well. If I recall correctly, I "fixed" the issue last time by simply calling get_ram_size() once before enabling the cache. This was in commit 4164289db882e. The SPL then informs U-Boot of the memory size via fdt fixup. However, something has probably changed now (possibly in the R5 SPL), meaning the cache is enabled earlier, so the cache is enabled again when get_ram_size() is called.

Quoted 6 lines
Quoted 3 lines

For the AMP use case, either "get_ram_size" should not be called once the cache is enabled, or a similar patch to the one I proposed is required.

I would lean towards the former if at all possible.

Quoted 8 lines

Just trying to understand, what is the reasoning behind ensuring get_ram_size is not called if cache is not enabled? Wasn't get_ram_size written with the possibility of cache being enabled (existence of dcache_en logic); then this patch is a valid fix right?

In parallel, I do agree we need to have a code analysis w.r.t dram_init, we are making certain cache and dram calls spuriously making this confusing.

Hello Tom,
I agree with Francis.

When I proposed commit 1c64b98c1ec4 ("common/memsize.c: Fix get_ram_size() when cache is enabled"), I was not considering the presence of other actors (other cores, DMA engines, etc.).

Quoted 8 lines
Quoted 5 lines

That patch fixes what I had overlooked at the time. We need to restore the actual RAM contents, not only what is perceived by the core executing get_ram_size().

To me this patch sounds intrinsically correct.

Alright. Can I please get some Reviewed / Tested by tags? Thanks.

#15 lore raw
In reply to Stefan Eichenberger
Quoted 6 lines · Stefan Eichenberger

The get_ram_size() function fails to restore the original RAM data when the data cache is enabled. This issue was observed on an AM625 R5 SPL with 512MB of RAM and is a regression that became visible with commit bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled").

Quoted 6 lines

Observed boot failure messages:
Warning: Did not detect image signing certificate. Skipping authentication to prevent boot failure. This will fail on Security Enforcing(HS-SE) devices Authentication passed
Starting ATF on ARM64 core...

[...]

Applied to u-boot/master, thanks!

[1/1] common/memsize.c: Fix get_ram_size() original data restore

      commit: 8d24789abed0822fbe41a2f9d72cf19650159dc6
Signature · 1 line
Tom