Searching \ for '[EE] SDHC Boot Sector location' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=sdhc+boot+sector
Search entire site for: 'SDHC Boot Sector location'.

Exact match. Not showing close matches.
PICList Thread
'[EE] SDHC Boot Sector location'
2011\11\07@200652 by IVP

face picon face
Hi all

Until recently I've been using a couple of unbranded 4GB cards that
format with a Boot Sector at address 0x000000, directory starting at
0x761000 and first file data at 0x762000

Now I've tried a couple of Strontium cards (half the price) and find
that the Boot Sector is at 0x400000, directory at 0xBAE000, first
file data at 0xBAF000

0x000000 to 0x761000 = 3b08 sectors, and 8 sectors to first file
0x400000 to 0xBAE000 = 3d70 sectors, and 8 sectors to first file

Between 0x000000 and 0x4000000 is all zeroes, except for this at
0x1c0 (d448)

03 01 0b 2e ee e7 00 20 00 00 00 d8 7a 00 00 00

The directory listing of the card in XP looks perfectly normal, but how
does XP know where to find the Boot Sector ? I've got fatgen.doc and
see no special mention of location 448. 0x400000 would be the 0x400th
cluster (@ 512 bytes x 8)

If 0x000000 to 0x3FFFFF is reserved, how is that communicated to
the PC ? I need to know so I can read any card with a dsPIC

Alternatively, can I force the format to put the Boot Sector at 0x000000 ?

TIA

Jo

2011\11\07@204950 by peter green

flavicon
face
IVP wrote:
> Hi all
>
> Until recently I've been using a couple of unbranded 4GB cards that
> format with a Boot Sector at address 0x000000, directory starting at
> 0x761000 and first file data at 0x762000
>
> Now I've tried a couple of Strontium cards (half the price) and find
> that the Boot Sector is at 0x400000, directory at 0xBAE000, first
> file data at 0xBAF000
>
> 0x000000 to 0x761000 = 3b08 sectors, and 8 sectors to first file
> 0x400000 to 0xBAE000 = 3d70 sectors, and 8 sectors to first file
>
> Between 0x000000 and 0x4000000 is all zeroes, except for this at
> 0x1c0 (d448)
>
> 03 01 0b 2e ee e7 00 20 00 00 00 d8 7a 00 00 00
>   Looks like your card has a "master boot record" with a partition table and then has the fat filesystem on a partition.

http://en.wikipedia.org/wiki/Master_boot_record

The first partition table entry starts at 0x1be and is 16 bytes long (there are places for three more entries)

So your table entry is

00 00 03 01 0b 2e ee e7 00 20 00 00 00 d8 7a 00

decoding that according to the table at we get

00: non bootable partition
00 03 01: chs start of partition, you can ignore this and use the LBA values
0b: parition type: "fat32 with CHS addressing"
2e ee e7 : chs end of partition again you can ignore this
00 20 00 00: start LBA sector of partition = sector 0x2000 = byte offset 0x400000
00 d8 7a 00: length of partition  = 0x7ad800 sectors = 0xF5B00000 bytes
{Quote hidden}

>

2011\11\07@222754 by IVP

face picon face
> The first partition table entry starts at 0x1be and is 16 bytes long
> (there are places for three more entries)

Thanks. I might not have thought to look for an MBR + partition

As I mentioned, the cards used before do have the Boot Sector at 0x0,
and "Remove disks or other media ....." starting at 0x1ac, including text
characters of that message at 0x1be

So I can check for a Boot Sector at 0x0 and if it's not there use what
is found at 0x1be (assuming one partition) as the pointer to where the
Boot Sector is ?

Why would these particular cards have or need a partition ?

Joe

2011\11\08@031039 by Yigit Turgut

picon face
Yes you can read any card with a dspic. Some cards are bundled with a
device where there are default data is contained (like  pictures or
videos for test etc) and depending on the architecture and r/w vector
partition and content may vary. You can do any change in the partition
table and data, as long as you know where to write and read. Unless
you are booting an os or equivalent structure from the card, boot
sector is not necessary.

I use a tool for these kinds of stuff "dd" which is open source and
very powerful. I believe I had seen a windows port a while ago. You
might want to check that out to verify if the data is written exactly
where it's supposed to be or not.

Boot sector is constant and pc reads it from the same location always
unless there has been an interrupt in BIOS that tells to read from
another location. You don't need it in your app, just format /u your
card and write/read to/from anywhere you want. You can force the
format to put the Boot Sector at 0x000000 but that wouldn't be a
bootable disk unless it contains the necessary flags.

On Tue, Nov 8, 2011 at 3:06 AM, IVP <spam_OUTjoecolquittTakeThisOuTspamclear.net.nz> wrote:
{Quote hidden}

>

2011\11\08@035030 by IVP

face picon face
> Unless you are booting an os or equivalent structure from the card,
> boot sector is not necessary

Yes, I have a couple of uses where the dsPIC's is the only s/w
involved and I don't have to make the data FAT compatible (ie the
card is just a big dumb block of memory and I can write anywhere).
However, I'm working on applications where card files will be written
by a PC so I had to know how to find them

> I use a tool for these kinds of stuff "dd"

Me too, after it was recommended here not so long ago. AFAIK it
doesn't have a GUI, just Command prompt

I'm using frhed to view file generated by dd. Together they are very
helpful for testing s/w and diagnosing problems. It's how I found that
the Boot Sector wasn't where I expected it

> u can force the format to put the Boot Sector at 0x000000 but that
>wouldn't be a bootable disk unless it contains the necessary flags

I've got the other two cards to refer to for how a Boot Sector at 0x0
is put together if I need to. Now that I understand that these cards have
a partition it's simple enough to work with that

Thanks

--------------------------------------

I've written the below, but not tried it yet. The numbers check out
for the first directory sector at byte 0xBAE000

Boot Sector at 0x2000 * 0x200 = byte 0x40000
numfat = 0x2, fatsz32 = 0x1EA7, resvdsec = 0x22

(0x400000 + 0x200*((2*1EA7 + 22))) = 0xBAE000

read_fat:  clr     sec_adr_lo              ;sector 0
          clr     sec_adr_hi
          mov     #ram2,w8
          call    getsector               ;read 512 bytes, store data at ram2

;find Boot Sector / Root Directory

          mov     ram2,w0                 ;read first byte of sector
          bra     z,partition             ;if 0, then Boot Sector is not at 0x0

                                          ;else E9 or EB
boot:      mov     ram2+numfat,w0          ;BPB_NumFATs
          mul     ram2+fatsz32            ;*BPB_FATSz32

          mov     ram2+resvdsec,w0
          add     w0,w2,w0                ;+BPB_ResvdSecCnt
          mov     w0,dir_sector           ;start sector of directory
          add     w0,#8,w1
          mov     w1,offset               ;offset to next cluster

          mov     w0,sec_adr_lo           ;fetch non-00 directory sectors
          mov     #dir_ram,w8
          call    getsector               ;store at dir_ram
dir_loop:  inc     sec_adr_lo
          skpnz
          inc     sec_adr_hi
          call    getsector
          mov     temp0,w0                ;test first byte of sector
          bra     nz,dir_loop

          return

;if nothing at sector 0 then look for Boot Sector

partition: mov     #1,w0                   ;Boot Sector address at 0x1be + 8 (0x1c6)
          mov     w0,sec_adr_lo
          mov     #ram2,w8
          call    getsector

          mov     ram2+#0xc6,w0           ;fetch 0x1c6 and 0x1c7, LSW
          mov     w0,sec_adr_lo

          mov     ram2+#0xc8,w0           ;fetch 0x1c8 and 0x1c9, MSW
          mov     w0,sec_adr_hi

          mov     #ram2,w8                ;get Boot Sector
          call    getsector

          bra     boot                    ;examine

2011\11\08@035926 by Electron

flavicon
face

Very interesting. So there are SD cards which have a MBR and others that
don't have it?

How can one identify one type vs the other? Is it totally a software thing
or is there some "hardware interference" that sets to one type or the other?

If it's a software thing, just by rewriting the first 2 sectors (MBR) then
we can set the type as we wish.

Does a MBR-type SD card REALLY allow multiple partitions? When I did some
experiments in this regard (SD not SDHS) I think they all failed, at least
on Windows. Like if it pretended it to be a partition already, not a disc,
even if I made a custom MBR for it.

