Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //this is placed at the end of board.c (as there's no way that I know of to cancel #pragma GCC optimize after it's applied)
- #define ONEMEG ((1<<20)/sizeof(u32))
- #define MAXERRORS 50
- #ifdef SMOKEMEM
- //HERE BE DRAGONS. No compiler optimization beyond this point!
- #pragma GCC optimize "O0"
- //this memtest writes a fixed value to memory and reads it back in 1M blocks.
- static void smokers_memtest(u32 pattern)
- {
- printf("smokers_memtest started, pattern %08x\n", pattern);
- const u8* init_addr = (u8*) 0x40000000;
- u32 errorcount=0;
- u32* addr;
- for(uint megs = 0; megs < 1024; megs++)
- {
- u32* baseaddr = (u32*)init_addr+ONEMEG*megs;
- if(!(megs % 128)) {
- printf("\n%d M || 0x%x\n", megs, baseaddr);
- }
- printf("."); //writing block
- for(u32 offset = 0; offset < ONEMEG; ++offset)
- {
- *((volatile uint32_t *)baseaddr + offset) = pattern;
- }
- printf("'"); //reading block
- for(u32 offset = 0; offset < ONEMEG; ++offset)
- {
- if (readl((u32*)baseaddr + offset) != pattern) {
- if(++errorcount < MAXERRORS)
- printf("\nerror @ %x: %x\n", (u32)addr, readl(addr));
- //break;
- }
- }
- }
- printf("\n%d errors in pattern %08x\n",errorcount, pattern);
- errorcount=0;
- printf("smokers_memtest finished\n");
- };
- //this memtest overwrites the whole DRAM with values of magic^addr, and then reads the whole DRAM back.
- static void magic_memtest(u32 magicval){
- printf("\n magic_memtest started, magic value: %08x\n", magicval);
- const u8* init_addr = (u8*) 0x40000000;
- const unsigned meg_shift = 3; //8M steps
- u32 errorcount=0;
- u32* addr;
- printf("writing...");
- for(uint megs = 0; megs < 1024; megs+=1<<meg_shift)
- {
- u32* baseaddr = (u32*)init_addr+ONEMEG*megs;
- if(!(megs % 128)) printf("\n%d M || 0x%x\n", megs, baseaddr);
- for(u32 offset = 0; offset < ONEMEG<<meg_shift; ++offset)
- {
- addr = (u32*)baseaddr+offset;
- *((volatile uint32_t *)baseaddr + offset) = magicval^(u32)addr;
- }
- printf(".");
- }
- printf("\nreading...");
- for(uint megs = 0; megs < 1024; megs+=1<<meg_shift)
- {
- u32* baseaddr = (u32*)init_addr+ONEMEG*megs;
- if(!(megs % 128)) printf("\n%d M || 0x%x\n", megs, baseaddr);
- for(u32 offset = 0; offset < ONEMEG<<meg_shift; ++offset)
- {
- addr = (u32*)baseaddr+offset;
- if ((u32)readl(addr) != (magicval^((u32)addr))) {
- if(++errorcount < MAXERRORS)
- printf("\nerror @ %08x: expected %08x, got %08x\n", (u32)addr, magicval^((u32)addr), (u32)readl(addr));
- //break;
- }
- }
- printf("'");
- }
- printf("\n\n%d errors for magic %08x\n",errorcount, magicval);
- printf("magic_memtest finished\n");
- }
- #endif //SMOKEMEM
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement