Project

General

Profile

Writing UBIFS rootfs to AM3354 with 512MB NAND

Added by Kim Weller over 10 years ago

What's the procedure for creating and writing the Linux UBIFS rootfs to the AM3354 512MB NAND? What ECC is used for the UBIFS partitions?

-Kim


Replies (18)

RE: Writing UBIFS rootfs to AM3354 with 512MB NAND - Added by Tim Iskander over 10 years ago

Kim
TI has a few pages on this.. check out http://processors.wiki.ti.com/index.php/UBIFS_Support
As long as you program the ubifs from linux there should not be an issue.
There is currently a disconnect between ECC used by u-boot and that used by linux on the 4kB page size NAND devices (like the 512MB NAND)
cheers
/Tim

RE: Writing UBIFS rootfs to AM3354 with 512MB NAND - Added by Kim Weller over 10 years ago

Hi Tim,

I've been following this steps and it looks like the ubi.img is writing to NAND, but I get error 28 (No space left on device) when trying to attach. Here are my steps for writing ubi.img:

root@mityarm335x:~# ubiformat /dev/mtd8 -f ubi.img -s 1024 -O 4096
ubiformat: mtd8 (nand), size 528220160 bytes (503.8 MiB), 2015 eraseblocks of 262144 bytes (256.0 KiB), min. I/O size 4096 bytes
libscan: scanning eraseblock 2014 -- 100 % complete  
ubiformat: 2015 eraseblocks are supposedly empty
ubiformat: flashing eraseblock 15 -- 100 % complete  
ubiformat: formatting eraseblock 2014 -- 100 % complete  
root@mityarm335x:~# ubiattach /dev/ubi_ctrl -m 8 -O 4096
ubiattach: error!: cannot attach mtd8
           error 28 (No space left on device)

root@mityarm335x:~# flash_erase /dev/mtd8 0 0
Erasing 256 Kibyte @ 1f780000 -- 100 % complete 
root@mityarm335x:~# mtdinfo /dev/mtd8
mtd8
Name:                           File System
Type:                           nand
Eraseblock size:                262144 bytes, 256.0 KiB
Amount of eraseblocks:          2015 (528220160 bytes, 503.8 MiB)
Minimum input/output unit size: 4096 bytes
Sub-page size:                  1024 bytes
OOB size:                       224 bytes
Character device major/minor:   90:16
Bad blocks are allowed:         true
Device is writable:             true

root@mityarm335x:~# ubiformat /dev/mtd8 -f ubi.img -s 1024 -O 4096
ubiformat: mtd8 (nand), size 528220160 bytes (503.8 MiB), 2015 eraseblocks of 262144 bytes (256.0 KiB), min. I/O size 4096 bytes
libscan: scanning eraseblock 2014 -- 100 % complete  
ubiformat: 2015 eraseblocks are supposedly empty
ubiformat: flashing eraseblock 15 -- 100 % complete  
ubiformat: formatting eraseblock 2014 -- 100 % complete  
root@mityarm335x:~# ubiattach /dev/ubi_ctrl -m 8 -O 4096
ubiattach: error!: cannot attach mtd8
           error 28 (No space left on device)
root@mityarm335x:~# 

Any suggestions?

Thanks,
Kim

RE: Writing UBIFS rootfs to AM3354 with 512MB NAND - Added by Kim Weller over 10 years ago

Here some additional information that maybe helpful. After ubiformat the erase blocks are all marked BAD.

root@mityarm335x:~# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00800000 00010000 "NOR User Defined" 
mtd1: 00040000 00040000 "SPL" 
mtd2: 00040000 00040000 "SPL.backup1" 
mtd3: 00040000 00040000 "SPL.backup2" 
mtd4: 00040000 00040000 "SPL.backup3" 
mtd5: 00200000 00040000 "U-Boot" 
mtd6: 00040000 00040000 "U-Boot Env" 
mtd7: 00500000 00040000 "Kernel" 
mtd8: 1f7c0000 00040000 "File System" 

root@mityarm335x:~# mtdinfo -M /dev/mtd7
mtd7
Name:                           Kernel
Type:                           nand
Eraseblock size:                262144 bytes, 256.0 KiB
Amount of eraseblocks:          20 (5242880 bytes, 5.0 MiB)
Minimum input/output unit size: 4096 bytes
Sub-page size:                  1024 bytes
OOB size:                       224 bytes
Character device major/minor:   90:14
Bad blocks are allowed:         true
Device is writable:             true
Eraseblock map:
  0: 00000000          1: 00040000          2: 00080000          3: 000c0000        
  4: 00100000          5: 00140000          6: 00180000          7: 001c0000        
  8: 00200000          9: 00240000         10: 00280000         11: 002c0000        
 12: 00300000         13: 00340000         14: 00380000         15: 003c0000        
 16: 00400000         17: 00440000         18: 00480000         19: 004c0000        

root@mityarm335x:~# ubiformat /dev/mtd7
ubiformat: mtd7 (nand), size 5242880 bytes (5.0 MiB), 20 eraseblocks of 262144 bytes (256.0 KiB), min. I/O size 4096 bytes
libscan: scanning eraseblock 19 -- 100 % complete  
ubiformat: 20 eraseblocks are supposedly empty
ubiformat: formatting eraseblock 19 -- 100 % complete  
root@mityarm335x:~# mtdinfo -M /dev/mtd7
mtd7
Name:                           Kernel
Type:                           nand
Eraseblock size:                262144 bytes, 256.0 KiB
Amount of eraseblocks:          20 (5242880 bytes, 5.0 MiB)
Minimum input/output unit size: 4096 bytes
Sub-page size:                  1024 bytes
OOB size:                       224 bytes
Character device major/minor:   90:14
Bad blocks are allowed:         true
Device is writable:             true
Eraseblock map:
  0: 00000000    BAD   1: 00040000    BAD   2: 00080000    BAD   3: 000c0000    BAD 
  4: 00100000    BAD   5: 00140000    BAD   6: 00180000    BAD   7: 001c0000    BAD 
  8: 00200000    BAD   9: 00240000    BAD  10: 00280000    BAD  11: 002c0000    BAD 
 12: 00300000    BAD  13: 00340000    BAD  14: 00380000    BAD  15: 003c0000    BAD 
 16: 00400000    BAD  17: 00440000    BAD  18: 00480000    BAD  19: 004c0000    BAD 

-Kim

RE: Writing UBIFS rootfs to AM3354 with 512MB NAND - Added by Tim Iskander over 10 years ago

Kim
I am not super familiar with ubifs, but it seems it can be a bit tricky to master. I know it can be done, as some of our customers are using it. One thing I have seen is to make sure the subpage size is the same as the page size (4k in this case).
There are a few posts on the TI e2e site about using ubifs.
http://e2e.ti.com/support/arm/sitara_arm/f/791/t/248144.aspx and http://e2e.ti.com/support/arm/sitara_arm/f/791/p/197671/706390.aspx#706390 (to start)
If you haven't seen the UBIFS FAQ and HOWTO, its here http://www.linux-mtd.infradead.org/faq/ubifs.html#L_free_space_fixup

cheers
/Tim

RE: Writing UBIFS rootfs to AM3354 with 512MB NAND - Added by Kim Weller over 10 years ago

Hi Tim,

Could someone at Critical Link send me the commands used for creating the ubifs image and writing it to the 512MB NAND flash on your MityARM development board?

Thanks,
Kim

RE: Writing UBIFS rootfs to AM3354 with 512MB NAND - Added by Jonathan Cormier over 10 years ago

Kim,
I tried to do the ubiformat on a 512MB nand som here and I ran into the same problem. It marked the whole nand as bad.

I was able to reset the bad block count by running the following in u-boot. Note: This will delete all data on the nand including the bad block messages. If you have the list of bad blocks before its recommended to mark them bad with nand markbad.

U-Boot# nand scrub.chip

Unfortunately this doesn't help getting ubifs working. I'd like to see if jffs2 will work to determine if the issue is with ubifs or with some configuration in the kernel, etc.

-Jonathan

RE: Writing UBIFS rootfs to AM3354 with 512MB NAND - Added by Jonathan Cormier over 10 years ago

Testing on a 256MB nand som, I was able to format mtd8 and mount it. See output:

RE: Writing UBIFS rootfs to AM3354 with 512MB NAND - Added by Jonathan Cormier over 10 years ago

For our 512mb nand, I believe the format command should be ubiformat /dev/mtd8 -s 1024 -O 4096 but it doesn't work.

RE: Writing UBIFS rootfs to AM3354 with 512MB NAND - Added by Jonathan Cormier over 10 years ago

Kim,

Due to the long holiday weekend, i'm not sure this will get looked at until atleast Monday.

Also what is the part number and model number of your module?

Thanks
Jonathan

RE: Writing UBIFS rootfs to AM3354 with 512MB NAND - Added by Kim Weller over 10 years ago

Tim,

Thanks for testing this. My module PN: 80-000517RC-1B.

I believe the problem is with the lower MTD NAND driver for NAND part MT29F4G08ABAEAWP. Simple NAND writes are giving me problems.

Kim

RE: Writing UBIFS rootfs to AM3354 with 512MB NAND - Added by Michael Karasoff over 10 years ago

To boot from UBI with the 512MB NAND, I had to modify the 2013.01 branch bootloader:

Viewing: 'include/configs/mityarm335x.h'
53c53
< #define CONFIG_SYS_MALLOC_LEN        (512 << 10) /* UBI needs >= 512K) (CONFIG_ENV_SIZE + (32 * 1024))*/
---
> /*Increase to support UBI mount*/
> #define CONFIG_SYS_MALLOC_LEN        (4096 << 10) /* UBI needs >= 512K) (CONFIG_ENV_SIZE + (32 * 1024))*/
Viewing: 'drivers/mtd/nand/nand_base.c'
3143c3143,3144
<     if (!(chip->options & NAND_NO_SUBPAGE_WRITE) &&
---
>  /*Subpage shift for hardware ECC is always 0*/
>     /*if (!(chip->options & NAND_NO_SUBPAGE_WRITE) &&
3155c3156,3159
<     }
---
>     }*/
> 
>    mtd->subpage_sft = 0; 
>   

RE: Writing UBIFS rootfs to AM3354 with 512MB NAND - Added by Jonathan Cormier over 10 years ago

Michael,

You should be able to replace your second change with:

diff --git a/drivers/mtd/nand/omap_gpmc.c b/drivers/mtd/nand/omap_gpmc.c
index 52b46d8..f76302e 100644
--- a/drivers/mtd/nand/omap_gpmc.c
+++ b/drivers/mtd/nand/omap_gpmc.c
@@ -867,6 +867,8 @@ int board_nand_init(struct nand_chip *nand)
        nand->ecc.calculate = omap_calculate_ecc_bch;
        nand->ecc.read_page = omap_read_page_bch;
        omap_hwecc_init_bch(nand, NAND_ECC_READ);
+       /* ECC engine doesn't support subpage writes */
+       nand->options |= NAND_NO_SUBPAGE_WRITE;

This option was set in linux but didn't make it to u-boot. Could you test it and verify it has the same effect as your change. I'm assuming that mtd->subpage_sft is set to 0 by default.

RE: Writing UBIFS rootfs to AM3354 with 512MB NAND - Added by Jonathan Cormier over 10 years ago

Do you have a reference for your first change? Or did you find this through trial and error?

RE: Writing UBIFS rootfs to AM3354 with 512MB NAND - Added by Michael Karasoff over 10 years ago

U-Boot# ubifsmount kernel
UBIFS: static UBI volume - read-only mode
UBIFS error (pid 0): ubifs_mount: Error reading superblock on volume 'ubi:configuration' *errno=-12!*

-12 -> ENOMEM?

RE: Writing UBIFS rootfs to AM3354 with 512MB NAND - Added by Jonathan Cormier over 10 years ago

Ok cool. We've never tried storing the kernel in a ubifs partition. If you have it working I'd be interested in your procedure.

RE: Writing UBIFS rootfs to AM3354 with 512MB NAND - Added by Jonathan Cormier over 10 years ago

Michael,

I've added your changes including my alternative change to a test branch on my machine. If you could test my alternative change I'll happily post it up on our site.

Thanks

RE: Writing UBIFS rootfs to AM3354 with 512MB NAND - Added by Michael Karasoff over 10 years ago

The procedure is simple - I create a UBI image (mkfs.ubifs & ubinize) with uImage and rootfile system volumes and programmed it into flash. There are lots of places on the web that explain this process, and once you have a UBI image you can program from u-boot or linux. The key gotchas in making images is that IO size and Sub-Page are both 4096. My understanding is that the 4096 subpage (essentially no subpage) is due to limitation on how the GPMC hardware handles ECC on these larger flash pages. Also, I make the image size smaller than the physical size by about 10% - for various reasons UBI needs the extra space, and 10% overhead seems about right. Obviously, you need to make sure the kernel is compiles to support UBI.

For the uboot, assuming that I have the ubi image named "usr0" with volume "kernel" (uImage) and "rootfs" (root file system) loaded into a partition called "linux" in mtdparts:

U-Boot# mtdparts

device nand0 <nand>, # parts = 7
#: name size offset mask_flags
0: mlo 0x00040000 0x00000000 0
1: mlo1 0x00040000 0x00040000 0
2: mlo2 0x00040000 0x00080000 0
3: mlo3 0x00040000 0x000c0000 0
4: uboot 0x001c0000 0x00100000 0
5: env 0x00040000 0x002c0000 0
6: linux 0x00a00000 0x00300000 0

The procedure for UBI boot (both kernel and uImage in UBI) is as follows:

U-Boot# ubi part linux
Creating 1 MTD partitions on "nand0":
0x000000d00000-0x00000a800000 : "mtd=6"
UBI: attaching mtd1 to ubi0
UBI: physical eraseblock size: 262144 bytes (256 KiB)
UBI: logical eraseblock size: 253952 bytes
UBI: smallest flash I/O unit: 4096
UBI: VID header offset: 4096 (aligned 4096)
UBI: data offset: 8192
UBI: attached mtd1 to ubi0
UBI: MTD device name: "mtd=6"
UBI: MTD device size: 155 MiB
UBI: number of good PEBs: 620
UBI: number of bad PEBs: 0
UBI: max. allowed volumes: 128
UBI: wear-leveling threshold: 4096
UBI: number of internal volumes: 1
UBI: number of user volumes: 2
UBI: available PEBs: 0
UBI: total number of reserved PEBs: 620
UBI: number of PEBs reserved for bad PEB handling: 6
UBI: max/mean erase counter: 172/10

U-Boot# ubifsmount kernel
UBIFS: static UBI volume - read-only mode
UBIFS: mounted UBI device 0, volume 0, name "kernel"
UBIFS: mounted read-only
UBIFS: file system size: 3555328 bytes (3472 KiB, 3 MiB, 14 LEBs)
UBIFS: journal size: 2285569 bytes (2232 KiB, 2 MiB, 8 LEBs)
UBIFS: media format: w4/r0 (latest is w4/r0)
UBIFS: default compressor: LZO
UBIFS: reserved for root: 0 bytes (0 KiB)

U-Boot# ubifsload ${kloadaddr} uImage
Loading file 'uImage' to addr 0x80007fc0 with size 2710280 (0x00295b08)...
Done

U-Boot# ubifsumount

U-Boot# setenv bootargs console=ttyO0,115200n8 ubi.mtd=7 root=ubi0:rootfs rootfstype=ubifs noinitrd rootwait=1 ip=none

U-Boot# bootm ${kloadaddr}

Because of the time to mount the ubi volumes, the boot time here is a bit longer than normal ~30sec.

RE: Writing UBIFS rootfs to AM3354 with 512MB NAND - Added by Jonathan Cormier over 10 years ago

Thanks for the procedure. In case you weren't aware I wrote up a guide on doing this without the kernel being stored in the ubifs partition. UBIFS_Nand_Boot

I'll definitely try to take some time to add your method as an alternative. The benefit of using ubifs for both of these as i understand it, is that ubi will do wear leveling so that overtime your flash will last longer (assuming you don't use nand erase on this partition which will destroy the ubifs wear leveling info). The added boot time however may not be worth it. The kernel is rarely flashed/updated so for most cases I think its still better to save it straight to flash.

Your correct about the 4096 subpage size. The ecc hardware the 335x uses can't handle subpage writes, at least not well. The older driver used to be able to support it for jffs2 but I guess didn't work very efficiently.

The 10% margin seems a good size. Also assuming the ubinize.cfg is set to autoresize, the first mount will auto fit to the partition so you can create an image that will work on various partition sizes. It will take into account the needed ubi reserved size.

    (1-18/18)
    Go to top
    Add picture from clipboard (Maximum size: 1 GB)