AndreRenaud / async_xmodem

C code for a simple state-machine based XModem implementation
The Unlicense
15 stars 2 forks source link

Checksum in 128B mode (Xmodem first protocol) #5

Open ddejean opened 1 year ago

ddejean commented 1 year ago

Hi Andre,

Thanks for this very nice little library. It's very easy to use and integrate in some custom code.

I'm trying to use the library in 128B mode and I'm wondering if the following line is correct for this case :

https://github.com/AndreRenaud/async_xmodem/blob/5972a49d150970af62212d232e27f5eb0a205000/xmodem_server.c#L111

As far as I understand the original Xmodem protocol (the one with 128B packets) the "checksum" is a sum of the data bytes in the packet, not a CRC (as in Modem-1k). Am I missing something ?

Best regards, Damien

AndreRenaud commented 1 year ago

Hi Damien, It looks as if you're probably right. What is implemented is technically XMODEM-CRC, which uses a 16-bit CRC, not the original 8-bit checksum. I never noticed, since it looks like the command line tools I was working with (sz) operate just fine with this.

Is this causing you grief? I'd welcome a patch to make it optional?

Regards, Andre

ddejean commented 1 year ago

I'm currently integrating this to a 16 bit firmware and it's not working. But I don't know yet if this is the root cause, or if my modifications are causing this. I just found this while investigating :)

Anyway I'll be happy to open a pull request if that's really an issue!

Damien

AndreRenaud commented 1 year ago

Are you using a PC as the client, or is this between two embedded systems? I've used this as the server on an embedded when doing firmware upgrades on other embedded devices, and not had grief.

I had a poke around, and it turns out it seems to be related to the special character that is sent out on startup. If the server sends out 'C', then it's assuming xmodem-crc. If it sends out 'NACK', then it's the original 8-bit checksum.

See https://github.com/UweOhse/lrzsz/blob/master/src/lsz.c#L994 & https://github.com/UweOhse/lrzsz/blob/master/src/lrz.c#L641

I've created a branch which adds a new parameter to enable this mode of operation. You need to tell the server which mode it should start in. Have a look here and see if it makes things any better?

https://github.com/AndreRenaud/async_xmodem/pull/6

ddejean commented 1 year ago

Are you using a PC as the client, or is this between two embedded systems?

I'm using a PC as client to upload a firmware to an embedded system. Eventually I'd like to be able to upload a new firmware to my board from a PC, and perform an upgrade.

I had a poke around, and it turns out it seems to be related to the special character that is sent out on startup. If the server sends out 'C', then it's assuming xmodem-crc. If it sends out 'NACK', then it's the original 8-bit checksum.

That's an interesting lead, let have a look at this and come back to you. Thanks for the new branch, it will be helpful!

AndreRenaud commented 1 year ago

If you're using a PC, I suspect this probably isn't the issue. Most PC-based software is going to support both modes of operation and should seamlessly swap between them as appropriate. Not 100% sure obviously :)

Let me know how it goes and if there's any else I can help with.