Fixes #1793 - cp won't work on some Linux distributions
This commit is contained in:
@@ -38,7 +38,7 @@ void CopyProcess::onTimer()
|
|||||||
|
|
||||||
if (sourceFile.open(QIODevice::ReadOnly)) {
|
if (sourceFile.open(QIODevice::ReadOnly)) {
|
||||||
QFile destinationFile(destination);
|
QFile destinationFile(destination);
|
||||||
if (destinationFile.open(QIODevice::WriteOnly)) {
|
if (destinationFile.open(QIODevice::ReadWrite)) {
|
||||||
progress->addText(tr("Writing file: "));
|
progress->addText(tr("Writing file: "));
|
||||||
for (int i=0; i<blocks; i++) {
|
for (int i=0; i<blocks; i++) {
|
||||||
int read = sourceFile.read(buf, BLKSIZE);
|
int read = sourceFile.read(buf, BLKSIZE);
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ const unsigned char STORAGE_Inquirydata[] = {//36
|
|||||||
};
|
};
|
||||||
|
|
||||||
#if defined(BOOT)
|
#if defined(BOOT)
|
||||||
int32_t fat12Write( const uint8_t *buffer, uint16_t sector, uint32_t count ) ;
|
int32_t fat12Write( const uint8_t *buffer, uint16_t sector, uint16_t count ) ;
|
||||||
int32_t fat12Read( uint8_t *buffer, uint16_t sector, uint16_t count ) ;
|
int32_t fat12Read( uint8_t *buffer, uint16_t sector, uint16_t count ) ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -158,7 +158,7 @@ int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_si
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if (!SD_CARD_PRESENT())
|
if (!SD_CARD_PRESENT())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@@ -744,10 +744,15 @@ int32_t fat12Read( uint8_t *buffer, uint16_t sector, uint16_t count )
|
|||||||
return 0 ;
|
return 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t fat12Write(const uint8_t *buffer, uint16_t sector, uint32_t count )
|
int32_t fat12Write(const uint8_t *buffer, uint16_t sector, uint16_t count)
|
||||||
{
|
{
|
||||||
static uint8_t eepromOffset = 0;
|
enum FatWriteOperation {
|
||||||
static uint8_t firmwareAllowed = 0;
|
FATWRITE_NONE,
|
||||||
|
FATWRITE_EEPROM,
|
||||||
|
FATWRITE_FIRMWARE
|
||||||
|
};
|
||||||
|
|
||||||
|
static unsigned int operation = FATWRITE_NONE;
|
||||||
|
|
||||||
TRACE("FAT12 Write(sector=%d, count=%d)", sector, count);
|
TRACE("FAT12 Write(sector=%d, count=%d)", sector, count);
|
||||||
|
|
||||||
@@ -755,20 +760,21 @@ int32_t fat12Write(const uint8_t *buffer, uint16_t sector, uint32_t count )
|
|||||||
// reserved, read-only
|
// reserved, read-only
|
||||||
}
|
}
|
||||||
else if (sector < 3 + (EESIZE/BLOCKSIZE)) {
|
else if (sector < 3 + (EESIZE/BLOCKSIZE)) {
|
||||||
|
// eeprom
|
||||||
while (count) {
|
while (count) {
|
||||||
if (eepromOffset == 0 && isEepromStart(buffer)) {
|
if (operation == FATWRITE_NONE && isEepromStart(buffer)) {
|
||||||
TRACE("EEPROM start found in sector %d", sector);
|
TRACE("EEPROM start found in sector %d", sector);
|
||||||
eepromOffset = sector;
|
operation = FATWRITE_EEPROM;
|
||||||
}
|
}
|
||||||
if (eepromOffset && sector >= eepromOffset && (sector-eepromOffset) < EESIZE/BLOCKSIZE) {
|
if (operation == FATWRITE_EEPROM) {
|
||||||
eeWriteBlockCmp((uint8_t *)buffer, (sector-eepromOffset)*BLOCKSIZE, BLOCKSIZE);
|
eeWriteBlockCmp((uint8_t *)buffer, (sector-3)*BLOCKSIZE, BLOCKSIZE);
|
||||||
}
|
}
|
||||||
buffer += BLOCKSIZE;
|
buffer += BLOCKSIZE;
|
||||||
sector++;
|
sector++;
|
||||||
count--;
|
count--;
|
||||||
if (sector-eepromOffset >= EESIZE/BLOCKSIZE) {
|
if (sector-3 >= (EESIZE/BLOCKSIZE)) {
|
||||||
TRACE("EEPROM end written at sector %d", sector-1);
|
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 = sector - 3 - (EESIZE/BLOCKSIZE);
|
||||||
address *= BLOCKSIZE;
|
address *= BLOCKSIZE;
|
||||||
address += FIRMWARE_ADDRESS;
|
address += FIRMWARE_ADDRESS;
|
||||||
|
|
||||||
while (count) {
|
while (count) {
|
||||||
for (uint32_t i=0; i<BLOCKSIZE/FLASH_PAGESIZE; i++) {
|
for (uint32_t i=0; i<BLOCKSIZE/FLASH_PAGESIZE; i++) {
|
||||||
if (address >= FIRMWARE_ADDRESS+BOOTLOADER_SIZE/*protect bootloader*/ && address <= FIRMWARE_ADDRESS+FLASHSIZE-FLASH_PAGESIZE) {
|
if (address >= FIRMWARE_ADDRESS+BOOTLOADER_SIZE/*protect bootloader*/ && address <= FIRMWARE_ADDRESS+FLASHSIZE-FLASH_PAGESIZE) {
|
||||||
if (address == FIRMWARE_ADDRESS+BOOTLOADER_SIZE) {
|
if (address == FIRMWARE_ADDRESS+BOOTLOADER_SIZE && isFirmwareStart(buffer)) {
|
||||||
firmwareAllowed = 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);
|
writeFlash((uint32_t *)address, (uint32_t *)buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
address += FLASH_PAGESIZE;
|
address += FLASH_PAGESIZE;
|
||||||
buffer += FLASH_PAGESIZE;
|
buffer += FLASH_PAGESIZE;
|
||||||
}
|
}
|
||||||
|
sector++;
|
||||||
count--;
|
count--;
|
||||||
|
if (sector-3-(EESIZE/BLOCKSIZE) >= (FLASHSIZE/BLOCKSIZE)) {
|
||||||
|
TRACE("FIRMWARE end written at sector %d", sector-1);
|
||||||
|
operation = FATWRITE_NONE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0 ;
|
return 0 ;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
|
||||||
|
|||||||
Reference in New Issue
Block a user