Flash memory (CM-i.MX27): Unterschied zwischen den Versionen
en>Peter K (1 Version importiert) |
Peter (Diskussion | Beiträge) K (1 Version importiert) |
(kein Unterschied)
|
Aktuelle Version vom 31. Oktober 2023, 09:03 Uhr
NAND Flash
A 512 MiB flash chip is available on the core module.
Test in Redboot
- Load any file onto the core module over Ethernet:
RedBoot> load -r -b 0x2100000 32MBrandomfile Using default protocol (TFTP) Raw file loaded 0x02100000-0x040fffff, assumed entry at 0x02100000
- Write into flash:
RedBoot> fis create -b 0x2100000 -l 0x2000000 nandtest ... Read from 0x07ee0000-0x07eff000 at 0x00080000: .. ... Read from 0x07ee0000-0x07eff000 at 0x00080000: .. ... Read from 0x07ee0000-0x07eff000 at 0x00080000: .. ... Erase from 0x000a0000-0x020a0000: Erase 0x000a0000: ................................ Erase 0x004a0000: ................................ Erase 0x008a0000: ................................ Erase 0x00ca0000: ................................ Erase 0x010a0000: ................................ Erase 0x014a0000: ....................... Warning: nfc_erase_region(addr=0x1780000, block=188): skipping bad ........ Erase 0x018a0000: ................................ Erase 0x01ca0000: ................................ Erase 0x020a0000: . nfc_erase_region(skip bad blocks=1 ... Program from 0x02100000-0x04100000 at 0x000a0000: ...................................................................................................................................................................................... Warning: nfc_program_region(addr=0x1780000, block=188): skipping bad ......................................................................... nfc_program_region(skip bad blocks=1 . ... Unlock from 0x00080000-0x000a0000: . ... Erase from 0x00080000-0x000a0000: Erase 0x00080000: . ... Program from 0x07ee0000-0x07f00000 at 0x00080000: .. ... Lock from 0x00080000-0x000a0000: .
- It must show up in the list of flash images now:
RedBoot> fis list ... Read from 0x07ee0000-0x07eff000 at 0x00080000: .. Name FLASH addr Mem addr Length Entry point RedBoot 0x00000000 0x00000000 0x00040000 0x00000000 FIS directory 0x00080000 0x00080000 0x0001F000 0x00000000 RedBoot config 0x0009F000 0x0009F000 0x00001000 0x00000000 nandtest 0x000A0000 0x02100000 0x02000000 0x02100000
- Load from NAND flash and compare with the original:
RedBoot> fis load -b 0x100000 nandtest ... Read from 0x07ee0000-0x07eff000 at 0x00080000: .. ... Read from 0x00100000-0x02100000 at 0x000a0000: ........................................................................................................................................................................................ Warning: nfc_read_region(addr=0x1780000, block=188): skipping bad .......................................................................... RedBoot> mcmp -s 0x100000 -d 0x2100000 -l 0x2000000 RedBoot>
- Done!
Update Redboot
We assume you have booted Redboot. Type
factive nand
to activate NAND flash in Redboot. Then load the new Redboot image onto the core module and run it:
load -r -b 0x100000 redboot.bin run
Now type
romupdate
to update Redboot in NAND flash.
Update Redboot from Linux
flash_eraseall /dev/mtd4 nandwrite -a -p /dev/mtd4 redboot.bin
Linux: JFFS2 file system
For NAND flash devices, the JFFS2 file system is recommended, because it handles bad blocks of the NAND flash correctly and transparently to the user. Here's how you create such a file system on the rootfs partition:
- List the available partitions on flash chips and choose the right one (here, we have to take mtd5):
root@btmxc27:~# cat /proc/mtd dev: size erasesize name mtd0: 02000000 00020000 "mxc_nor_flash.0" mtd1: 00080000 00020000 "nand.RedBoot" mtd2: 0001f000 00020000 "nand.FIS_directory" mtd3: 00001000 00020000 "nand.RedBoot_config" mtd4: 00500000 00020000 "nand.kernel" mtd5: 1fa00000 00020000 "nand.rootfs"
- Erase the partition (you have to use the char device /dev/mtdX):
root@btmxc27:~# flash_eraseall /dev/mtd5 Erasing 128 Kibyte @ 1560000 -- 4 % complete. Skipping bad block at 0x01580000 Erasing 128 Kibyte @ 2de0000 -- 9 % complete. Skipping bad block at 0x02e00000 Erasing 128 Kibyte @ 151e0000 -- 66 % complete. Skipping bad block at 0x15200000 Erasing 128 Kibyte @ 16b40000 -- 71 % complete. Skipping bad block at 0x16b60000 Erasing 128 Kibyte @ 16fc0000 -- 72 % complete. Skipping bad block at 0x16fe0000 Erasing 128 Kibyte @ 1f960000 -- 99 % complete. Skipping bad block at 0x1f980000
Skipping bad block at 0x1f9a0000
Skipping bad block at 0x1f9c0000
Skipping bad block at 0x1f9e0000 Erasing 128 Kibyte @ 1fa00000 -- 100 % complete.
- Now, simply mount the partition as jffs2 (you have to use the block device /dev/mtdblockX). JFFS2 will automatically create the necessary structure.
root@btmxc27:~# mount -t jffs2 /dev/mtdblock5 /mnt/card/ JFFS2 doesn't use OOB. root@btmxc27:~#
- Ready!
Test in Linux
We assume that you have mounted your rootfs partition on NAND flash at /mnt/card (see "Linux: JFFS2 file system").
- We load a 32 MiB large random file onto the core module:
root@btmxc27:~# tftp -r 32MBrandomfile -g 192.168.5.1
- We write the file to the NAND flash for 15 times:
root@btmxc27:~# for i in `seq 1 15` ; do cp 32MBrandomfile /mnt/card/file${i} ; done
- and compare each file with the original afterwards. If "diff" does not output anything, the files are identical.
root@btmxc27:~# for i in `seq 1 15` ; do diff 32MBrandomfile /mnt/card/file${i} ; done root@btmxc27:~#
Remarks
- It is possible to incorporate a larger NAND flash device (> 512 MiB) on a custom board. In this case, the NAND flash on the core module is
automatically deactivated.
- The i.MX27 supports NAND flash devices with 512 B or 2KiB page sizes. The maximum supported size is 8 GiB (for 2KiB page size chips) and 1 GiB (for 512 B page size chips) respectively. (See i.MX27 Reference Manual, Chapter 19 NAND Flash Controller (NFC)).
NOR Flash
A 32 MiB NOR flash chip is available on the core module V2.1.
Test in Redboot
- Initialize the Redboot flash image system:
RedBoot> fis init About to initialize [format] FLASH image system - continue (y/n)? y *** Initialize FLASH Image System ... Unlock from 0xc1fe0000-0xc2000000: . ... Erase from 0xc1fe0000-0xc2000000: . ... Program from 0x07ee0000-0x07f00000 at 0xc1fe0000: . ... Lock from 0xc1fe0000-0xc2000000: .
- Load any file onto the module via Ethernet:
RedBoot> load -r -b 0x200000 1MBrandomfile Using default protocol (TFTP) Raw file loaded 0x00200000-0x002fffff, assumed entry at 0x00200000
- Write it to NOR flash:
RedBoot> fis create -b 0x200000 -l 0x100000 testfile ... Read from 0x07ee0000-0x07eff000 at 0xc1fe0000: . ... Read from 0x07ee0000-0x07eff000 at 0xc1fe0000: . ... Read from 0x07ee0000-0x07eff000 at 0xc1fe0000: . ... Erase from 0xc0040000-0xc0140000: ........ ... Program from 0x00200000-0x00300000 at 0xc0040000: ........ ... Unlock from 0xc1fe0000-0xc2000000: . ... Erase from 0xc1fe0000-0xc2000000: . ... Program from 0x07ee0000-0x07f00000 at 0xc1fe0000: . ... Lock from 0xc1fe0000-0xc2000000: .
- It must show up in the list of flash images now:
RedBoot> fis list ... Read from 0x07ee0000-0x07eff000 at 0xc1fe0000: . Name FLASH addr Mem addr Length Entry point RedBoot 0xC0000000 0xC0000000 0x00040000 0x00000000 testfile 0xC0040000 0x00200000 0x00100000 0x00200000 FIS directory 0xC1FE0000 0xC1FE0000 0x0001F000 0x00000000 RedBoot config 0xC1FFF000 0xC1FFF000 0x00001000 0x00000000
- Load from flash and compare with the original:
RedBoot> fis load testfile ... Read from 0x07ee0000-0x07eff000 at 0xc1fe0000: . ... Read from 0x00200000-0x00300000 at 0xc0040000: ........ RedBoot> mcmp -s 0x100000 -d 0x200000 -l 0x100000 RedBoot>
- If mcmp does not output anything, the files are identical.
Update Redboot
We assume you have booted Redboot. Type
factive nor
to activate NOR flash in Redboot. Then load the new Redboot image onto the core module and run it:
load -r -b 0x100000 redboot.bin run
Now type
romupdate
to update Redboot in NOR flash.
JFFS2 file system
If you want a file system on NOR flash, it is recommended to use JFFS2.
- List all MTD partitions. As you can see, the rootfs on NOR flash corresponds to /dev/mtd2.
root@btmxc27:~# cat /proc/mtd dev: size erasesize name mtd0: 00040000 00020000 "nor.bootloader" mtd1: 00200000 00020000 "nor.kernel" mtd2: 01da0000 00020000 "nor.rootfs" mtd3: 00020000 00020000 "nor.redbootconf" mtd4: 00100000 00020000 "nand.bootloader" mtd5: 00500000 00020000 "nand.kernel" mtd6: 1fa00000 00020000 "nand.rootfs" root@btmxc27:~#
- Delete the contents (if any) of the rootfs partition:
root@btmxc27:~# flash_eraseall /dev/mtd2 Erasing 128 Kibyte @ 1da0000 -- 100 % complete. root@btmxc27:~#
- Mount the partition with the JFFS2 file system:
root@btmxc27:~# mount -t jffs2 /dev/mtdblock2 /mnt/card/ root@btmxc27:~# mount ... /dev/mtdblock2 on /media/card type jffs2 (rw) ... root@btmxc27:~#
You have successfully created a JFFS2 file system on the rootfs partition.
Test in Linux
We copy a 1 MiB random file to the partition, unmount and re-mount it, and compare the file:
root@btmxc27:~# tftp -r 1MBrandomfile -g 192.168.5.1 root@btmxc27:~# cp 1MBrandomfile /mnt/card/ root@btmxc27:~# ls -l /mnt/card/ -rw-r--r-- 1 root root 1048576 Feb 10 12:39 1MBrandomfile root@btmxc27:~# umount /mnt/card/ root@btmxc27:~# mount -t jffs2 /dev/mtdblock2 /mnt/card/ root@btmxc27:~# diff 1MBrandomfile /mnt/card/1MBrandomfile root@btmxc27:~#