signed FlashDevice2 (struct plc * plc) { uint32_t options = (PLC_COMMIT_FORCE | PLC_COMMIT_NORESET | PLC_COMMIT_FACTPIB); if (plc->CFG.file != -1) { if (FlashSoftloader (plc, options)) { return (-1); } } if ((plc->NVM.file != -1) && (plc->PIB.file != -1)) { if (FlashFirmware (plc, options)) { return (-1); } return (0); } if (plc->PIB.file != -1) { if (FlashParameters (plc, options)) { return (-1); } return (0); } return (0); }
//------------------------------------------------------------------------------ // Copy flash function to RAM. //------------------------------------------------------------------------------ void Upgrade(void) { unsigned char *flash_start_ptr; // Initialize pointers unsigned char *flash_end_ptr; unsigned char *RAM_start_ptr; if (CheckUpgrade() != 0xff) return; //Initialize flash and ram start and end address flash_start_ptr = (unsigned char *)__segment_begin("FLASHCODE"); flash_end_ptr = (unsigned char *)__segment_end("FLASHCODE"); RAM_start_ptr = (unsigned char *)__segment_begin("RAMCODE"); //calculate function size unsigned long function_size = (unsigned long)(flash_end_ptr) - (unsigned long)(flash_start_ptr); // Copy flash function to RAM printf("Copy From %p to %p size=%ld\n", flash_start_ptr, RAM_start_ptr, function_size); memcpy(RAM_start_ptr,flash_start_ptr,function_size); motor_on(0, 0); printf("Jump to %p\n", FlashFirmware); // remove the flag of firmware struct _header h; SPI_FLASH_BufferRead((void*)&h, FIRMWARE_BASE, sizeof(h)); SPI_FLASH_BufferWrite((void*)&h, FIRMWARE_BASE + h.length + 2 * sizeof(h), sizeof(h)); FlashFirmware(); }