Skip to contentSkip to conversation

nandwrite/ubi memory corruption?

DISCUSSION Michal Ludvig 3 participants 16 messages Oct 16, 2008 – Oct 18, 2008 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

Hi all,

I've got an ARM board with 64MB of NAND flash with 3 logical partitions and am experiencing (probably) memory corruption of UBI/UBIFS on /dev/mtd2 after writing data with nandwrite to /dev/mtd1.

These are my logical partitions on NAND:

S3C24XX NAND Driver, (c) 2004 Simtec Electronics s3c2410-nand s3c2410-nand: Tacls=3, 30ns Twrph0=7 70ns, Twrph1=3 30ns NAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit)
Scanning device for bad blocks
Creating 3 MTD partitions on "NAND 64MiB 3,3V 8-bit":
0x00000000-0x00050000 : "boot"
0x00050000-0x00220000 : "kernel"
0x00220000-0x04000000 : "ubi"
s3c2410-nand s3c2410-nand: clock idle support enabled

I use u-boot 1.1.4 as the bootloader and 2.6.27 as the kernel. The kernel image size is 1492552 bytes, that should fit into the kernel partition as far as I can tell.

When I load the kernel in u-boot and write into NAND with 'nandw' command of u-boot it works fine.

However when I use nandwrite from linux it does "something" but
1) the kernel won't boot
2) it probably corrupted the 'ubi' partition:

~ # nandwrite -p /dev/mtd1 uimage26
Writing data to block 0
Writing data to block 4000
[...]
Writing data to block 164000
Writing data to block 168000
Writing data to block 16c000

~ # ls
UBI error: ubi_io_write: error -5 while writing 512 bytes to PEB 2414:15360, written 0 bytes
UBI warning: ubi_eba_write_leb: failed to write data to PEB 2414
UBI: recover PEB 2414, move data to PEB 2428
UBI warning: ubi_io_read_vid_hdr: bad magic number at PEB 2414: 00000000 instead of 55424921
UBI warning: ubi_ro_mode: switch to read-only mode
UBIFS error (pid 224): ubifs_wbuf_sync_nolock: cannot write 512 bytes to LEB 746:14336
UBIFS error (pid 224): ubifs_bg_wbufs_sync: cannot sync write-buffer, error -5
UBIFS warning (pid 224): ubifs_ro_mode: switched to read-only mode, error -5

So it experienced some corruption and switched to read-only mode.

Auto-completeing commands in shell doesn't work either:

~ # nandd<tab>
UBIFS error (pid 241): ubifs_read_node: bad node type (0 but expected 9) UBIFS error (pid 241): ubifs_read_node: bad node at LEB 757:11760 UBIFS error (pid 241): ubifs_iget: failed to read inode 232, error -22 UBIFS error (pid 241): ubifs_lookup: dead directory entry 'nanddump', error -22

When I reset the board the just written kernel won't boot:

NAND Flash Reading
dst base address = 0x30100000
Source start block number = 20
Source size (0x4000*n) = 0x180000
status 1
## Booting image at 30100000 ...
status 2
Bad Header Checksum
status -2

But after reloading a good kernel into NAND in u-boot and booting it everything looks ok and I can run 'ls' and 'nanddump' just fine. I can't tell whether the UBIFS volume is corrupted or not (is there some ubifsck tool available?) but nothing obvious pops up.

Nandwrite is ~2 days old one from git, kernel is 2.6.27, both compiled with gcc 3.4.6. CPU is Samsung S3C2410 (ARM920T arch), NAND as above.

So the summary is
1) Writing a kernel image with nandwrite into a MTD partition /dev/mtd1, where the kernel image is smaller than the partition.
2) Ubi/ubifs using MTD partition /dev/mtd2 gets corrupted (memory only?)
3) The written kernel won't boot. The same one written from u-boot works fine.

It's all 100% reproducible.

Do you need any other information?

Michal

#1 lore raw
Quoted 40 lines · Michal Ludvig

Hi all,

