CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

CCS SD/MMC driver MBR support

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

CCS SD/MMC driver MBR support
PostPosted: Fri Aug 20, 2010 3:24 am     Reply with quote

I know there's quite a few people using this driver because it's bundled with the compiler. It may not be the best, but the price is hard to beat!

One of its shortcomings is that it doesn't handle cards with a Master Boot Record. Naturally, every single SD card I had on hand had an MBR! Rolling Eyes Support for the MBR is relatively trivial to implement, so I thought I'd post how. This involves the "mmcsd.c" CCS driver file with "Copyright 2007" in the header comments. Make a backup copy of it before starting to edit it, just in case.

Search for:
Code:
uint32_t g_mmcsdBufferAddress;
and add under it:
Code:
uint32_t g_mmcsdPartitionOffset;

Next, just before the "mmcsd_init" function add a new function:
Code:
void mmcsd_check_part(uint16_t off)
{
  if (g_mmcsd_buffer[off + 0] == 0x80)
  {
    // active partition
    uint8_t t;
    t = g_mmcsd_buffer[off + 4];
    if (t == 0x04 || t == 0x06 || t == 0x0B)
    {
      // FAT16 or FAT32 partition
      g_mmcsdPartitionOffset = make32(
        g_mmcsd_buffer[off + 11], g_mmcsd_buffer[off + 10],
        g_mmcsd_buffer[off + 9], g_mmcsd_buffer[off + 8]) * MMCSD_MAX_BLOCK_SIZE;
    }
  }
}

In the "mmcsd_init" function, right after the line:
Code:
r1 = mmcsd_load_buffer();
Add the lines:
Code:
g_mmcsdPartitionOffset = 0;
mmcsd_check_part(0x1EE);
mmcsd_check_part(0x1DE);
mmcsd_check_part(0x1CE);
mmcsd_check_part(0x1BE);

Finally, in the function "mmcsd_move_buffer", after the line:
Code:
new_block = new_addr - (new_addr % MMCSD_MAX_BLOCK_SIZE);
Add the line:
Code:
new_block += g_mmcsdPartitionOffset;

This doesn't do anything about FAT16 vs FAT32 or SD vs SDHC. If only dynamic runtime support for all those was as easy!
_________________
Andrew


Last edited by andrewg on Sat Oct 02, 2010 7:02 am; edited 1 time in total
ryanmurray9



Joined: 01 Oct 2010
Posts: 1

View user's profile Send private message

altering sd mbr partition table
PostPosted: Fri Oct 01, 2010 12:21 pm     Reply with quote

How could I use the mmcsd.c file to alter my MBR to make the sd card bootable? I am new to the forum, so if I am asking this in the wrong place, the could you direct me to where I should be asking?
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Sat Oct 02, 2010 7:28 am     Reply with quote

You would need to understand how your chosen operating system makes a bootable SD card. Use a "sector editor" (Google that) to examine the disk structure.

In general, though, the MBR must have a boot program written into it. Sometimes the disk must be partitioned such that there is a chunk of unpartitioned space after the MBR and before the first partition that is used to store the boot program. Sometimes boot programs are stored as regular files on one of the partitions. The boot sector of each partition can also have executable code.

It's all really quite complicated, plus it will require quite a bit of code and data storage for all the boot software so you can write it to the card. IMO, making an SD bootable is a job best done by a PC, not a microcontroller.
_________________
Andrew
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group