linux4sam / at91bootstrap

Second level bootloader for Microchip SoC (aka AT91)
https://www.linux4sam.org/linux4sam/bin/view/Linux4SAM/AT91Bootstrap4
114 stars 232 forks source link

ddram: add missing volatile keywords #93

Closed pbugalski closed 5 years ago

pbugalski commented 5 years ago

Memory initialization requires specific procedure which might confuse compiler. Missing volatile keyords are causing errors when gcc 8 is used. Issue were reproduced on XULT board, first memory access gets broken as a result of memory access re-ordering by compiler.

Signed-off-by: Piotr Bugalski bugalski.piotr@gmail.com

pbugalski commented 5 years ago

First DDR memory access is broken when gcc 8.2.0 is used. This patch adds missing volatile keywords in memory initialization procedure.

ehristev commented 5 years ago

Did you test this change with older GCC as well (one not causing issues?) Can this be caused by doing over optimization in compiler configuration? Perhaps now you are using -O3 vs previous lower settings ? I do agree that volatile is crucial in such operations, I want to make sure older compiler configurations are not somehow broken (unlikely but we have to make sure)

pbugalski commented 5 years ago

I've tested using gcc 4.9.3 from Ubuntu 16.04.5 LTS, linaro gcc 7.2.1, gcc 8.2 and gcc built with yocto. All the time I'm using the same optimization level, only difference is related to compiler version. In gcc 8.2 generated assembly code access during RAM initialization is different than in C source and as a result memory doesn't work properly. But only first access is broken, we've discovered it accidentally when uboot code was not starting. However any access to RAM makes issue invisible.

If you wish I can try do some more tests with older gcc version, but I have only XULT(DDR3) and SOM1-EK (LPDDR2) boards. However additional volatile should not break the code. And missing allows optimizer to even remove access.

pbugalski commented 5 years ago

I've done the test again. I've used two eval boards: XULT rev.B and SOM1-EK. In both cases I'm using sdcard boot and linux image from: https://www.at91.com/linux4sam/bin/view/Linux4SAM Compiler version as mentioned before: 4.9.3, 7.2.1 and 8.2.1. As a test I was booting Linux to login prompt - and it was working correctly in all tested configurations.