Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transfer file via can0 #432

Open
DDBender opened this issue May 26, 2023 · 7 comments
Open

Transfer file via can0 #432

DDBender opened this issue May 26, 2023 · 7 comments

Comments

@DDBender
Copy link

Hello,

we are currently trying to use a bootloader (https://github.com/qnx425/PIC18FXXK80-CAN-Bootloader) with one of our microcontrollers.
Since we have a physical CAN module on our RPI (5.4.65-v7 custom kernel) compatible solution (Axotec IGX-560, compute module with some extensions. Kernel cannot be recompiled, don't have access to the source) we are using that to currently send single messages via QT and SocketCAN.
Our next step was to use the bootloader to flash the MCU without physically accessing it every single time (each behind multiple screws, 1000+ of them in different places around multiple cities).

The bootloader should receive a new firmware (hex file) via can and afterwards restarts the MCU with the new firmware. But I currently cannot find a way to send the file. I tried looking up some solutions but some require more kernel modules and others use USB adapters. For testing purposes we have a PCAN with PCANView to check what is working and what isn't after the firmware update.
Is sending a file generally possible this way? Did I miss anything in the documentation? Do I just need to split the hex file into 8-byte sized frames and send them after each other in a loop for example?
If you have any questions (or just tell me I'm blind and it is written "here or here") just ask/tell me :)

@hartkopp
Copy link
Member

hartkopp commented May 27, 2023

we are currently trying to use a bootloader (https://github.com/qnx425/PIC18FXXK80-CAN-Bootloader) with one of our microcontrollers. Since we have a physical CAN module on our RPI (5.4.65-v7 custom kernel) compatible solution (Axotec IGX-560, compute module with some extensions. Kernel cannot be recompiled, don't have access to the source) we are using that to currently send single messages via QT and SocketCAN.

Ok, that means that you have at least CAN_RAW socket support - which provides a programming interface similar to a stand-alone CAN driver.

Our next step was to use the bootloader to flash the MCU without physically accessing it every single time (each behind multiple screws, 1000+ of them in different places around multiple cities).

Is this CAN bootloader already implemented?

The bootloader should receive a new firmware (hex file) via can and afterwards restarts the MCU with the new firmware. But I currently cannot find a way to send the file.

The main problem is that you always need to implement some kind of protocol and process for downloading the firmware. E.g. when the system is up and running, you need to

  1. set it into the flash/bootloader mode
  2. send the firmware content (reading from a file, e.g. in hex file format)
  3. reboot the system to start the updated application

I tried looking up some solutions but some require more kernel modules and others use USB adapters.

As written above: When you have a working CAN bootloader/firmware update process in your CAN MCU you need to think about the flash program that reads the hex file and can handle the flash process and data transfer.

For testing purposes we have a PCAN with PCANView to check what is working and what isn't after the firmware update. Is sending a file generally possible this way?

Not sure whether PCANView supports any kind of data transfer of hex files.

E.g. the PCAN routers use some CAN update protocol to get firmware updates: https://github.com/peak-system/pcanflash

You can use a Linux (Debian/Ubuntu) Laptop together with the PCAN USB Adapter to develop your flashing program. And when this is working you can simply compile it for the RasPi and it should work on your target system.

Did I miss anything in the documentation? Do I just need to split the hex file into 8-byte sized frames and send them after each other in a loop for example?

Yes. But you need some kind of protocol to make sure that the receiver knows the start and end of the transmission or some message counters or checksums that the receiver can check for the correct firmware transmission before programming it to the flash chip.

If you have any questions (or just tell me I'm blind and it is written "here or here") just ask/tell me :)

I hope I was able to make the general ideas and concepts behind firmware updates over CAN clear to you.

@olerem
Copy link
Contributor

olerem commented May 27, 2023

To avoid inventing new protocols, ISOBUS specification defines ISOBUS file system protocol ISO 11783 - 13. I'm working on implementation of client and server part, here:
https://github.com/olerem/can-utils/tree/isobusfs-2023.05.15
Since it is my hobby work, it takes some time until it will be finished.

@marckleinebudde
Copy link
Member

BTW:

Kernel cannot be recompiled, don't have access to the source) we are using that to currently send single messages via QT and SocketCAN.

Ask axotec for the source code of the kernel. In order to comply with the Linux kernel's GPL-2 license, they have to give you the source code including all patches.

@marckleinebudde
Copy link
Member

The bootloader should receive a new firmware (hex file) via can and afterwards restarts the MCU with the new firmware. But I currently cannot find a way to send the file. I tried looking up some solutions but some require more kernel modules and others use USB adapters. For testing purposes we have a PCAN with PCANView to check what is working and what isn't after the firmware update.

You basically have to port the existing CAN flash utility to QT.

@marckleinebudde
Copy link
Member

marckleinebudde commented May 29, 2023

The bit rate is 500 kbit/s. and you have to port the loop in main to QT. Note in usb-windows.c it doesn't send RAW CAN data to the serial port, but SL-CAN compatible data.

@DDBender
Copy link
Author

DDBender commented Jun 1, 2023

Is this CAN bootloader already implemented?

The bootloader is not yet available everywhere (we will need to use the PICKIT to flash it first either way)

E.g. the PCAN routers use some CAN update protocol to get firmware updates: https://github.com/peak-system/pcanflash

You can use a Linux (Debian/Ubuntu) Laptop together with the PCAN USB Adapter to develop your flashing program. And when this is working you can simply compile it for the RasPi and it should work on your target system.

Thanks, will look into it

I hope I was able to make the general ideas and concepts behind firmware updates over CAN clear to you.

Definitely!

Ask axotec for the source code of the kernel. In order to comply with the Linux kernel's GPL-2 license, they have to give you the source code including all patches.

We contacted them and they will give it to us if we give them our reason.

You basically have to port the existing CAN flash utility to QT.

Was afraid it was going to be like this but will look into it as well

Thanks for the information you gave me! Will look into all of it as soon as possible.

@marckleinebudde
Copy link
Member

Ask axotec for the source code of the kernel. In order to comply with the Linux kernel's GPL-2 license, they have to give you the source code including all patches.

We contacted them and they will give it to us if we give them our reason.

The obvious reason is: "I have the binary, therefor I request the sources.", you can send them the link to the GPL-2.0 FAQ.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants