Skip to content

BSL430.NET.FirmwareTools.Library

Jakub Parez edited this page Sep 18, 2019 · 13 revisions

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.

Framework Support

  • .NET Framework 4.0
  • .NET Framework 4.5
  • .NET Framework 4.6.1
  • .NET Standard 2.0

About

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.

Code Samples

Parse

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 FirmwarePath)
{
    Firmware fw1 = FwTools.Parse(FirmwarePath);                // Fw.Format = AUTO
    Firmware fw2 = FwTools.Parse(FirmwarePath, FillFF: true);  // gaps are filled with 0xFF
    Firmware fw3 = FwTools.Parse(FirmwarePath, FwFormat.SREC); // Fw.Format = SREC
    Firmware fw4 = FwTools.Parse(FirmwarePath, Log: new StringWriter()) // save parse log
}

Create

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, LineLength = default
    string fw2 = Create(Fw, FwFormat.INTEL_HEX); // Fw.Format = Intel-HEX
    string fw3 = Create(Fw, LineLength: 64);     // custom fw line length, for compatibility
}

public void CreateFromRawData(IEnumerable<byte> Data, int AddrStart)
{
    string fw1 = Create(Data, AddrStart);        // Fw.Format = AUTO, LineLength = default
    string fw2 = Create(Data, AddrStart, FwFormat.TI_TXT);     // Fw.Format = TI-TXT
    string fw3 = Create(FwData, AddrStart, LineLength: 128);   // custom fw line length
}

Convert

...

public void ConvertFirmware()
{
}

Combine

...

public void CombineFirmwares()
{
}

Compare

...

public void CompareFirmwares()
{
}

Validate

...

public void ValidateFirmware()
{
}

GetPassword

...

public void GetBSLPassword()
{
}
Clone this wiki locally