This article is all about flashing device tree, linux kernel image to QSPI using uboot.
Also, we will read back the device tree and linux kernel image from QSPI NOR flash.
After reading back, we will boot the linux kernel.
What is the DRAM memory size?
In order to find the DRAM memory size in uboot, we can run the following command.
we can see that the size is 0x40000000 in hexadecimal.
How do I convert the hexadecimal to memory size?
Here given number is 0x4 0000000 i.e 0x4 and 7 zeroes.
So, hexadecimal is nothing but 4 bits representation or nibble you can say.
In our example, we have 7 zeroes or we can say it has 7*4 = 28 bits zero.
Now, 0x4 is nothing but 2^2. Thus, in total it is 2^2 * 2^28 = 2^30.
Now, 2^10 is kilobytes, 2^20 is Megabytes, 2^30 is 1 Gigabytes.
So, we have 1 Gigabytes RAM.
List the directory contents of the SD card formatted in FAT
How to flash uImage to QSPI?
The first thing here is to read the uImage from the FAT partition of sd card and load that image
into memory. In this example, we are loading the uImage i.e. kernel image from mmc 0 and storing the
uImage at memory address - 0x3000000 i.e 0x3 and 6 zeroes.
The 6 zeroes is nothing but 6*4 = 24 bits or 2^24 and 0x3.
Next, we know that 2^20 is 1 Mb, so it is 2^4 * 0x3 = 48Mb. So, we are placing the UImage at the offset of 48Mbytes
in DRAM.
Now, flash the QSPI NOR
Probe the SPI Nor.
We cannot directly onto QSPI Nor flash, first we need to erase the block and then only we can write the
data. So, let’s first erase 8Mb for kernel image. I know this pretty big. In theory, my zedboard kernel image size is just a little over 4 Mb. So, 8 Mb is pretty safe.
Write the uImage i.e. kernel image to the QSPI.
Now, let’s readback the uImage from SPI NOR and store that uImage onto memory location -
0x8000000 i.e. 0x8 and 6 zeroes. i.e. 2^3 and 6*4 = 24 or 2^24. This means 2^27 or 2^7 *2^20 = 128Mb.
So, now we are reading the uImage from QSPI and store at the memory location - 128Mb from the base address i.e 0x000.
Now, check wether the uImage is there in the memory address 0x8000000 or not.
Similarly, read the device tree.
Load device tree from FAT
Flash device tree into QSPI
Since, we have already consumed first 8Mb from QSPI for uImage purpose, we should write the
device tree after 8Mb in QSPI. Thus, the offset should be 8Mb.
Erase 4Mb for device tree into QSPI
Flash/write device tree into QSPI
Readback device tree from QSPI into different memory location
Previously, we have read uImage into memory space - 128Mb and as I know my kernel size is not more than 5Mb.
Thus, any memory address 128Mb + 5Mb = 133Mb should be fine. Here, I have taken the memory address -
140Mb. Thus, 140 Mb is nothing 0x8C and 5 zeroes. The 0x8C equals to 140 in decimal.
Flash/write device tree into QSPI
Verify the device tree image using memory dump
Boot kernel image
The command here is bootm “uImage address” “rootfs address if you have otherwise put -“ “device tree address”.
In my case, I don’t have rootfs address. Thus, I am putting ‘-‘.
How to run elf image using uboot
Similar to bootm, you can use bootelf to run an elf executable.
Suppose an elf is stored at the memory address 0x1000000.