mirror of
				https://github.com/mfulz/qmk_firmware.git
				synced 2025-10-31 05:12:33 +01:00 
			
		
		
		
	FAT heuristics mean a disk as small as the one emulated in the incomplete Mass Storage bootloader *must* be FAT12, not FAT16. Update to use a FAT12 cluster chain.
This commit is contained in:
		
							parent
							
								
									6da1677bc3
								
							
						
					
					
						commit
						f00754ed97
					
				| @ -42,15 +42,15 @@ static const FATBootBlock_t BootBlock = | |||||||
| 		.TotalSectors16          = LUN_MEDIA_BLOCKS, | 		.TotalSectors16          = LUN_MEDIA_BLOCKS, | ||||||
| 		.MediaDescriptor         = 0xF8, | 		.MediaDescriptor         = 0xF8, | ||||||
| 		.SectorsPerFAT           = 1, | 		.SectorsPerFAT           = 1, | ||||||
| 		.SectorsPerTrack         = 32, | 		.SectorsPerTrack         = LUN_MEDIA_BLOCKS % 64, | ||||||
| 		.Heads                   = 64, | 		.Heads                   = LUN_MEDIA_BLOCKS / 64, | ||||||
| 		.HiddenSectors           = 0, | 		.HiddenSectors           = 0, | ||||||
| 		.TotalSectors32          = 0, | 		.TotalSectors32          = 0, | ||||||
| 		.PhysicalDriveNum        = 0, | 		.PhysicalDriveNum        = 0, | ||||||
| 		.ExtendedBootRecordSig   = 0x29, | 		.ExtendedBootRecordSig   = 0x29, | ||||||
| 		.VolumeSerialNumber      = 0x12345678, | 		.VolumeSerialNumber      = 0x12345678, | ||||||
| 		.VolumeLabel             = "LUFA BOOT  ", | 		.VolumeLabel             = "LUFA BOOT  ", | ||||||
| 		.FilesystemIdentifier    = "FAT16   ", | 		.FilesystemIdentifier    = "FAT12   ", | ||||||
| 		.BootstrapProgram        = {0}, | 		.BootstrapProgram        = {0}, | ||||||
| 		.MagicSignature          = 0xAA55, | 		.MagicSignature          = 0xAA55, | ||||||
| 	}; | 	}; | ||||||
| @ -67,7 +67,6 @@ static FATDirectoryEntry_t FirmwareFileEntry = | |||||||
| 		.FileSizeBytes   = 2049, | 		.FileSizeBytes   = 2049, | ||||||
| 	}; | 	}; | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| static void WriteBlock(uint16_t BlockNumber) | static void WriteBlock(uint16_t BlockNumber) | ||||||
| { | { | ||||||
| 	uint8_t BlockBuffer[512]; | 	uint8_t BlockBuffer[512]; | ||||||
| @ -83,6 +82,23 @@ static void WriteBlock(uint16_t BlockNumber) | |||||||
| 	// TODO: Write to FLASH
 | 	// TODO: Write to FLASH
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void WriteFAT12ClusterEntry(uint8_t* FATTable, uint8_t Index, uint16_t NextEntry) | ||||||
|  | { | ||||||
|  | 	uint8_t StartOffset = ((uint16_t)Index * 3) / 2; | ||||||
|  | 
 | ||||||
|  | 	/* Check if the start of the entry is at an upper nibble of the byte */ | ||||||
|  | 	if (((uint16_t)Index * 3) % 2) | ||||||
|  | 	{ | ||||||
|  | 		FATTable[StartOffset]     |= ((NextEntry & 0x0F) << 4); | ||||||
|  | 		FATTable[StartOffset + 1]  =  (NextEntry >> 4); | ||||||
|  | 	} | ||||||
|  | 	else | ||||||
|  | 	{ | ||||||
|  | 		FATTable[StartOffset]      =  NextEntry; | ||||||
|  | 		FATTable[StartOffset + 1]  = (NextEntry >> 8); | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
| static void ReadBlock(uint16_t BlockNumber) | static void ReadBlock(uint16_t BlockNumber) | ||||||
| { | { | ||||||
| 	uint8_t BlockBuffer[512]; | 	uint8_t BlockBuffer[512]; | ||||||
| @ -102,19 +118,17 @@ static void ReadBlock(uint16_t BlockNumber) | |||||||
| 			printf(" <F>\r\n"); | 			printf(" <F>\r\n"); | ||||||
| 
 | 
 | ||||||
| 			/* Cluster 0: Media type/Reserved */ | 			/* Cluster 0: Media type/Reserved */ | ||||||
| 			((uint16_t*)&BlockBuffer)[0] = 0xFF00 | BootBlock.MediaDescriptor; | 			WriteFAT12ClusterEntry(BlockBuffer, 0, 0xF00 | BootBlock.MediaDescriptor); | ||||||
| 
 | 
 | ||||||
| 			/* Cluster 1: Reserved */ | 			/* Cluster 1: Reserved */ | ||||||
| 			((uint16_t*)&BlockBuffer)[1] = 0xFFFF; | 			WriteFAT12ClusterEntry(BlockBuffer, 1, 0xFFF); | ||||||
| 
 | 
 | ||||||
| 			/* Cluster 2 onwards: Cluster chain of FIRMWARE.BIN */ | 			/* Cluster 2 onwards: Cluster chain of FIRMWARE.BIN */ | ||||||
| 			for (uint16_t i = 0; i < FILE_CLUSTERS(2049); i++) | 			for (uint16_t i = 0; i < FILE_CLUSTERS(2049); i++) | ||||||
| 			{ | 			  WriteFAT12ClusterEntry(BlockBuffer, i+2, i+3); | ||||||
| 				((uint16_t*)&BlockBuffer)[i + 2] = i + 3; |  | ||||||
| 			} |  | ||||||
| 
 | 
 | ||||||
| 			/* Mark last cluster as end of file */ | 			/* Mark last cluster as end of file */ | ||||||
| 			((uint16_t*)&BlockBuffer)[FILE_CLUSTERS(2049) + 1] = 0xFFFF; | 			WriteFAT12ClusterEntry(BlockBuffer, FILE_CLUSTERS(2049) + 1, 0xFFF); | ||||||
| 			break; | 			break; | ||||||
| 
 | 
 | ||||||
| 		case 3: | 		case 3: | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Dean Camera
						Dean Camera