Documentation:NGW/Firmware upgrade

From AVRFreaks Wiki

Jump to: navigation, search

Contents


[edit] Introduction

This step by step guide explains how to perform a firmware upgrade of your Network Gateway. First it is explained how to update U-Boot using an JTAGICE mkII programmer. In a second step it is shown how to upgrade your root file system and /usr part of the file system

To update the root file system there are four methods:

  1. SD card
  2. Network
  3. Serial
  4. JTAGICE mkII

The SD card method is preferred, but is known to not work with some setups.

The network method requires some (advanced) setup in your network environment, but when in place, it will ease both upgrades and development with the Network Gateway.

The serial method requires nothing but an RS-232 cable and the windows' hyper terminal. This method thus have the least prerequisites, but it is rather lengthy.

For the JTAGICE mkII method it's needless to say you require a JTAGICE mkII programmer from Atmel.

The Network Gatway file system consists of 3 partitions

  1. The Uboot boot loader
  2. The Linux root file system
  3. The /usr partition of Linux

The procedure described here can be used to upgrade the Network Gateway Linux root file system and the /usr partition. This guide assumes that the U-boot boot loader is installed and working correctly.

Be careful to write the memory addresses exactly as written so you do not corrupt the U-boot boot loader. If U-boot gets corrupted, a JTAGICEmkII is required to resurrect the Network Gateway!

[edit] Preparation

To obtain an U-Boot binary either build one using Atmel's buildroot or download and compile U-Boot sources from AVR32 Linux/UbootPatches.

For the root and user files system you will find on Atmel.no beta ware two files below the NGW100 Firmware Images heading.

  • A tar archive with the root and usr image files to be written to the Network Gateway flash.
  • A pre-built SD card image for automatic upgrade with the SD card method below.

Note that you will only need one of the two.

Connect a RS-232 cable between the Network Gateway kit and your PC to gain access to the boot console. (com port settings 115200-8N1) When powering up the kit, press space to abort the automatic loading. This will present you with the bootloader prompt: "Uboot>"

[edit] Memory Technology Device

The Linux 2.6.22 kernel in:

arch/avr32/boards/atngw100/flash.c

defines partitions /dev/mtd0, 1, 2

I find no mtd3 defined for /usr

mtd2 is used to shared info such as MAC, IP addresses between u-boot & the kernel.

static struct mtd_partition flash_parts[] = {
        {
                .name           = "u-boot",
                .offset         = 0x00000000,
                .size           = 0x00020000,           /* 128 KiB */
                .mask_flags     = MTD_WRITEABLE,
        },
        {
                .name           = "root",
                .offset         = 0x00020000,
                .size           = 0x007d0000,
        },
        {
                .name           = "env",
                .offset         = 0x007f0000,
                .size           = 0x00010000,
                .mask_flags     = MTD_WRITEABLE,
        },
};

[edit] Update Das U-Boot with JTAGICE mkII

Connect the JTAGICE mkII, and then use "avr32program" from the (Cygwin or Linux) command line prompt:

To erase the *entire* flash. It's not possible to only erase part of the flash.

> avr32program erase -fcfi@0

To program Das U-Boot

> avr32program program -F bin -vfcfi@0 uboot.bin

To program the file system, additionally

> avr32program program -F bin -vfcfi@0 -O 0x20000 ngw_jffs2_root.img

[edit] With SD card

On Atmel.no beta ware You can find a pre-built image of a SD card which will upgrade your Network Gateway more or less automatically. This image is tested and known to work with the following cards:

  • No-name MMC 32 MB (supplied with Nokia phones)
  • TwinMOS MMC 32MB
  • No-name HP SD 64MB (supplied with a camera)
  • Kingston SD 128 MB (stk1000 & NGW100)
  • SanDisk SD 128 MB (stk1000)
  • SanDisk SD 512 MB (ngw100)
  • SanDisk SD 2.0 GB (ngw100)
  • Kingston Elite Pro SD 256 MB
  • Viking SD Interworks 256 MB
  • TwinMOS Ultra-X SD 512 MB
  • Transcend microSD 2GB (stk1000)
  • Platinum 1GB SD (NGW100)

Not working cards:

  • extreMEmory SD 2GB EM premium (works after upgrade to u-boot 1.3)
  • no Name 32 MB MMC Card (NGW100)

Assuming that sdb is the device of your SD card, write the image with dd on your Linux workstation with:

~# sudo dd if=ngw_fw_upgrade.img of=/dev/sdb 

If you are using Windows, please refer to writing images with dd on Windows.

If you are using Linux and wish to format your SD card at any stage, you can use "cfdisk" from the command line or install "gparted" into your graphical interface (possibilities include installation va rpm, yum, apt-get etc).

Note that the image distributed is a complete SD card image, this means to write the image correctly onto the SD card, the specified device should be sdb not sdb1 (or sda not sda1) etc.

This is important. You want to end up having dd write a complete 32mb image into a new partition of 32mb. If you specify sda1 instead when you should have sda, you might end up with a successful write by dd but it won't have set up the partitions correctly and this means the following UBoot commands will fail.


With the SD card ready, you must now boot the Network Gateway from the SD card and copy the usr and root images to flash. This is done automatically by the pre-built image and you can monitor progress on the rs-232 console.

To boot the SD card type the following in Uboot:

Uboot> askenv bootcmd
Please enter 'bootcmd': mmcinit; ext2load mmc 0:1 0x10300000 /uImage; bootm 0x10300000
Uboot> set bootargs 'console=ttyS0 root=/dev/mmcblk0p1 ro' 
Uboot> boot

The Linux system will now boot, and if you are using the pre-built image, upgrade will complete without further user interaction. The LEDs on the ATNGW100 will flash while upgrading. Once complete, the LEDs will not flash but remain lit. At this point the Linux shell prompt will be presented at the console. The upgrade is now complete. Remove power and SD card and the Network Gateway upgrade is complete. If the upgrade fails, the LEDs will turn off.

If you have trouble and wish to verify that Uboot can access the SD card you can issue the command "ext2ls mmc 0:1" at the Uboot prompt (Note you need to run mmcinit before the ext2ls mmc 0:1). If you see a listing of the files on the SD, it means that Uboot can access the SD card properly. If you do not see a listing of the files then it is more likely than not that you have not successfully copied the image onto the SD card.

The root and /usr images can also be flashed from SD card by using the u-boot command ext2load.

~protect off 0x20000 0x7EFFFF
~erase 0x20000 0x7EFFFF
~mmcinit
~ext2load mmc 0:1 0x90000000 ngw_jffs2_root.img
~cp.b 0x90000000 0x20000 0xXXXXX
~protect on all

Expert option

You can also build the SD card your self:

Format a SD-card with ext2 copy a ATNGW100 Linux filesystem to it together with ngw_jffs2_root.img and ngw_jffs2_usr.img. The latest usr and root images can be found at Atmel.no beta ware

When your SD card is done booting, you can copy the images onto the ATNGW100 flash with:

~# flash_eraseall /dev/mtd3 
~# flash_eraseall /dev/mtd1
~# dd if=/ngw_jffs2_root.img of=/dev/mtd1 bs=1024
~# dd if=/ngw_jffs2_usr.img of=/dev/mtd3 bs=1056


This also works for the images created by Buildroot. For example:

~# flash_eraseall /dev/mtd3 
~# flash_eraseall /dev/mtd1
~# dd if=/media/mmcblk0p1/rootfs.avr32_nofpu.jffs2-root of=/dev/mtd1 bs=1024
~# dd if=/media/mmcblk0p1/rootfs.avr32_nofpu.jffs2-usr of=/dev/mtd3 bs=1056

(Please note that /dev/mtd1 is the 8M flash so your root image you created from Buildroot cannot be larger than 8M. If you need to have a root filesystem larger than 8M then you will need to mount an SD card or a NFS mount and tell uBoot to look there instead)

(Also note that /dev/mtd3 is the 8M dataflash so likewise, you need to keep your usr filesystem smaller than 8M or use SD or Network mounts for it.)

You will then need to tell uBoot how to find the new root image and where in that filesystem to find the kernel.

Reboot, press space to get a uBoot console and then type

~#setenv bootcmd 'fsload boot/uImage;bootm'
~$boot

You can also type "saveenv" before typing "boot" above to make the change permanent

See the following forum post: [1]

