Flashing uboot image from existing uboot prompt

Many a times, while playing around with u-boot, you will face a need to change its source code, compile it and reflash it on your board. For raw board (means when there is nothing on the board and your doing it for the first time) you may deploy different methods like JTAG, Serial Flasher, etc. But suppose you already have and existing u-boot image in your flash or RAM than bringing in a new image to your RAM and falshing it to the derisred flahs, NAND or NOR, is easy enough, thanks to the various commands provided by u-boot.


NOTE & DISCLAIMER: I have tested this steps with the Freescale power-pc architecture and am sure will be same for the TI Davinci architecture as well. I havn't tested this with any other architecture.

So to flash a new u-boot image from the u-boot prompt, forst we will need to bring the image to the RAM at a known location. I have already mentioned the steps for this in a previous post http://embeddedbuzz.blogspot.in/2012/10/flashing-new-u-boot-image-from-existing.html

Please refer the initial section of the post uptil the tftp command execution. After executing the tftp command, if successfull the u-boot binary will be brought into the RAM at the mentioned location. Now we need to put this image into the NAND or the NOR flash as you wish.

But before this you will need to know the base address (start address) (address from which the Processor will understand that its NAND or NOR we are meaning to address) of the NAND or the NOR flash. After knowing the base address then you'll have to add to it the offset in the flash memory where you want to put the image. This will require understanding of the organization of the NAND, NOR, etc flash memory you want to use. Explaining it here is out of the scope of this post but I may cover it in later posts.


A] Putting the image in the NAND flash:
  
    NAND is organized as blocks and pages. A block contains several pages. The datasheet of your NAND part will list the size of the page and the block of your NAND part. The main catch here is that the erase and the read/write operation act different in NAND flash. The erase operation in NAND will erase a whole block while the read/write operation can be performed per page.

      Keeping all this in mind following commands will flash the u-boot image in RAM at location - 0x1000000 to the NAND flash at your desired, calculated location.

NOTE: To get help on any u-boot command refer the post http://embeddedbuzz.blogspot.in/2013/04/getting-help-on-u-boot-command-usage.html
i) Unlocking the desired region:  Before performing any operations below, it is possible that your NAND is locked from reading or writing currently just to ensure mistaken erasure or read/write operations. Locking can be performed on the whole NAND or only particular section (pages). In this case you will need to unlock the NAND by following command first:


    #nand unlock [offset] [size]

ii) Erasing the desired block:   'nand erase' command in u-boot is used to erase a desired block. It takes the block address (base adress + offset) (hex) as an argument and the size of erasure. If no arguments are given the whole NAND device is erased:

    #nand erase [offset] [size(hex)] - erase `size' bytes from
    offset `off' (entire device if not specified)
    eg. :- nand erase 0 0x80000

iii) Writing the image to NAND:   'nand write' command is used to write to NAND. It takes the source RAM address (hex), the NAND device number (int) and the destination NAND page address (hex)(base address + offset to a page in block) (the first page of any block has same address as block).

    #nand write [addr(hex)] [off|partiton] [size(hex)] - read/write `size' bytes starting at offset `off' to/from memory address `addr'
    eg. :- nand write 0x1000000 0 0x80000


B] Putting the image in the NOR flash:

    NOR memory can be accessed non-sequentially just like RAM (its not volatile of curse). Now to put the image into NOR follow the below steps:

i) Unprotecting the NOR memory: Same as NAND memory if you NOR flash is protected then we need to first unprotect it using the following command:

    #protect off all

ii) Erasing the desired region: We erase the desired NOR region where we want to flash the image as follows:

    #erase [start_address(base+offset) (hex)] [end_address(base+offset) (hex)]
    eg. :- erase 0xfe000000 0xfe07ffff

iii) Writing the image to NOR: For this we simply use the cp command as follows:

    #cp[.b, .w, .l] [source_address(hex)] [target/destination_address(hex)] [count/size(hex)]
            - copy memory

.b means bytewise
.w is wordwise
.l is long wordwise
    eg. :- cp.b 0x2000000 0xfe000000 0x7ffff


Happy ubooting...

No comments:

Post a Comment