I've got an ARM board with 64MB of NAND flash with 3 logical partitions and am experiencing (probably) memory corruption of UBI/UBIFS on /dev/mtd2 after writing data with nandwrite to /dev/mtd1.

These are my logical partitions on NAND:

S3C24XX NAND Driver, (c) 2004 Simtec Electronics s3c2410-nand s3c2410-nand: Tacls=3, 30ns Twrph0=7 70ns, Twrph1=3 30ns NAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit)
Scanning device for bad blocks
Creating 3 MTD partitions on "NAND 64MiB 3,3V 8-bit":
0x00000000-0x00050000 : "boot"
0x00050000-0x00220000 : "kernel"
0x00220000-0x04000000 : "ubi"
s3c2410-nand s3c2410-nand: clock idle support enabled

I use u-boot 1.1.4 as the bootloader and 2.6.27 as the kernel. The kernel image size is 1492552 bytes, that should fit into the kernel partition as far as I can tell.

When I load the kernel in u-boot and write into NAND with 'nandw' command of u-boot it works fine.

However when I use nandwrite from linux it does "something" but
1) the kernel won't boot
2) it probably corrupted the 'ubi' partition:

~ # nandwrite -p /dev/mtd1 uimage26
Writing data to block 0
Writing data to block 4000
[...]
Writing data to block 164000
Writing data to block 168000
Writing data to block 16c000

Quoted 13 lines

~ # ls
UBI error: ubi_io_write: error -5 while writing 512 bytes to PEB 2414:15360, written 0 bytes
UBI warning: ubi_eba_write_leb: failed to write data to PEB 2414
UBI: recover PEB 2414, move data to PEB 2428
UBI warning: ubi_io_read_vid_hdr: bad magic number at PEB 2414: 00000000 instead of 55424921
UBI warning: ubi_ro_mode: switch to read-only mode
UBIFS error (pid 224): ubifs_wbuf_sync_nolock: cannot write 512 bytes to LEB 746:14336
UBIFS error (pid 224): ubifs_bg_wbufs_sync: cannot sync write-buffer, error -5
UBIFS warning (pid 224): ubifs_ro_mode: switched to read-only mode, error -5

Could you please try ubiformat instead of nandwrite? See here:
http://www.linux-mtd.infradead.org/faq/ubi.html#L_ubierase

Signature · 2 lines
Best regards,
Artem Bityutskiy (Битюцкий Артём)
#2 lore raw
Quoted 55 lines · Artem Bityutskiy
Quoted 40 lines · Michal Ludvig

Hi all,

I've got an ARM board with 64MB of NAND flash with 3 logical partitions and am experiencing (probably) memory corruption of UBI/UBIFS on /dev/mtd2 after writing data with nandwrite to /dev/mtd1.

These are my logical partitions on NAND:

S3C24XX NAND Driver, (c) 2004 Simtec Electronics s3c2410-nand s3c2410-nand: Tacls=3, 30ns Twrph0=7 70ns, Twrph1=3 30ns NAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit)
Scanning device for bad blocks
Creating 3 MTD partitions on "NAND 64MiB 3,3V 8-bit":
0x00000000-0x00050000 : "boot"
0x00050000-0x00220000 : "kernel"
0x00220000-0x04000000 : "ubi"
s3c2410-nand s3c2410-nand: clock idle support enabled

I use u-boot 1.1.4 as the bootloader and 2.6.27 as the kernel. The kernel image size is 1492552 bytes, that should fit into the kernel partition as far as I can tell.

When I load the kernel in u-boot and write into NAND with 'nandw' command of u-boot it works fine.

However when I use nandwrite from linux it does "something" but
1) the kernel won't boot
2) it probably corrupted the 'ubi' partition:

~ # nandwrite -p /dev/mtd1 uimage26
Writing data to block 0
Writing data to block 4000
[...]
Writing data to block 164000
Writing data to block 168000
Writing data to block 16c000

Quoted 13 lines

