Hi folks,

We are still using PrePi on some of our platforms and the code is still running on Flash at this stage. We found there is global data write in ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S. The change was introduced by this commit: 5dbacdb21b59748e885c2eccae370b81271ab795:

+mSystemMemoryEnd:  .8byte 0^M

 ASM_PFX(_ModuleEntryPoint):
   // Do early platform specific actions
@@ -40,12 +42,23 @@ _SetSVCMode:
 // Check if we can install the stack at the top of the System Memory or if we need
 // to install the stacks at the bottom of the Firmware Device (case the FD is located
 // at the top of the DRAM)
-_SetupStackPosition:
-  // Compute Top of System Memory
-  LoadConstantToReg (FixedPcdGet64 (PcdSystemMemoryBase), x1)
-  LoadConstantToReg (FixedPcdGet64 (PcdSystemMemorySize), x2)
+_SystemMemoryEndInit:^M
+  ldr   x1, mSystemMemoryEnd^M
+^M
+  // Is mSystemMemoryEnd initialized?^M
+  cmp   x1, #0^M
+  bne   _SetupStackPosition^M
+^M
+  LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryBase), x1)^M
+  LoadConstantToReg (FixedPcdGet32(PcdSystemMemorySize), x2)^M
   sub   x2, x2, #1
-  add   x1, x1, x2      // x1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize
+  add   x1, x1, x2^M
+  // Update the global variable^M
adr   x2, mSystemMemoryEnd^M
str   x1, [x2]^M

I think direct write to flash should be forbidden. This change may work well for platforms which use ATF and load PrePi into memory, but not for other platforms.

Please let me know your comments about this.

Thanks and regards,

Heyi