tessel / t2-cli

Tessel 2 Command Line Interface
MIT License
114 stars 56 forks source link

[version] Need a way to identify if firmware was not updated properly #657

Open johnnyman727 opened 8 years ago

johnnyman727 commented 8 years ago

With our current update and versioning architecture, it's possible for the OpenWRT and firmware image to get out of sync. This can happen if an update hangs between completing OpenWRT and writing the firmware image and the user aborts. Because t2 version just reads a git commit sha in a file on the OpenWRT file system to determine the image version, the firmware version can remain out of date. We need to make a mechanism for the firmware on the SAMD21 to contribute to the version returned by the t2 version command.

yoonghm commented 8 years ago

It is possible to get an checksum to verify the data is written correctly by reading the data back?

johnnyman727 commented 8 years ago

@yoonghm it's relatively easy to confirm a checksum of the OpenWRT image but I'm not sure how easy it is to confirm the checksum of the firmware on the co-processor. I don't think we have any mechanisms to read the onboard flash from the SAMD21.

yoonghm commented 8 years ago

@johnnyman727: From SAMD21 datasheet (chapter 13.11.3. 32-bit Cyclic Redundancy Check CRC32) it is possible to request CRC32 over a range of memory. Do you think it is sufficient? I am not familiar with tessel 2 at the moment.

Please refer to this too http://atmel.force.com/support/articles/en_US/FAQ/Reading-unique-serial-number-on-SAM-D20-SAM-D21-SAM-R21-devices

johnnyman727 commented 8 years ago

@yoonghm good find! Yes, that does look like it would deliver a CRC that we could use to confirm firmware versions. The instructions outlined in the datasheet (page 75) give a very straightforward description of how to run the CRC.

In addition, one would need to add switch case to the USB control transfer handling block that calls the CRC function and sends the result like this (keep in mind the CRC is larger than 8 bits so you'll need to send back more data than just that example.

The above changes will occur in the t2-firmware repo.

Then, we'll need to add a CLI command like tessel.firmwareVersion() to send that USB control transfer and resolve a Promise with the result.

I'm happy to help advise for anyone that wants to take this on.

yoonghm commented 8 years ago

I can have a look but the setup seems complicated. Worry it would brick my tessel 2...

johnnyman727 commented 8 years ago

@yoonghm I can almost guarantee that you wouldn't brick your T2. If you corrupt the firmware somehow, you can just use dfu-util and the firmware's bootloader to update the flash memory.