@pali, I appreciate the attempt to fix, but as you point out, it shouldn't be happening due to reserved space. Also, I think the environment is in a different order anyway, such that it isn't hitting the beginning of scriptaddr. And lastly, I've been playing with u-boot 2022.10 and TF-A 2.8, and I can't repeat the problem myself. So it may be some deeper problem that includes even the toolchain, or even something to do with starting from the older environment first.
We've noted that the existence of "scriptaddr" and not "criptaddr" is an important check when board fails to boot. Better still will be to keep the platform firmware up to date so as to not have this bug at all.
But as for your patch: Doesn't it check each byte two times? Do we care about efficiency? I propose:
while (*ptr != '\0') {
do { ptr++; } while (*ptr != '\0') ;
ptr++;
}
The inner while will scan until the end of the current string, while the outer loop ends on the second null. There's an initial condition of being at the end of the list already, which is detected by starting on a null rather than a character.