OK, here is the second part of my approach to (safely) apply software application updates remotely to a Blackfin device without using netboot.
See Part 1 for the background.
So, we now have our Blackfin booting uClinux from a compressed image stored in a flash partition. We allocated two other flash partitions:
- Bootloader (Das U-Boot)
- Flash filesystem (jffs2)
In the startup messages, you should see something like this:
Creating 3 MTD partitions on "physmap-flash.0":
0x00000000-0x00040000 : "Bootloader"
0x00040000-0x00100000 : "jffs2"
0x00100000-0x00400000 : "uImage"
The jffs2 partition is mounted in the startup script /etc/rc. You need these two lines somewhere:
mount -t jffs2 /dev/mtdblock1 /mnt/flash
The mounted directory /mnt/flash/ is used to store application updates. Those will persist between device power cycles and are deployed each time the device boots.
The application deployment is kicked off by another line in /etc/rc. I simply call a script I created: /bin/deploy. Here’s what is inside /bin/deploy:
md5sum -c $md5name
if [ $? -ne 0 ]
echo "md5 BAD! Deploy aborted."
echo "md5 OK. Deploying applications."
tar zxvf $pkgname -C /
This script changes to the directory /mnt/flash/ (our persistant flash filesystem) and checks if a valid tarball exists for this device. The tarball must begin with the hostname of the device and includes a version id. The tarball must also pass an md5 check. If the check is successful, the tarball is exploded from / (root), placing new software in the device.
Now, how do we get the tarball of updated software and its md5 into /mnt/flash? I created another script for that:
if [ $# -ne 1 ]
echo "Syntax Error"
echo "Usage $0 <version> e.g. $0 1.0.2"
if [ -f $pkgname ]
echo "$pkgname already exists. Download new copy? [Y/n]"
if [ $ans == "N" -o $ans == "n" ]
echo "Using local copy of $pkgname."
echo "Downloading new copy of $pkgname."
echo "$pkgname needs to be downloaded."
if [ $download -eq 1 ]
tftp -g -l $pkgname -r $pkgname fs
tftp -g -l $md5name -r $md5name fs
md5sum -c $md5name
This script is just a smart downloader. It takes an input parameter as the version number of the device application upgrade to download. It prepends the hostname to the version number and creates two filenames: 1) the tarball, and 2) the md5.
It first checks if the upgrade needs to be downloaded and allows the user a choice to download a new copy or use existing one if upgrade version exists. It it does not exist, it automatically downloads it (via TFTP) from a TFTP server. (The setup of that server is outside of the scope of this, but I will explain below how the tarball and md5 are created.)
After the download of the upgrade, it performs an md5 check and deploys the new upgrade.
The final step is creating the upgrade tarball and md5. To accomplish this, I created a slightly crude ant task:
tar czvf $(LCO_VER_FW).tgz -C romfs/ bin/lco-fw-post bin/lco-enviro-update home/httpd/cgi-bin/command home/httpd/cgi-bin/status
md5sum $(LCO_VER_FW).tgz > $(LCO_VER_FW).md5
scp $(LCO_VER_FW).* root@fs:/tftpboot/
It contains three steps:
- Create tarball – based from root dir (romfs), include necessary files
- Create md5
- scp both files to TFTP server
LCO_VER_FW is just a variable conatining the hostname and version id.
And there you have it! A complete, safe solution to upgrade device-specific software remotely without using netboot!