Commit 6098f150 authored by Federico Vaga's avatar Federico Vaga

flash-wrs: two MAC addresses as script parameters

The script accepts two MAC address. The first MAC address (MAC1) will
be assigned to the ethernet port on board. The second MAC address
(MAC2) will be assigned to the first switch port; the following switch
ports are sequential MAC addresses from this one.
Signed-off-by: 's avatarFederico Vaga <federico.vaga@gmail.com>
parent eeaa6024
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
showhelp() showhelp()
{ {
printf "Usage: $0 [options] MAC [<firmware>.tar.gz] [DEV]\n\n" printf "Usage: $0 [options] [<firmware>.tar.gz] [DEV]\n\n"
printf "MAC:\t MAC address in hexadecimal seperated by ':' (i.e, AB:CD:EF:01:23:45)\n" printf "MAC:\t MAC address in hexadecimal seperated by ':' (i.e, AB:CD:EF:01:23:45)\n"
printf "<firmware>.tar.gz: Use the file in the firmware to flash the device\n" printf "<firmware>.tar.gz: Use the file in the firmware to flash the device\n"
printf "DEV:\t The usb device (by default it is /dev/ttyACM0)\n" printf "DEV:\t The usb device (by default it is /dev/ttyACM0)\n"
...@@ -27,7 +27,8 @@ showhelp() ...@@ -27,7 +27,8 @@ showhelp()
printf " -e \t\t Completely erase the memory (Can erase your configuration)\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 file that you have build in the WRS_OUTPUT_DIR\n"
printf " --test\t Use file for testing the switch (not available)\n" printf " --test\t Use file for testing the switch (not available)\n"
printf " --silent\t Don't ask MAC or S/N and use default 02:0B:AD:C0:FF:EE\n\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"
exit 0 exit 0
} }
...@@ -62,13 +63,18 @@ modifyMAC() ...@@ -62,13 +63,18 @@ modifyMAC()
new=$2 new=$2
cp $origin $new cp $origin $new
echo "Configure the MAC addresses:"
echo " MAC1 $MAC1"
echo " MAC2 $MAC2"
# MAC address doesn't need any modification # MAC address doesn't need any modification
if [ $silent ]; then if [ $silent ]; then
return 1; return 1;
fi fi
# Modify MAC address # Modify MAC address
sed -i "s/02:0B:AD:C0:FF:EE/$MAC/" $new sed -i "s/$MAC1_DEF/$MAC1/" $new
echo "MAC is now: $MAC" echo "MAC1 is now: $MAC1"
sed -i "s/$MAC2_DEF/$MAC2/" $new
echo "MAC2 is now: $MAC2"
return 0 return 0
} }
...@@ -87,7 +93,14 @@ if CC=cc make -s -C ${topdir}/usb-loader; then true; else ...@@ -87,7 +93,14 @@ if CC=cc make -s -C ${topdir}/usb-loader; then true; else
fi fi
# parse command line # parse command line
MAC=""
# Default MAC address for the switch board ethernet
MAC1_DEF="02:34:56:78:9A:BC"
MAC1=$MAC1_DEF
# Default base MAC address for the 18 switch ports
MAC2_DEF="02:34:56:78:9A:00"
MAC2=$MAC2_DEF
DEV="" DEV=""
FLAGS="" FLAGS=""
...@@ -104,6 +117,7 @@ while [ $# -ge 1 ]; do ...@@ -104,6 +117,7 @@ while [ $# -ge 1 ]; do
kernel=${WRS_OUTPUT_DIR}/images/zImage kernel=${WRS_OUTPUT_DIR}/images/zImage
rootfs=${WRS_OUTPUT_DIR}/images/wrs-image.jffs2.img rootfs=${WRS_OUTPUT_DIR}/images/wrs-image.jffs2.img
shift;; shift;;
*.tar.gz) *.tar.gz)
checkExit $1 checkExit $1
tar --directory /tmp -xzf $1 tar --directory /tmp -xzf $1
...@@ -112,7 +126,9 @@ while [ $# -ge 1 ]; do ...@@ -112,7 +126,9 @@ while [ $# -ge 1 ]; do
kernel=/tmp/zImage kernel=/tmp/zImage
rootfs=/tmp/wrs-image.jffs2.img rootfs=/tmp/wrs-image.jffs2.img
shift;; shift;;
-h|--help) showhelp; shift;; -h|--help) showhelp; shift;;
-m|--memmode) -m|--memmode)
# verify memory mode # verify memory mode
if [ "$2" != "nf" ] && [ "$2" != "df" ] && [ "$2" != "ddr" ] && [ "$2" != "default" ]; then if [ "$2" != "nf" ] && [ "$2" != "df" ] && [ "$2" != "ddr" ] && [ "$2" != "default" ]; then
...@@ -122,33 +138,46 @@ while [ $# -ge 1 ]; do ...@@ -122,33 +138,46 @@ while [ $# -ge 1 ]; do
fi fi
memmode="$2" memmode="$2"
shift; shift;; shift; shift;;
--silent)
# set default the MAC address if user didn't set a MAC address
if [ "x$MAC" = "x" ]; then
MAC="02:0B:AD:C0:FF:EE"
fi
silent=1;
shift;;
/* ) DEV="-s $1"; shift ;; /* ) DEV="-s $1"; shift ;;
*:* ) MAC="$1"; shift ;;
-m1|--mac1)
MAC1="$2"
checkMAC $MAC1
if [ $? -eq 1 ];then
echo "Error: MAC address 1 invalid ($MAC1)"
exit 1
fi
shift; shift;;
-m2|--mac2)
MAC2="$2"
checkMAC $MAC2
if [ $? -eq 1 ];then
echo "Error: MAC address 2 invalid ($MAC2)"
exit 1
fi
shift; shift;;
-*) FLAGS="${FLAGS} $1"; shift;; -*) FLAGS="${FLAGS} $1"; shift;;
* ) echo "$0: Invalid argument \"$1\"" >&2; exit 1;; * ) echo "$0: Invalid argument \"$1\"" >&2; exit 1;;
esac esac
done done
#MAC address is a mandatory field ## MAC1 and MAC2 are really recommended
if [ "x$MAC" = "x" ]; then if [ "x$MAC1" = "x$MAC1_DEF" ]; then
echo "Error: MAC address is mandatory" echo "---------------------------------------"
showhelp echo "WARNING: YOU DID NOT SET THE MAC1 FIELD"
exit 1 echo "---------------------------------------"
else fi
checkMAC $MAC if [ "x$MAC2" = "x$MAC2_DEF" ]; then
if [ $? -eq 1 ];then echo "---------------------------------------"
echo "Error: MAC address is invalid ($MAC)" echo "WARNING: YOU DID NOT SET THE MAC2 FIELD"
exit 1 echo "---------------------------------------"
fi
fi fi
echo "Starting flashing procedure in 3 seconds ..."
sleep 3
## Selecting the running memmode ## Selecting the running memmode
if [ "x$memmode" = "xdf" ]; then if [ "x$memmode" = "xdf" ]; then
......
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