c4ev3 / ev3duder

The LEGO® EV3 Downloader/UploaDER.
http://c4ev3.github.io/ev3duder/doc/html/globals_func.html
GNU General Public License v3.0
32 stars 12 forks source link

[Feature Request] Updating brick firmware #16

Closed JakubVanek closed 4 years ago

JakubVanek commented 4 years ago

Hi,

I think it is sometimes useful to have the ability to upload a new firmware to the brick. So far on Linux this has been provided by the C# firmware loader. I have written a different tool for my need, but I think it would be nice to have this in ev3duder too.

I believe the builtin EV3 EEPROM is responsible for handling the upload. ~The write protect pin is permanently activated, so I think it is not possible to hard-brick the brick this way.~ see last comment

I don't know from where the protocol originates. I think it comes from BricxCC and it is not publicly documented. However it is very similar to the protocol that the LMS2012 VM uses when it is running. It is using system commands too, but it is using different command IDs.

The upload has four phases:

There are two more commands:

It may be even possible do partial uploads that would preserve user data by not erasing the whole chip. However I have not yet tested this. The remaining functionality is tested to work.

I have the following proposal for the interface:

# Exit Linux and enter firmware upload mode
ev3 flash enter

# Upload the firmware
# - either performing all the steps or only the upload phase (advanced)
# - optionally upload from address n to address n+len(@file.img)
# - optionally select flash erase mode
ev3 flash upload <file.img> [--only] [--start n] [--erase-mode=separate/merged]

# Erase the entire flash contents (= separate flash erasure)
ev3 flash erase

# Ask the bootloader for flash CRC32
ev3 flash crc32 <start> <end>

# Show information about the bootloader
ev3 flash info

# Exit the bootloader
ev3 flash exit

Best regards,

Jakub

a3f commented 4 years ago

Just to be sure: you can't overwrite the bootloader that way, right?

JakubVanek commented 4 years ago

Yes, this bootloader is stored in a separate chip that cannot be written via USB (as far as I know). There's uboot in the main flash image, but it is chainloaded from the EEPROM.

However, I have noticed that the EEPROM containing it is not write protected (WP is tied low, for some reason I thought it was tied high). This means that it could be possible to reprogram the EEPROM from booted Linux. eeprom