~ # ls
UBI error: ubi_io_write: error -5 while writing 512 bytes to PEB 2414:15360, written 0 bytes
UBI warning: ubi_eba_write_leb: failed to write data to PEB 2414
UBI: recover PEB 2414, move data to PEB 2428
UBI warning: ubi_io_read_vid_hdr: bad magic number at PEB 2414: 00000000 instead of 55424921
UBI warning: ubi_ro_mode: switch to read-only mode
UBIFS error (pid 224): ubifs_wbuf_sync_nolock: cannot write 512 bytes to LEB 746:14336
UBIFS error (pid 224): ubifs_bg_wbufs_sync: cannot sync write-buffer, error -5
UBIFS warning (pid 224): ubifs_ro_mode: switched to read-only mode, error -5

Quoted 2 lines

Could you please try ubiformat instead of nandwrite? See here:
http://www.linux-mtd.infradead.org/faq/ubi.html#L_ubierase

Also, please, give me your page and sub-page size. See here:
http://www.linux-mtd.infradead.org/faq/ubi.html#L_find_min_io_size

Signature · 2 lines
Best regards,
Artem Bityutskiy (Битюцкий Артём)
#3 lore raw
Quoted 24 lines · Artem Bityutskiy
Quoted 23 lines · Artem Bityutskiy
Quoted 22 lines · Michal Ludvig

Hi all,

I've got an ARM board with 64MB of NAND flash with 3 logical partitions and am experiencing (probably) memory corruption of UBI/UBIFS on /dev/mtd2 after writing data with nandwrite to /dev/mtd1.

These are my logical partitions on NAND:
[...]

~ # ls
UBI error: ubi_io_write: error -5 while writing 512 bytes to PEB 2414:15360, written 0 bytes
UBI warning: ubi_eba_write_leb: failed to write data to PEB 2414
UBI: recover PEB 2414, move data to PEB 2428
UBI warning: ubi_io_read_vid_hdr: bad magic number at PEB 2414: 00000000 instead of 55424921
UBI warning: ubi_ro_mode: switch to read-only mode
UBIFS error (pid 224): ubifs_wbuf_sync_nolock: cannot write 512 bytes to LEB 746:14336
UBIFS error (pid 224): ubifs_bg_wbufs_sync: cannot sync write-buffer, error -5
UBIFS warning (pid 224): ubifs_ro_mode: switched to read-only mode, error -5

Quoted 1 line
Quoted 1 line

Could you please try ubiformat instead of nandwrite?

~ # ubiformat /dev/mtd1 -v
ubiformat: mtd1 (NAND), size 1900544 bytes (1.8 MiB), 16384 eraseblocks of 16384 bytes (16.0 KiB), min. I/O size 512 bytes
libscan: start scanning eraseblocks 0-116
libscan: scanning eraseblock 0: alien
libscan: scanning eraseblock 1: alien
[...]
libscan: scanning eraseblock 90: alien
libscan: scanning eraseblock 91: alien
libscan: scanning eraseblock 92: empty
libscan: scanning eraseblock 93: empty

[...]
libscan: scanning eraseblock 115: empty
libscan: finished, mean EC 0, 0 OK, 0 corrupted, 24 empty, 92 alien, bad 0
ubiformat: 24 eraseblocks are supposedly empty
ubiformat: warning!: 92 of 116 eraseblocks contain non-ubifs data
ubiformat: continue? (yes/no) yes
ubiformat: warning!: only 0 of 116 eraseblocks have valid erase counter
ubiformat: erase counter 0 will be used for all eraseblocks
ubiformat: note, arbitrary erase counter value may be specified using -e option
ubiformat: continue? (yes/no) yes
ubiformat: use erase counter 0 for all eraseblocks
ubiformat: eraseblock 0: erase, do not write EC, leave for vtbl
ubiformat: eraseblock 1: erase, do not write EC, leave for vtbl
ubiformat: eraseblock 2: erase, write EC 0
ubiformat: eraseblock 3: erase, write EC 0

[...]
ubiformat: eraseblock 115: erase, write EC 0
ubiformat: write volume table to eraseblocks 0 and 1 ~ #

Nothing was apparently broken after ubiformat, system kept running smoothly. But I can't use ubiformat for writing kernel image, can I?

