From 1d7740ef4c28d8b393baedf54a81e3fc257997b4 Mon Sep 17 00:00:00 2001 From: bsongis Date: Sun, 4 Jan 2015 15:50:57 +0100 Subject: [PATCH] Fixes #1793 - cp won't work on some Linux distributions --- companion/src/process_copy.cpp | 2 +- .../src/targets/taranis/usbd_storage_msd.cpp | 42 ++++++++++++------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/companion/src/process_copy.cpp b/companion/src/process_copy.cpp index e1aa3ed4e..5c0f41791 100755 --- a/companion/src/process_copy.cpp +++ b/companion/src/process_copy.cpp @@ -38,7 +38,7 @@ void CopyProcess::onTimer() if (sourceFile.open(QIODevice::ReadOnly)) { QFile destinationFile(destination); - if (destinationFile.open(QIODevice::WriteOnly)) { + if (destinationFile.open(QIODevice::ReadWrite)) { progress->addText(tr("Writing file: ")); for (int i=0; i= eepromOffset && (sector-eepromOffset) < EESIZE/BLOCKSIZE) { - eeWriteBlockCmp((uint8_t *)buffer, (sector-eepromOffset)*BLOCKSIZE, BLOCKSIZE); + if (operation == FATWRITE_EEPROM) { + eeWriteBlockCmp((uint8_t *)buffer, (sector-3)*BLOCKSIZE, BLOCKSIZE); } buffer += BLOCKSIZE; sector++; count--; - if (sector-eepromOffset >= EESIZE/BLOCKSIZE) { + if (sector-3 >= (EESIZE/BLOCKSIZE)) { TRACE("EEPROM end written at sector %d", sector-1); - eepromOffset = 0; + operation = FATWRITE_NONE; } } } @@ -778,24 +784,28 @@ int32_t fat12Write(const uint8_t *buffer, uint16_t sector, uint32_t count ) address = sector - 3 - (EESIZE/BLOCKSIZE); address *= BLOCKSIZE; address += FIRMWARE_ADDRESS; - while (count) { for (uint32_t i=0; i= FIRMWARE_ADDRESS+BOOTLOADER_SIZE/*protect bootloader*/ && address <= FIRMWARE_ADDRESS+FLASHSIZE-FLASH_PAGESIZE) { - if (address == FIRMWARE_ADDRESS+BOOTLOADER_SIZE) { - firmwareAllowed = isFirmwareStart(buffer); + if (address == FIRMWARE_ADDRESS+BOOTLOADER_SIZE && isFirmwareStart(buffer)) { + TRACE("FIRMWARE start found in sector %d", sector); + operation = FATWRITE_FIRMWARE; } - if (firmwareAllowed) { + if (operation == FATWRITE_FIRMWARE) { writeFlash((uint32_t *)address, (uint32_t *)buffer); } } address += FLASH_PAGESIZE; buffer += FLASH_PAGESIZE; } + sector++; count--; + if (sector-3-(EESIZE/BLOCKSIZE) >= (FLASHSIZE/BLOCKSIZE)) { + TRACE("FIRMWARE end written at sector %d", sector-1); + operation = FATWRITE_NONE; + } } } return 0 ; } #endif -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/