Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow updating with just a USB connection #595

Merged
merged 1 commit into from
Apr 12, 2016
Merged

Conversation

johnnyman727
Copy link
Contributor

Dependent on: tessel/openwrt-tessel#47

@johnnyman727 johnnyman727 force-pushed the jon-update-usb branch 2 times, most recently from 52237dd to 717b0ec Compare February 25, 2016 20:26
@johnnyman727
Copy link
Contributor Author

On weird issue I'm facing is that running sysupgrade /tmp/openwrt.bin does not seem to work. The only thing it seems to do is kill the SPI Daemon permanently so perhaps it is beginning to restart? @kevinmehall what do you think could be happening to keep sysupgrade from completing when I exec it from the USB Daemon?

@kevinmehall
Copy link
Member

Try adding spid and usbexecd to the whitelist of processes that sysupgrade won't kill when starting the update: https://github.com/tessel/openwrt/blob/2015-10-26/package/base-files/files/lib/upgrade/common.sh#L128.

@kevinmehall
Copy link
Member

You can just modify /lib/upgrade/common.sh on a Tessel, and if it works then patch the linked file in the openwrt repo.

@johnnyman727
Copy link
Contributor Author

Thanks, I'll give that a try.

@johnnyman727
Copy link
Contributor Author

Unfortunately, modifying /lib/upgrade/common.sh didn't seem to work.

Strangely, ubus call system upgrade is a ubus option but it doesn't seem to do anything either.

But I could run either require('child_process').exec('sysupgrade /tmp/openwrt.bin') or require('child_process').spawn('sysupgrade, ['/tmp/openwrt.bin']) within node with positive results so I guess we could do that worst case...

flag: false,
help: 'Update with the OpenWRT image at the indicated local path.'
})
.option('firmwarePath', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid camel casing command line options :P

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@johnnyman727
Copy link
Contributor Author

I think something else must be going on because I was able to successfully sysupgrade from the CLI with this patch and the t2-cli usb-exec sysupgrade /tmp/openwrt.bin command... That should be essentially exactly the same as what happens in the t2 update command so there is something else causing the issue.

@johnnyman727
Copy link
Contributor Author

I've confirmed that two changes are necessary:

  1. The patch as outlined by @kevinmehall above
  2. Not closing the child process that execed the sysupgrade for about two minutes (or until it reports that the upgrade completed).

Because I did not implement 2, it seemed as though 1 made no difference but with both implementations, the update succeeds.

@johnnyman727
Copy link
Contributor Author

Working on the OpenWRT patch here but the documentation on patches is pretty lacking. @kevinmehall can you look it over for me when you get a chance?

@kevinmehall
Copy link
Member

The file is in the openwrt tree, so just modify it in a normal commit. Patches are used to make changes to 3rd-party code that is downloaded as an upstream tarball and doesn't live in the repository. (The directory where you added that patch is supposed to be for patches against the uClibc source)

@johnnyman727
Copy link
Contributor Author

Ah okay, that makes much more sense. Thanks for the clarification.

@johnnyman727 johnnyman727 force-pushed the jon-update-usb branch 3 times, most recently from 4387b9c to 845a18e Compare March 8, 2016 03:41
@johnnyman727
Copy link
Contributor Author

So this feature introduces a fun complication which is that because we have to update our OpenWRT build to make updating over USB work, all previous builds will not have this capability. That means we have to check the version running on the Tessel and confirm that it's > 0.0.11 before moving forward with a USB-only update.

@rwaldron any thoughts on that? It's kind of shitty but I'm not sure we have a good way to get around it.

@johnnyman727 johnnyman727 changed the title [WIP] Allow updating with just a USB connection Allow updating with just a USB connection Mar 8, 2016
@kevinmehall
Copy link
Member

If you want a hack, the CLI could modify /lib/upgrade/common.sh on old versions before performing the update...

@johnnyman727
Copy link
Contributor Author

@kevinmehall I'm ashamed of you for even suggesting such a dirty hack.

But yeah, does sed '/*procd*\|*ash*\|*init*/c \ \*procd*|*ash*|*init*|*watchdog*|*ssh*|*dropbear*|*telnet*|*login*|*hostapd*|*wpa_supplicant*|*nas*|*spid*|*usbexecd*) : ;;'\ /lib/upgrade/common.sh look good?

@kevinmehall
Copy link
Member

Don't you need sed -i for in-place edit? Or write to a temp file and mv over the original if busybox sed doesn't have that option.

If you were to include the whole original line, it would be a no-op in the case that the update had already been applied. Also, watch the escaping of the * characters in addition to the |.

@johnnyman727
Copy link
Contributor Author

Don't you need sed -i for in-place edit? Or write to a temp file and mv over the original if busybox sed doesn't have that option.

Yes, I do and busybox sed does support it.

If you were to include the whole original line, it would be a no-op in the case that the update had already been applied. Also, watch the escaping of the * characters in addition to the |.

Ugh I don't think my fingers can type that many escapes. It's not physically possible.

@johnnyman727
Copy link
Contributor Author

For anyone who's checking in on this PR, it's currently blocked by my effort to add a hacky to fix an issue described here so that folks running older versions of the T2 firmware can do updates over USB.

The command to overwrite a specific line of a file which determines how the update process works doesn't seem to be effective over the USB Daemon but it does work on the Tessel shell console. I'm guessing the escapes aren't being handled properly...

@rwaldron
Copy link
Contributor

rwaldron commented Apr 3, 2016

There must be an easier way to do that :\

@johnnyman727
Copy link
Contributor Author

I've tried all kinds of escaping with no luck. I may go the kinda hackier route and just ship the file with the CLI, then write it to a temporary file on T2, then rename the temporary file to the real file name (thus replacing it).

remoteProc.once('close', resolve);
// Write the image
remoteProc.stdin.end(image);
logs.info('Transferring image of size', (image.length / 1e6).toFixed(2), 'MB. This will take 2-4 minutes...');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use template string

@rwaldron
Copy link
Contributor

Damn dude, that was smoooooooth

$ t2 update
INFO Looking for your Tessel...
INFO Connected to Tessel-02A347EF35F2.
INFO New firmware version found...0.0.12
INFO Updating Tessel-02A347EF35F2 to latest version (0.0.12)...
INFO Beginning update download. This could take a couple minutes..
  downloading [====================] 100% 0.0s remaining
INFO Download complete!
INFO Updating OpenWRT (1/2)
INFO Transferring image of size 19.14 MB. This will take 2-4 minutes...
INFO Transfer complete.
INFO Starting OpenWRT update.
INFO Please do not remove power from Tessel.
INFO This process will take at least two minutes...
INFO Updating firmware (2/2)
INFO Firmware update complete!
INFO Updated Tessel-02A347EF35F2 from  0.0.11  to  0.0.12

First time, with new Tessel 2 out of the box.

@rwaldron
Copy link
Contributor

Unplugged, re-plugged, ran t2 wifi setup and we're in business.

Please address the nit-picks and I will land this tomorrow

@johnnyman727
Copy link
Contributor Author

Nit-picks addressed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants