After some growing frustration with using cybootloaderutils C library with .NET applications, I figure since we have the source code why not take a crack at porting the bootloader host library to a proper managed library written in C#? This would serve a couple purposes:
- Hopefully much easier integration for bootloader hosts written in C#: no longer having to deal with interop services, as well as other issues that can crop up when integrating an unmanaged library into a managed project.
- It seems to be a good bit easier to debug a managed library as opposed to an unmanaged library/unsafe code.
- A someone who really only deals with C# .NET occasionally to throw together a GUI for talking to a microcontroller, doing something to increase my familiarity with .NET and OOP will almost surely be beneficial in general.
- Recently, trying to use the bootloader utils library with a .NET Core project has proven to be more trouble than expected. Hopefully a rewrite into C# will allow for easier building across multiple .NET flavors and platforms.
I'm creating this thread as a way to keep track of progress of the project, as well as share it with others who will almost certainly have ideas for improvement. As someone who, as mentioned above, is not overly familiar with the patterns and feature sets of OOP and C#, there will doubtless be places in which the code I port over can be improved.
This will mostly be a spare time project, so I don't have a real timeline on it, but it looks like it shouldn't be too terribly much code to work through. First bit of progress is coming in the net post.
Current Link to VS2019 project is attached.
First Successful Bootload
- g_validRows now fills properly with blank data
- fixed a false error being flagged in CyBtldr_StartBootloaderOperation()
- Fixed CyBtldr_CreateGetAppStatusCmd() call inside CyBtldr_GetApplicationStatus()
loading outBuf instead of inBuf.
- Fixed problem with SendData() and CyBtldr_ProgramRow_v1() creating bad data packets
- Removed Array.Copy() that was messing up data packet creation in both methods
- buf.Skip() was being given incorrect argument in SendData()
- Fixed RunAction_v0() from flagging an error and aborting the load if the
target bootloader is single-application. Error status is now overridden to
CYRET_SUCCESS if CyBtldr_GetApplicationStatus() returns an error, but the
bootloader response is valid.
- Fixed fillData32() not properly loading the LSB (word was not being shifted)
- CyBtldr_CreateEnterBootloaderCmd() had a length zero check that would fail if securityKeyBuff is null. Replaced with only a null check.
- Replaced cmdBuf.SetValue() call with fillData16() in CyBtldr_CreateEnterBootloaderCmd_v1().
- CyBtldr_CreateSendDataCmd() was assembling commands at the wrong index (7).
This has been corrected to 4, where the command data should properly begin.
- Added WPF test application to VS solution
- Fixed CyBtldr_StartBootloaderOperation() not filling g_validRows properly
- CyBtldr_FromHex() brought closer to original code. char.GetNumericValue() not working in the same way.
- CyBtldr_ReadLine now uses a StreamReader to properly read single lines
- api/api2 is "done" (untested)
- Project renamed to correct typo (was bool_netlib)
- Implemented interface for application to define communication functions
- TODO: re-evaluate all ref keywords for passing arguments.
- command.cs porting is "done" (untested)
- renamed namespace to CyBootloaderUtils
- Dropped the CyBtldr_ class name prefix. "CyBtldr_Parse" class is now just "Parse"
- parse.cs first pass porting is done (untested, will probably need work)
- command.cs porting is in progress
Message was edited by: Kyle Trenholm - Adding 11-2-20 updated project