TODOPIC

Microcontroladores PIC => Todo en microcontroladores PIC => Mensaje iniciado por: Thulsa Doom en 14 de Julio de 2020, 05:53:57

Título: BootLoader en PIC18FxxJyy ¿se puede implementar en esta familias?
Publicado por: Thulsa Doom en 14 de Julio de 2020, 05:53:57
Hola a todos, estoy desarrollando un proyecto con un PIC18F67J50 y quiero darle una vuelta más de turca a mi código añadiéndole un bootloader encriptado, he encontrado uno open source que parece muy interesante BootLoader (http://usb-pic.org/) pero no funciona en los PIC de la familia que estoy usando, según leo estos pic no tienen eeprom interna.
¿Hay alguna manera de ajustar este bootloader para estos microcontroladores?.
Gracias por la ayuda
Título: Re:BootLoader en PIC18FxxJyy ¿se puede implementar en esta familias?
Publicado por: Nocturno en 14 de Julio de 2020, 06:03:03
Para un bootloader no necesitas EEPROM, lo que necesitas es poder grabar en la memoria de programa y ese PIC lo permite.
Título: Re:BootLoader en PIC18FxxJyy ¿se puede implementar en esta familias?
Publicado por: Thulsa Doom en 14 de Julio de 2020, 06:29:06
Pero creo (si no me equivoco) que como éste código utiliza encriptación para proteger el hex, los datos los guarda en una eeprom interna y por eso no funciona en los PIC18xxjyy
Título: Re:BootLoader en PIC18FxxJyy ¿se puede implementar en esta familias?
Publicado por: Nocturno en 14 de Julio de 2020, 06:33:10
Ah, vale, eso lo desconozco. Aunque siempre puedes reservar un trozo de la memoria de programa y usarla para datos.
Título: Re:BootLoader en PIC18FxxJyy ¿se puede implementar en esta familias?
Publicado por: Thulsa Doom en 14 de Julio de 2020, 06:47:02
Se supone que con este código AN1095 (https://www.microchip.com/wwwAppNotes/AppNotes.aspx?appnote=en530593), puedes emular lo que es una eeprom interna en el chip, lo que no sé como puedo adaptar esto para que funcione con el código de bootloader
Título: Re:BootLoader en PIC18FxxJyy ¿se puede implementar en esta familias?
Publicado por: elreypic2 en 14 de Julio de 2020, 10:18:51
Que tal Thulsa Doom,

Le he dado una leída rápida a la información disponible en el link que has proporcionado para este bootloader en particular, y según esta documentación, el bootloader usa el algoritmo de XTEA para la encriptación del firmware. El password que este requiere no se guarda en la memoria EEPROM del microconcontrolador, sino en la memoria FLASH de programa, por lo que ahí en primera instancia no necesitas que el micro a usar contenga memoria EEPROM de datos.

Citar

XTEA encryption algorithm protects user mode application from unauthorized copying. The encryption password together with the bootloader is burned into microcontroller flash memory during device production. To update the user mode application, you can send the encrypted file to customer. This application will only work fine on the devices containing the same bootloader with the same password. Any attempt to install this program into device with another password will result in complete inoperability. Bootloader itself and the password is protected by internal microcontroller configuration bits. Nobody can read it from the microcontroller.

Ahora bien, siguiendo leyendo en la documentación, en la sección de Bootloader configuration es donde se menciona el uso de la memoria EEPROM, pero eso es para definir el modo de operación. Pero en esa misma sección se menciona que para ingresar al modo de Firmware tienes dos opciones:
1) Por un marker en la memoria eeprom, que está asignado a la dirección 0x00, pero este puede ser habilitado o deshabiltiado mediante un #define en el código fuente.

Citar
EEPROM Mark configuration
EEPROM mark is used to guarantee fail-safe user mode application update. Bootloader sets mark in EEPROM memory at receiving of the first command from host and removes it during reset command (after the programming is completed). At the moment of user application programming the mark is always set. If any errors occur (e.g., power drop or off), EEPROM mark remains. At the next switch-on bootloader sees the EEPROM mark and enters the programming mode automatically. User application can be reprogrammed. Only in case host completes application upload and sends BOOT_RESET command, bootloader will clear EEPROM mark and run user application.

EEPROM mark can also be used for soft entry into the programming mode. All user-mode application has to do is to jump to 0x0016 address:

goto 0x0016
Bootloader will set EEPROM mark and reset the microcontroller to enter the programming mode.

EEPROM mark use is configured in boot.inc file with USE_EEPROM_MARK macro.

To use EEPROM mark macros value must be set to 1.

#define USE_EEPROM_MARK   1

If EEPROM mark is not used macros value must be set to 0.

#define USE_EEPROM_MARK   0

By default mark is located at address 0x00 of EEPROM memory. Bootloader enters the programming mode, if it reads 0x5A or 0xF0 at this address. 0xF0 value is used for fail-safe user mode application update. Bootloader doesn’t change this value unless it receives BOOT_RESET command from host. 0x5A value is used for soft reset. Bootloader resets this value (writes 0xFF instead of it) when it enters the programming mode.

If necessary to change mark address or values, override the following macros:

in EEPROM_MARK_ADDR macro specify EEPROM memory address to place the mark;
in EEPROM_MARK macro specify the value for fail-safe update mark;
in EEPROM_MARK_SOFT_RESET macro specify the value for soft-reset mark;
These macros are defined in boot.inc file as shown below:

After EEPROM erase all bytes values are equal to 0xFF, therefore, it is better to use other values for marks. If you use bootloader to program the microcontroller EEPROM memory, put the EEPROM mark into the image file. Otherwise if any errors occur bootloader will enter the user mode and launch the corrupted application.
2) Por medio de un jumper asignado al puerto E.0. Este también puede ser habilitado o deshabilitado mediante un #define que existe en el código fuente.