NB: Be careful to only erase mtd3 and or mtd1. If you erase anything else you could erase uBoot and this would require a JTAGmkII to un-brick your NGW

[edit] With Network (TFTP/FTP/NFS) expert option!

If you already have a TFTP server and working network boot environment, this can be used to upgrade the Network Gateway.

Put the ngw_jffs2_root.img file on your tftp server. (the latest image can be found at Atmel.no beta ware

in uboot type:

Uboot> protect off 0x20000 0x7EFFFF
Uboot> erase 0x20000 0x7EFFFF
Uboot> dhcp 0x90000000 ngw_jffs2_root.img
Bytes transferred = 6553600 (640000 hex)

Note that the size is stored to a variable $(filesize) and use it as the last argument to cp.b

Uboot> cp.b 0x90000000 0x20000 $(filesize)
Copy to Flash... done
Uboot> protect on all
Uboot> 

reboot your network gateway

The Network Gateway will now boot the new root image. The amount of error messages is due to a non upgraded /usr partition.

Note to users without a DHCP server

If you do not have a DHCP server you must set the ip address of the Network Gateway and the tftp server manually. In addition you must replace the dhcp command with tftp:

Uboot> set ipaddr 10.0.0.100   
Uboot> set tftpip 10.0.0.1
Uboot> tftp 0x90000000 ngw_jffs2_root.img


[edit] Upgrading the /usr part of the file system

the ngw_jffs2_usr.img contains the /usr part of the Network Gateway Linux. This is upgraded from the Network Gateway console after Linux has booted.

Stop all processes running from /usr

~# /etc/init.d/S90reboot

Unmount the /usr disk

~# umount /usr

(!! On newest releases unmounting is automatically performed by S90reboot script).

In buildroot v2.1.0 S90reboot does not exist (anymore). Use

~# ps

to display all running process and kill all application/services which are located in /usr. Unmount /usr as explained above.

Erase flash disk

~# flash_eraseall /dev/mtd3

Get ngw_jffs2_usr.img to the ATNGW100

You can use an SD card, or retrieve retrieve the file from an NFS, FTP or web server.

For SD card

~# mount /dev/mmcblk0p1 mnt

For NFS server

use these instructions to mount the nfs share to /mnt.

For ftp or web server

use wget to retrieve the file and replace "/mnt" with "/tmp" with dd below.
~# cd /tmp
~# busybox wget http://put_your_server_here.com/ngw_jffs2_usr.img


Copy ngw_jffs2_usr.img to /dev/mtd3

~# dd if=/mnt/ngw_jffs2_usr.img of=/dev/mtd3 bs=1056

[edit] With serial link

These steps will upload the root image to your Network gateway. The root image can be found at Atmel.no beta ware. You can use any terminal program that supports the Kermit transfer protocol

in uboot type:

Uboot> protect off 0x20000 0x7EFFFF
Uboot> erase 0x20000 0x7EFFFF
Uboot> loadb 0x90000000
## Ready for binary (kermit) download to 0x90000000 at 115200 bps...

Now select file transfer from in your terminal program, and upload the file 'ngw_jffs2_root.img' with Kermit as protocol. Be prepared to wait ~25 minutes for the transfer to complete!

## Total Size      = 0x00640000 = 6553600 Bytes
## Start Addr      = 0x90000000

Note the size and use it as the last argument to cp.b

Uboot> cp.b 0x90000000 0x20000 0x640000
Copy to Flash... done
Uboot> protect on all
Uboot> 

reboot your network gateway

The Network Gateway will now boot the new root image. The amount of error messages is due to a non upgraded /usr partition. Please follow the steps for upgrading the /usr partition above to complete the Network Gateway upgrade.

[edit] Summary of U-Boot commands

protect off <from_addr> <to_addr> unlock flash
protect on <from_addr> <to_addr> lock flash
erase <from_addr> <to_addr> erase flash
cp.b <from_addr> <to_addr> <count> copy data (bytewise)

The flash of the Network Gateway is partitioned:

0x000000 - 0x01FFFF U-Boot partition. You'll need a JTAGICEmkII if you corrupt this
0x020000 - 0x7EFFFF Linux root partition. (This is what we'll update with this guide)
0x7F0000 - 0x7FFFFF U-Boot environment area. Handled by U-Boot.
Personal tools