Commit a8710d02 authored by Alessandro Rubini's avatar Alessandro Rubini

flash-wrs and doc: various changes

This changes a while the flash script, and updates the documentation
accordingly. It is a single commit because I couldn't test the script
until all changes were in place

Main changes:
  - fixed used interation: now it stops asking to remove the jumper
  - if "-b" is used and WRS_BASE_DIR is unset, defaults to current dir
  - all temporary files are in a specific directory, reported to the user
  - the script checks for the required files as first step, to err out soon
  - the 5-second sleep is removed, as there's an interactive step anyways
  - error messages are a little more verbose, to understand what was wrong
  - option parsing is more selective about flags for the flasher
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent ef05b20e
......@@ -26,7 +26,7 @@ showhelp()
printf " -h|--help\t Show this help message\n"
printf " -m|--mode\t can be: default (df and nf), df (dataflash),\n\t\t nf (nandflash), ddr (ddr memories).\n"
printf " -e \t\t Completely erase the memory (Can erase your configuration)\n"
printf " -b|--build\t Use file that you have build in the WRS_OUTPUT_DIR\n"
printf " -b|--build\t Use files that you have built in the WRS_OUTPUT_DIR\n"
printf " -m1|--mac1\t Default MAC address for the ethernet port on board\n"
printf " -m2|--mac2\t Default base MAC address for the switch ports\n"
exit 0
......@@ -35,17 +35,14 @@ showhelp()
checkExit()
{
err=0;
if [ $1 ]; then
if [ -f $1 ]; then
return 0;
else
echo "Can't find $1" >& 2;
fi
# $1 == what, $2 == filename
# (assumes $me is the script name)
if [ -f $2 ]; then
return 0;
else
echo "varname not set"
echo "$me: Can't find file \"$2\" ($1)" >& 2;
exit 1
fi
exit 1
}
checkMAC()
......@@ -72,9 +69,7 @@ modifyMAC()
fi
# Modify MAC address
sed -i "s/$MAC1_DEF/$MAC1/" $new
echo "MAC1 is now: $MAC1"
sed -i "s/$MAC2_DEF/$MAC2/" $new
echo "MAC2 is now: $MAC2"
return 0
}
......@@ -84,13 +79,22 @@ WRS_BASE_DIR=$(cd $dir && /bin/pwd)
# Sanity checks
if [ -d ${WRS_BASE_DIR}/usb-loader ]; then true; else
echo "$0: usb-loader is not found" >& 2
echo "$0: ${WRS_BASE_DIR}/usb-loader: no such directory" >& 2
exit 1
fi
if [ "x${WRS_OUTPUT_DIR}" = "x" ]; then
export WRS_OUTPUT_DIR=$(/bin/pwd)
fi
# build flasher itself
if CC=cc make -s -C ${WRS_BASE_DIR}/usb-loader; then true; else
echo "$0: Error compiling usb-loader" >&2; exit 1;
FLASHER="${WRS_BASE_DIR}/usb-loader/mch_flasher"
if [ -x $FLASHER ]; then
true
else
if CC=cc make -s -C ${WRS_BASE_DIR}/usb-loader; then true; else
echo "$0: Error compiling in directory ${WRS_BASE_DIR}/usb-loader" >&2; exit 1;
fi
fi
# add /usr/sbin for mkfs.jffs2
......@@ -121,6 +125,8 @@ rootfsjffs2=""
# full path to the file system directory
TMPFS=""
TMPDIR=$(mktemp -d /tmp/flash-wrs-XXXXXX)
while [ $# -ge 1 ]; do
case $1 in
-b|--build)
......@@ -131,12 +137,12 @@ while [ $# -ge 1 ]; do
shift;;
*.tar.gz)
checkExit $1
tar --directory /tmp -xzf $1
at91bs=/tmp/at91bootstrap.bin;
barebox=/tmp/barebox.bin
kernel=/tmp/zImage
rootfsgz=/tmp/wrs-image.tar.gz
checkExit "tar-file" $1
tar --directory $TMPDIR -xzf $1
at91bs=$TMPDIR/at91bootstrap.bin;
barebox=$TMPDIR/barebox.bin
kernel=$TMPDIR/zImage
rootfsgz=$TMPDIR/wrs-image.tar.gz
shift;;
-h|--help) showhelp; shift;;
......@@ -144,7 +150,7 @@ while [ $# -ge 1 ]; do
-m|--memmode)
# verify memory mode
if [ "$2" != "nf" ] && [ "$2" != "df" ] && [ "$2" != "ddr" ] && [ "$2" != "default" ]; then
echo "Error: Invalid memory mode"
echo "Error: Invalid memory mode \"$2\""
showhelp
exit 1
fi
......@@ -171,7 +177,9 @@ while [ $# -ge 1 ]; do
fi
shift; shift;;
-*) FLAGS="${FLAGS} $1"; shift;;
-[ecs])
# e == erase, c == check, s == scrub
FLAGS="${FLAGS} $1"; shift;;
* ) echo "$0: Invalid argument \"$1\"" >&2; exit 1;;
esac
......@@ -181,20 +189,23 @@ if [ "x$rootfsgz" = "x" ]; then
showhelp
fi
echo "---------------------------------------"
# Even if not all files are always needed, check all of them immediately
me=$(basename $0)
echo "${me}: Working in $TMPDIR"
checkExit barebox $barebox
checkExit at91bootstrap $at91bs
checkExit kernel $kernel
checkExit root-filesystem $rootfsgz
## MAC1 and MAC2 are really recommended
if [ "x$MAC1" = "x$MAC1_DEF" ]; then
echo "WARNING: YOU DID NOT SET THE MAC1 FIELD"
echo "---------------------------------------"
echo "Warning: you did not set the MAC1 value; using \"$MAC1_DEF\""
fi
if [ "x$MAC2" = "x$MAC2_DEF" ]; then
echo "WARNING: YOU DID NOT SET THE MAC2 FIELD"
echo "---------------------------------------"
echo "Warning: you did not set the MAC2 value; using \"$MAC2_DEF\""
fi
echo "Starting flashing procedure in 5 seconds ..."
sleep 5
## Selecting the running memmode
if [ "x$memmode" = "xdf" ]; then
df=1
......@@ -207,56 +218,55 @@ else
nf=1
fi
# Check if atmel sam-ba is find by lusb
msg="Waiting for at91sam SAMBA bootloader on usb\nPlease check that the Dataflash is short-circuited!\n"
while true; do
lsusb | grep "at91sam" > /dev/null
if [ "$?" -eq "0" ]; then
break
else
if [ -n "$msg" ]; then
printf "$msg"
msg=""
# Check if atmel sam-ba is found by lsusb
if lsusb | grep -q "at91sam"; then
true;
else
echo ""
echo "$me: Waiting for at91sam SAMBA bootloader on usb."
echo " Please check the jumper is plugged"
echo " and the USB cable is connected."
echo " Then reset the switch or turn it on."
while true; do
if lsusb | grep -q "at91sam"; then
break
fi
sleep 1
printf "."
fi
done
if [ -z "$msg" ]; then
printf "\tOK\n"
read -p "Remove the Dataflash jumper (Press any key)" notused
echo -n "."
done
echo " Ok"
fi
# Remove the jumper now, before proceeding
echo "$me: I'm talking with the switch;"
echo -n " please remove the jumper and press Enter to start flashing: "
read unused
# Create a temporary barebox binary with modified MAC addresses
checkExit $barebox
Tbarebox=$(mktemp /tmp/barebox.XXXXXX)
Tbarebox=$TMPDIR/bb.new
modifyMAC ${barebox} ${Tbarebox}
## Flashing DataFlash
if [ $df ]; then
checkExit $at91bs
${WRS_BASE_DIR}/usb-loader/mch_flasher -m df $FLAGS $DEV ${at91bs} 0 ${Tbarebox} 33792
${FLASHER} -m df $FLAGS $DEV ${at91bs} 0 ${Tbarebox} 33792
fi
## Prepare for the NAND flashing procedure
if [ $nf ]; then
checkExit $kernel
checkExit $rootfsgz
TMPCPIO=$(mktemp /tmp/wrsflash-cpio.XXXXXX.cpio.gz)
TMPFS=$(mktemp -d /tmp/wrsfs-tgz.XXXXXX)
rootfsjffs2=/tmp/wrs-image.jffs2.img
TMPFS=$TMPDIR/wrsfs-tgz; mkdir $TMPFS
rootfsjffs2=$TMPDIR/wrs-image.jffs2
# The TMPCPIO is used for the NAND flashing procedure. It
# contains the magic string "paperino" (0x61706570 0x69726f6e)
# in the first 8bytes and in the following byte the whole
# file system. Barebox use this magic string to identify
# the flashing procedure.
echo -n "paperino" > $TMPCPIO
TMPCPIO=$TMPDIR/wrsflash.cpio.gz
# make flashing cpio from the unzipped file system
TMPSCRIPT=$(mktemp /tmp/wrsrootfs-script.XXXXXX)
TMPSCRIPT=$TMPDIR/wrsrootfs-script
cat > $TMPSCRIPT << EOF
tar --directory $TMPFS -xzf $rootfsgz
......@@ -276,15 +286,16 @@ cp ${rootfsjffs2} $TMPFS/flashing/wrs-image.jffs2.img
cp ${kernel} $TMPFS/flashing/zImage
cp ${WRS_BASE_DIR}/usb-loader/S99flash-from-kernel.sh $TMPFS/etc/init.d/
cd ..
echo -n "paperino" > $TMPCPIO
(cd "$TMPFS" && find . | cpio -o -H newc | gzip) >> $TMPCPIO
EOF
fakeroot bash $TMPSCRIPT
rm $TMPSCRIPT
# Erase all nand memory
${WRS_BASE_DIR}/usb-loader/mch_flasher -e -m nand
$FLASHER -e -m nand
# Start nand flashing procedure
${WRS_BASE_DIR}/usb-loader/mch_flasher -m ddr $FLAGS $DEV ${Tbarebox} 0x0 ${kernel} 0x1000000 ${TMPCPIO} 0x1FFFFF8
$FLASHER -m ddr $FLAGS $DEV ${Tbarebox} 0x0 ${kernel} 0x1000000 ${TMPCPIO} 0x1FFFFF8
rm -rf $TMPFS
rm -rf $TMPCPIO
......@@ -293,8 +304,6 @@ fi
## Loading in DDR
if [ $test ]; then
checkExit $kernel
checkExit $rootfsgz
TMPFS=$(mktemp -d /tmp/wrsfs-tgz.XXXXXX)
rootfsjffs2=/tmp/wrs-image.jffs2.img
......@@ -308,7 +317,7 @@ EOF
rm $TMPSCRIPT
rm $TMPFS
${WRS_BASE_DIR}/usb-loader/mch_flasher -m ddr $FLAGS $DEV ${Tbarebox} 0x0 ${kernel} 0x1000000 ${rootfsjffs2} 0x2000000
$FLASHER -m ddr $FLAGS $DEV ${Tbarebox} 0x0 ${kernel} 0x1000000 ${rootfsjffs2} 0x2000000
fi
rm $Tbarebox
......
......@@ -545,17 +545,20 @@ The command to flash is this:
@end example
You can also flash the image you have build using @ref{Building} by
adding the tag @code{-b|--build}. To use this option you must define the
WRS_OUTPUT_DIR environment variable.
adding the tag @code{-b|--build}. To use this option you must call
the script from the build directory, or define the @t{WRS_OUTPUT_DIR}
environment variable.
@example
/path/to/wr-switch-sw/build/flash-wrs -e -b
@end example
Please note that the ``@code{-e}'', which requires erasing the
whole data flash, is mandatory because otherwise bits of your previous
whole data flash, is almost mandatory because otherwise bits of your previous
installation may leak into the newly-programmed one. Only on factory-new
devices you can avoid this ``@code{-e}'' argument. When you program
devices you can avoid this ``@code{-e}'' argument.
When you program
the NAND memory the script applies automatically @code{-e} option.
It is recomended to configure the MAC addresses during the flashing
......@@ -569,24 +572,30 @@ MAC address to sequentially assign a MAC address for every switch ports.
-m2 02:34:34:34:34:00
@end example
If you don't configure a MAC address, a big warning will be displayed and
you have 3 seconds to abort the procedure. If you don't abort the flashing
If you don't configure a MAC address, a warning will be displayed and
you can abort the procedure. If you don't abort the flashing
procedure, the script will use default MAC addresses. Default MAC addresses
are: 02:34:56:78:9A:BC for MAC1, 02:34:56:78:9A:00 for MAC2.
are: 02:34:56:78:9A:BC for MAC1 (the Ethernet port of the ARM CPU)
and 02:34:56:78:9A:00 for MAC2 (the base address for the 18 SFP ports).
@example
/path/to/wr-switch-sw/build/flash-wrs -e -b
---------------------------------------
WARNING: YOU DID NOT SET THE MAC1 FIELD
---------------------------------------
---------------------------------------
WARNING: YOU DID NOT SET THE MAC2 FIELD
---------------------------------------
Starting flashing procedure in 3 seconds ...
@end example
@smallexample
tornado% ~/wip/wr-switch-sw/build/flash-wrs -e -b
flash-wrs: Working in /tmp/flash-wrs-1vV9z6
Warning: you did not set the MAC1 value; using "02:34:56:78:9A:BC"
Warning: you did not set the MAC2 value; using "02:34:56:78:9A:00"
flash-wrs: I'm talking with the switch;
please remove the jumper and press Enter to start flashing:
@end smallexample
If the script cannot find the Atmel programming interface on your USB
bus, it prints a message and waits for the switch to be turned on
in the proper way (with the humber plugged).
The process calls the flasher program twice (so you'll see the
initialization strings two times) an takes around 3 minutes.
initialization strings two times) an takes slightly less than 3
minutes. the longest step is erasure of @i{DataFlash}: if run
without @t{-e} the script takes just 20 seconds.
This is the a summary of the output you are expected to see,
trimmed to save pages:
......@@ -603,7 +612,7 @@ Initializing DataFlash...
loading applet isp-dataflash-at91sam9g45 at 0x00300000
Initializing DataFlash > Done!
Erasing DataFlash > DONE
Erasing DataFlash [... there is a long delay here ...] > DONE
Programming DataFlash...
@ 0x70000000 : at91bootstrap.bin ; size 0xf7c (3Kb)
......@@ -634,11 +643,10 @@ Loading DDR...
DDR: Writing 21119306 bytes at offset 0x0 buffer 70000000....ABCDEF
[...]
@end smallexample
If you look at the serial port, during programming, you will see
messages like these:
It is suggested to look at the CPU's serial port during programming,
where you you will see messages like these:
@smallexample
-I- Statup: PMC_MCKR 1202 MCK = 100000000 command = 0
......@@ -697,7 +705,7 @@ Options:
-m|--mode can be: default (df and nf), df (dataflash),
nf (nandflash), ddr (ddr memories).
-e Completely erase the memory (Can erase your configuration)
-b|--build Use file that you have build in the WRS_OUTPUT_DIR
-b|--build Use files that you have built in the WRS_OUTPUT_DIR
-m1|--mac1 Default MAC address for the ethernet port on board
-m2|--mac2 Default base MAC address for the switch ports
@end smallexample
......@@ -721,9 +729,9 @@ install different binaries on these memories:
@item nandflash: @emph{kernel} zImage and the @emph{file-system}
@end itemize
You can also erase the dataflash memory before write your binaries; to do this
add the option @code{-e}. Note that the script always erase nandflash before
write on it.
You can also erase the dataflash memory before writing your binaries; to do this
add the option @code{-e}. Note that the script always erases nandflash before
writing on it.
Finally,
......@@ -731,13 +739,13 @@ The script performs the following steps:
@itemize @bullet
@item It compiles the loader (@i{usb-loader/} subdir).
@item Check if SAMBA bootloader is present.
@item It checks if the SAMBA bootloader is present.
@item It picks the correct binaries according to the options.
@item Optionally, it changes the default MAC addresses in @i{barebox}
default environment, so you can make all switches different.
default environment, so you can use a different MAC for each switch.
@item Optionally, it erases the dataflash memory.
@item And finally, it writes the corresponding binaries to @i{dataflash},
or @i{ddr}.
or @i{nand}.
@end itemize
@c ############################################################################
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment