What's new

Automated Firmware Upgrade

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

ethician

Occasional Visitor
Hey folks,

I am trying to find a way to implement an automated firmware upgrade process. I went through some of the "relevant" source code but cannot seem to pinpoint the exact mechanism of how AsusWRT handles upgrading firmware manually from the website.

If I am not mistaken, somewhere along this process it creates a /tmp/linux.trx. Is that correct? What happens next? Is there a tool for grabing this trx and using it to restructure the partitions? Or does it call mtd-erase / write directly in some succession?

I am going to keep looking but if you know the answer to any of these question, please shoot.

Thanks!
 
The firmware simply writes that trx file on top of the linux mtd partition. On ARM routers:

Code:
mtd-write2 /tmp/linux.trx linux
reboot

Note that doing so over SSH can occasionally have the router hang during the shutdown, as the filesystem becomes invalid. The firmware avoids this problem by having a temporary rootfs which contains what's necessary to complete the process.

You might be able to manually trigger an upgrade, but you will have to look at the Firmware upgrade page to determine how the process gets triggered - I never bothered to look myself.
 
I wrote a small script run on a cronjob to do just this, I just compare an sha hash with my build server and pull the new file if anything is different.
 
Thanks M!

For those interested, the relevant code resides in rc/services.c under handle_notifications()
Code:
...
if (nvram_contains_word("rc_support", "nandflash")) /* RT-AC56S,U/RT-AC68U/RT-N16UHP */
  eval("mtd-write2", upgrade_file, "linux");
else
  eval("mtd-write", "-i", upgrade_file, "-d", "linux");
...

And if I am not mistaken the web upgrade process triggers do_upgrade_post() in httpd/web.c which at some point invokes /usr/sbin/webs_upgrade.sh.

I wrote a small script run on a cronjob to do just this, I just compare an sha hash with my build server and pull the new file if anything is different.

Thanks. Would you mind sharing the script?
 
Thanks M!

For those interested, the relevant code resides in rc/services.c under handle_notifications()
Code:
...
if (nvram_contains_word("rc_support", "nandflash")) /* RT-AC56S,U/RT-AC68U/RT-N16UHP */
  eval("mtd-write2", upgrade_file, "linux");
else
  eval("mtd-write", "-i", upgrade_file, "-d", "linux");
...

And if I am not mistaken the web upgrade process triggers do_upgrade_post() in httpd/web.c which at some point invokes /usr/sbin/webs_upgrade.sh.



Thanks. Would you mind sharing the script?

This is just a snippet from a much larger script, my build server is currently down so you will need to host your own and replace the links for the time being.

Code:
        if [ X"`cat /jffs/scripts/sha512`" = X"`wget -q -O - http://192.3.148.21/AC68U/sha512`" ]; then
            echo "Firmware Up To Date"
        else
            logger -t Skynet "[SYSTEM] Firmware Update Detected - Updating... ... ..."
            rm -rf /tmp/RT-AC68U_Latest.trx
            wget -O /tmp/RT-AC68U_Latest.trx http://192.3.148.21/AC68U/RT-AC68U_Latest.trx
            wget -O /jffs/scripts/sha512 http://192.3.148.21/AC68U/sha512
            cd /tmp
                if test -e /opt/bin/coreutils-sha512sum ; then
                    sha512sum -c /jffs/scripts/sha512 && mtd-write2 /tmp/RT-AC68U_Latest.trx linux && reboot || logger -t Skynet "[ERROR] Firmware Update Failed (Check SHA512 Sum)"
                else
                    mtd-write2 /tmp/RT-AC68U_Latest.trx linux && reboot || logger -t Skynet "[ERROR] Firmware Update Failed"   
                fi
        fi
 
Just curious as to what good this would do you when/if the firmware upgrade requires a factory reset to avoid issues from whatever was changed in the firmware upgrade.
 
Just curious as to what good this would do you when/if the firmware upgrade requires a factory reset to avoid issues from whatever was changed in the firmware upgrade.

You can set this up with git so it only builds/flashes tagged builds etc to relieve that problem, I personally prefer being on bleeding edge nightly code and keep on-top of the changes enough to know when a reset is required. Its not for everyone but it saves me oodles of time doing it manually every day.
 
Just curious as to what good this would do you when/if the firmware upgrade requires a factory reset to avoid issues from whatever was changed in the firmware upgrade.
What Adamm said, or simply so that you are in control and you know when a further action needs to be taken.
 

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top