USB Blasting

From embeddedTS Manuals

Overview

As many uses for our embedded boards require large quantities to be programmed we have added a mechanism for quickly blasting systems. In all of our linuxrc scripts we have added a function that will on boot:

  • Check for a USB drive
  • Turn on red LED
  • If detected load USB and ethernet modules
  • Mount the first partition of the drive
  • Execute tsinit
  • Turn off red LED

Preparing a tsinit USB drive

To prepare the USB drive, create either a FAT32 or EXT2 partition. The script will only mount the first partition, so keep all of your images and the script there. When you copy on the script, you only need to make sure it is executable and named 'tsinit'. You can in place add a natively compiled binary, but usually a shell script will be the simplest for blasting purposes.

Simple blast script

This example expects an xnand-image.dd and/or an sd-image.dd in the root of the flash drive. If you exclude either, it will still run while only programming one. Normally, it will begin programming both and wait for them both to finish executing. When the script exits, the red LED will turn off. This will be compatible with the TS-75XX, TS-4200, TS-4500, TS-4700, and the TS-4800. Though you can tweak the nand and SD writing to the restore commands for other applicable boards.

Create this file named "tsinit" in the root of the thumbdrive, and run "chmod a+x" on this file.

#!/bin/sh

# The linuxrc file will mount the USB drive in /mnt/usbdev/, so any
# files you access must use that path.

## Program Nand ##
killall nandctl
nandctl -XW 2048 -z 131072 -i /mnt/usbdev/xnand-image.dd &

## Program SD ##
dd if=/mnt/usbdev/sd-image.dd bs=32k conv=sync of=/dev/nbd5 &

## Program Onboard and Offboard SPI flash ##
spiflashctl -l 0 -W 64 -z 65536 -i /mnt/usbdev/spiflash-image.dd &
spiflashctl -l 1 -W 64 -z 65536 -i /mnt/usbdev/spiflash-image.dd &

wait

How this works

In all of the linuxrc scripts we have a function to check if there is a USB drive inserted. This example is from the TS-75XX/TS-4500 series linuxrc:

if [ "$x" -eq 1 ]; then
  (
        ts7500ctl --redledon
        mount -t tmpfs tmpfs /lib/modules
        tar -x -z -f /modules.tar.gz -C /
        modprobe scsi_mod
        modprobe sd_mod
        modprobe usbcore
        modprobe ehci_hcd
        modprobe usb_storage
        modprobe smscusbnet
        modprobe smsc9500
        modprobe ohci_hcd
        umount /lib/modules
        x=0
        while [ "$x" -lt 150 -a ! -e /sys/block/sda ]; do
                x=$((x+1))
                sleep .1
        done
        mount -o ro /dev/sda1 /mnt/usbdev
        if [ -x /mnt/usbdev/tsinit ]; then 
                /mnt/usbdev/tsinit <$CONSOLE >$CONSOLE 2>&1
        fi
        umount /mnt/usbdev
        ts7500ctl --redledoff
  ) &
fi