Forums » Software Development »
Load DTB from NAND
Added by Angelos Spanos over 9 years ago
Hi,
In the the text found here (https://support.criticallink.com/redmine/projects/armc8-platforms/wiki/UBIFS_Nand_Boot#512MB-NAND) the DTB file is loaded duing boot time from the MMC. I would like to change that and load it from the NAND.
Could you please let me where the .dtb file should be stored and loaded from in the NAND?
All the best,
Angelos
Replies (15)
RE: Load DTB from NAND - Added by Jonathan Cormier over 9 years ago
We haven't gotten to testing the NAND support for the 3.14 kernel yet. Because of this I haven't looked at rearranging the nand partitioning scheme. So lets try to come up with a workable solution.
Looking at the am335x-evm.dts and TIs wiki http://processors.wiki.ti.com/index.php/Linux_Core_U-Boot_User%27s_Guide#Using_NAND. They call the device tree partition 'NAND.u-boot-spl-os' and allocate two erase blocks to it.
After reviewing at the evm partition table, it looks pretty good so lets stick with it.
Note: Partition 0 is reserved for MitySOMs with a NOR.
Here is the 256MB version.
partition@1 { /* 128 KB */ label = "NAND.SPL"; reg = <0x00000000 0x00020000>; }; partition@2 { /* 128 KB */ label = "NAND.SPL.backup1"; reg = <0x00020000 0x00020000>; }; partition@3 { /* 128 KB */ label = "NAND.SPL.backup2"; reg = <0x00040000 0x00020000>; }; partition@4 { /* 128 KB */ label = "NAND.SPL.backup3"; reg = <0x00060000 0x00020000>; }; partition@5 { /* 256 KB - DTB */ label = "NAND.u-boot-spl-os"; reg = <0x00080000 0x00040000>; }; partition@6 { /* 1 MB */ label = "NAND.u-boot"; reg = <0x000C0000 0x00100000>; }; partition@7 { /* 128 KB */ label = "NAND.u-boot-env"; reg = <0x001C0000 0x00020000>; }; partition@8 { /* 128 KB */ label = "NAND.u-boot-env.backup1"; reg = <0x001E0000 0x00020000>; }; partition@9 { /* 8 MB */ label = "NAND.kernel"; reg = <0x00200000 0x00800000>; }; partition@10 { /* 246 MB */ label = "NAND.file-system"; reg = <0x00A00000 0x0F600000>; };
512 MB Version
partition@1 { /* 256 KB */ label = "NAND.SPL"; reg = <0x00000000 0x00040000>; }; partition@2 { /* 256 KB */ label = "NAND.SPL.backup1"; reg = <0x00040000 0x00040000>; }; partition@3 { /* 256 KB */ label = "NAND.SPL.backup2"; reg = <0x00080000 0x00040000>; }; partition@4 { /* 256 KB */ label = "NAND.SPL.backup3"; reg = <0x000C0000 0x00040000>; }; partition@5 { /* 512 KB - DTB */ label = "NAND.u-boot-spl-os"; reg = <0x00100000 0x00080000>; }; partition@6 { /* 2 MB */ label = "NAND.u-boot"; reg = <0x00180000 0x00200000>; }; partition@7 { /* 256 KB */ label = "NAND.u-boot-env"; reg = <0x00380000 0x00040000>; }; partition@8 { /* 256 KB */ label = "NAND.u-boot-env.backup1"; reg = <0x003C0000 0x00040000>; }; partition@9 { /* 8 MB */ label = "NAND.kernel"; reg = <0x00400000 0x00800000>; }; partition@10 { /* 500 MB */ label = "NAND.file-system"; reg = <0x00C00000 0x1F400000>; };
Note that this will break compatibility with Nands flashed with the 3.2 kernel, but this should be a valid partition scheme.
RE: Load DTB from NAND - Added by Angelos Spanos over 9 years ago
Hi Jonathan,
Many thanks for your pointers.
I have created a tested solution with a different partition scheme. I have added a 512KB partition at the end of the Linux filesystem. My partition layout looks as follows:
partition@0 { label = "NAND.SPL"; reg = <0x00000000 0x00040000>; }; partition@1 { label = "NAND.SPL.backup1"; reg = <0x00040000 0x00040000>; }; partition@2 { label = "NAND.SPL.backup2"; reg = <0x00080000 0x00040000>; }; partition@3 { label = "NAND.SPL.backup3"; reg = <0x000c0000 0x00040000>; }; partition@4 { label = "NAND.u-boot"; reg = <0x00100000 0x00200000>; }; partition@5 { label = "NAND.u-boot-env"; reg = <0x00300000 0x00040000>; }; partition@6 { label = "NAND.kernel"; reg = <0x00340000 0x00500000>; }; partition@7 { label = "NAND.rootfs"; reg = <0x00840000 0x1F740000>; }; partition@8 { label = "NAND.DTB"; reg = <0x1FF80000 0x80000>; };
Please let me know if you see any potential problems with this layout.
All the best,
Angelos
RE: Load DTB from NAND - Added by Angelos Spanos over 9 years ago
The following commands were used for flashing the NAND from U-Boot:
setenv dtb_file_name am335x-mitysom.dtb setenv dtb_size 0x7d31 setenv dtb_partition_size 0x80000 setenv dtb_partition_address 0x1FF80000 setenv dtb_ram_adress 0x80F80000 setenv kloadaddr 0x80007fc0 setenv kernel_partition_address 0x340000 setenv kernel_partition_size 0x500000 setenv bootcmd 'nandecc hw 1; nand read.i ${dtb_ram_adress} ${dtb_partition_address} ${dtb_size}; nand read.i ${kloadaddr} ${kernel_partition_address} ${kernel_partition_size}; bootm ${kloadaddr} - ${dtb_ram_adress}' mw.b ${kloadaddr} ff 0x80000 fatload mmc ${mmc_index} ${kloadaddr} ${dtb_file_name} nand write.i ${kloadaddr} ${dtb_partition_address} ${dtb_size}
I hope they are of use.
RE: Load DTB from NAND - Added by Angelos Spanos over 9 years ago
Also, the solution you proposed should also work, but I haven't got around to testing it yet. If I do I will let you know.
All the best,
Angelos
RE: Load DTB from NAND - Added by Jonathan Cormier over 9 years ago
Angelos Spanos wrote:
Hi Jonathan,
Many thanks for your pointers.
I have created a tested solution with a different partition scheme. I have added a 512KB partition at the end of the Linux filesystem. My partition layout looks as follows:
[...]
Please let me know if you see any potential problems with this layout.
All the best,
Angelos
The only problem I see is with the NAND.u-boot-env. And this is a problem you copied from our initial partition layout. Because the u-boot-env only has 1 erase block assigned to it, if this block happens be marked bad at the factory or goes bad then you won't have a working place to store the u-boot environment.
RE: Load DTB from NAND - Added by Angelos Spanos over 9 years ago
Jonathan Cormier wrote:
Angelos Spanos wrote:
Please let me know if you see any potential problems with this layout.
[...] Because the u-boot-env only has 1 erase block assigned to it, if this block happens be marked bad at the factory or goes bad then you won't have a working place to store the u-boot environment.
Thanks for the review. Is 1 erase block assigned to every 256KiB or to every partition?
RE: Load DTB from NAND - Added by Jonathan Cormier over 9 years ago
For the 512MB Nand an erase block is 256KB. It was 128KB on the 256MB Nand.
RE: Load DTB from NAND - Added by Angelos Spanos over 9 years ago
OK. So should I increase the partition by 256KiB or should I introduce the partition "NAND.u-boot-env.backup1"?
RE: Load DTB from NAND - Added by Jonathan Cormier over 9 years ago
I believe the backup partition is preferable, since u-boot will save the env in both so if one becomes corrupt there will be a good copy. Note that u-boot does need to be setup to use the backup environment.
Also if you use my partitioning scheme, u-boot would also need to be updated to load the u-boot.img from the new NAND.u-boot offset. For this reason alone, I'm going to veto my proposed layout as it would require a separate u-boot build for the 3.2 kernel and for the 3.14 kernel. Instead I propose putting the NAND.u-boot-spl-os partition after the kernel partition or after NAND.file-system. Though I like the idea of the filesystem having the rest of the space to itself..
RE: Load DTB from NAND - Added by Angelos Spanos over 9 years ago
Hi Jonathan,
Jonathan Cormier wrote:
Note that u-boot does need to be setup to use the backup environment.
What is the u-boot setup required for using the backup environment? Is there some md5sum or CRC command available?
All the best,
Angelos
RE: Load DTB from NAND - Added by Jonathan Cormier over 9 years ago
Angelos Spanos wrote:
Hi Jonathan,
Jonathan Cormier wrote:
Note that u-boot does need to be setup to use the backup environment.
What is the u-boot setup required for using the backup environment?
In the file include/configs/mityarm335x.h, you need to define CONFIG_ENV_OFFSET_REDUND and CONFIG_ENV_SIZE_REDUND. They are currently there but are commented out on lines 375, 376. Offset would need to be set correctly.
Is there some md5sum or CRC command available?
U-Boot# crc crc32 - checksum calculation Usage: crc32 address count [addr] - compute CRC32 checksum [save at addr]
If you want md5sum you would need to enable it and rebuild u-boot. #define CONFIG_CMD_MD5SUM
RE: Load DTB from NAND - Added by Angelos Spanos over 9 years ago
Hi Jonathan,
Thanks for the commands.
Could you please verify whether the erase blocks are only used and can be corrupted during a NAND write? Or is it the case that NAND reads make use of and can corrupt erase blocks?
All the best,
Angelos
RE: Load DTB from NAND - Added by Jonathan Cormier over 9 years ago
There are several ways that data can have bitflips. See the below link for some cases. The minimum ECC level specified by the manufacturer is intended to take some of these into account to guarantee a certain level of life for the NAND device. BCH16 in this case can correct up to 16 bitflips before data becomes corrupt. The ubifs filesystem is intended to handle these limitations and will track erases and reads in order to move data around and prevent corruption.
RE: Load DTB from NAND - Added by Angelos Spanos over 9 years ago
Hi Jonathan,
Thanks for your answer.
In my application, I would like to have three subpartitions inside the /rootfs partition. I am a little bit confused about how I should declare it. Should it go both to the device tree definitions as well as to the U-boot sequence? Would you have a working example?
All the best,
Angelos
RE: Load DTB from NAND - Added by Jonathan Cormier over 9 years ago
Angelos,
This would depend on what your trying to accomplish.
I believe the preferable way would be to have ubi handle the separate partitions and keep the mtd rootfs partition as a single partition. This has the advantage of that ubi will have access to more space in order to move data around to lengthen the life of the nand device.
Please read the following for information about ubi and ubifs.
http://www.linux-mtd.infradead.org/doc/ubi.html#L_overview
http://www.linux-mtd.infradead.org/doc/ubifs.html#L_overview