[RFC] tar --to-command
Denys Vlasenko
vda.linux at googlemail.com
Fri Jun 18 00:41:08 UTC 2010
On Friday 18 June 2010 02:15, Ladislav Michl wrote:
> Hi,
>
> I needed a convenient way of upgrading device firmware where available RAM is
> smaller than image size. Firmware file contains kernel, rootfs image and a
> few fpga images. Easiest way seems to pack everything into tar file and write
> to appropriate places based on filename (idea comes from Marc Kleine-Budde @
> pengutronix). Here is an (simplyfied) example:
>
> #!/bin/sh
>
> FWFILE=$1
>
> #
> # Generate command script for tar(1)
> #
>
> # get unique filename
> WRITECMD=`mktemp /tmp/tarcmd.XXXXXXXX` || exit 1
>
> # output script body (substitution turned off)
> cat > $WRITECMD << 'EOF'
>
> #!/bin/sh
>
> case $TAR_FILENAME in
> kernel*)
> PARTNAME=kernel
> ;;
> rootfs*)
> PARTNAME=rootfs
> ;;
> *)
> echo "Skipping $TAR_FILENAME."
> exit 0;
> ;;
> esac
>
> DEV=`sed -n "s/\([^:]*\):[^\"]*\"$PARTNAME\"/\1/p" < /proc/mtd`
> if test -c /dev/$DEV
> then
> echo "$PARTNAME is $DEV"
> else
> echo "Unable to find flash device"
> exit 1
> fi
>
> echo "Erasing $DEV. "
> flash_eraseall -q /dev/$DEV >/dev/null 2>&1
> if test "$?" -ne 0
> then
> echo "ERROR!"
> exit 1
> fi
>
> echo "Writing $TAR_FILENAME to $DEV. "
> nandwrite -q -p /dev/$DEV -
> if test "$?" -ne 0
> then
> echo "ERROR!"
> exit 1
> fi
>
> exit 0
> EOF
>
> chmod 755 $WRITECMD
>
> tar --to-command=$WRITECMD -x -f $FWFILE
> if test "$?" -ne 0
> then
> echo "failed."
> exit 1
> fi
>
> Above is typicaly fed with firmware file over ssh:
> ssh -l root <target_ip> "fw_install -" < fwfile
This adds an incompatible option to tar.
> Patch bellow is the very first draw adding support for --to-command into
> busybox' tar. Comments and suggestions welcome.
I hesitate to add options and features which are not provided
by upstream utilities.
--
vda
More information about the busybox
mailing list