From 2fb2ef54ce4685331b35dab02eea0e7447560cf8 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Wed, 13 Oct 2021 15:39:36 +0300 Subject: [PATCH] Calculate properly Firmware MSC fat table sectors --- cores/esp32/FirmwareMSC.cpp | 1 + cores/esp32/firmware_msc_fat.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cores/esp32/FirmwareMSC.cpp b/cores/esp32/FirmwareMSC.cpp index e4703f96e..e869cbef0 100644 --- a/cores/esp32/FirmwareMSC.cpp +++ b/cores/esp32/FirmwareMSC.cpp @@ -113,6 +113,7 @@ static size_t msc_update_get_required_disk_sectors(){ log_d("USING FAT12"); mcs_is_fat16 = false; } + log_d("FAT sector size: %u", DISK_SECTOR_SIZE); log_d("FAT data sectors: %u", data_sectors); log_d("FAT table sectors: %u", msc_table_sectors); log_d("FAT total sectors: %u (%uKB)", total_sectors, (total_sectors * DISK_SECTOR_SIZE) / 1024); diff --git a/cores/esp32/firmware_msc_fat.c b/cores/esp32/firmware_msc_fat.c index 6dd74ef3b..30a1a64ea 100644 --- a/cores/esp32/firmware_msc_fat.c +++ b/cores/esp32/firmware_msc_fat.c @@ -39,7 +39,7 @@ static const char * FAT12_FILE_SYSTEM_TYPE = "FAT12"; static uint16_t fat12_sectors_per_alloc_table(uint32_t sector_num){ uint32_t required_bytes = (((sector_num * 3)+1)/2); - return (required_bytes / DISK_SECTOR_SIZE) + ((required_bytes & DISK_SECTOR_SIZE)?1:0); + return (required_bytes / DISK_SECTOR_SIZE) + ((required_bytes & (DISK_SECTOR_SIZE - 1))?1:0); } static uint8_t * fat12_add_table(uint8_t * dst, fat_boot_sector_t * boot){ @@ -68,7 +68,7 @@ static const char * FAT16_FILE_SYSTEM_TYPE = "FAT16"; static uint16_t fat16_sectors_per_alloc_table(uint32_t sector_num){ uint32_t required_bytes = sector_num * 2; - return (required_bytes / DISK_SECTOR_SIZE) + ((required_bytes & DISK_SECTOR_SIZE)?1:0); + return (required_bytes / DISK_SECTOR_SIZE) + ((required_bytes & (DISK_SECTOR_SIZE - 1))?1:0); } static uint8_t * fat16_add_table(uint8_t * dst, fat_boot_sector_t * boot){ @@ -129,7 +129,7 @@ fat_boot_sector_t * fat_add_boot_sector(uint8_t * dst, uint16_t sector_num, uint boot->num_heads = 1; boot->hidden_sectors_count = 0; boot->total_sectors_32 = 0; - boot->physical_drive_number = 0x00; + boot->physical_drive_number = 0x80; boot->reserved0 = 0x00; boot->extended_boot_signature = 0x29; boot->serial_number = serial_number; -- GitLab