This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Writing uImage to NAND Flash

Hi to all,

For my custom DM6446 design I followed the below link to write kernel image to NAND flash

http://processors.wiki.ti.com/index.php/Writing_Kernel_Image_to_NAND_Flash

-------------------------------------------------------------------------------------------

DaVinci EVM #tftp 0x80700000 uImage
TFTP from server 192.168.170.238; our IP address is 192.168.184.91
Filename 'uImage'.
Load address: 0x80700000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################
done
Bytes transferred = 1495924 (16d374 hex)
DaVinci EVM # nand erase 0x2060000 0x16d400

NAND erase: device 0 offset 0x2060000, size 0x16d400
Erasing at 0x21cc000 -- 100% complete.
OK
DaVinci EVM # nand write 0x80700000 0x2060000 0x16d400

NAND write: device 0 offset 0x2060000, size 0x16d400
 1496064 bytes written: OK
DaVinci EVM # setenv bootcmd 'nboot 80700000 0 2060000;bootm'
DaVinci EVM # saveenv
Saving Environment to NAND...
Erasing Nand...Writing to Nand... done
DaVinci EVM # boot


Loading from NAND 64MiB 1,8V 8-bit, offset 0x2060000
   Image Name:   Linux-2.6.10_mvl401
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    1495860 Bytes =  1.4 MB
   Load Address: 80008000
   Entry Point:  80008000
## Booting image at 80700000 ...
   Image Name:   Linux-2.6.10_mvl401
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    1495860 Bytes =  1.4 MB
   Load Address: 80008000
   Entry Point:  80008000
   Verifying Checksum ... OK
OK

Starting kernel ...

Linux version 2.6.10_mvl401

-------------------------------------------------------------------------------------------

It can succesfully start the kernel read from NAND . However when I reboot the system it gives the below error:

-------------------------------------------------------------------------------------------

Loading from NAND 64MiB 1,8V 8-bit, offset 0x2060000

** Bad Magic Number 0xffffffff **
## Booting image at 80700000 ...
Bad Magic Number

-------------------------------------------------------------------------------------------

I also tried to erase /dev/mtd2 and write uImage to /dev/mtd2 from NFS and saw that my bootparams are erased when I boot it.

What may be the reason for "Bad Magic Number" after reboot?

 

Thanks and best regards

Ferhat

 

 

  • Ferhat,

    May I know what all steps you executed after the Linux kernel booted for the first time and before you issued reboot from the command prompt? It seems that Linux Kernel is following different partition layout compared to what you are writing from U-Boot. So if you have written something to NAND partitions from Linux kernel, then that would have corrupted the offset at which Linux Kernel was written, causing boot failure.

    I think, the WIKI page which you are referring is based on Community Kernel, where as you are using Linux Kernel from MV Pro4.0 package.

    Regards, Sudhakar

  • Thanks Sudhakar,

    After your post I realized something related;

    When I :

    -write kernel image from bootloader with "nand erase", "nand write"

    -boot from flash with "nboot"

    -mount to NFS filesystem

    -reboot the board

    No problem at all. It can always read kernel image from NAND and boot succesfully.

    However from the NFS filesys booted:

    -flash_eraseall -j /dev/mtd3

    -mount -t jffs2 /dev/mtdblock3 /mnt/flash

    -tar xzf /home/user/workdir/rootfs.tar.gz

    -umount /mnt/flash

    -reboot the board

    I get ** Bad Magic Number 0xffffffff ** . It seems that kernel image is corrupted. Again I wrote kernel to flash and boot to mount jffs2 filesys.

    It can mount to jffs2 filesys with following errors:

    ****************************************************************************************************

    mtd->read(0x400 bytes from 0x1d58000) returned ECC error

    jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x01d58000: 0xd01a instead

     

    ****************************************************************************************************

    What may be the reason for this error? I also tried writing both kernel image and filesys to NAND on NFS server then bootargs are corrupted.  How can I know the correct addresses to write and boot?

    I used bootloader at "dvsdk_1_30_01_41/PSP_01_20_00_014/board_utilities/u-boot-1.2".

    While configuring kernel with NAND support I could not find the "Hardware ECC support on NAND Device for Davinci" stated on below link

    http://processors.wiki.ti.com/index.php/Flash_configuration_in_the_Kernel

    Regards

    Ferhat

  • Ferhat,

    Ferhat OLGUN said:
    How can I know the correct addresses to write and boot?

    The partition layout used by the Linux Kernel is printed during booting. You can also get this information using dmesg command after Linux is booted. Your write offset from U-Boot should conform with the Linux partition layout to avoid any errors.

    Ferhat OLGUN said:
    While configuring kernel with NAND support I could not find the "Hardware ECC support on NAND Device for Davinci" stated on below link

    This option was present in older releases but might have been removed in later releases.

    Regards, Sudhakar

  • Sudhakar,

    Below is the partition information printed during booting:

    ************************************

    Scanning device for bad blocks

    Bad eraseblock 816 at 0x00cc0000

    Creating 4 MTD partitions on "nand_davinci.0":

    0x00000000-0x00040000 : "bootloader"

    0x00040000-0x00060000 : "params"

    0x00060000-0x00460000 : "kernel"

    0x00460000-0x04000000 : "filesystem"

    ************************************

    I can succesfully write kernel image to NAND from bootloader by the following command "nand write 0x80700000 0x2060000 0x16d400" which includes the offset address 0x2060000. I think the problem is that : writing jffs2 filesys to /dev/mtd3 on NFS mounted filesys corrupts kernel image.

    Do you think are the following errors realted to the problem?

    While jffs2 mounting kernel prints:

    *********************************

    mtd->read(0x400 bytes from 0x1c40000) returned ECC error

    jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x01c40000: 0x6bb2 instead

    *********************************

    While mounting jffs2 filesys:

    *********************************

    jffs2: Erase block size too small (16KiB). Using virtual blocks size (32KiB) instead

    *********************************

    Regards

    Ferhat

  • Ferhat,

    Ferhat OLGUN said:

    mtd->read(0x400 bytes from 0x1c40000) returned ECC error

    jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x01c40000: 0x6bb2 instead

    I am not sure why these errors come. These errors are not seen for the first time but they start coming during subsequent boots.

    Ferhat OLGUN said:

    jffs2: Erase block size too small (16KiB). Using virtual blocks size (32KiB) instead

    This is just a warning. You can ignore this.

    Regards, Sudhakar

  • Thanks Sudhakar,

    Everytime I erase /dev/mtd3 at NFS filesys using the below command, kernel image on /dev/mtd2 is corrupted.

    -flash_eraseall -j /dev/mtd3

    What may be the reason for this?

    Is "0x2060000" the true address for kernel offset? Coudl you please explain where the offset comes?

    Can you suggest me the way I can flash kernel image and filesys to NAND?

    Thanks and best regards,

    Ferhat

  • Ferhat,

    Partition information used by Linux is in your case is as follows:

    0x00000000-0x00040000 : "bootloader"

    0x00040000-0x00060000 : "params"

    0x00060000-0x00460000 : "kernel"

    0x00460000-0x04000000 : "filesystem"

    Currently the offset at which you are writing the Linux kernel (0x2060000) is within the range 0x00460000-0x04000000. This range is reserved for file system in Linux. So, from U-Boot you should write Linux Kernel at offset 0x60000 and filesystem at 0x460000.

    Regards, Sudhakar

     

  • Thanks Sudhakar,

    Since I was following the wiki page http://processors.wiki.ti.com/index.php/Writing_Kernel_Image_to_NAND_Flash, I assumed the offset address of kernel is 0x2060000.

    I first tried the offset 0x60000 which gives me Bad Magic Number. Then I tried offset 0x2e0000 which is in between 0x60000-0x460000 and could succesfully boot from NAND and wrote filesys to /dev/mtd3 by using NFS MTD utils.

    Now it can succesfully boot from NAND and mount to jffs2 filesys on every boot with some errors given below:

    ********************************

    jffs2: Erase block size too small (16KiB). Using virtual blocks size (32KiB) instead
    Empty flash at 0x00474a34 ends at 0x00474c00

    jffs2_get_inode_nodes(): Data CRC failed on node at 0x00474668: Read 0xa6c81156, calculated 0xf93cb568

    ********************************

    Thanks and best regards,

    Ferhat