OpenWrt Forum Archive

Topic: Easier OpenWRT install on Meraki

The content of this topic has been archived between 4 Apr 2018 and 29 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Alrighty, I've written a little Expect script for Windows XP - it shouldn't be too hard to adapt it to Linux or other OSes.

I am using Expect for Windows NT and Solarwinds TFTP Server 8.0

EDIT: I actually was using Solarwinds TFTP Server 6.0 during testing and switched to version 8.0 late in the piece.  The problem is - I can't get version 8.0 to work with RedBoot!  If you can find version 6.0 anywhere, use it. (I still have a copy of the install file)

You just put your linux kernel and rootfs image files in the same directory as the meraki-flash.bat batch file and it does the rest.  Expect even runs the TFTP server for you.  You just need to make sure the TFTP server is set to "C:\TFTP-Root" for it's root dir, and that it's security setting is set to "Transmit Only" or "Transmit and Receive files".  The script assumes all applications are installed in their default directories, and that the hard drive is C.  And of course, the LAN interface on your Windows PC needs to be 192.168.84.9 (netmask 255.255.255.0).

I've opted for a 1.0MB linux kernel partition instead of 1.5MB.  This leaves room for a slightly larger rootfs.  I don't expect that the OpenWRT linux kernel will ever be larger than 1.0MB - if it ever is, it's a simple matter to edit this script.

The script pauses 3 minutes while the Linux image is written to flash, and 5 minutes while the rootfs is written to flash.  So the whole script takes about 9 minutes to execute.  After Expect changes the RedBoot boot script, it should reset the Meraki and OpenWRT should begin it's firstboot procedure.

I will shortly put together a zip file with all the install files and a batch file that installs them and makes the appropriate registry changes to the TFTP Server config.

I execute the expect script via a batch file:

meraki-flash.bat

@ECHO OFF
CLS

SET linux_file=openwrt-atheros-2.6-vmlinux.gz
SET rootfs_file=openwrt-atheros-2.6-root.squashfs

REM The above files are copied to the tftp server root directory so the meraki can load them

ECHO .
ECHO .
ECHO About to erase the Meraki's memory
ECHO and flash %linux_file% and %rootfs_file%
ECHO .
ECHO The Meraki should be turned off now
ECHO Power it after the first ping timeout...
ECHO .
ECHO Press Ctrl-C to abort... or...
PAUSE
ECHO .
ECHO .
ECHO Confirm - Ctrl-C to abort... or...
PAUSE

COPY ".\%linux_file%" "C:\TFTP-Root\" || ECHO . && ECHO Please place %linux_file% in the same directory as meraki-flash.bat && PAUSE && EXIT

COPY ".\%rootfs_file%" "C:\TFTP-Root\"|| ECHO . && ECHO Please place %rootfs_file% in the same directory as meraki-flash.bat && PAUSE && EXIT

"C:\Program Files\Expect-5.21\bin\expect.exe" ".\data\meraki-redboot.exp" %linux_file% %rootfs_file%

REM Clean up TFTP-Root directory
DEL "C:\TFTP-Root\%linux_file%"
DEL "C:\TFTP-Root\%rootfs_file%"

ECHO meraki-flash.bat ends here
PAUSE

here is the Expect script - which I put in a subdirectory called data

data/meraki-redboot.exp

# start TFTP server
spawn "C:/Program Files/SolarWinds/2003 Standard Edition/TFTP-Server.exe"
# ping meraki, make 20 telnet attempts upon ping reply
spawn ping -t -w 5 192.168.84.1
set timeout 30
expect {
    "TTL"    {close}
    timeout    {close; send_user "\n\n\n\nNo response! Exiting...\n\n"; exit 10}
}
set timeout 1
for {set i 0} {$i<20} {incr i 1} {
spawn "C:/Program Files/Expect-5.21/bin/Telnet.exe" 192.168.84.1 9000
expect {
    "Connected to"    {set i 20;send "\03"}
    timeout        {close}
}
}

# erase/format flash
set timeout 20
expect "RedBoot>"
send "fis init\n"
expect "continue (y/n)?"
send "y\n"
expect {
    "Program from 0x80ff0000-0x81000000 at 0xa87d0000"    {send_user "\n\nFLASH init succeeded\n\n"}
#    timeout        {close; send_user "\n\n\n\nFLASH init failed!\n\n"; exit 10}
}


# TFTP upload linux kernel image
expect "RedBoot>"
send "load -r -b 0x80041000 -m tftp -h 192.168.84.9 [lindex $argv 0]\n"
set timeout 5
expect {
    "Raw file loaded"    {send_user "\n\nLinux kernel TFTP load succeeded\n\n"}
    timeout            {close; send_user "\n\n\n\nLinux file not loaded! Exiting...\n\n"; exit 20}
}

# flash linux kernel image
expect "RedBoot>"
send "fis create -r 0x80041000 -l 0x100000 -e 0x80041000 linux\n"
set timeout 10
expect

# Close telnet session - it takes a long time to flash and telnet times out anyway
close
spawn cmd
expect "Corp."
send_user "\n\n\n\n"

send_user "Don't Panic!  Telnet session closed while Linux image is flashed\n"
send_user "Please wait 3 minutes\n"

# Countdown 180 seconds
set timeout 1
for {set i 180} {$i>0} {incr i -1} {
send_user "\b\b\b\b$i "
expect
}
close

# Re-open telnet session
set timeout 2
for {set i 0} {$i<20} {incr i 1} {
spawn "C:/Program Files/Expect-5.21/bin/telnet.exe" 192.168.84.1 9000
expect {
    "Connected to"    {set i 20;send "\n"}
    timeout        {close}
}
}

# Check that linux kernel flashed correctly
set timeout 5
send "fis list\n"
expect {
    "linux"        {send_user "\n\nLinux kernel flash succeeded\n\n"}
#    timeout        {close; send_user "\n\n\n\nLinux flash failed!\n\n"; exit 30}
}

# TFTP upload rootfs image
expect "RedBoot>"
send "load -r -b 0x80041000 -m tftp -h 192.168.84.9 [lindex $argv 1]\n"
set timeout 20
expect {
    "Raw file loaded"    {send_user "\n\nrootfs TFTP load succeeded\n\n"}
    timeout            {close; send_user "\n\n\n\nrootfs load failed!\n\n"; exit 40}
}

# Flash rootfs image
expect "RedBoot>"
send "fis create -r 0x80041000 -l 0x6A0000 rootfs\n"    
set timeout 10
expect

# Close telnet session - it takes a long time to flash and telnet times out anyway
close
spawn cmd
expect "Corp."
send_user "\n\n\n\n"

send_user "Don't Panic!  Telnet session closed while rootfs image is flashed\n"
send_user "Please wait 5 minutes\n"

# Countdown 300 seconds
set timeout 1
for {set i 300} {$i>0} {incr i -1} {
send_user "\b\b\b\b$i "
expect
}
close

# Re-open telnet session
set timeout 2
for {set i 0} {$i<20} {incr i 1} {
spawn "C:/Program Files/Expect-5.21/bin/telnet.exe" 192.168.84.1 9000
expect {
    "Connected to"    {set i 20;send "\n"}
    timeout        {close}
}
}

# Check that rootfs image flashed correctly
set timeout 5
send "fis list\n"
expect {
    "rootfs"    {send_user "\n\nrootfs flash succeeded\n\n"}
    timeout        {close; send_user "\n\n\n\nrootfs flash failed!\n\n"; exit 50}
}

# change boot script
expect "RedBoot>"
send "\nfconfig boot_script_data\n"
set timeout 5
expect ">>"
send "fis load -d linux\n"
expect ">>"
send "exec\n"
expect ">>"
send "\n"
expect "continue (y/n)?"
send "y\n"

# Check that boot script change ocurred
expect "RedBoot>"
send "\nfconfig -l -n\n"
set timeout 30
expect {
    "fis load -d linux"    {send_user "\n\nboot script change succeeded\n\n"; send "\n\n" }
    timeout            {close; send_user "\n\n\n\nboot scrpit change failed!\n\n"; exit 60}
}

# Reset (reboot) Meraki
expect "RedBoot>"
send "\nreset\n"
send_user "\n\n\n\n"
send_user "OpenWRT flash to Meraki successful!  The Meraki is now rebooting\n\n"
send_user "You sould be able to connect to OpenWRT via Telnet on 192.168.1.1 in about 90 seconds from now\n\n"
send_user "The firstboot operation will take about 3.5 minutes, starting now\n"
send_user "please leave the power plugged in during this time\n\n\n\n"

Here's a Windows registry file that makes the appropriate config changes to the Solarwinds TFTP server to make sure it works with the above script
chng-tftpserver.reg

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\SolarWinds.Net\TFTP Server\Config]
"RootDir"="C:\\TFTP-Root"
"TransmitOnly"="False"
"ReceiveOnly"="False"

(Last edited by danversj on 25 May 2007, 03:22)

I've packaged up these scripts with the necessary applications into a ZIP file for Windows users here:

http://danversj.bravehost.com/meraki-flash-v1.0.zip

Extract it wherever you want and run "install-apps.bat" to install everything you need.

Set up your network card with the IP 192.168.84.9, netmask 255.255.255.0.

Copy openwrt-atheros-2.6-vmlinux.gz and openwrt-atheros-2.6-root.squashfs into the same directory as "meraki-flash.bat".

Plug your Meraki's LAN port into your PC (a straight-through cat-5 network cable is fine).  Run "meraki-flash.bat" and power on the Meraki when instructed to.

didn't put the source up though, typical windows people smile
I might modify your script to work with serial, and save myself some typing, but it's kind of a tradeoff, as I only have a few devices and don't flash them often

The discussion might have continued from here.