Is there any other way to write raw kernel image to /dev/mtd1 other than using nandwrite?

Quoted 1 line

Also, please, give me your page and sub-page size.

UBI: attaching mtd2 to ubi0
UBI: physical eraseblock size: 16384 bytes (16 KiB)
UBI: logical eraseblock size: 15360 bytes
UBI: smallest flash I/O unit: 512
UBI: VID header offset: 512 (aligned 512)
UBI: data offset: 1024
UBI: attached mtd2 to ubi0
UBI: MTD device name: "ubi"
UBI: MTD device size: 61 MiB
UBI: number of good PEBs: 3960
UBI: number of bad PEBs: 0
UBI: max. allowed volumes: 89
UBI: wear-leveling threshold: 256
UBI: number of internal volumes: 1
UBI: number of user volumes: 1
UBI: available PEBs: 2054
UBI: total number of reserved PEBs: 1906
UBI: number of PEBs reserved for bad PEB handling: 195
UBI: max/mean erase counter: 4/0

Michal

#4 lore raw
Quoted 2 lines · Michal Ludvig

Nothing was apparently broken after ubiformat, system kept running smoothly. But I can't use ubiformat for writing kernel image, can I?

No, but I do not think it would be very difficult to add this functionality.

Signature · 2 lines
Best regards,
Artem Bityutskiy (Битюцкий Артём)
#5 lore raw
Quoted 6 lines · Artem Bityutskiy
Quoted 2 lines · Michal Ludvig

Nothing was apparently broken after ubiformat, system kept running smoothly. But I can't use ubiformat for writing kernel image, can I?

No, but I do not think it would be very difficult to add this functionality.

Wait. Sorry, your kernel sit in different partition and that partition is not UBI. This means ubiformat will not help you and you should use nandwrite. Just debug nandwrite and fix it.

Signature · 2 lines
Best regards,
Artem Bityutskiy (Битюцкий Артём)
#6 lore raw
Quoted 9 lines · Artem Bityutskiy
Quoted 5 lines · Artem Bityutskiy
Quoted 2 lines · Michal Ludvig

Nothing was apparently broken after ubiformat, system kept running smoothly. But I can't use ubiformat for writing kernel image, can I?

No, but I do not think it would be very difficult to add this functionality.

Wait. Sorry, your kernel sit in different partition and that partition is not UBI. [...] Just debug nandwrite and fix it.

Just that? Easy ;-)
I'll have a look at it but as I don't know much about the whole flash / mtd interface it may be a bit of challenge.

Michal

#7 lore raw
In reply to Michal Ludvig
Quoted 5 lines · Michal Ludvig

Nothing was apparently broken after ubiformat, system kept running smoothly. But I can't use ubiformat for writing kernel image, can I?

Is there any other way to write raw kernel image to /dev/mtd1 other than using nandwrite?

Using nandwrite for UBI is bad by definition because you loose your erase-counters and screw up wear-leveling.

Signature · 2 lines
Best regards,
Artem Bityutskiy (Битюцкий Артём)
#8 lore raw
In reply to Michal Ludvig
Quoted 8 lines · Michal Ludvig

Hi all,

I've got an ARM board with 64MB of NAND flash with 3 logical partitions and am experiencing (probably) memory corruption of UBI/UBIFS on /dev/mtd2 after writing data with nandwrite to /dev/mtd1.

These are my logical partitions on NAND:

Quoted 10 lines

S3C24XX NAND Driver, (c) 2004 Simtec Electronics s3c2410-nand s3c2410-nand: Tacls=3, 30ns Twrph0=7 70ns, Twrph1=3 30ns NAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit)
Scanning device for bad blocks
Creating 3 MTD partitions on "NAND 64MiB 3,3V 8-bit":
0x00000000-0x00050000 : "boot"
0x00050000-0x00220000 : "kernel"
0x00220000-0x04000000 : "ubi"
s3c2410-nand s3c2410-nand: clock idle support enabled

hmm, could you try disabling the clock-idle support?

Quoted 82 lines

I use u-boot 1.1.4 as the bootloader and 2.6.27 as the kernel. The kernel image size is 1492552 bytes, that should fit into the kernel partition as far as I can tell.

When I load the kernel in u-boot and write into NAND with 'nandw' command of u-boot it works fine.

However when I use nandwrite from linux it does "something" but
1) the kernel won't boot
2) it probably corrupted the 'ubi' partition:

~ # nandwrite -p /dev/mtd1 uimage26
Writing data to block 0
Writing data to block 4000
[...]
Writing data to block 164000
Writing data to block 168000
Writing data to block 16c000

~ # ls
UBI error: ubi_io_write: error -5 while writing 512 bytes to PEB 2414:15360, written 0 bytes
UBI warning: ubi_eba_write_leb: failed to write data to PEB 2414
UBI: recover PEB 2414, move data to PEB 2428
UBI warning: ubi_io_read_vid_hdr: bad magic number at PEB 2414: 00000000 instead of 55424921
UBI warning: ubi_ro_mode: switch to read-only mode
UBIFS error (pid 224): ubifs_wbuf_sync_nolock: cannot write 512 bytes to LEB 746:14336
UBIFS error (pid 224): ubifs_bg_wbufs_sync: cannot sync write-buffer, error -5
UBIFS warning (pid 224): ubifs_ro_mode: switched to read-only mode, error -5

So it experienced some corruption and switched to read-only mode.

Auto-completeing commands in shell doesn't work either:

~ # nandd<tab>
UBIFS error (pid 241): ubifs_read_node: bad node type (0 but expected 9) UBIFS error (pid 241): ubifs_read_node: bad node at LEB 757:11760 UBIFS error (pid 241): ubifs_iget: failed to read inode 232, error -22 UBIFS error (pid 241): ubifs_lookup: dead directory entry 'nanddump', error -22

When I reset the board the just written kernel won't boot:

NAND Flash Reading
dst base address = 0x30100000
Source start block number = 20
Source size (0x4000*n) = 0x180000
status 1
## Booting image at 30100000 ...
status 2
Bad Header Checksum
status -2

But after reloading a good kernel into NAND in u-boot and booting it everything looks ok and I can run 'ls' and 'nanddump' just fine. I can't tell whether the UBIFS volume is corrupted or not (is there some ubifsck tool available?) but nothing obvious pops up.

Nandwrite is ~2 days old one from git, kernel is 2.6.27, both compiled with gcc 3.4.6. CPU is Samsung S3C2410 (ARM920T arch), NAND as above.

So the summary is
1) Writing a kernel image with nandwrite into a MTD partition /dev/mtd1, where the kernel image is smaller than the partition.
2) Ubi/ubifs using MTD partition /dev/mtd2 gets corrupted (memory only?)
3) The written kernel won't boot. The same one written from u-boot works fine.

It's all 100% reproducible.

Do you need any other information?

Michal

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
#9 lore raw
Quoted 10 lines · Ben Dooks
Quoted 7 lines · Michal Ludvig

Hi all,

I've got an ARM board with 64MB of NAND flash with 3 logical partitions and am experiencing (probably) memory corruption of UBI/UBIFS on /dev/mtd2 after writing data with nandwrite to /dev/mtd1. [...]
s3c2410-nand s3c2410-nand: clock idle support enabled

hmm, could you try disabling the clock-idle support?

How do I do that?

Michal

#10 lore raw
Quoted 10 lines · Michal Ludvig
Quoted 9 lines · Ben Dooks
Quoted 7 lines · Michal Ludvig

Hi all,

I've got an ARM board with 64MB of NAND flash with 3 logical partitions and am experiencing (probably) memory corruption of UBI/UBIFS on /dev/mtd2 after writing data with nandwrite to /dev/mtd1. [...]
s3c2410-nand s3c2410-nand: clock idle support enabled

Quoted 3 lines
Quoted 1 line

hmm, could you try disabling the clock-idle support?

How do I do that?

there should be a Kconfig entry to do it when the s3c2410 nand driver is selected.

Quoted 1 line

Michal

Signature · 5 lines
-- 
Ben

