Running mtest with U-Boot
Memories is, of course, a very important part of any embedded system. They come in different speeds, types, sizes, requirements and technologies. All with different requirements on both software configuration and hardware design.
With that said, it is easy to get something wrong, and memory issues is not the easiest thing to debug as the symptoms can be very different depending and "works most of the time".
Running mtest
mtest [1] is a memory test program that is used to test the memory from U-Boot. It is a simple program that writes and reads data from the memory to check if it is working correctly. It is not bullet-proof, but it is a good start to check if the memory is working correctly. Compile U-Boot with CONFIG_CMD_MTEST=y to enable the mtest command.
The syntax is as follows:
1mtest <start> <end> <pattern>
where the pattern is optional.
Find out which memory range to test
The start and end of the RAM varies depending on the board and the memory configuration. You can find this information in the U-Boot environment variables or by using the bdinfo command.
You will find the following output from bdinfo below:
=> bdinfo boot_params = 0x80000100 DRAM bank = 0x00000000 -> start = 0x80000000 -> size = 0x20000000 flashstart = 0x00000000 flashsize = 0x00000000 flashoffset = 0x00000000 baudrate = 115200 bps relocaddr = 0x9ff3f000 reloc off = 0x1f73f000 Build = 32-bit current eth = unknown ethaddr = (not set) IP addr = <NULL> fdt_blob = 0x9df19870 new_fdt = 0x9df19870 fdt_size = 0x00021640 lmb_dump_all: memory.cnt = 0x1 memory[0] [0x80000000-0x9fffffff], 0x20000000 bytes flags: 0 reserved.cnt = 0x3 reserved[0] [0x95700000-0x9577ffff], 0x00080000 bytes flags: 4 reserved[1] [0x95800000-0x98ffffff], 0x03800000 bytes flags: 0 reserved[2] [0x9cf15000-0x9fffffff], 0x030eb000 bytes flags: 0
Not all of these are related to the RAM, but lets go through them one by one anyway.
- boot_params: This is the address where the boot parameters are stored. It is not related to the RAM.
- DRAM bank: This is the start address and size of the DRAM bank. Size of DRAM: 0x20000000 = 512 MB.
- flashstart: Indicates that flash memory is either not present, not mapped, or disabled in this U-Boot config. It is not related to the RAM.
- baudrate: This is the baud rate for the serial console. It is not related to the RAM.
- relocaddr: This is the address where the U-Boot relocation is done.
- reloc off: Offset from original link address to relocated address.
- Build: Indicates that this is a 32-bit build of U-Boot. It is not related to RAM.
- current eth: This is the current Ethernet interface. It is not related to the RAM.
- ethaddr: This is the Ethernet address. It is not related to the RAM.
- IP addr: This is the IP address. It is not related to the RAM.
- fdt_blob: This is the address of the flattened device tree blob.
- new_fdt: This is the address of the new flattened device tree blob.
- fdt_size: This is the size of the flattened device tree blob.
- lmb_dump_all: This is the LMB (Logical Memory Blocks). It shows the memory regions that are available and reserved.
- memory.cnt: Number of memory regions.
- memory[0]: The first memory region, which is the DRAM bank. Start address: 0x80000000, size: 0x20000000 (512 MB).
- reserved.cnt: Number of reserved memory regions.
- reserved[0]: The first reserved memory region. Start address: 0x95700000, size: 0x00080000 (512 KB). I'm not sure about this one, but it is likely used for some specific purpose, such as a bootloader or other firmware.
- reserved[1]: The second reserved memory region. Start address: 0x95800000, size: 0x03800000 (56 MB). This is likely used for some specific purpose, such as kernel image or other boot components.
- reserved[2]: The third reserved memory region. Start address: 0x9cf15000, size: 0x030eb000 (49 MB). High memory, likely for U-Boot, stack, malloc area, FDT etc.
It is important to not run a test that overlaps with the reserved memory regions, as this can cause the test to fail or even crash the system.
Therefor, we will use the start address of the DRAM bank and the end address of the DRAM bank minus the size of the reserved memory regions:
1mtest 0x80000000 0x956FFFFF 0x12345678
A successfull test is no guarantee that the memory is working correctly (these error could be tricky). But a failed test clearly indicate that there probably is something wrong with the memory.