Last but not least, if I get a SD which is MBR-type (or convert one to it,
if it's even possible (hardware registers/flags?)), and make it bootable,
can I run a OS from it (through a USB-SD adapter)?

Greets,
Mario


At 02.49 2011.11.08, you wrote:
{Quote hidden}

>

2011\11\08@040235 by Electron

flavicon
face
At 09.10 2011.11.08, you wrote:
>Yes you can read any card with a dspic. Some cards are bundled with a
>device where there are default data is contained (like  pictures or
>videos for test etc) and depending on the architecture and r/w vector
>partition and content may vary. You can do any change in the partition
>table and data, as long as you know where to write and read. Unless
>you are booting an os or equivalent structure from the card, boot
>sector is not necessary.
>
>I use a tool for these kinds of stuff "dd" which is open source and
>very powerful. I believe I had seen a windows port a while ago. You
>might want to check that out to verify if the data is written exactly
>where it's supposed to be or not.

Here:

http://www.chrysocome.net/dd

2011\11\08@042201 by IVP

face picon face
> Very interesting. So there are SD cards which have a MBR and others
> that don't have it?

Appears so, for SDHC anyway

> How can one identify one type vs the other? Is it totally a software
> thing or is there some "hardware interference" that sets to one type
> or the other?

AFAICT these Strontium blank cards are sold partitioned, but I don't
know why. Seems a waste of 4MB

> If it's a software thing, just by rewriting the first 2 sectors (MBR) then
> we can set the type as we wish.

Yes, it's just data. The cards I treat as just memory are no longer FAT-
compatible. Now they're Joe-disks. Look out Bill, here I come ;-)

> Does a MBR-type SD card REALLY allow multiple partitions?

If it's following the FAT32 rules then those 4 locations Peter Green
pointed me too would be useable to make partitions

> Last but not least, if I get a SD which is MBR-type (or convert one
> to it, if it's even possible (hardware registers/flags?)), and make it
> bootable, can I run a OS from it (through a USB-SD adapter)?

Pretty sure I read that's possible. And once upon a time 4GB was a
sizeable HDD

Joe

2011\11\08@045841 by Yigit Turgut

picon face
On Tue, Nov 8, 2011 at 10:50 AM, IVP <.....joecolquittKILLspamspam@spam@clear.net.nz> wrote:
>> Unless you are booting an os or equivalent structure from the card,
>> boot sector is not necessary
>
> Yes, I have a couple of uses where the dsPIC's is the only s/w
> involved and I don't have to make the data FAT compatible (ie the
> card is just a big dumb block of memory and I can write anywhere).
> However, I'm working on applications where card files will be written
> by a PC so I had to know how to find them

Food for thought ; you don't need to partition the card to write/read
from, you can bulk write/read as long as the device is recognized by
the os (not the filesystem). A filesystem is not necessary but it
surely will make things simpler.

>
>> I use a tool for these kinds of stuff "dd"
>
> Me too, after it was recommended here not so long ago. AFAIK it
> doesn't have a GUI, just Command prompt
>
> I'm using frhed to view file generated by dd. Together they are very
> helpful for testing s/w and diagnosing problems. It's how I found that
> the Boot Sector wasn't where I expected it

dd lacks gui but it's so straightforward that I doubt you will need
one.It's output will be written to a file and file can be viewed with
vi, pico, kwrite, notepad, frhed and so on.  I live in bash usually
thus it's easy to do any kind of manipulation for directing
input/output of dd.
>
>> u can force the format to put the Boot Sector at 0x000000 but that
>>wouldn't be a bootable disk unless it contains the necessary flags
>
> I've got the other two cards to refer to for how a Boot Sector at 0x0
> is put together if I need to. Now that I understand that these cards have
> a partition it's simple enough to work with that
>

Each SSD card  I have played with allowed multi partition on it even
the old MMC ones. I remember I got ext3, reiserfs and jfs on the same
card.

{Quote hidden}

Your code will check if 0xBAE000 is occupied or not, give it a try.

2011\11\08@051507 by IVP

face picon face
> A filesystem is not necessary but it surely will make things simpler

That's true. All very well when you start off with a clean card but as
files are replaced, added or deleted you need something to track the
useage

> Your code will check if 0xBAE000 is occupied or not, give it a try

Sure, the first draft is a little simpler than it should be, but it did
work,
so that's something to build on. I've added quite a few more lines in
the last couple of hours to eliminate static values, begin covering the
"what ifs" etc

Joe

2011\11\08@074658 by Nicola Perotto

picon face


On 08/11/2011 8.59, Electron wrote:
>
> Does a MBR-type SD card REALLY allow multiple partitions?
NO! It's prohibited from the SD specification. Only the first of four is allowed.


> Last but not least, if I get a SD which is MBR-type (or convert one to it,
> if it's even possible (hardware registers/flags?)), and make it bootable,
> can I run a OS from it (through a USB-SD adapter)?
Yes. In both cases you can boot an OS.

2011\11\08@075849 by peter green

flavicon
face
Nicola Perotto wrote:
> On 08/11/2011 8.59, Electron wrote:
>  
>> Does a MBR-type SD card REALLY allow multiple partitions?
>>    
> NO! It's prohibited from the SD specification. Only the first of four is allowed.
>   Of course just because it's prohibited by the spec doesn't mean people don't do it ;)

>> Last but not least, if I get a SD which is MBR-type (or convert one to it,
>> if it's even possible (hardware registers/flags?)), and make it bootable,
>> can I run a OS from it (through a USB-SD adapter)?
>>    
> Yes. In both cases you can boot an OS.
>
>
>

2011\11\08@103938 by Herbert Graf

picon face
On Tue, 2011-11-08 at 09:59 +0100, Electron wrote:
> Does a MBR-type SD card REALLY allow multiple partitions? When I did some
> experiments in this regard (SD not SDHS) I think they all failed, at least
> on Windows. Like if it pretended it to be a partition already, not a disc,
> even if I made a custom MBR for it.

Then that's an (odd) limitation of windows.

FWIW I've regularly had multiple partitions on my SD cards, with no
issues.

TTYL

2011\11\08@104051 by Herbert Graf

picon face
On Tue, 2011-11-08 at 22:21 +1300, IVP wrote:
> AFAICT these Strontium blank cards are sold partitioned, but I don't
> know why. Seems a waste of 4MB

Seriously? 4MB is the size of a rather heavily compressed JPG coming
from today's digital cams. For a card with the space for thousands of
pictures, I don't see loosing the space for one picture to be a big
deal.

2011\11\08@135700 by IVP

face picon face
> Seems a waste of 4MB
>
> Seriously? 4MB is the size of a rather heavily compressed JPG ....

Yes, I know it's only 0.1% of the available memory, and it's all
sand and plastic anyway. Just curious as to why a new card
would be partitione

More... (looser matching)
- Last day of these posts
- In 2011 , 2012 only
- Today
- New search...