-
Notifications
You must be signed in to change notification settings - Fork 10
BSL430.NET.FirmwareTools.Library
BSL430.NET.FirmwareTools is Cross-Platform library, BSL430.NET sub-package, that tries to make firmware manipulation easy. It supports Intel-HEX, TI-TXT and SREC formats for both read/write Parse/Create, and ELF format for read-only(currently dont have time to implement write support). Key functions are to Parse (read from file) and Create (write to file or string) a firmware. On top of that functions there is the rest, using them to provide extended abilities: Convert, Combine and Compare between any firmware formats, Validate firmware file and get information like addresses, CRC, sizes and finally Get BSL password used to correctly download fw by BSL430.NET (this is MSP430 specific functionality).
Note: This library can be built as any architecture possible (x86, x64, ARM..),
because it doesnt depend on unmanaged code, it uses standard C# api only.
- .NET Framework 4.0
- .NET Framework 4.5
- .NET Framework 4.6.1
- .NET Standard 2.0
Whole library is static, because it doesnt hold any state or use any instance data. This simplifies a lot, calling methods without instance management is nice for utility library like this. FwFormat is main enum providing information about format (INTEL_HEX, TI_TXT, SREC, ELF). Firmware is main class serving as a generic firmware container. It consists of FwInfo, information class with properties (Format, AddrFirst, AddrLast, SizeFull, SizeCode, CRC16, Valid..) and List of FwNodes. FwNode is the atomic piece of any firmware, holding address (long) and data (byte). This is enough to describe any firmware in the most basic kind of way. Firmware class provides also nice functionality with ToString, Equals and equality operators overiden. Firmware is usually created by Parse methods, but can also be created with raw List of FwNodes or with a MemoryStream, plus there is Getter for MemoryStream from already created class as well.
Parse firmware file from FirmwarePath in TI-TXT, Intel-HEX or ELF format and returns List of FwNode (Data+Addr) and Info. Auto Mode reads data and based on some particular characters determine what firmare format it should be. FillFF is optional parameter forcing to fill missing addr nodes with 0xFF and return monolithic piece of code, which is usefull for crc calc or overwriting whole memory in mcu. Log writes text (new line formatted) output only when parsing ELF firmware file.
public void ParseFirmware(string FwPath)
{
Firmware fw1 = FwTools.Parse(FwPath); // Fw.Format = AUTO
Firmware fw2 = FwTools.Parse(FwPath, FillFF: true); // gaps are filled with 0xFF
Firmware fw3 = FwTools.Parse(FwPath, FwFormat.SREC); // Fw.Format = SREC
Firmware fw4 = FwTools.Parse(FwPath, Log: new StringWriter()) // save parse log
}Create firmware multi-line string in TI-TXT or Intel-HEX format. ELF is not supported yet. AUTO format will force TI-TXT format. AddrStart is address of first byte in data collection. LineLength defines amount of data bytes per one text row. When = 0, default values are set (TI-TXT = 16, Intel-HEX = 32, SREC = 32).
public void CreateFromFirmware(Firmware Fw)
{
string fw1 = Create(Fw); // Fw.Format = AUTO, Line Len = default
string fw2 = Create(Fw, FwFormat.INTEL_HEX); // Fw.Format = Intel-HEX
string fw3 = Create(Fw, LineLength: 64); // custom line length, compatibility
}
public void CreateFromRawData(IEnumerable<byte> RawData, int AddrStart)
{
string fw1 = Create(RawData, AddrStart); // Fw.Format = AUTO, Line Len = default
string fw2 = Create(RawData, AddrStart, FwFormat.TI_TXT); // Fw.Format = TI-TXT
string fw3 = Create(RawData, AddrStart, LineLength: 128); // custom fw line length
}
public void CreateFromFwNodes(ICollection<FwNode> FwNodes)
{
string fw1 = Create(FwNodes); // Fw.Format = AUTO, Line Len = default
string fw2 = Create(FwNodes, FwFormat.SREC); // Fw.Format = SREC
string fw3 = Create(FwNodes, LineLength: 24); // custom fw line length
}Convert firmware TI-TXT, Intel-HEX or ELF format (auto detected) to firmware in TI-TX or Intel-HEX format. Returned Fw is firmware and Format is useful for auto-detect feedback, indicates input format. FillFF is optional parameter forcing to fill missing addr nodes with 0xFF and return monolithic piece of code, which is usefull for crc calc or overwriting whole memory in mcu. LineLength defines amount of data bytes per one text row. When = 0, default values are set (TI-TXT = 16, Intel-HEX = 32, SREC = 32).
public void ConvertFirmware(string FwPath)
{
var (Fw1, Format1) = Convert(FwPath, FwFormat.TI_TXT); // simple convert
var (Fw2, Format2) = Convert(FwPath, FwFormat.INTEL_HEX, true); // gaps FF filled
var (Fw3, Format3) = Convert(FwPath, FwFormat.SREC, LineLength: 16); // custom line len
}Combines two firmware files into single one with format specified. Usually, main firmware and EEPROM file is done this way, or main firmware and Info A flash content is merged. Returned Fw is firmware and Format1 with Format2 are useful for auto-detect feedback, indicates input formats. FillFF is optional parameter forcing to fill missing addr nodes with 0xFF and return monolithic piece of code, which is usefull for crc calc or overwriting whole memory in mcu. LineLength defines amount of data bytes per one text row. When = 0, default values are set (TI-TXT = 16, Intel-HEX = 32, SREC = 32).
public void CombineFirmwares(string FwPath1, string FwPath2)
{
// simple combine of two firmware files
var (Fw1, Format11, Format12) = Combine(FwPath1, FwPath2, FwFormat.TI_TXT);
// combine and fill gaps with 0xFF
var (Fw1, Format11, Format12) = Combine(FwPath1, FwPath2, FwFormat.TI_TXT, true);
// combine and set custom output line length
var (Fw1, Format11, Format12) = Combine(FwPath1, FwPath2, FwFormat.TI_TXT, LineLength: 64);
}...
public void CompareFirmwares()
{
}...
public void ValidateFirmware()
{
}...
public void GetBSLPassword()
{
}