But I think it behaves out of my assumption.
public static void Main()
SystemUpdate.SystemUpdateMode mode = SystemUpdate.GetMode();
Log("EMX starts. Mode: " + mode.ToString());
// Allow firmware on the board to be upgradable.
if (mode == SystemUpdate.SystemUpdateMode.NonFormatted)
// Force a hard reboot
// Start to upgrade firmware
if (mode == SystemUpdate.SystemUpdateMode.Bootloader)
Log("Start to upgrade ...");
// Force mount all removable disks
if (firmwarePath.Length > 0)
// Start to upgrade
FileStream fs = new FileStream(firmwarePath, FileMode.Open, FileAccess.Read);
byte buffer = new byte[10 * 1024];
int len = 0;
len = fs.Read(buffer, 0, buffer.Length);
SystemUpdate.ApplicationUpdate.Write(buffer, 0, len);
throw new Exception(); // throw an exception to interrupt updating
} while (len == buffer.Length);
catch (Exception ex)
Log("Failed to upgrade.");
if (mode == SystemUpdate.SystemUpdateMode.Application)
PersistentStorage ps = new PersistentStorage("SD");
Log("Prepare to upgrade. Rebooting ...");
I write the code above in main function. It reads firmware from a micro SD card and upgrade it to the EMX board. I use an exception in write loop to interrupt the upgrading. The firmware size is 260+ KB, so in my code it only write 10KB to EMX.
After I reboot the EMX board, I can see a debug message from MFDeploy:
This is the version. You have succeeded to upgrade the firmware.
This message is the only Debug.Print message of the firmware in SD card.