简体   繁体   中英

Partition Program in embedded C

//------------------------------------------------------------------------------
//Partition boot sector at LBA = 1
//------------------------------------------------------------------------------
//Physical Sector - 1, Logical Sector - 0.  
//This is the first sector in the partition, and is known as the "volume boot record" or "partition boot sector"
//Note: This table is filesystem specific.  Re-formatting the drive will overwrite this table.  
const uint8_t PARTITION_ATTRIBUTES(BOOT_SECTOR_ADDRESS) BootSector[FILEIO_CONFIG_MEDIA_SECTOR_SIZE]  BOOT_SEC_ADDR_TAG =
{
0xEB, 0x3C, 0x90,           //Jump instruction
'M', 'S', 'D', 'O', 'S', '5', '.', '0', //OEM Name "MSDOS5.0"
(FILEIO_CONFIG_MEDIA_SECTOR_SIZE&0xFF), (FILEIO_CONFIG_MEDIA_SECTOR_SIZE>>8),       //Bytes per sector (FILEIO_CONFIG_MEDIA_SECTOR_SIZE)
0x01,               //Sectors per cluster
DRV_FILEIO_INTERNAL_FLASH_NUM_RESERVED_SECTORS, 0x00,           //Reserved sector count (usually 1 for FAT12 or FAT16)
0x01,               //number of FATs 
DRV_FILEIO_CONFIG_INTERNAL_FLASH_MAX_NUM_FILES_IN_ROOT, 0x00,           //Max number of root directory entries - 16 files allowed
0x00, 0x00,         //total sectors (0x0000 means: use the 4 byte field at offset 0x20 instead)
0xF8,               //Media Descriptor
DRV_FILEIO_INTERNAL_FLASH_NUM_FAT_SECTORS, 0x00,         //Sectors per FAT
0x3F, 0x00,                 //Sectors per track
0xFF, 0x00,                 //Number of heads
0x01, 0x00, 0x00, 0x00,     //Hidden sectors
(uint8_t)DRV_FILEIO_INTERNAL_FLASH_PARTITION_SIZE, (uint8_t)(DRV_FILEIO_INTERNAL_FLASH_PARTITION_SIZE >> 8), (uint8_t)(DRV_FILEIO_INTERNAL_FLASH_PARTITION_SIZE >> 16), (uint8_t)(DRV_FILEIO_INTERNAL_FLASH_PARTITION_SIZE >> 24),  //Total sectors (when WORD value at offset 20 is 0x0000)

0x00,           //Physical drive number
0x00,           //Reserved("current head")
0x29,           //Signature
0x32, 0x67, 0x94, 0xC4,     //ID(serial number)
'N', 'O', ' ', 'N', 'A', 'M', 'E', ' ', ' ', ' ', ' ',  //Volume Label (11 bytes) - "NO NAME    "
'F', 'A', 'T', '1', '2', ' ', ' ', ' ', //FAT system "FAT12   "
//Operating system boot code
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x55, 0xAA          //End of sector (0x55AA)
};

I am trying to use part of the program memory of my dspic33 controller as mass storage device. I am using a reference program to understand what happens inside of the program. When I go through it, I find this section. Actually I don't know it's syntax and it seems new to me. I want to understand about this section. If anybody come across these type of programs in c, kindly explain it.

It seems to contain the first block of the physical drive.

When your system boots up, it loads the first block of the physical disk into a pre-determined place in memory (pre-determined by the BIOS) and then transfers control to this block. There it encounters a jump instruction and jumps there. The jump instruction has been hard-coded and may need to know where the BIOS loaded the block. I did not decode the jump instruction but was expecting it to jump into the section called "operating system boot code" but that section contains only nulls.

Following this jump instruction are what seems the data of a FAT12 filesystem.

Without more information it is difficult to say more about it. So it could be a boot block that is written physically to block 0 of the drive, but it seems to require the boot code. To some part it depends on the detailed definition of the boot block and FAT12 filesystem, and on the BIOS code of the actual machine reading this into memory.

So, though not a definitive and complete explanation, I hope this helps.

In const uint8_t PARTITION_ATTRIBUTES(BOOT_SECTOR_ADDRESS) BootSector[FILEIO_CONFIG_MEDIA_SECTOR_SIZE] BOOT_SEC_ADDR_TAG = { … }; :

  • const says the elements of the array being defined will not be modified after the arary is created.

  • uint8_t says the elements of the array being defined are 8-bit unsigned integers.

  • PARTITION_ATTRIBUTES(BOOT_SECTOR_ADDRESS) is likely a preprocessor macro defined in some header that may contain some compiler-specific keywords for describing attributes of the object being declared. (This hypothesis is based on the contents of the text and on experience, not on strict requirements of the C language.)

  • BootSector is the name of the array being defined.

  • [FILEIO_CONFIG_MEDIA_SECTOR_SIZE] says the array contains FILEIO_CONFIG_MEDIA_SECTOR_SIZE elements, where FILEIO_CONFIG_MEDIA_SECTOR_SIZE is likely a preprocessor macro defined in some header.

  • BOOT_SEC_ADDR_TAG is likely some preprocessor macro containing compiler-specific keywords, as above.

  • = { … } provides the data used to initialize the array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM