Okey, that’s good new. It must be something I do wrong.
Heres my methods for update, I also tested from SD but with same problem. Firmware is wipped.
public static string FIRMWARE_PATH = @ "\SD\Firmware\";
/// <summary>
/// Check if there is any firmware files on SD to update system with
/// </summary>
public static bool CheckForUpdates()
{
if (Directory.Exists(FIRMWARE_PATH))
{
bool loaded = false;
string[] files = Directory.GetFiles(FIRMWARE_PATH);
foreach (string file in files)
{
using (FileStream fs = new FileStream(file, FileMode.Open))
{
if (!LoadFirmware(Path.GetFileName(file), fs, fs.Length))
return false;
loaded = true;
}
}
FlashAndReset();
}
return true;
}
public static bool LoadFirmware(string filename, Stream dataStream, long length)
{
//LogHandler.Instance.LogInformation("Updater", "Loading file: " + filename);
SystemUpdate.SystemUpdateType updateType;
try
{
updateType = GetUpdateType(filename);
if (updateType == 0)
{
//LogHandler.Instance.LogError("Updater", "Unknown file type!");
return false;
}
if (SystemUpdate.CurrentSystemUpdateStatus == SystemUpdate.SystemUpdateStatus.Inactive)
{
//SystemUpdate.Initialize(updateType);
// Set that we are going to update all areas, we may not do all but there is no way later to adjust it.
SystemUpdate.Initialize(SystemUpdate.SystemUpdateType.Deployment |
SystemUpdate.SystemUpdateType.Config |
SystemUpdate.SystemUpdateType.Firmware);
}
string fileExtension = Path.GetExtension(filename).ToUpper();
if (fileExtension != ".HEX" && fileExtension != ".CHX") // Normal or crypted file
{
//LogHandler.Instance.LogInformation("Updater", "Wrong file extenstion (" + fileExtension + ")");
SystemUpdate.Abort();
return false;
}
if (!Updater.LoadFirmware(dataStream,
length,
GetUpdateType(filename),
fileExtension == ".CHX" ? true : false))
{
SystemUpdate.Abort();
//LogHandler.Instance.LogError("Updater", "Error while loading file.");
return false;
}
//LogHandler.Instance.LogInformation("Updater", "File loaded succesful!");
if (SystemUpdate.CanUpdate)
return true;
}
catch (Exception e)
{
//LogHandler.Instance.LogException("Updater", e);
SystemUpdate.Abort();
return false;
}
SystemUpdate.Abort();
Log.//LogHandler.Instance.LogError("Updater", "Not possible to flash device!");
return false;
}
public static SystemUpdate.SystemUpdateType GetUpdateType(string fileName)
{
if (StringExtensions.IsNullOrEmpty(fileName))
return 0;
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName).ToUpper();
if (fileNameWithoutExtension.StartsWith("APPLICATION"))
return SystemUpdate.SystemUpdateType.Deployment;
else if (fileNameWithoutExtension.StartsWith("FIRMWARE"))
return SystemUpdate.SystemUpdateType.Firmware;
else if (fileNameWithoutExtension.StartsWith("CONFIG"))
return SystemUpdate.SystemUpdateType.Config;
return 0;
}
public static bool LoadFirmware(Stream stream, long length, SystemUpdate.SystemUpdateType ifutype, bool encrypted)
{
int rest;
byte[] hex, data;
int blocknum;
int blockCount = 0;
int byteCount = 0;
int count = 0;
if (stream == null)
return false;
//Crypter crypter = new Crypter();
blocknum = (int)length / BLOCK_SIZE;
rest = (int)length % BLOCK_SIZE;
data = new byte[BLOCK_SIZE];
hex = new byte[BLOCK_SIZE];
if (stream.CanTimeout)
stream.ReadTimeout = 10000; // To support CDC stream
do
{
count = stream.Read(data, 0, (int)(length - byteCount < BLOCK_SIZE ? length - byteCount : BLOCK_SIZE)); // Read the remainging part
if (count <= 0)
break;
if (blockCount == 0 && stream.CanTimeout)
stream.ReadTimeout = 1000; // We are now in sync, reduce timeout
if (encrypted)
hex = crypter.Decrypt(data, count);
else
hex = data;
// Check that the line starts with a 'S' (0x53) and ends with line feed 0x0D + 0x0A)
if (hex[0] != 0x53 || hex[count - 2] != 0x0D || hex[count - 1] != 0x0A)
{
//LogHandler.Instance.LogError("Updater",
// "Wrong start or end of hex line." +
// " Start: " + Converter.ToString(hex[0], true) +
// " End: " + Converter.ToString(hex[count - 1], true) +
// ". Block " + blockCount++ + "/" + blocknum + ", Bytes: " + byteCount + "/" + length);
return false;
}
SystemUpdate.Load(ifutype, hex, count);
byteCount += count;
//LogHandler.Instance.LogInformation("Updater", "Block " + blockCount++ + "/" + blocknum + ", Bytes: " + byteCount + "/" + length);
} while (count == BLOCK_SIZE);
hex = null;
//Debug.GC(true);
if (byteCount != length)
return false;
return true;
}
public static void FlashAndReset()
{
SystemUpdate.FlashAndReset();
}