{{{#!html
Some Gateworks Laguna family products have an 'Alternate boot device' that can be used for alternate firmware images, such as a flash recovery image.
Please note that if you have a board with a 4MB SPI flash device, such as the GW2388-4 you will need to use u-boot-2014.10 cns3xxx bootloader.
There are 2 ways that you can instruct the 'Gateworks System Controller' to boot to the alternate boot device (an SPI FLASH device) vs the primary boot device (a NOR FLASH device):
i2cset -f -y 0 0x20 0 0x08
This is an example from a Laguna 2388 with 16MB NOR and 4MB SPI. The mapping is set by us but can be changed.
root@(none):/# cat /proc/mtd dev: size erasesize name mtd0: 00040000 00020000 "uboot" mtd1: 00020000 00020000 "params" mtd2: 00200000 00020000 "kernel" mtd3: 00da0000 00020000 "rootfs" mtd4: 007c0000 00020000 "rootfs_data" mtd5: 00040000 00010000 "uboot" mtd6: 00040000 00010000 "params" mtd7: 00180000 00010000 "kernel" mtd8: 00200000 00010000 "rootfs"
The Gateworks System Controller implements an 'Auto Switch Boot Device' feature that can be useful as a firmware recovery mechanism. GSC register R1.6 (SWITCH_BOOT_ENABLE) enables this mode. When this is set and the board powers on it will initiate a countdown timer that expires in 30 seconds. Writing a 1 to GSC R1.7 (SWITCH_BOOT_CLEAR) will cancel this timer. If the timer expires the boot device will be 'toggled' and the board will be hard reset.
If you need to progamattically hard power cycle the board you can put it to sleep for a few seconds.
Within the linux command-line shell, you can use i2cset from the i2c-tools package.
To enable 'switch boot check':
i2cset -f -y 0 0x20 1 0x40 ;# enable R1.6 (SWITCH_BOOT_ENABLE)
To assert 'SWITCH_BOOT_CLEAR' and cancel the countdown timer (within 30 seconds of power up):
i2cset -f -y 0 0x20 1 0xC0 ;# cancel countdown by asserting R1.7 (SWITCH_BOOT_CLEAR) but keep enabled R1.6 (SWITCH_BOOT_ENABLE) # or i2cset -f -y 0 0x20 1 0x80 ;# cancel countdown by asserting R1.7 (SWITCH_BOOT_CLEAR) and disable R1.6 (SWITCH_BOOT_ENABLE)
To programatically hard power-cycle the board by putting it to sleep for a few seconds while also enabling 'switch boot':
# power cycle board: must be a hard power cycle, not a soft reboot (which can be done manually or via sleep/wake timer control) i2cset -f -y 0 0x20 6 5 ;# write add timer to 5sec i2cset -f -y 0 0x20 7 0 i2cset -f -y 0 0x20 8 0 i2cset -f -y 0 0x20 9 0 i2cset -f -y 0 0x20 1 0x04 ;# set add time bit (must be a separate i2c transaction than activating sleep) i2cset -f -y 0 0x20 1 0x43 ;# enable R1.6 (SWITCH_BOOT_ENABLE), sleep operation (R1.0) and activate sleep (R1.1) # wait for board to reboot into linux and within 30 seconds of powerup cancel the boot timer i2cset -f -y 0 0x20 1 0xC0 ;# set R1.7 (SWITCH_BOOT_CLEAR) to cancel timer but leave R1.6 (SWITCH_BOOT_ENABLE) enabled
Within the u-boot environment you can use the imw command to set i2c registers.
To enable 'switch boot check':
Laguna > imw 0x20 1 0x40 1 ;# enable R1.6 (SWITCH_BOOT_ENABLE)
To assert R1.7 (SWITCH_BOOT_CLEAR) and cancel the countdown timer (within 30 seconds of power up):
Laguna > imw 0x20 1 0xc0 1 # set SWITCH_BOOT_CLEAR (R1.7)
To programatically hard power-cycle the board by putting it to sleep for a few seconds while also enabling 'switch boot':
Laguna > imw 0x20 6 0x05 1 # LSB (5 secs) Laguna > imw 0x20 7 0x00 1 Laguna > imw 0x20 8 0x00 1 Laguna > imw 0x20 9 0x00 1 # MSB Laguna > imw 0x20 1 0x04 1 # latch R6-R9 and add to RTC Laguna > imw 0x20 1 0x43 1 # set SWITCH_BOOT_ENABLE (R1.6), sleep operation (R1.0) and activate sleep (R1.1)
The alternate boot device and the primary boot device require different bootloaders (SPI vs NOR FLASH). Only the primary boot device is programmed with a bootable image by Gateworks. In order to program the alternate boot device you will need to do so from Linux (as u-boot-nor.bin on the primary boot device without modification can only access NOR flash).
REQUIRED: You will also need to modify your Linux kernel to allow writing to the u-boot partition of SPI flash by commenting out the '.mask_flags = MTD_WRITEABLE' in the laguna_spi_partitions structure in:
/gateworks-openwrt/trunk$ vi build_dir/target-arm_v6k_uClibc-0.9.33.2_eabi/linux-cns3xxx/linux-3.8.6/arch/arm/mach-cns3xxx/laguna.c
Once modified, recompile the BSP. Then flash this to the NOR flash on your board.
Once booted to NOR flash with this modified kernel you can write the laguna u-boot-spi.bin to /dev/mtd5 via mtd:
root@OpenWrt:/# mtd write u-boot_spi.bin /dev/mtd5 Unlocking /dev/mtd5 ... Writing from u-boot_spi.bin to /dev/mtd5 ... root@OpenWrt:/#
Now you can follow the instructions above to boot off the Alternate Boot Device (SPI Flash) and setup your kernel/rootfs using the instructions for an SPI FLASH device such as the GW2380 found here here
Depending on the size of the SPI FLASH you will likely need to prune features from your kernel/filesystem. A good starting point may be the Laguna test_config file which uses a ramdisk and a minimal set of utilities used by Gateworks to test boards. As this OpenWrt config file specifies an INTRAMFS ramdisk, you only need to flash the kernel which includes the root filesystem.
... Hit any key to stop autoboot: 0 Laguna> printenv bootcmd bootcmd=bootm 0x60080000
Laguna > imw 0x20 1 0xc0 1 # set SWITCH_BOOT_CLEAR (R1.7)
Laguna> sete ipaddr 192.168.1.211 Laguna> sete serverip 192.168.1.14
Laguna> erase 0x60080000 0x60ffffff
Laguna> tftpboot 0x00800000 laguna/openwrt-cns3xxx-uImage_ramdisk Laguna> cp.b 0x00800000 0x60080000 $(filesize)
setenv bootargs 'console=ttyS0,115200 root=/dev/ram0 rootfstype=ramfs' saveenv
Laguna> bootm
Notes:
Laguna> protect off 0x60040000 +0x40000 Laguna> erase 0x60040000 +0x40000 Laguna> reset
If using the u-boot-2014.10-cns3xxx which supports both the 16MB and 4MB SPI flash devices used on Laguna products, you will need to use the 'sf' commands within uboot to access flash.
Update kernel:
setenv serverip 192.168.1.146 setenv ipaddr 192.168.1.1 setenv spi_koffset 0x80000 setenv spi_klen 0x180000 setenv spi_roffset 0x200000 # update kernel tftp ${loadaddr} laguna/openwrt-cns3xxx-uImage && sf probe && sf update ${loadaddr} ${spi_koffset} ${filesize}
Update SPI uboot:
# update SPI uboot setenv serverip 192.168.1.146 setenv ipaddr 192.168.1.1 tftp ${loadaddr} laguna/u-boot_spi.bin && sf probe && sf update ${loadaddr} 0 ${filesize}
Enable Alternate Boot timer:
i2c mw 0x20 1 0x40 1 # set R1.6 SWITCH_BOOT_ENABLE
Clear Alternate Boot timer:
i2c mw 0x20 1 0xc0 1 # set R1.7 SWITCH_BOOT_CLEAR