Q:      What's a light-year?
A:      One-third less calories than a regular year.
#11 lore raw
Quoted 10 lines · Ben Dooks
Quoted 9 lines · Michal Ludvig
Quoted 8 lines · Ben Dooks
Quoted 7 lines · Michal Ludvig

Hi all,

I've got an ARM board with 64MB of NAND flash with 3 logical partitions and am experiencing (probably) memory corruption of UBI/UBIFS on /dev/mtd2 after writing data with nandwrite to /dev/mtd1. [...]
s3c2410-nand s3c2410-nand: clock idle support enabled

Quoted 5 lines
Quoted 2 lines
Quoted 1 line

hmm, could you try disabling the clock-idle support?

How do I do that?

there should be a Kconfig entry to do it when the s3c2410 nand driver is selected.

Ah, I see. OK, with clock-idle off nandwrite didn't corrupt ubi/ubifs but the kernel still wouldn't boot:

NAND Flash Reading
dst base address = 0x30100000
Source start block number = 20
Source size (0x4000*n) = 0x180000
status 1
## Booting image at 30100000 ...
Bad Magic Number
status -1
u-boot>

Michal

#12 lore raw
Quoted 11 lines · Michal Ludvig
Quoted 10 lines · Ben Dooks
Quoted 9 lines · Michal Ludvig
Quoted 8 lines · Ben Dooks
Quoted 7 lines · Michal Ludvig

Hi all,

I've got an ARM board with 64MB of NAND flash with 3 logical partitions and am experiencing (probably) memory corruption of UBI/UBIFS on /dev/mtd2 after writing data with nandwrite to /dev/mtd1. [...]
s3c2410-nand s3c2410-nand: clock idle support enabled

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line

hmm, could you try disabling the clock-idle support?

How do I do that?

there should be a Kconfig entry to do it when the s3c2410 nand driver is selected.

Ah, I see. OK, with clock-idle off nandwrite didn't corrupt ubi/ubifs but the kernel still wouldn't boot:

It looks like if nandwrite writes some nonsense onto the flash.

I did:
~ # nanddump -o -b -f dump.pre-nandwrite /dev/mtd1 ~ # nandwrite -p /dev/mtd1 uimage26
~ # nanddump -o -b -f dump.post-nandwrite /dev/mtd1

dump.post-nandwrite is different from dump.pre-nandwrite but doesn't seem to have much in common with uimage26.

OTOH dump.pre-nandwrite contains the kernel image that has been stored by u-boot's nandw. So the /dev/mtd1 offset is probably OK.

Any ideas on what's wrong?

Michal

#13 lore raw
In reply to Ben Dooks
Quoted 2 lines · Ben Dooks

there should be a Kconfig entry to do it when the s3c2410 nand driver is selected.

Ben,

is that right that s3c2410-nand does not support sub-pages?

Signature · 2 lines
Best regards,
Artem Bityutskiy (Битюцкий Артём)
#14 lore raw
Quoted 7 lines · Artem Bityutskiy
Quoted 2 lines · Ben Dooks

there should be a Kconfig entry to do it when the s3c2410 nand driver is selected.

Ben,

is that right that s3c2410-nand does not support sub-pages?

do you mean reads from non-page aligned addresses? currently a whole page must be read/written to allow the hardware ecc unit to function properly.

Signature · 4 lines
Ben

Q:      What's a light-year?
A:      One-third less calories than a regular year.
#15 lore raw
Quoted 10 lines · Ben Dooks
Quoted 7 lines · Artem Bityutskiy
Quoted 2 lines · Ben Dooks

there should be a Kconfig entry to do it when the s3c2410 nand driver is selected.

Ben,

is that right that s3c2410-nand does not support sub-pages?

do you mean reads from non-page aligned addresses?

I meant the ability to do two 256-byte writes to NAND pages, instead of only one 512-byte write.

Quoted 3 lines

currently a whole
page must be read/written to allow the hardware ecc unit to function properly.

OK, thanks.

Signature · 2 lines
Best regards,
Artem Bityutskiy (Битюцкий Артём)