commit 63085ebd4c96d76ef9fc441e97362530308f3711 Author: yul Date: Thu May 19 14:57:38 2022 +0200 first commit diff --git a/bootloader.c b/bootloader.c new file mode 100644 index 0000000..b3ce05e --- /dev/null +++ b/bootloader.c @@ -0,0 +1,76 @@ +/* +=============================================================================== + Name : bootloader.c + Author : $(author) + Version : + Copyright : $(copyright) + Description : main definition +=============================================================================== +*/ + +#ifdef __USE_CMSIS +#include "LPC17xx.h" +#endif + +#include + +#include +#include + +#include "uart_commands.h" + +error_code status; + +char okk[4] = "OK\r\n"; +char errr[5] = "ERR\r\n"; + +char buff[256]; + + + +cmd_t cmd; + +uint32_t offset, total_size, offset_pointer; + +crc_t crc_prog, crc_data; + + +// TODO: insert other include files here + +// TODO: insert other definitions and declarations here + +int main(void) { + uart_init(115200); + //iap_read_part_id(); + //iap_copy_to_flash(0x8000,(uint8_t*)test, 4); + while(1){ + uart_receive_command(buff); + uart_parse_command(buff, &cmd); + if (strcmp("GETID", cmd.argv[0])==0){ + uart_commands_getid(&status); + }else if(strcmp("GETSERIAL", cmd.argv[0])==0){ + uart_commands_getserial(&status); + }else if(strcmp("PROG", cmd.argv[0])==0){ + crc_prog = uart_string_to_int(cmd.argv[3]); + total_size = uart_string_to_int(cmd.argv[2]); + offset = uart_string_to_int(cmd.argv[1]); + crc_data = uart_commands_prog(); + offset_pointer = offset; + }else if(strcmp("DATA", cmd.argv[0])==0){ + int size = uart_string_to_int(cmd.argv[1]); + crc_t local_checksum = uart_string_to_int(cmd.argv[2]); + uart_commands_data(&status, size, &crc_data, local_checksum, offset_pointer); + if(status == 0) offset_pointer += size; + }else if(strcmp("CHECK", cmd.argv[0])==0){ + if(crc_prog == crc_data){ + uart_send(okk, 5); + }else{ + uart_send(errr, 6); + } + } + + //uart_commands_data(&status, 0x00004000, 0x00048f40, 0x4); + } + while(1); + return 0 ; +} diff --git a/cr_startup_lpc175x_6x.c b/cr_startup_lpc175x_6x.c new file mode 100644 index 0000000..94fb767 --- /dev/null +++ b/cr_startup_lpc175x_6x.c @@ -0,0 +1,367 @@ +//***************************************************************************** +// LPC175x_6x Microcontroller Startup code for use with LPCXpresso IDE +// +// Version : 150706 +//***************************************************************************** +// +// Copyright(C) NXP Semiconductors, 2014-2015, 2020 +// All rights reserved. +// +// NXP Confidential. This software is owned or controlled by NXP and may only be +// used strictly in accordance with the applicable license terms. +// +// By expressly accepting such terms or by downloading, installing, activating +// and/or otherwise using the software, you are agreeing that you have read, and +// that you agree to comply with and are bound by, such license terms. +// +// If you do not agree to be bound by the applicable license terms, then you may not +// retain, install, activate or otherwise use the software. +//***************************************************************************** + +#if defined (__cplusplus) +#ifdef __REDLIB__ +#error Redlib does not support C++ +#else +//***************************************************************************** +// +// The entry point for the C++ library startup +// +//***************************************************************************** +extern "C" { + extern void __libc_init_array(void); +} +#endif +#endif + +#define WEAK __attribute__ ((weak)) +#define ALIAS(f) __attribute__ ((weak, alias (#f))) + +//***************************************************************************** +#if defined (__cplusplus) +extern "C" { +#endif + +//***************************************************************************** +#if defined (__USE_CMSIS) || defined (__USE_LPCOPEN) +// Declaration of external SystemInit function +extern void SystemInit(void); +#endif + +//***************************************************************************** +// +// Forward declaration of the default handlers. These are aliased. +// When the application defines a handler (with the same name), this will +// automatically take precedence over these weak definitions +// +//***************************************************************************** + void ResetISR(void); +WEAK void NMI_Handler(void); +WEAK void HardFault_Handler(void); +WEAK void MemManage_Handler(void); +WEAK void BusFault_Handler(void); +WEAK void UsageFault_Handler(void); +WEAK void SVC_Handler(void); +WEAK void DebugMon_Handler(void); +WEAK void PendSV_Handler(void); +WEAK void SysTick_Handler(void); +WEAK void IntDefaultHandler(void); + +//***************************************************************************** +// +// Forward declaration of the specific IRQ handlers. These are aliased +// to the IntDefaultHandler, which is a 'forever' loop. When the application +// defines a handler (with the same name), this will automatically take +// precedence over these weak definitions +// +//***************************************************************************** +void WDT_IRQHandler(void) ALIAS(IntDefaultHandler); +void TIMER0_IRQHandler(void) ALIAS(IntDefaultHandler); +void TIMER1_IRQHandler(void) ALIAS(IntDefaultHandler); +void TIMER2_IRQHandler(void) ALIAS(IntDefaultHandler); +void TIMER3_IRQHandler(void) ALIAS(IntDefaultHandler); +void UART0_IRQHandler(void) ALIAS(IntDefaultHandler); +void UART1_IRQHandler(void) ALIAS(IntDefaultHandler); +void UART2_IRQHandler(void) ALIAS(IntDefaultHandler); +void UART3_IRQHandler(void) ALIAS(IntDefaultHandler); +void PWM1_IRQHandler(void) ALIAS(IntDefaultHandler); +void I2C0_IRQHandler(void) ALIAS(IntDefaultHandler); +void I2C1_IRQHandler(void) ALIAS(IntDefaultHandler); +void I2C2_IRQHandler(void) ALIAS(IntDefaultHandler); +void SPI_IRQHandler(void) ALIAS(IntDefaultHandler); +void SSP0_IRQHandler(void) ALIAS(IntDefaultHandler); +void SSP1_IRQHandler(void) ALIAS(IntDefaultHandler); +void PLL0_IRQHandler(void) ALIAS(IntDefaultHandler); +void RTC_IRQHandler(void) ALIAS(IntDefaultHandler); +void EINT0_IRQHandler(void) ALIAS(IntDefaultHandler); +void EINT1_IRQHandler(void) ALIAS(IntDefaultHandler); +void EINT2_IRQHandler(void) ALIAS(IntDefaultHandler); +void EINT3_IRQHandler(void) ALIAS(IntDefaultHandler); +void ADC_IRQHandler(void) ALIAS(IntDefaultHandler); +void BOD_IRQHandler(void) ALIAS(IntDefaultHandler); +void USB_IRQHandler(void) ALIAS(IntDefaultHandler); +void CAN_IRQHandler(void) ALIAS(IntDefaultHandler); +void DMA_IRQHandler(void) ALIAS(IntDefaultHandler); +void I2S_IRQHandler(void) ALIAS(IntDefaultHandler); +#if defined (__USE_LPCOPEN) +void ETH_IRQHandler(void) ALIAS(IntDefaultHandler); +#else +void ENET_IRQHandler(void) ALIAS(IntDefaultHandler); +#endif +void RIT_IRQHandler(void) ALIAS(IntDefaultHandler); +void MCPWM_IRQHandler(void) ALIAS(IntDefaultHandler); +void QEI_IRQHandler(void) ALIAS(IntDefaultHandler); +void PLL1_IRQHandler(void) ALIAS(IntDefaultHandler); +void USBActivity_IRQHandler(void) ALIAS(IntDefaultHandler); +void CANActivity_IRQHandler(void) ALIAS(IntDefaultHandler); + +//***************************************************************************** +// +// The entry point for the application. +// __main() is the entry point for Redlib based applications +// main() is the entry point for Newlib based applications +// +//***************************************************************************** +#if defined (__REDLIB__) +extern void __main(void); +#endif +extern int main(void); +//***************************************************************************** +// +// External declaration for the pointer to the stack top from the Linker Script +// +//***************************************************************************** +extern void _vStackTop(void); + +//***************************************************************************** +// +// External declaration for LPC MCU vector table checksum from Linker Script +// +//***************************************************************************** +WEAK extern void __valid_user_code_checksum(); + +//***************************************************************************** +#if defined (__cplusplus) +} // extern "C" +#endif +//***************************************************************************** +// +// The vector table. +// This relies on the linker script to place at correct location in memory. +// +//***************************************************************************** +extern void (* const g_pfnVectors[])(void); +__attribute__ ((used,section(".isr_vector"))) +void (* const g_pfnVectors[])(void) = { + // Core Level - CM3 + &_vStackTop, // The initial stack pointer + ResetISR, // The reset handler + NMI_Handler, // The NMI handler + HardFault_Handler, // The hard fault handler + MemManage_Handler, // The MPU fault handler + BusFault_Handler, // The bus fault handler + UsageFault_Handler, // The usage fault handler + __valid_user_code_checksum, // LPC MCU Checksum + 0, // Reserved + 0, // Reserved + 0, // Reserved + SVC_Handler, // SVCall handler + DebugMon_Handler, // Debug monitor handler + 0, // Reserved + PendSV_Handler, // The PendSV handler + SysTick_Handler, // The SysTick handler + + // Chip Level - LPC17 + WDT_IRQHandler, // 16, 0x40 - WDT + TIMER0_IRQHandler, // 17, 0x44 - TIMER0 + TIMER1_IRQHandler, // 18, 0x48 - TIMER1 + TIMER2_IRQHandler, // 19, 0x4c - TIMER2 + TIMER3_IRQHandler, // 20, 0x50 - TIMER3 + UART0_IRQHandler, // 21, 0x54 - UART0 + UART1_IRQHandler, // 22, 0x58 - UART1 + UART2_IRQHandler, // 23, 0x5c - UART2 + UART3_IRQHandler, // 24, 0x60 - UART3 + PWM1_IRQHandler, // 25, 0x64 - PWM1 + I2C0_IRQHandler, // 26, 0x68 - I2C0 + I2C1_IRQHandler, // 27, 0x6c - I2C1 + I2C2_IRQHandler, // 28, 0x70 - I2C2 + SPI_IRQHandler, // 29, 0x74 - SPI + SSP0_IRQHandler, // 30, 0x78 - SSP0 + SSP1_IRQHandler, // 31, 0x7c - SSP1 + PLL0_IRQHandler, // 32, 0x80 - PLL0 (Main PLL) + RTC_IRQHandler, // 33, 0x84 - RTC + EINT0_IRQHandler, // 34, 0x88 - EINT0 + EINT1_IRQHandler, // 35, 0x8c - EINT1 + EINT2_IRQHandler, // 36, 0x90 - EINT2 + EINT3_IRQHandler, // 37, 0x94 - EINT3 + ADC_IRQHandler, // 38, 0x98 - ADC + BOD_IRQHandler, // 39, 0x9c - BOD + USB_IRQHandler, // 40, 0xA0 - USB + CAN_IRQHandler, // 41, 0xa4 - CAN + DMA_IRQHandler, // 42, 0xa8 - GP DMA + I2S_IRQHandler, // 43, 0xac - I2S +#if defined (__USE_LPCOPEN) + ETH_IRQHandler, // 44, 0xb0 - Ethernet +#else + ENET_IRQHandler, // 44, 0xb0 - Ethernet +#endif + RIT_IRQHandler, // 45, 0xb4 - RITINT + MCPWM_IRQHandler, // 46, 0xb8 - Motor Control PWM + QEI_IRQHandler, // 47, 0xbc - Quadrature Encoder + PLL1_IRQHandler, // 48, 0xc0 - PLL1 (USB PLL) + USBActivity_IRQHandler, // 49, 0xc4 - USB Activity interrupt to wakeup + CANActivity_IRQHandler, // 50, 0xc8 - CAN Activity interrupt to wakeup +}; + +//***************************************************************************** +// Functions to carry out the initialization of RW and BSS data sections. These +// are written as separate functions rather than being inlined within the +// ResetISR() function in order to cope with MCUs with multiple banks of +// memory. +//***************************************************************************** +__attribute__ ((section(".after_vectors"))) +void data_init(unsigned int romstart, unsigned int start, unsigned int len) { + unsigned int *pulDest = (unsigned int*) start; + unsigned int *pulSrc = (unsigned int*) romstart; + unsigned int loop; + for (loop = 0; loop < len; loop = loop + 4) + *pulDest++ = *pulSrc++; +} + +__attribute__ ((section(".after_vectors"))) +void bss_init(unsigned int start, unsigned int len) { + unsigned int *pulDest = (unsigned int*) start; + unsigned int loop; + for (loop = 0; loop < len; loop = loop + 4) + *pulDest++ = 0; +} + +//***************************************************************************** +// The following symbols are constructs generated by the linker, indicating +// the location of various points in the "Global Section Table". This table is +// created by the linker via the Code Red managed linker script mechanism. It +// contains the load address, execution address and length of each RW data +// section and the execution and length of each BSS (zero initialized) section. +//***************************************************************************** +extern unsigned int __data_section_table; +extern unsigned int __data_section_table_end; +extern unsigned int __bss_section_table; +extern unsigned int __bss_section_table_end; + +//***************************************************************************** +// Reset entry point for your code. +// Sets up a simple runtime environment and initializes the C/C++ +// library. +//***************************************************************************** +__attribute__ ((section(".after_vectors"))) +void +ResetISR(void) { + + // + // Copy the data sections from flash to SRAM. + // + unsigned int LoadAddr, ExeAddr, SectionLen; + unsigned int *SectionTableAddr; + + // Load base address of Global Section Table + SectionTableAddr = &__data_section_table; + + // Copy the data sections from flash to SRAM. + while (SectionTableAddr < &__data_section_table_end) { + LoadAddr = *SectionTableAddr++; + ExeAddr = *SectionTableAddr++; + SectionLen = *SectionTableAddr++; + data_init(LoadAddr, ExeAddr, SectionLen); + } + // At this point, SectionTableAddr = &__bss_section_table; + // Zero fill the bss segment + while (SectionTableAddr < &__bss_section_table_end) { + ExeAddr = *SectionTableAddr++; + SectionLen = *SectionTableAddr++; + bss_init(ExeAddr, SectionLen); + } + +#if defined (__USE_CMSIS) || defined (__USE_LPCOPEN) + SystemInit(); +#endif + +#if defined (__cplusplus) + // + // Call C++ library initialisation + // + __libc_init_array(); +#endif + +#if defined (__REDLIB__) + // Call the Redlib library, which in turn calls main() + __main() ; +#else + main(); +#endif + + // + // main() shouldn't return, but if it does, we'll just enter an infinite loop + // + while (1) { + ; + } +} + +//***************************************************************************** +// Default exception handlers. Override the ones here by defining your own +// handler routines in your application code. +//***************************************************************************** +__attribute__ ((section(".after_vectors"))) +void NMI_Handler(void) +{ while(1) {} +} + +__attribute__ ((section(".after_vectors"))) +void HardFault_Handler(void) +{ while(1) {} +} + +__attribute__ ((section(".after_vectors"))) +void MemManage_Handler(void) +{ while(1) {} +} + +__attribute__ ((section(".after_vectors"))) +void BusFault_Handler(void) +{ while(1) {} +} + +__attribute__ ((section(".after_vectors"))) +void UsageFault_Handler(void) +{ while(1) {} +} + +__attribute__ ((section(".after_vectors"))) +void SVC_Handler(void) +{ while(1) {} +} + +__attribute__ ((section(".after_vectors"))) +void DebugMon_Handler(void) +{ while(1) {} +} + +__attribute__ ((section(".after_vectors"))) +void PendSV_Handler(void) +{ while(1) {} +} + +__attribute__ ((section(".after_vectors"))) +void SysTick_Handler(void) +{ while(1) {} +} + +//***************************************************************************** +// +// Processor ends up here if an unexpected interrupt occurs or a specific +// handler is not present in the application code. +// +//***************************************************************************** +__attribute__ ((section(".after_vectors"))) +void IntDefaultHandler(void) +{ while(1) {} +} diff --git a/crc.c b/crc.c new file mode 100644 index 0000000..7db6454 --- /dev/null +++ b/crc.c @@ -0,0 +1,52 @@ +/** + * \file crc.c + * Functions and types for CRC checks. + * + * Generated on Sun Dec 18 16:52:06 2016, + * by pycrc v0.9, https://pycrc.org + * using the configuration: + * Width = 32 + * Poly = 0x04c11db7 + * Xor_In = 0xffffffff + * ReflectIn = True + * Xor_Out = 0xffffffff + * ReflectOut = True + * Algorithm = table-driven + *****************************************************************************/ +#include "crc.h" /* include the header file generated with pycrc */ +#include +#include + +/** + * Static table used for the table_driven implementation. + *****************************************************************************/ +static const crc_t crc_table[16] = { + 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, + 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c +}; + +/** + * Update the crc value with new data. + * + * \param crc The current crc value. + * \param data Pointer to a buffer of \a data_len bytes. + * \param data_len Number of bytes in the \a data buffer. + * \return The updated crc value. + *****************************************************************************/ +crc_t crc_update(crc_t crc, const void *data, size_t data_len) +{ + const unsigned char *d = (const unsigned char *)data; + unsigned int tbl_idx; + + while (data_len--) { + tbl_idx = crc ^ (*d >> (0 * 4)); + crc = crc_table[tbl_idx & 0x0f] ^ (crc >> 4); + tbl_idx = crc ^ (*d >> (1 * 4)); + crc = crc_table[tbl_idx & 0x0f] ^ (crc >> 4); + + d++; + } + return crc & 0xffffffff; +} + + diff --git a/crc.h b/crc.h new file mode 100644 index 0000000..4b45157 --- /dev/null +++ b/crc.h @@ -0,0 +1,82 @@ +/** + * \file crc.h + * Functions and types for CRC checks. + * + * Generated on Sun Dec 18 16:52:09 2016, + * by pycrc v0.9, https://pycrc.org + * using the configuration: + * Width = 32 + * Poly = 0x04c11db7 + * Xor_In = 0xffffffff + * ReflectIn = True + * Xor_Out = 0xffffffff + * ReflectOut = True + * Algorithm = table-driven + *****************************************************************************/ +#ifndef __CRC_H__ +#define __CRC_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * The definition of the used algorithm. + * + * This is not used anywhere in the generated code, but it may be used by the + * application code to call algoritm-specific code, is desired. + *****************************************************************************/ +#define CRC_ALGO_TABLE_DRIVEN 1 + + +/** + * The type of the CRC values. + * + * This type must be big enough to contain at least 32 bits. + *****************************************************************************/ +typedef uint_fast32_t crc_t; + + +/** + * Calculate the initial crc value. + * + * \return The initial crc value. + *****************************************************************************/ +static inline crc_t crc_init(void) +{ + return 0xffffffff; +} + + +/** + * Update the crc value with new data. + * + * \param crc The current crc value. + * \param data Pointer to a buffer of \a data_len bytes. + * \param data_len Number of bytes in the \a data buffer. + * \return The updated crc value. + *****************************************************************************/ +crc_t crc_update(crc_t crc, const void *data, size_t data_len); + + +/** + * Calculate the final crc value. + * + * \param crc The current crc value. + * \return The final crc value. + *****************************************************************************/ +static inline crc_t crc_finalize(crc_t crc) +{ + return crc ^ 0xffffffff; +} + + +#ifdef __cplusplus +} /* closing brace for extern "C" */ +#endif + +#endif /* __CRC_H__ */ diff --git a/crp.c b/crp.c new file mode 100644 index 0000000..6e33068 --- /dev/null +++ b/crp.c @@ -0,0 +1,27 @@ +//***************************************************************************** +// crp.c +// +// Source file to create CRP word expected by LPCXpresso IDE linker +//***************************************************************************** +// +// Copyright(C) NXP Semiconductors, 2013, 2020 +// All rights reserved. +// +// NXP Confidential. This software is owned or controlled by NXP and may only be +// used strictly in accordance with the applicable license terms. +// +// By expressly accepting such terms or by downloading, installing, activating +// and/or otherwise using the software, you are agreeing that you have read, and +// that you agree to comply with and are bound by, such license terms. +// +// If you do not agree to be bound by the applicable license terms, then you may not +// retain, install, activate or otherwise use the software. +//***************************************************************************** + +#if defined (__CODE_RED) +#include +// Variable to store CRP value in. Will be placed automatically +// by the linker when "Enable Code Read Protect" selected. +// See crp.h header for more information +__CRP const unsigned int CRP_WORD = CRP_NO_CRP ; +#endif diff --git a/iap.c b/iap.c new file mode 100644 index 0000000..5e49178 --- /dev/null +++ b/iap.c @@ -0,0 +1,138 @@ +/* +=============================================================================== + Name : iap.c + Author : $(author) + Version : + Copyright : $(copyright) + Description : main definition +=============================================================================== +*/ + +#ifdef __USE_CMSIS +#include "LPC17xx.h" +#endif + +#include "iap.h" + +uint32_t command[5]; +uint32_t output[5]; +IAP iap_entry =(IAP) IAP_LOCATION; + + +volatile char test[32] = {'t', 'e', 's', 't', 'i', 'n', 'g', '!', + 't', 'e', 's', 't', 'i', 'n', 'g', '!', + 't', 'e', 's', 't', 'i', 'n', 'g', '!', + 't', 'e', 's', 't', 'i', 'n', 'g', '!'}; + +void iap_everything_is_alright(void){ + LPC_GPIO2->FIOPIN = 0x00; +} +void iap_something_went_wrong(int error_code){ + LPC_GPIO2->FIOPIN = error_code; +} +void iap_entry_wrapped(void){ + __disable_irq(); + iap_entry(command, output); + __enable_irq(); +} + +/*void iap_read_part_id(void){ + command[0] = 54; + iap_entry_wrapped(); + if(output[0] == IAP_CMD_SUCCESS){ + iap_everything_is_alright(); + printf("part id is %d\n", output[1]); + }else{ + iap_something_went_wrong(output[0]); + } +}*/ + +void iap_prepare_sectors(error_code* status, int start, int end){ + command[0] = 50; + command[1] = start; + command[2] = end; + iap_entry_wrapped(); + if(output[0] == IAP_CMD_SUCCESS) { + iap_everything_is_alright(); + *status = 0; + }else{ + iap_something_went_wrong(output[0]); + *status = -1; + } +} + +void iap_erase_sectors(error_code* status, int start, int end){ + iap_prepare_sectors(status, start, end); + command[0] = 52; //erase sectors + command[1] = start; //start sector + command[2] = end; //end sector + command[3] = IAP_CLOCK_100M; + iap_entry_wrapped(); + if(output[0] == IAP_CMD_SUCCESS) { + iap_everything_is_alright(); + }else{ + iap_something_went_wrong(output[0]); + } +} + +uint32_t iap_read_part_id(error_code* status){ + //iap_prepare_sectors(dst_flash, dst_flash+num_bytes-1); + iap_prepare_sectors(status, 2, 9); + command[0] = 54; + iap_entry_wrapped(); + if(output[0] == IAP_CMD_SUCCESS) { + iap_everything_is_alright(); + *status = 0; + return output[1]; + }else{ + iap_something_went_wrong(output[0]); + *status = -1; + return -1; + } +} + +void iap_copy_to_flash(error_code* status, int dst_flash, uint32_t* src_ram, int num_bytes){ + iap_prepare_sectors(status, dst_flash, dst_flash+num_bytes); + //iap_prepare_sectors(2, 9); + command[0] = 51; + command[1] = dst_flash; + command[2] = *src_ram; + command[3] = num_bytes; + iap_entry_wrapped(); + if(output[0] == IAP_CMD_SUCCESS) { + iap_everything_is_alright(); + *status = 0; + }else{ + iap_something_went_wrong(output[0]); + *status = -1; + } +} + +void iap_read_serial(error_code* status, uint32_t* res){ + iap_prepare_sectors(status, 2, 9); + command[0] = 58; + iap_entry_wrapped(); + if(output[0] == IAP_CMD_SUCCESS) { + iap_everything_is_alright(); + *status = 0; + res[0] = output[1]; + res[1] = output[2]; + res[2] = output[3]; + res[3] = output[4]; + }else{ + iap_something_went_wrong(output[0]); + *status = -1; + } +} + +// TODO: insert other include files here + +// TODO: insert other definitions and declarations here +/* +int main(void) { + LPC_PINCON->PINSEL4 &= ~0xFF; //Configure the PORT2 Pins as GPIO; + LPC_GPIO2->FIODIR = 0xff; //Configure the PORT2 pins as OUTPUT; + iap_read_part_id(); + iap_erase_sectors(2, 9); + iap_copy_to_flash(0x8000,(uint8_t*)test, 4); +}*/ diff --git a/iap.h b/iap.h new file mode 100644 index 0000000..cc780b8 --- /dev/null +++ b/iap.h @@ -0,0 +1,43 @@ +#include + +#include + +#define IAP_LOCATION 0x1FFF1FF1 +#define IAP_CMD_SUCCESS 0 +#define IAP_INVALID_COMMAND 1 +#define IAP_SRC_ADDR_ERROR 2 +#define IAP_DST_ADDR_ERROR 3 +#define IAP_SRC_ADDR_NOT_MAPPED 4 +#define IAP_DST_ADDR_NOT_MAPPED 5 +#define IAP_COUNT_ERROR 6 +#define IAP_INVALID_SECTOR 7 +#define IAP_SECTOR_NOT_BLANK 8 +#define IAP_SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION 9 +#define IAP_COMPARE_ERROR 10 +#define IAP_BUSY 11 +#define IAP_CLOCK_100M 100000 + + +typedef enum _error_code { + ok, general_error, invalid_command, global_checksum, + local_checksum, erase_error, write_error, invalid_size, + invalid_offset, invalid_arguments +} error_code; + +typedef void (*IAP)(unsigned int[], unsigned int[]); + + +void iap_everything_is_alright(void); +void iap_something_went_wrong(int error_code); + + +void iap_prepare_sectors(error_code* status, int start, int end); + +void iap_erase_sectors(error_code* status, int start, int end); + +void iap_copy_to_flash(error_code* status, int dst_flash, uint32_t* src_ram, int num_bytes); + +uint32_t iap_read_part_id(error_code* status); + +void iap_read_serial(error_code* status, uint32_t* res); + diff --git a/log b/log new file mode 100644 index 0000000..f42e956 --- /dev/null +++ b/log @@ -0,0 +1,893 @@ +python3 mylab2-programmer.py --port /dev/ttyUSB0 sonic_50b03eb0.bin --verbose +>>> b'GETID\r\n' +<<< b'OK\r\n' +<<< b'0x26113f37\r\n' +>>> b'GETSERIAL\r\n' +<<< b'OK\r\n' +<<< b'0x101600caf27a5225a53f5f9f50020c2\r\n' +Connecté au bootloader myLab2-MIP: +PartID: 0x26113f37 +Serial: 0x101600caf27a5225a53f5f9f50020c2 +Envoi sonic_50b03eb0.bin à la myLab2, taille: 298816, CRC32: 0x50b03eb0, bs=1024 +>>> b'PROG,0x00004000,0x00048f40,0x50b03eb0\r\n' +<<< b'OK\r\n' +Envoi bloc 1/292 (0x00000000 à 0x000003ff) +>>> b'DATA,0x0400,0x743f4089\r\n' +<<< b'OK\r\n' +Envoi bloc 2/292 (0x00000400 à 0x000007ff) +>>> b'DATA,0x0400,0xb6e5b801\r\n' +<<< b'OK\r\n' +Envoi bloc 3/292 (0x00000800 à 0x00000bff) +>>> b'DATA,0x0400,0xb03a067d\r\n' +<<< b'OK\r\n' +Envoi bloc 4/292 (0x00000c00 à 0x00000fff) +>>> b'DATA,0x0400,0x32a91d8d\r\n' +<<< b'OK\r\n' +Envoi bloc 5/292 (0x00001000 à 0x000013ff) +>>> b'DATA,0x0400,0x03a96542\r\n' +<<< b'OK\r\n' +Envoi bloc 6/292 (0x00001400 à 0x000017ff) +>>> b'DATA,0x0400,0xaf5221cc\r\n' +<<< b'OK\r\n' +Envoi bloc 7/292 (0x00001800 à 0x00001bff) +>>> b'DATA,0x0400,0xeca6a6a0\r\n' +<<< b'OK\r\n' +Envoi bloc 8/292 (0x00001c00 à 0x00001fff) +>>> b'DATA,0x0400,0x786e241a\r\n' +<<< b'OK\r\n' +Envoi bloc 9/292 (0x00002000 à 0x000023ff) +>>> b'DATA,0x0400,0xd84c0e06\r\n' +<<< b'OK\r\n' +Envoi bloc 10/292 (0x00002400 à 0x000027ff) +>>> b'DATA,0x0400,0x91e29ff7\r\n' +<<< b'OK\r\n' +Envoi bloc 11/292 (0x00002800 à 0x00002bff) +>>> b'DATA,0x0400,0x90c3380c\r\n' +<<< b'OK\r\n' +Envoi bloc 12/292 (0x00002c00 à 0x00002fff) +>>> b'DATA,0x0400,0x4309179b\r\n' +<<< b'OK\r\n' +Envoi bloc 13/292 (0x00003000 à 0x000033ff) +>>> b'DATA,0x0400,0x206c4b74\r\n' +<<< b'OK\r\n' +Envoi bloc 14/292 (0x00003400 à 0x000037ff) +>>> b'DATA,0x0400,0xcb32819b\r\n' +<<< b'OK\r\n' +Envoi bloc 15/292 (0x00003800 à 0x00003bff) +>>> b'DATA,0x0400,0xff10adbc\r\n' +<<< b'OK\r\n' +Envoi bloc 16/292 (0x00003c00 à 0x00003fff) +>>> b'DATA,0x0400,0x704a5bea\r\n' +<<< b'OK\r\n' +Envoi bloc 17/292 (0x00004000 à 0x000043ff) +>>> b'DATA,0x0400,0x08bbbd57\r\n' +<<< b'OK\r\n' +Envoi bloc 18/292 (0x00004400 à 0x000047ff) +>>> b'DATA,0x0400,0x2609eaaa\r\n' +<<< b'OK\r\n' +Envoi bloc 19/292 (0x00004800 à 0x00004bff) +>>> b'DATA,0x0400,0xf98d6399\r\n' +<<< b'OK\r\n' +Envoi bloc 20/292 (0x00004c00 à 0x00004fff) +>>> b'DATA,0x0400,0xdb949daf\r\n' +<<< b'OK\r\n' +Envoi bloc 21/292 (0x00005000 à 0x000053ff) +>>> b'DATA,0x0400,0x5cc74aa0\r\n' +<<< b'OK\r\n' +Envoi bloc 22/292 (0x00005400 à 0x000057ff) +>>> b'DATA,0x0400,0xd22a8b62\r\n' +<<< b'OK\r\n' +Envoi bloc 23/292 (0x00005800 à 0x00005bff) +>>> b'DATA,0x0400,0xded1be71\r\n' +<<< b'OK\r\n' +Envoi bloc 24/292 (0x00005c00 à 0x00005fff) +>>> b'DATA,0x0400,0xc9102f12\r\n' +<<< b'OK\r\n' +Envoi bloc 25/292 (0x00006000 à 0x000063ff) +>>> b'DATA,0x0400,0x7d7a5c4c\r\n' +<<< b'OK\r\n' +Envoi bloc 26/292 (0x00006400 à 0x000067ff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 27/292 (0x00006800 à 0x00006bff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 28/292 (0x00006c00 à 0x00006fff) +>>> b'DATA,0x0400,0xd3265046\r\n' +<<< b'OK\r\n' +Envoi bloc 29/292 (0x00007000 à 0x000073ff) +>>> b'DATA,0x0400,0x9e107903\r\n' +<<< b'OK\r\n' +Envoi bloc 30/292 (0x00007400 à 0x000077ff) +>>> b'DATA,0x0400,0xecc38415\r\n' +<<< b'OK\r\n' +Envoi bloc 31/292 (0x00007800 à 0x00007bff) +>>> b'DATA,0x0400,0x84a0604f\r\n' +<<< b'OK\r\n' +Envoi bloc 32/292 (0x00007c00 à 0x00007fff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 33/292 (0x00008000 à 0x000083ff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 34/292 (0x00008400 à 0x000087ff) +>>> b'DATA,0x0400,0x3866cad8\r\n' +<<< b'OK\r\n' +Envoi bloc 35/292 (0x00008800 à 0x00008bff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 36/292 (0x00008c00 à 0x00008fff) +>>> b'DATA,0x0400,0x6cc8853d\r\n' +<<< b'OK\r\n' +Envoi bloc 37/292 (0x00009000 à 0x000093ff) +>>> b'DATA,0x0400,0xc44f4bff\r\n' +<<< b'OK\r\n' +Envoi bloc 38/292 (0x00009400 à 0x000097ff) +>>> b'DATA,0x0400,0xb50c0027\r\n' +<<< b'OK\r\n' +Envoi bloc 39/292 (0x00009800 à 0x00009bff) +>>> b'DATA,0x0400,0x950d6587\r\n' +<<< b'OK\r\n' +Envoi bloc 40/292 (0x00009c00 à 0x00009fff) +>>> b'DATA,0x0400,0x354871d0\r\n' +<<< b'OK\r\n' +Envoi bloc 41/292 (0x0000a000 à 0x0000a3ff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 42/292 (0x0000a400 à 0x0000a7ff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 43/292 (0x0000a800 à 0x0000abff) +>>> b'DATA,0x0400,0x94c72b47\r\n' +<<< b'OK\r\n' +Envoi bloc 44/292 (0x0000ac00 à 0x0000afff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 45/292 (0x0000b000 à 0x0000b3ff) +>>> b'DATA,0x0400,0xf63fdc5e\r\n' +<<< b'OK\r\n' +Envoi bloc 46/292 (0x0000b400 à 0x0000b7ff) +>>> b'DATA,0x0400,0x7203b3f5\r\n' +<<< b'OK\r\n' +Envoi bloc 47/292 (0x0000b800 à 0x0000bbff) +>>> b'DATA,0x0400,0x29b270e4\r\n' +<<< b'OK\r\n' +Envoi bloc 48/292 (0x0000bc00 à 0x0000bfff) +>>> b'DATA,0x0400,0x2db03acb\r\n' +<<< b'OK\r\n' +Envoi bloc 49/292 (0x0000c000 à 0x0000c3ff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 50/292 (0x0000c400 à 0x0000c7ff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 51/292 (0x0000c800 à 0x0000cbff) +>>> b'DATA,0x0400,0xc8d176f3\r\n' +<<< b'OK\r\n' +Envoi bloc 52/292 (0x0000cc00 à 0x0000cfff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 53/292 (0x0000d000 à 0x0000d3ff) +>>> b'DATA,0x0400,0xdc2d9889\r\n' +<<< b'OK\r\n' +Envoi bloc 54/292 (0x0000d400 à 0x0000d7ff) +>>> b'DATA,0x0400,0xce3f9041\r\n' +<<< b'OK\r\n' +Envoi bloc 55/292 (0x0000d800 à 0x0000dbff) +>>> b'DATA,0x0400,0xc81d96b9\r\n' +<<< b'OK\r\n' +Envoi bloc 56/292 (0x0000dc00 à 0x0000dfff) +>>> b'DATA,0x0400,0xd1971639\r\n' +<<< b'OK\r\n' +Envoi bloc 57/292 (0x0000e000 à 0x0000e3ff) +>>> b'DATA,0x0400,0xe1fec03e\r\n' +<<< b'OK\r\n' +Envoi bloc 58/292 (0x0000e400 à 0x0000e7ff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 59/292 (0x0000e800 à 0x0000ebff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 60/292 (0x0000ec00 à 0x0000efff) +>>> b'DATA,0x0400,0x07eecd61\r\n' +<<< b'OK\r\n' +Envoi bloc 61/292 (0x0000f000 à 0x0000f3ff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 62/292 (0x0000f400 à 0x0000f7ff) +>>> b'DATA,0x0400,0x378f2e3a\r\n' +<<< b'OK\r\n' +Envoi bloc 63/292 (0x0000f800 à 0x0000fbff) +>>> b'DATA,0x0400,0xf4752beb\r\n' +<<< b'OK\r\n' +Envoi bloc 64/292 (0x0000fc00 à 0x0000ffff) +>>> b'DATA,0x0400,0x1361f2d5\r\n' +<<< b'OK\r\n' +Envoi bloc 65/292 (0x00010000 à 0x000103ff) +>>> b'DATA,0x0400,0x90f09d53\r\n' +<<< b'OK\r\n' +Envoi bloc 66/292 (0x00010400 à 0x000107ff) +>>> b'DATA,0x0400,0x982225b1\r\n' +<<< b'OK\r\n' +Envoi bloc 67/292 (0x00010800 à 0x00010bff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 68/292 (0x00010c00 à 0x00010fff) +>>> b'DATA,0x0400,0xa7ce9994\r\n' +<<< b'OK\r\n' +Envoi bloc 69/292 (0x00011000 à 0x000113ff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 70/292 (0x00011400 à 0x000117ff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 71/292 (0x00011800 à 0x00011bff) +>>> b'DATA,0x0400,0x0b5d0a73\r\n' +<<< b'OK\r\n' +Envoi bloc 72/292 (0x00011c00 à 0x00011fff) +>>> b'DATA,0x0400,0x1f13ca84\r\n' +<<< b'OK\r\n' +Envoi bloc 73/292 (0x00012000 à 0x000123ff) +>>> b'DATA,0x0400,0xfba052c3\r\n' +<<< b'OK\r\n' +Envoi bloc 74/292 (0x00012400 à 0x000127ff) +>>> b'DATA,0x0400,0x2ee8ea2a\r\n' +<<< b'OK\r\n' +Envoi bloc 75/292 (0x00012800 à 0x00012bff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 76/292 (0x00012c00 à 0x00012fff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 77/292 (0x00013000 à 0x000133ff) +>>> b'DATA,0x0400,0x58bd92dd\r\n' +<<< b'OK\r\n' +Envoi bloc 78/292 (0x00013400 à 0x000137ff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 79/292 (0x00013800 à 0x00013bff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 80/292 (0x00013c00 à 0x00013fff) +>>> b'DATA,0x0400,0x28c08220\r\n' +<<< b'OK\r\n' +Envoi bloc 81/292 (0x00014000 à 0x000143ff) +>>> b'DATA,0x0400,0x72d754e4\r\n' +<<< b'OK\r\n' +Envoi bloc 82/292 (0x00014400 à 0x000147ff) +>>> b'DATA,0x0400,0x2d7942d6\r\n' +<<< b'OK\r\n' +Envoi bloc 83/292 (0x00014800 à 0x00014bff) +>>> b'DATA,0x0400,0xc506a186\r\n' +<<< b'OK\r\n' +Envoi bloc 84/292 (0x00014c00 à 0x00014fff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 85/292 (0x00015000 à 0x000153ff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 86/292 (0x00015400 à 0x000157ff) +>>> b'DATA,0x0400,0xcdf8f836\r\n' +<<< b'OK\r\n' +Envoi bloc 87/292 (0x00015800 à 0x00015bff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 88/292 (0x00015c00 à 0x00015fff) +>>> b'DATA,0x0400,0x6a5c9725\r\n' +<<< b'OK\r\n' +Envoi bloc 89/292 (0x00016000 à 0x000163ff) +>>> b'DATA,0x0400,0xa3d2ba5f\r\n' +<<< b'OK\r\n' +Envoi bloc 90/292 (0x00016400 à 0x000167ff) +>>> b'DATA,0x0400,0xdabfd721\r\n' +<<< b'OK\r\n' +Envoi bloc 91/292 (0x00016800 à 0x00016bff) +>>> b'DATA,0x0400,0xc3168641\r\n' +<<< b'OK\r\n' +Envoi bloc 92/292 (0x00016c00 à 0x00016fff) +>>> b'DATA,0x0400,0xb3f0c585\r\n' +<<< b'OK\r\n' +Envoi bloc 93/292 (0x00017000 à 0x000173ff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 94/292 (0x00017400 à 0x000177ff) +>>> b'DATA,0x0400,0x4f0ab4ec\r\n' +<<< b'OK\r\n' +Envoi bloc 95/292 (0x00017800 à 0x00017bff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 96/292 (0x00017c00 à 0x00017fff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 97/292 (0x00018000 à 0x000183ff) +>>> b'DATA,0x0400,0x600e10fc\r\n' +<<< b'OK\r\n' +Envoi bloc 98/292 (0x00018400 à 0x000187ff) +>>> b'DATA,0x0400,0xca0a6740\r\n' +<<< b'OK\r\n' +Envoi bloc 99/292 (0x00018800 à 0x00018bff) +>>> b'DATA,0x0400,0x3db01e96\r\n' +<<< b'OK\r\n' +Envoi bloc 100/292 (0x00018c00 à 0x00018fff) +>>> b'DATA,0x0400,0x12be8748\r\n' +<<< b'OK\r\n' +Envoi bloc 101/292 (0x00019000 à 0x000193ff) +>>> b'DATA,0x0400,0x92420a9c\r\n' +<<< b'OK\r\n' +Envoi bloc 102/292 (0x00019400 à 0x000197ff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 103/292 (0x00019800 à 0x00019bff) +>>> b'DATA,0x0400,0x0a720279\r\n' +<<< b'OK\r\n' +Envoi bloc 104/292 (0x00019c00 à 0x00019fff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 105/292 (0x0001a000 à 0x0001a3ff) +>>> b'DATA,0x0400,0xae4b70e7\r\n' +<<< b'OK\r\n' +Envoi bloc 106/292 (0x0001a400 à 0x0001a7ff) +>>> b'DATA,0x0400,0x1dfc98c2\r\n' +<<< b'OK\r\n' +Envoi bloc 107/292 (0x0001a800 à 0x0001abff) +>>> b'DATA,0x0400,0xd7133a9d\r\n' +<<< b'OK\r\n' +Envoi bloc 108/292 (0x0001ac00 à 0x0001afff) +>>> b'DATA,0x0400,0xca4c0f59\r\n' +<<< b'OK\r\n' +Envoi bloc 109/292 (0x0001b000 à 0x0001b3ff) +>>> b'DATA,0x0400,0xb5236d41\r\n' +<<< b'OK\r\n' +Envoi bloc 110/292 (0x0001b400 à 0x0001b7ff) +>>> b'DATA,0x0400,0xfd5cb16b\r\n' +<<< b'OK\r\n' +Envoi bloc 111/292 (0x0001b800 à 0x0001bbff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 112/292 (0x0001bc00 à 0x0001bfff) +>>> b'DATA,0x0400,0xbceb5cfa\r\n' +<<< b'OK\r\n' +Envoi bloc 113/292 (0x0001c000 à 0x0001c3ff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 114/292 (0x0001c400 à 0x0001c7ff) +>>> b'DATA,0x0400,0x0aeca21f\r\n' +<<< b'OK\r\n' +Envoi bloc 115/292 (0x0001c800 à 0x0001cbff) +>>> b'DATA,0x0400,0x4a26b094\r\n' +<<< b'OK\r\n' +Envoi bloc 116/292 (0x0001cc00 à 0x0001cfff) +>>> b'DATA,0x0400,0xc1bc99b7\r\n' +<<< b'OK\r\n' +Envoi bloc 117/292 (0x0001d000 à 0x0001d3ff) +>>> b'DATA,0x0400,0xb08ce103\r\n' +<<< b'OK\r\n' +Envoi bloc 118/292 (0x0001d400 à 0x0001d7ff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 119/292 (0x0001d800 à 0x0001dbff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 120/292 (0x0001dc00 à 0x0001dfff) +>>> b'DATA,0x0400,0xf465ab82\r\n' +<<< b'OK\r\n' +Envoi bloc 121/292 (0x0001e000 à 0x0001e3ff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 122/292 (0x0001e400 à 0x0001e7ff) +>>> b'DATA,0x0400,0x0c11b8c0\r\n' +<<< b'OK\r\n' +Envoi bloc 123/292 (0x0001e800 à 0x0001ebff) +>>> b'DATA,0x0400,0x2c04d917\r\n' +<<< b'OK\r\n' +Envoi bloc 124/292 (0x0001ec00 à 0x0001efff) +>>> b'DATA,0x0400,0xa3553245\r\n' +<<< b'OK\r\n' +Envoi bloc 125/292 (0x0001f000 à 0x0001f3ff) +>>> b'DATA,0x0400,0x09143cae\r\n' +<<< b'OK\r\n' +Envoi bloc 126/292 (0x0001f400 à 0x0001f7ff) +>>> b'DATA,0x0400,0xf2d45f03\r\n' +<<< b'OK\r\n' +Envoi bloc 127/292 (0x0001f800 à 0x0001fbff) +>>> b'DATA,0x0400,0x06d86dec\r\n' +<<< b'OK\r\n' +Envoi bloc 128/292 (0x0001fc00 à 0x0001ffff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 129/292 (0x00020000 à 0x000203ff) +>>> b'DATA,0x0400,0x99311ca4\r\n' +<<< b'OK\r\n' +Envoi bloc 130/292 (0x00020400 à 0x000207ff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 131/292 (0x00020800 à 0x00020bff) +>>> b'DATA,0x0400,0x9538ede0\r\n' +<<< b'OK\r\n' +Envoi bloc 132/292 (0x00020c00 à 0x00020fff) +>>> b'DATA,0x0400,0x01f1d0aa\r\n' +<<< b'OK\r\n' +Envoi bloc 133/292 (0x00021000 à 0x000213ff) +>>> b'DATA,0x0400,0x5fc36d67\r\n' +<<< b'OK\r\n' +Envoi bloc 134/292 (0x00021400 à 0x000217ff) +>>> b'DATA,0x0400,0x3b61ca7b\r\n' +<<< b'OK\r\n' +Envoi bloc 135/292 (0x00021800 à 0x00021bff) +>>> b'DATA,0x0400,0xd4401316\r\n' +<<< b'OK\r\n' +Envoi bloc 136/292 (0x00021c00 à 0x00021fff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 137/292 (0x00022000 à 0x000223ff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 138/292 (0x00022400 à 0x000227ff) +>>> b'DATA,0x0400,0xc74fc22d\r\n' +<<< b'OK\r\n' +Envoi bloc 139/292 (0x00022800 à 0x00022bff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 140/292 (0x00022c00 à 0x00022fff) +>>> b'DATA,0x0400,0x8c44f3c3\r\n' +<<< b'OK\r\n' +Envoi bloc 141/292 (0x00023000 à 0x000233ff) +>>> b'DATA,0x0400,0xf2a29ff4\r\n' +<<< b'OK\r\n' +Envoi bloc 142/292 (0x00023400 à 0x000237ff) +>>> b'DATA,0x0400,0x62d2a1ce\r\n' +<<< b'OK\r\n' +Envoi bloc 143/292 (0x00023800 à 0x00023bff) +>>> b'DATA,0x0400,0xf3c597f7\r\n' +<<< b'OK\r\n' +Envoi bloc 144/292 (0x00023c00 à 0x00023fff) +>>> b'DATA,0x0400,0xf94dec31\r\n' +<<< b'OK\r\n' +Envoi bloc 145/292 (0x00024000 à 0x000243ff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 146/292 (0x00024400 à 0x000247ff) +>>> b'DATA,0x0400,0xfd2ac2a6\r\n' +<<< b'OK\r\n' +Envoi bloc 147/292 (0x00024800 à 0x00024bff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 148/292 (0x00024c00 à 0x00024fff) +>>> b'DATA,0x0400,0xe1320841\r\n' +<<< b'OK\r\n' +Envoi bloc 149/292 (0x00025000 à 0x000253ff) +>>> b'DATA,0x0400,0x59fa90e6\r\n' +<<< b'OK\r\n' +Envoi bloc 150/292 (0x00025400 à 0x000257ff) +>>> b'DATA,0x0400,0x079d54cc\r\n' +<<< b'OK\r\n' +Envoi bloc 151/292 (0x00025800 à 0x00025bff) +>>> b'DATA,0x0400,0xb914ab8f\r\n' +<<< b'OK\r\n' +Envoi bloc 152/292 (0x00025c00 à 0x00025fff) +>>> b'DATA,0x0400,0x79ba480c\r\n' +<<< b'OK\r\n' +Envoi bloc 153/292 (0x00026000 à 0x000263ff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 154/292 (0x00026400 à 0x000267ff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 155/292 (0x00026800 à 0x00026bff) +>>> b'DATA,0x0400,0x261d6cea\r\n' +<<< b'OK\r\n' +Envoi bloc 156/292 (0x00026c00 à 0x00026fff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 157/292 (0x00027000 à 0x000273ff) +>>> b'DATA,0x0400,0xbd079d5d\r\n' +<<< b'OK\r\n' +Envoi bloc 158/292 (0x00027400 à 0x000277ff) +>>> b'DATA,0x0400,0x2fde35b9\r\n' +<<< b'OK\r\n' +Envoi bloc 159/292 (0x00027800 à 0x00027bff) +>>> b'DATA,0x0400,0x0f804b73\r\n' +<<< b'OK\r\n' +Envoi bloc 160/292 (0x00027c00 à 0x00027fff) +>>> b'DATA,0x0400,0xd8f5c66f\r\n' +<<< b'OK\r\n' +Envoi bloc 161/292 (0x00028000 à 0x000283ff) +>>> b'DATA,0x0400,0xc673f60e\r\n' +<<< b'OK\r\n' +Envoi bloc 162/292 (0x00028400 à 0x000287ff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 163/292 (0x00028800 à 0x00028bff) +>>> b'DATA,0x0400,0xff57319f\r\n' +<<< b'OK\r\n' +Envoi bloc 164/292 (0x00028c00 à 0x00028fff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 165/292 (0x00029000 à 0x000293ff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 166/292 (0x00029400 à 0x000297ff) +>>> b'DATA,0x0400,0x1ea86e8c\r\n' +<<< b'OK\r\n' +Envoi bloc 167/292 (0x00029800 à 0x00029bff) +>>> b'DATA,0x0400,0x4c712980\r\n' +<<< b'OK\r\n' +Envoi bloc 168/292 (0x00029c00 à 0x00029fff) +>>> b'DATA,0x0400,0xf1bdce3d\r\n' +<<< b'OK\r\n' +Envoi bloc 169/292 (0x0002a000 à 0x0002a3ff) +>>> b'DATA,0x0400,0x95d3cfd3\r\n' +<<< b'OK\r\n' +Envoi bloc 170/292 (0x0002a400 à 0x0002a7ff) +>>> b'DATA,0x0400,0xdc7ef068\r\n' +<<< b'OK\r\n' +Envoi bloc 171/292 (0x0002a800 à 0x0002abff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 172/292 (0x0002ac00 à 0x0002afff) +>>> b'DATA,0x0400,0x48aee718\r\n' +<<< b'OK\r\n' +Envoi bloc 173/292 (0x0002b000 à 0x0002b3ff) +>>> b'DATA,0x0400,0x3cb0b52c\r\n' +<<< b'OK\r\n' +Envoi bloc 174/292 (0x0002b400 à 0x0002b7ff) +>>> b'DATA,0x0400,0x7c7f908f\r\n' +<<< b'OK\r\n' +Envoi bloc 175/292 (0x0002b800 à 0x0002bbff) +>>> b'DATA,0x0400,0xd8fc6d9c\r\n' +<<< b'OK\r\n' +Envoi bloc 176/292 (0x0002bc00 à 0x0002bfff) +>>> b'DATA,0x0400,0x1341e75e\r\n' +<<< b'OK\r\n' +Envoi bloc 177/292 (0x0002c000 à 0x0002c3ff) +>>> b'DATA,0x0400,0x7c3dbc9c\r\n' +<<< b'OK\r\n' +Envoi bloc 178/292 (0x0002c400 à 0x0002c7ff) +>>> b'DATA,0x0400,0x757ca3fd\r\n' +<<< b'OK\r\n' +Envoi bloc 179/292 (0x0002c800 à 0x0002cbff) +>>> b'DATA,0x0400,0x3cb0b52c\r\n' +<<< b'OK\r\n' +Envoi bloc 180/292 (0x0002cc00 à 0x0002cfff) +>>> b'DATA,0x0400,0x3cb0b52c\r\n' +<<< b'OK\r\n' +Envoi bloc 181/292 (0x0002d000 à 0x0002d3ff) +>>> b'DATA,0x0400,0x647fe3d7\r\n' +<<< b'OK\r\n' +Envoi bloc 182/292 (0x0002d400 à 0x0002d7ff) +>>> b'DATA,0x0400,0x3cb0b52c\r\n' +<<< b'OK\r\n' +Envoi bloc 183/292 (0x0002d800 à 0x0002dbff) +>>> b'DATA,0x0400,0x552c3917\r\n' +<<< b'OK\r\n' +Envoi bloc 184/292 (0x0002dc00 à 0x0002dfff) +>>> b'DATA,0x0400,0xabde84c3\r\n' +<<< b'OK\r\n' +Envoi bloc 185/292 (0x0002e000 à 0x0002e3ff) +>>> b'DATA,0x0400,0xbcd84cfd\r\n' +<<< b'OK\r\n' +Envoi bloc 186/292 (0x0002e400 à 0x0002e7ff) +>>> b'DATA,0x0400,0xc7f7005d\r\n' +<<< b'OK\r\n' +Envoi bloc 187/292 (0x0002e800 à 0x0002ebff) +>>> b'DATA,0x0400,0x0dbd37fa\r\n' +<<< b'OK\r\n' +Envoi bloc 188/292 (0x0002ec00 à 0x0002efff) +>>> b'DATA,0x0400,0x3cb0b52c\r\n' +<<< b'OK\r\n' +Envoi bloc 189/292 (0x0002f000 à 0x0002f3ff) +>>> b'DATA,0x0400,0x0c77f51b\r\n' +<<< b'OK\r\n' +Envoi bloc 190/292 (0x0002f400 à 0x0002f7ff) +>>> b'DATA,0x0400,0x3cb0b52c\r\n' +<<< b'OK\r\n' +Envoi bloc 191/292 (0x0002f800 à 0x0002fbff) +>>> b'DATA,0x0400,0x3cb0b52c\r\n' +<<< b'OK\r\n' +Envoi bloc 192/292 (0x0002fc00 à 0x0002ffff) +>>> b'DATA,0x0400,0xe8a9a1dd\r\n' +<<< b'OK\r\n' +Envoi bloc 193/292 (0x00030000 à 0x000303ff) +>>> b'DATA,0x0400,0x9f59d483\r\n' +<<< b'OK\r\n' +Envoi bloc 194/292 (0x00030400 à 0x000307ff) +>>> b'DATA,0x0400,0x14c1d17d\r\n' +<<< b'OK\r\n' +Envoi bloc 195/292 (0x00030800 à 0x00030bff) +>>> b'DATA,0x0400,0x6c1dcfa0\r\n' +<<< b'OK\r\n' +Envoi bloc 196/292 (0x00030c00 à 0x00030fff) +>>> b'DATA,0x0400,0xf898a883\r\n' +<<< b'OK\r\n' +Envoi bloc 197/292 (0x00031000 à 0x000313ff) +>>> b'DATA,0x0400,0x3cb0b52c\r\n' +<<< b'OK\r\n' +Envoi bloc 198/292 (0x00031400 à 0x000317ff) +>>> b'DATA,0x0400,0x48f9eead\r\n' +<<< b'OK\r\n' +Envoi bloc 199/292 (0x00031800 à 0x00031bff) +>>> b'DATA,0x0400,0x3cb0b52c\r\n' +<<< b'OK\r\n' +Envoi bloc 200/292 (0x00031c00 à 0x00031fff) +>>> b'DATA,0x0400,0x25aaa865\r\n' +<<< b'OK\r\n' +Envoi bloc 201/292 (0x00032000 à 0x000323ff) +>>> b'DATA,0x0400,0x319590be\r\n' +<<< b'OK\r\n' +Envoi bloc 202/292 (0x00032400 à 0x000327ff) +>>> b'DATA,0x0400,0x6df5ac5c\r\n' +<<< b'OK\r\n' +Envoi bloc 203/292 (0x00032800 à 0x00032bff) +>>> b'DATA,0x0400,0x8d8cc48d\r\n' +<<< b'OK\r\n' +Envoi bloc 204/292 (0x00032c00 à 0x00032fff) +>>> b'DATA,0x0400,0xc89c2fd7\r\n' +<<< b'OK\r\n' +Envoi bloc 205/292 (0x00033000 à 0x000333ff) +>>> b'DATA,0x0400,0x05bb6835\r\n' +<<< b'OK\r\n' +Envoi bloc 206/292 (0x00033400 à 0x000337ff) +>>> b'DATA,0x0400,0x3cb0b52c\r\n' +<<< b'OK\r\n' +Envoi bloc 207/292 (0x00033800 à 0x00033bff) +>>> b'DATA,0x0400,0x534c79ab\r\n' +<<< b'OK\r\n' +Envoi bloc 208/292 (0x00033c00 à 0x00033fff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 209/292 (0x00034000 à 0x000343ff) +>>> b'DATA,0x0400,0x0444a8a9\r\n' +<<< b'OK\r\n' +Envoi bloc 210/292 (0x00034400 à 0x000347ff) +>>> b'DATA,0x0400,0xcf45508e\r\n' +<<< b'OK\r\n' +Envoi bloc 211/292 (0x00034800 à 0x00034bff) +>>> b'DATA,0x0400,0x8e06c2c8\r\n' +<<< b'OK\r\n' +Envoi bloc 212/292 (0x00034c00 à 0x00034fff) +>>> b'DATA,0x0400,0xfa4f8566\r\n' +<<< b'OK\r\n' +Envoi bloc 213/292 (0x00035000 à 0x000353ff) +>>> b'DATA,0x0400,0xa4be5b03\r\n' +<<< b'OK\r\n' +Envoi bloc 214/292 (0x00035400 à 0x000357ff) +>>> b'DATA,0x0400,0xefb5af2e\r\n' +<<< b'OK\r\n' +Envoi bloc 215/292 (0x00035800 à 0x00035bff) +>>> b'DATA,0x0400,0x47100cfe\r\n' +<<< b'OK\r\n' +Envoi bloc 216/292 (0x00035c00 à 0x00035fff) +>>> b'DATA,0x0400,0xccfa36dd\r\n' +<<< b'OK\r\n' +Envoi bloc 217/292 (0x00036000 à 0x000363ff) +>>> b'DATA,0x0400,0x53eabdc3\r\n' +<<< b'OK\r\n' +Envoi bloc 218/292 (0x00036400 à 0x000367ff) +>>> b'DATA,0x0400,0xc6f6f848\r\n' +<<< b'OK\r\n' +Envoi bloc 219/292 (0x00036800 à 0x00036bff) +>>> b'DATA,0x0400,0x6bcd01e0\r\n' +<<< b'OK\r\n' +Envoi bloc 220/292 (0x00036c00 à 0x00036fff) +>>> b'DATA,0x0400,0xa61603de\r\n' +<<< b'OK\r\n' +Envoi bloc 221/292 (0x00037000 à 0x000373ff) +>>> b'DATA,0x0400,0xa2598fc5\r\n' +<<< b'OK\r\n' +Envoi bloc 222/292 (0x00037400 à 0x000377ff) +>>> b'DATA,0x0400,0x27a82e49\r\n' +<<< b'OK\r\n' +Envoi bloc 223/292 (0x00037800 à 0x00037bff) +>>> b'DATA,0x0400,0x0b2f921e\r\n' +<<< b'OK\r\n' +Envoi bloc 224/292 (0x00037c00 à 0x00037fff) +>>> b'DATA,0x0400,0x3c5323a1\r\n' +<<< b'OK\r\n' +Envoi bloc 225/292 (0x00038000 à 0x000383ff) +>>> b'DATA,0x0400,0x39c02243\r\n' +<<< b'OK\r\n' +Envoi bloc 226/292 (0x00038400 à 0x000387ff) +>>> b'DATA,0x0400,0x2342ae03\r\n' +<<< b'OK\r\n' +Envoi bloc 227/292 (0x00038800 à 0x00038bff) +>>> b'DATA,0x0400,0x536a74f3\r\n' +<<< b'OK\r\n' +Envoi bloc 228/292 (0x00038c00 à 0x00038fff) +>>> b'DATA,0x0400,0x61348b91\r\n' +<<< b'OK\r\n' +Envoi bloc 229/292 (0x00039000 à 0x000393ff) +>>> b'DATA,0x0400,0x74489bbc\r\n' +<<< b'OK\r\n' +Envoi bloc 230/292 (0x00039400 à 0x000397ff) +>>> b'DATA,0x0400,0xfde3b1df\r\n' +<<< b'OK\r\n' +Envoi bloc 231/292 (0x00039800 à 0x00039bff) +>>> b'DATA,0x0400,0x1d7b4a06\r\n' +<<< b'OK\r\n' +Envoi bloc 232/292 (0x00039c00 à 0x00039fff) +>>> b'DATA,0x0400,0xed5dc596\r\n' +<<< b'OK\r\n' +Envoi bloc 233/292 (0x0003a000 à 0x0003a3ff) +>>> b'DATA,0x0400,0xb522deb3\r\n' +<<< b'OK\r\n' +Envoi bloc 234/292 (0x0003a400 à 0x0003a7ff) +>>> b'DATA,0x0400,0x0896f10b\r\n' +<<< b'OK\r\n' +Envoi bloc 235/292 (0x0003a800 à 0x0003abff) +>>> b'DATA,0x0400,0xb4b63fd3\r\n' +<<< b'OK\r\n' +Envoi bloc 236/292 (0x0003ac00 à 0x0003afff) +>>> b'DATA,0x0400,0x555dd6c6\r\n' +<<< b'OK\r\n' +Envoi bloc 237/292 (0x0003b000 à 0x0003b3ff) +>>> b'DATA,0x0400,0x9fc70584\r\n' +<<< b'OK\r\n' +Envoi bloc 238/292 (0x0003b400 à 0x0003b7ff) +>>> b'DATA,0x0400,0x06d0aedc\r\n' +<<< b'OK\r\n' +Envoi bloc 239/292 (0x0003b800 à 0x0003bbff) +>>> b'DATA,0x0400,0x19f5015b\r\n' +<<< b'OK\r\n' +Envoi bloc 240/292 (0x0003bc00 à 0x0003bfff) +>>> b'DATA,0x0400,0xa9523fd5\r\n' +<<< b'OK\r\n' +Envoi bloc 241/292 (0x0003c000 à 0x0003c3ff) +>>> b'DATA,0x0400,0x46b65734\r\n' +<<< b'OK\r\n' +Envoi bloc 242/292 (0x0003c400 à 0x0003c7ff) +>>> b'DATA,0x0400,0xbf04b212\r\n' +<<< b'OK\r\n' +Envoi bloc 243/292 (0x0003c800 à 0x0003cbff) +>>> b'DATA,0x0400,0xb2bb9e5c\r\n' +<<< b'OK\r\n' +Envoi bloc 244/292 (0x0003cc00 à 0x0003cfff) +>>> b'DATA,0x0400,0x0c7c8dda\r\n' +<<< b'OK\r\n' +Envoi bloc 245/292 (0x0003d000 à 0x0003d3ff) +>>> b'DATA,0x0400,0x0a7d25ac\r\n' +<<< b'OK\r\n' +Envoi bloc 246/292 (0x0003d400 à 0x0003d7ff) +>>> b'DATA,0x0400,0x89a9f3ce\r\n' +<<< b'OK\r\n' +Envoi bloc 247/292 (0x0003d800 à 0x0003dbff) +>>> b'DATA,0x0400,0xb11cc12f\r\n' +<<< b'OK\r\n' +Envoi bloc 248/292 (0x0003dc00 à 0x0003dfff) +>>> b'DATA,0x0400,0xc59de2eb\r\n' +<<< b'OK\r\n' +Envoi bloc 249/292 (0x0003e000 à 0x0003e3ff) +>>> b'DATA,0x0400,0xf0561443\r\n' +<<< b'OK\r\n' +Envoi bloc 250/292 (0x0003e400 à 0x0003e7ff) +>>> b'DATA,0x0400,0xe7af97e4\r\n' +<<< b'OK\r\n' +Envoi bloc 251/292 (0x0003e800 à 0x0003ebff) +>>> b'DATA,0x0400,0x5e3ef771\r\n' +<<< b'OK\r\n' +Envoi bloc 252/292 (0x0003ec00 à 0x0003efff) +>>> b'DATA,0x0400,0xd0eb8e02\r\n' +<<< b'OK\r\n' +Envoi bloc 253/292 (0x0003f000 à 0x0003f3ff) +>>> b'DATA,0x0400,0x90229cba\r\n' +<<< b'OK\r\n' +Envoi bloc 254/292 (0x0003f400 à 0x0003f7ff) +>>> b'DATA,0x0400,0xf0115912\r\n' +<<< b'OK\r\n' +Envoi bloc 255/292 (0x0003f800 à 0x0003fbff) +>>> b'DATA,0x0400,0x56428172\r\n' +<<< b'OK\r\n' +Envoi bloc 256/292 (0x0003fc00 à 0x0003ffff) +>>> b'DATA,0x0400,0x4f1b8f39\r\n' +<<< b'OK\r\n' +Envoi bloc 257/292 (0x00040000 à 0x000403ff) +>>> b'DATA,0x0400,0xc1e1b48c\r\n' +<<< b'OK\r\n' +Envoi bloc 258/292 (0x00040400 à 0x000407ff) +>>> b'DATA,0x0400,0x21f743e0\r\n' +<<< b'OK\r\n' +Envoi bloc 259/292 (0x00040800 à 0x00040bff) +>>> b'DATA,0x0400,0x7a7683bc\r\n' +<<< b'OK\r\n' +Envoi bloc 260/292 (0x00040c00 à 0x00040fff) +>>> b'DATA,0x0400,0xb4f08c87\r\n' +<<< b'OK\r\n' +Envoi bloc 261/292 (0x00041000 à 0x000413ff) +>>> b'DATA,0x0400,0x966ba76b\r\n' +<<< b'OK\r\n' +Envoi bloc 262/292 (0x00041400 à 0x000417ff) +>>> b'DATA,0x0400,0x5a786873\r\n' +<<< b'OK\r\n' +Envoi bloc 263/292 (0x00041800 à 0x00041bff) +>>> b'DATA,0x0400,0x5990bd26\r\n' +<<< b'OK\r\n' +Envoi bloc 264/292 (0x00041c00 à 0x00041fff) +>>> b'DATA,0x0400,0x7fce1c7e\r\n' +<<< b'OK\r\n' +Envoi bloc 265/292 (0x00042000 à 0x000423ff) +>>> b'DATA,0x0400,0x9a254d51\r\n' +<<< b'OK\r\n' +Envoi bloc 266/292 (0x00042400 à 0x000427ff) +>>> b'DATA,0x0400,0xe7922aa5\r\n' +<<< b'OK\r\n' +Envoi bloc 267/292 (0x00042800 à 0x00042bff) +>>> b'DATA,0x0400,0x2efd9b5b\r\n' +<<< b'OK\r\n' +Envoi bloc 268/292 (0x00042c00 à 0x00042fff) +>>> b'DATA,0x0400,0x807332d9\r\n' +<<< b'OK\r\n' +Envoi bloc 269/292 (0x00043000 à 0x000433ff) +>>> b'DATA,0x0400,0x75b40d3f\r\n' +<<< b'OK\r\n' +Envoi bloc 270/292 (0x00043400 à 0x000437ff) +>>> b'DATA,0x0400,0xd0885472\r\n' +<<< b'OK\r\n' +Envoi bloc 271/292 (0x00043800 à 0x00043bff) +>>> b'DATA,0x0400,0x8c59c72d\r\n' +<<< b'OK\r\n' +Envoi bloc 272/292 (0x00043c00 à 0x00043fff) +>>> b'DATA,0x0400,0xf3fe1e75\r\n' +<<< b'OK\r\n' +Envoi bloc 273/292 (0x00044000 à 0x000443ff) +>>> b'DATA,0x0400,0x48c349af\r\n' +<<< b'OK\r\n' +Envoi bloc 274/292 (0x00044400 à 0x000447ff) +>>> b'DATA,0x0400,0x1aceeecf\r\n' +<<< b'OK\r\n' +Envoi bloc 275/292 (0x00044800 à 0x00044bff) +>>> b'DATA,0x0400,0xabf3b4ce\r\n' +<<< b'OK\r\n' +Envoi bloc 276/292 (0x00044c00 à 0x00044fff) +>>> b'DATA,0x0400,0x06e5a042\r\n' +<<< b'OK\r\n' +Envoi bloc 277/292 (0x00045000 à 0x000453ff) +>>> b'DATA,0x0400,0x2a56de6b\r\n' +<<< b'OK\r\n' +Envoi bloc 278/292 (0x00045400 à 0x000457ff) +>>> b'DATA,0x0400,0xf253173d\r\n' +<<< b'OK\r\n' +Envoi bloc 279/292 (0x00045800 à 0x00045bff) +>>> b'DATA,0x0400,0xca83a9b9\r\n' +<<< b'OK\r\n' +Envoi bloc 280/292 (0x00045c00 à 0x00045fff) +>>> b'DATA,0x0400,0x8721bea2\r\n' +<<< b'OK\r\n' +Envoi bloc 281/292 (0x00046000 à 0x000463ff) +>>> b'DATA,0x0400,0x14955fd4\r\n' +<<< b'OK\r\n' +Envoi bloc 282/292 (0x00046400 à 0x000467ff) +>>> b'DATA,0x0400,0x2aec8a44\r\n' +<<< b'OK\r\n' +Envoi bloc 283/292 (0x00046800 à 0x00046bff) +>>> b'DATA,0x0400,0x2aec8a44\r\n' +<<< b'OK\r\n' +Envoi bloc 284/292 (0x00046c00 à 0x00046fff) +>>> b'DATA,0x0400,0x2aec8a44\r\n' +<<< b'OK\r\n' +Envoi bloc 285/292 (0x00047000 à 0x000473ff) +>>> b'DATA,0x0400,0x2aec8a44\r\n' +<<< b'OK\r\n' +Envoi bloc 286/292 (0x00047400 à 0x000477ff) +>>> b'DATA,0x0400,0xcc9f7252\r\n' +<<< b'OK\r\n' +Envoi bloc 287/292 (0x00047800 à 0x00047bff) +>>> b'DATA,0x0400,0x79303db9\r\n' +<<< b'OK\r\n' +Envoi bloc 288/292 (0x00047c00 à 0x00047fff) +>>> b'DATA,0x0400,0x6e24d3bc\r\n' +<<< b'OK\r\n' +Envoi bloc 289/292 (0x00048000 à 0x000483ff) +>>> b'DATA,0x0400,0x26003be4\r\n' +<<< b'OK\r\n' +Envoi bloc 290/292 (0x00048400 à 0x000487ff) +>>> b'DATA,0x0400,0x1acf3ad9\r\n' +<<< b'OK\r\n' +Envoi bloc 291/292 (0x00048800 à 0x00048bff) +>>> b'DATA,0x0400,0xd07c4f3d\r\n' +<<< b'OK\r\n' +Envoi bloc 292/292 (0x00048c00 à 0x00048f3f) +>>> b'DATA,0x0340,0x86335944\r\n' +<<< b'OK\r\n' +>>> b'CHECK\r\n' +<<< b'OK\r\n' +Vérification OK + diff --git a/mylab2-programmer.py b/mylab2-programmer.py new file mode 100644 index 0000000..9d68611 --- /dev/null +++ b/mylab2-programmer.py @@ -0,0 +1,209 @@ +''' +Script de programmation pour le bootloader myLab2 du cours MIP + +Christian Abegg, HEPIA +''' + + +import argparse +import binascii +import sys +try: + import serial +except: + print("pyserial est requis: pip3 install pyserial") + +DEFAULT_PORT = '/dev/ttyUSB0' +BL_ERR_CODE = {'0': 'Success', 1: 'Erreur générale', '2': 'Commande invalide', + '3': 'Checksum global incorrect', '4': 'Checksum de bloc incorrect', + '5': 'Erreur lors de l’effacement', '6': 'Erreur lors de l’écriture', + '7': 'Taille des données invalide', '8': 'Offset invalide', + '9': 'Argument(s) invalide(s)', + '99': 'Pas de réponse'} +LPC1769_PARTID = 0x26113f37 +LPC1769_FLASH_SIZE = 0x80000 +APP_OFFSET = 0x4000 +MAX_PROG_SIZE = LPC1769_FLASH_SIZE - APP_OFFSET + +def show_error(error_code): + if error_code != 0: + return "Erreur {} lors de la commande: {}".format(error_code, BL_ERR_CODE.get(error_code, '---')) + +def raise_error(error_code): + raise Exception(show_error(error_code)) + +class MyLab2: + def __init__(self, serialport, verbose=False, timeout=1): + self.v = verbose + self.connected = False + if timeout == -1: + self.timeout = 0 + elif timeout == 0: + self.timeout = None + else: + self.timeout = timeout + try: + self.port = serial.Serial(serialport, baudrate=115200, bytesize=8, + stopbits=1, parity=serial.PARITY_NONE, timeout=self.timeout) + + # Empty buffer in case some char are left in FTDI device + self.port.timeout = 0.01 + for i in range(16): + self.port.read() + self.port.timeout = self.timeout + + self.partid = self.get_part_id() + self.serial = self.get_serial() + if self.partid and self.serial: + self.connected = True + + except Exception as e: + print("Impossible d'établir la connexion à la carte: {}".format(e)) + self.port = None + self.connected = False + if sys.platform.startswith('win') and 'PermissionError' in str(e): + print("Windows refuse l'accès au port série spécifié. " + "Vérifiez que vous n'avez pas d'autres applications qui utilisent ce port.") + + def run_cmd(self, cmd, wait_answer=True): + send_buf = "{}\r\n".format(cmd).encode() + if self.v: print(">>> {}".format(send_buf)) + self.port.write(send_buf) + self.last_cmd = cmd + if not wait_answer: + return 0, None + retcode = self.port.readline() + if self.v: print("<<< {}".format(retcode)) + retcode = retcode.strip().decode() + if retcode == "OK": + # Read answer + if cmd.startswith("GETID") or cmd.startswith("GETSERIAL"): + retvalue = self.port.readline() + if self.v: print("<<< {}".format(retvalue)) + return 0, retvalue.strip().decode() + else: + return 0, None + else: + if not retcode: + return '99', None + err = retcode.split(",")[-1] + return err, None + + def get_answer(self): + retcode = self.port.readline() + if self.v: print("<<< {}".format(retcode)) + retcode = retcode.strip().decode() + if retcode == "OK": + return 0, None + else: + if not retcode: + return '99', None + err = retcode.split(",")[-1] + return err, None + + def get_part_id(self): + code, val = self.run_cmd("GETID") + return val + + def get_serial(self): + code, val = self.run_cmd("GETSERIAL") + return val + + def write_program(self, filename, blocksize=1024, fuzzing=False): + if not self.partid or int(self.partid, 16) != LPC1769_PARTID: + raise Exception("Part id non reconnu: {}".format(self.partid)) + try: + with open(filename, 'rb') as file: + bindata = file.read() + except Exception as e: + print("Impossible d'ouvrir le fichier '{}': {}".format(filename, e)) + return + + if len(bindata) > MAX_PROG_SIZE: + raise Exception("Taille du fichier binaire trop grande: {} (le maximum est de {})".format(len(bindata), + MAX_PROG_SIZE)) + + binfile_crc = binascii.crc32(bindata) + binfile_length = len(bindata) + nb_blocs = binfile_length//blocksize + 1 + print("Envoi {} à la myLab2, taille: {}, CRC32: {}, bs={}".format(filename, + binfile_length, + hex(binfile_crc), + blocksize)) + _r, _ = self.run_cmd("PROG,0x{:08x},0x{:08x},0x{:08x}".format(APP_OFFSET, binfile_length, binfile_crc)) + if _r: + raise_error(_r) + remaining_size = binfile_length + position = 0 + for block in range(nb_blocs): + if remaining_size < blocksize: + blocksize = remaining_size + blockcrc = binascii.crc32(bindata[position:(position+blocksize)]) + if self.v: + print("Envoi bloc {:3d}/{:3d} (0x{:08x} à 0x{:08x})".format(block+1, nb_blocs, + position, + position + blocksize - 1)) + else: + print("\r{:3d}% ".format(int(position / binfile_length * 100)), end='') + self.run_cmd("DATA,0x{:04x},0x{:08x}".format(blocksize, blockcrc), wait_answer=False) + + # send the data + blockdata = bindata[position:(position + blocksize)] + is_fuzz = False + if fuzzing and block == 3: + # TODO: Meilleur fuzzing + blockdata = b'\x02' + bindata[position+1:(position+blocksize)] + is_fuzz = True + self.port.write(blockdata) + _r, _ = self.get_answer() + if _r: + print(show_error(_r)) + if is_fuzz: + print("Note: le fuzzing était actif sur ce bloc") + return + if is_fuzz: + print("!!! Fuzzing actif lors de l'envoi de ce bloc, mais la carte a quand même validé le CRC !!!") + # if ok.... + position += blocksize + remaining_size -= blocksize + if not self.v: + print("\r{:3d}% ".format(int(position/binfile_length*100)), end='') + + if not self.v: + print() + _r, _ = self.run_cmd("CHECK") + if _r: + raise_error(_r) + else: + print("Vérification OK") + + def __str__(self): + if not self.connected: + return "Pas de connexion au bootloader myLab2-MIP" + return "Connecté au bootloader myLab2-MIP:\nPartID: {}\nSerial: {}".format(self.partid, + self.serial) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Programmeur pour bootloader myLab2 MIP') + parser.add_argument('--port', default=DEFAULT_PORT, + help='Port série à utiliser pour la communication, "{}" par défaut'.format(DEFAULT_PORT)) + parser.add_argument('--fuzzing', action="store_true", + help='Introduit des erreurs lors de la programmation') + parser.add_argument('--verbose', dest="verbose", action="store_true", + help='Mode verbeux') + parser.add_argument('binfile', default='', + help='Programme à écrire, au format bin') + parser.add_argument('--blksize', default=1024, type=int, + help='Taille des blocs lors de l\'envoi') + parser.add_argument('--timeout', default=2, type=int, + help='Durée en secondes après laquelle la réponse doit être reçue. 0=attente infinie') + args = parser.parse_args() + ml2 = MyLab2(args.port, verbose=args.verbose, timeout=args.timeout) + print(ml2) + if not ml2.connected: + sys.exit(1) + try: + ml2.write_program(args.binfile, blocksize=args.blksize, fuzzing=args.fuzzing) + except Exception as e: + print("Erreur lors de la programmation: {}".format(e)) diff --git a/sonic_50b03eb0.bin b/sonic_50b03eb0.bin new file mode 100644 index 0000000..f497d51 Binary files /dev/null and b/sonic_50b03eb0.bin differ diff --git a/uart.c b/uart.c new file mode 100644 index 0000000..7923f1d --- /dev/null +++ b/uart.c @@ -0,0 +1,62 @@ +/* + * uart.c + * + * Created on: 15 Mar 2022 + * Author: pika + */ + +#include "uart.h" +#ifdef __USE_CMSIS +#include "LPC17xx.h" +#endif + + + +void uart_init(uint32_t baudrate){ + LPC_SC->PCLKSEL0 &= ~(3<<6); + + LPC_SC->PCLKSEL0 |= 1<<6; // pclk set to 100 MHz + + LPC_PINCON->PINSEL0 |= (1<<4); //TXD0 + + LPC_PINCON->PINSEL0 |= (1<<6); //RXD0 + + + uint32_t Fdiv = (UART_PCLK)/(16*baudrate); + LPC_UART0->LCR = 0x83; + LPC_UART0->DLM = (Fdiv>>8)&0xff; + LPC_UART0->DLL = Fdiv&0xff; + + LPC_UART0->LCR = 0x3; + LPC_UART0->FCR = 0x07|(2<<6);//(2<<6) to active RX trigger level +} + +void uart_send(char* buff, uint32_t length){ + int tmp; + while (length-- != 0 ){ + LPC_UART0->THR = *buff++; + while(((LPC_UART0->LSR)&(1<<5)) == 0);//stuck in while when U1THR contains valid data + tmp = LPC_UART0->RBR; + LPC_GPIO2->FIOCLR = 0xff; + LPC_GPIO2->FIOSET = tmp; + } + +} + +void uart_receive_command(char* chara){ + char* curr = chara; + while(strncmp(curr, "\r\n", 2) != 0){ + while(((LPC_UART0->LSR)&(1)) == 0); + *curr = LPC_UART0->RBR; + if(strncmp(curr, "\r\n", 2) != 0) curr++; + } +} + +void uart_receive_data(uint8_t* chara){ + uint8_t* curr = chara; + while(*curr != '\0'){ + while(((LPC_UART0->LSR)&(1)) == 0); + *curr = LPC_UART0->RBR; + curr++; + } +} diff --git a/uart.h b/uart.h new file mode 100644 index 0000000..c54416f --- /dev/null +++ b/uart.h @@ -0,0 +1,59 @@ +/* + * uart.h + * + * Created on: 15 Mar 2022 + * Author: pika + */ + +#ifndef UART_H_ +#define UART_H_ + +#ifndef __SYSTEM_LPC17xx_H +#define __SYSTEM_LPC17xx_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __USE_CMSIS +#include "LPC17xx.h" +#endif + +#include +#include + +#endif /* __SYSTEM_LPC17xx_H */ + +#define DLAB_SET LPC_UART1->LCR |= (1<<7) //DLAB == 1 +#define DLAB_CLR LPC_UART1->LCR &= ~(1<<7) //DLAB == 0 //not needed + +#define SIZE_OF_BUFFER 8 +#define UART_PCLK (100000000) + +typedef struct circbuff_t{ +uint8_t data[SIZE_OF_BUFFER]; +uint16_t ptr_write; +uint16_t ptr_read; +} circbuff; + + + +void uart_init(uint32_t baudrate); + +void uart_send(char* buff, uint32_t length); + +void uart_receive_command(char* chara); + +void uart_receive_data(uint8_t* chara); + + +#define THRE (1<<5) +#define MULVAL 15 +#define DIVADDVAL 2 +#define Ux_FIFO_EN (1<<0) +#define RX_FIFO_RST (1<<1) +#define TX_FIFO_RST (1<<2) +#define DLAB_BIT (1<<7) +#define CARRIAGE_RETURN 0x0D + +#endif /* UART_H_ */ diff --git a/uart_commands.c b/uart_commands.c new file mode 100644 index 0000000..fef33a4 --- /dev/null +++ b/uart_commands.c @@ -0,0 +1,105 @@ +#include "uart_commands.h" + +static uint8_t data[4096]; + +char OK[4] = "OK\r\n"; +char ERR[5] = "ERR\r\n"; + +void uart_commands_getid(error_code* status){ + char hex[15]; + uint32_t res = iap_read_part_id(status); + sprintf(hex, "0x%x\r\n", res); + if(*status == 0){ + uart_send(OK, 5); + uart_send(hex, 12); + } +} + + +void uart_commands_getserial(error_code* status){ + char hex[40]; + uint32_t res[4]; + iap_read_serial(status, res); + sprintf(hex, "0x%x%x%x%x\r\n", res[0], res[1], res[2], res[3]); + if(*status == 0){ + uart_send(OK, 5); + uart_send(hex, 35); + } +} + +crc_t uart_commands_prog(void){ + return crc_init(); + uart_send(OK, 5); +} + +void uart_commands_data(error_code* status, int size, crc_t* checksum_global, crc_t checksum_loc, int offset){ + uart_receive_data(data); + crc_t checksum_tmp = crc_init(); + checksum_tmp = crc_update(checksum_tmp, data, size); + if(checksum_loc == checksum_tmp){ + int tmp = size; + while(tmp > 4096){ + iap_copy_to_flash(status, offset, &checksum_loc, 4096); + if(*status != ok){ + uart_send(ERR, 6); + } + tmp = tmp - 4096; + } + while(tmp > 1024){ + iap_copy_to_flash(status, offset, &checksum_loc, 1024); + if(*status != ok){ + uart_send(ERR, 6); + } + tmp = tmp - 1024; + } + while(tmp > 512){ + iap_copy_to_flash(status, offset, &checksum_loc, 512); + if(*status != ok){ + uart_send(ERR, 6); + } + tmp = tmp - 512; + } + while(tmp > 256){ + iap_copy_to_flash(status, offset, &checksum_loc, 256); + if(*status != ok){ + uart_send(ERR, 6); + } + tmp = tmp - 256; + } + *checksum_global = crc_update(*checksum_global, data, size); + }else{ + uart_send(ERR, 6); + } +} + + +// return: -1 in case of ERR otherwise 0. +int uart_parse_command(char *user_input, cmd_t *cmd) { + + //Initialize a simple command (empty, simple, foreground) + cmd->argv = NULL; + cmd->argc = -1; + + //Separate string in different token (i.e. command name + params + &) + do { + //A new element will be added + cmd->argc += 1; + + //Allocate a new pointer on char for next argv element + if((cmd->argv = realloc(cmd->argv, (cmd->argc+1)*sizeof(char*))) == NULL) + perror("uart_parse_command::realloc"); + + //Get the adress of the next token (could be NULL to indicate end of argv) + cmd->argv[cmd->argc] = strtok(user_input, DELIMIERS); + user_input = NULL; //Useless to execute it each time but easier than having two different strtok calls + } while (cmd->argv[cmd->argc] != NULL); // while there are still tokens + + + return 0; +} + +uint32_t uart_string_to_int(const char *str) { + // Convert input in port number + unsigned long int hex = strtoul(str, NULL, 16); + return hex; +} diff --git a/uart_commands.h b/uart_commands.h new file mode 100644 index 0000000..840b701 --- /dev/null +++ b/uart_commands.h @@ -0,0 +1,30 @@ +#include +#include +#include + +#include "uart.h" +#include "iap.h" +#include "crc.h" + +#define DELIMIERS "," + + + + +typedef struct cmd { + char** argv; // a first command splitted as arguments in the argv style + int argc; // number of arguments in the first command +} cmd_t; + + +void uart_commands_getid(error_code* status); + +void uart_commands_getserial(error_code* status); + +crc_t uart_commands_prog(void); + +void uart_commands_data(error_code* status, int size, crc_t* checksum_global, crc_t checksum_loc, int offset); + +int uart_parse_command(char *user_input, cmd_t *cmd); + +uint32_t uart_string_to_int(const char* str);