Open main menu

DAVE Developer's Wiki β

Changes

Flashing Images (Naon)

3,452 bytes added, 08:07, 9 May 2012
introduction to spi flash
{{InfoBoxTop}}
{{AppliesToNaon}}
{{Applies To U-Boot}}
{{InfoBoxBottom}}

=== Introduction ===

In this article we'll see in detail how to flash binaries images into Naon on-board flash memories.

Three kind of binaries are usually programmed on flash memory:
# U-Boot (1st and 2nd stage)
# Kernel
# root file system, which can be
#* ramdisk binary image
#* flash file system (e.g. JFFS2 or UBIFS) image/files

Flash devices are also called [[Memory Tecnology Device (MTD)]] in Linux kernel terms. Please also take a look at [[Memory Tecnology Device (MTD)|MTD]] article on this wiki for flash memories usage in Linux. In this article we'll take a look only at flash memories from [[:Category:U-Boot|U-Boot]] point of view.

We also assume that:
* user have a valid U-Boot image flashed on the board with the required flash device support
** if this is not your case, visit [[Recovery U-Boot Image (Naon)]] article
* user can load the image into ram via TFTP
** there's also a serial load option (using kermit or ymodem protocol) but we'll take care of this (primary due its slowness). Anyway, you can refer to [[Recovery U-Boot Image (Naon)]] again, which uses the serial port to download the 2nd stage U-Boot binary.

{{Board Specific Information|text=Before continue reading, we suggest to first have a look at [[Memory organization (Naon)|Naon Memory organization]], where details of memory addresses and size are detailed.}}

=== Flashing images on SPI NOR Flash ===

SPI NOR Flash is commonly used for:
* U-Boot (1st and 2nd stage) storage
* U-Boot environment storage
* Linux Kernel Image storage

Anyway it can be used as generic storage too (application custom data or even file systems)

==== Using SPI NOR Flash ====

U-Boot uses <code>sf</code> (''SPI flash sub-system'') commands and all its subcommands, to manage SPI NOR flashes.

As with all U-Boot commands, there's a brief <code>help</code> description:

<pre class="board-terminal">
NAON#help sf
sf - SPI flash sub-system

Usage:
sf probe [bus:]cs [hz] [mode] - init flash device on given SPI bus
and chip select
sf read addr offset len - read `len' bytes starting at
`offset' to memory at `addr'
sf write addr offset len - write `len' bytes from memory
at `addr' to flash at `offset'
sf erase offset len - erase `len' bytes from `offset'
</pre>

First of all we need to detect which kind of flash is attached to our board. This needs to be done after each boot and before using other <code>sf</code> command, otherwise an error arises:

<pre class="board-terminal">
NAON#sf read 81000000 0 20000
No SPI flash selected. Please run `sf probe'
</pre>

By using <code>sf probe</code> we can fix the above error:

<pre class="board-terminal">
NAON#sf probe 0:0
8192 KiB AT45DB642D at 0:0 is now current device
NAON#sf read 81000000 0 20000
NAON#
</pre>

The <code>sf read</code> command read from SPI flash (in the example 128KiB from offset 0) into a ram buffer (at address 0x81000000)

Generally speaking flashing a binary from U-Boot into SPI flash requires
# download the binary image (via TFTP)
# probe the SPI bus
# erase a flash range
# write the binary image from RAM to SPI Flash

==== Flashing U-Boot 1st Stage ====

==== Flashing U-Boot 2nd Stage ====

==== Flashing Linux Kernel ====


=== Flashing images on NAND Flash ===

{{WorkInProgress}}