Citar
Jumper configuration
Jumper is used for hardware entry into the programming mode. It connects the corresponding microcontroller pin to ground (GND). To enter the programming mode close the jumper at the moment of device connection to USB. During initialization bootloader checks the value at the corresponding pin. If value is equal to zero, bootloader enters the programming mode.

If you want to launch user mode application after firmware update, you have to open the jumper before bootloader resets the microcontroller. Otherwise it will enter the programming mode once again.

Bootloader can also enter the programming mode with the help of EEPROM Mark.

The same pin can be used both for the jumper and for LED. First Bootloader verifies the value at this pin. At zero value (when the jumper is closed), it enters the programming mode, configures the pin as digital output, and outputs zero value there (LED is on). As an example of schematic solution see PIC USB Demo Board.

Jumper use is configured in io_cfg.inc file with USE_JP_Bootloader_EN macro. To use the jumper macros value must be set to 1.

#define USE_JP_Bootloader_EN   1
If the jumper is not used macros value must be set to 0.

#define USE_JP_Bootloader_EN   0
By default microcontroller pin E.0 is reserved for the jumper. If you need to use another pin change the following macros:

in JP_Bootloader_PORT macros specify PORT register address;
in JP_Bootloader_TRIS macros specify TRIS register address;
in JP_Bootloader_PIN macros specify the pin number.
These macros are defined in io_cfg.inc file as shown below:

#define JP_Bootloader_TRIS   TRISE
#define JP_Bootloader_PORT   PORTE
#define JP_Bootloader_PIN    0

Por lo tanto, basado en esa información, el bootloader se puede implementar en el microcontrolador que necesitas.

elreypic.
Título: Re:BootLoader en PIC18FxxJyy ¿se puede implementar en esta familias?
Publicado por: Thulsa Doom en 15 de Julio de 2020, 06:13:25
Hola, gracias por la información, pero el código sigue necesitando la dirección de una eeprom interna, la active o no la active con
Código: [Seleccionar]
#define USE_EEPROM_MARK 0 ; Enable EEPROM MARK. To disable = 0Ahora la pregunta es ¿Se puede emular esa eeprom en el micro? y ¿cómo sería?