Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Boot sector not beaing read properly from sd card

Status
Not open for further replies.

sachinkp21587

Member level 2
Member level 2
Joined
Mar 15, 2010
Messages
51
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
india (U.P.)
Visit site
Activity points
1,703
Boot sector not being read properly from sd card

hello all!!!!

a problem i am facing these days is when i try to read the very first sector of my sd card it gets fetched but seems all the information is not fetched. how is it possible?

i am looking for the below mentioned information for fat16 formatted sd card

00h Jump Code + NOP 3 Bytes
03h OEM Name 8 Bytes
0Bh Bytes Per Sector 1 Word
0Dh Sectors Per Cluster 1 Byte
0Eh Reserved Sectors 1 Word
10h Number of Copies of FAT 1 Byte
11h Maximum Root Directory Entries 1 Word
13h Number of Sectors in Partition Smaller than 32MB 1 Word
15h Media Descriptor (F8h for Hard Disks) 1 Byte
16h Sectors Per FAT 1 Word
18h Sectors Per Track 1 Word
1Ah Number of Heads 1 Word
1Ch Number of Hidden Sectors in Partition 1 Double Word
20h Number of Sectors in Partition 1 Double Word
24h Logical Drive Number of Partition 1 Word
26h Extended Signature (29h) 1 Byte
27h Serial Number of Partition 1 Double Word
2Bh Volume Name of Partition 11 Bytes
36h FAT Name (FAT16) 8 Bytes
3Eh Executable Code 448 Bytes
1FEh Executable Marker (55h AAh) 2 Bytes

but every time i am getting only the signature values correct and rest are just 0x00. how is it possible?
the same card when read in winhex gives info that is attached herewith.

Someone please help in sorting out the problem
 

Attachments

  • Drive G.pdf
    28.8 KB · Views: 100
Last edited:

sorry for the mistake sir.
but the bytes i just mentioned over above fall in MASTER BOOT RECORD right?
what could be the reason that i am getting the info wrong? i can upload the code if that can help.
 

I guess you didn't yet understand the overall structure involving MBR partition tables. A hex editor can show both, physical disk starting with MBR and logical drive, starting with boot sector.
 

as much as i know first 512 bytes represent the boot sector where the information listed above is stored (as far as i have read).
this also contains a MBR at a particular offset of 446 bytes that actually contains info about physical drives. each drive info in MBR is 16 bytes long containing information of beginning and ending address for a drive. I am not much into it sir. please correct if m mistaken at any point.

and do u mean the hexviewer is showing something else rather thn what i am looking for?

my fat file system is to make a check of a few of above mentioned byte values to load the file system. due to improper reading fat initialization is interrupted at every point excluding the signature value check.

Please guide. and thank you very much to look into this regard
 

I was facing the same problem as you a few days ago. Below is what i understand, hope it helps.
Experts : if i'm wrong, pls correct me.

The 1st 512 is boot sector call MBR not LBR. The boot sector you were trying access is LBR. LBR location can be calculate from MBR (offset location 0x1C6 : size 4 bytes)
eg.
my 16mb sdcard's MBR reads from offset location 0x1BF (0x00 0x01 0x1A 0x00 0x01 0x01 0x60 0xc1 0x39 0x00 0x00 0x00 0x47 0x70 0x00 0x00)
meaning at offset location 0x1c6 (4 bytes) = 0x39
so go read address location (0x39 * 512) for LBR

in my winhex, u can see at the bottom right side,value of physical sector no = 57 =0x39



Now i am face with another problem with reading the LBR of SDHC sd card; i.e I can read LBR of SD Ver1.x, Ver2.00 standard capacity but not Ver2.00 high capacity.

My SPI initialization flow does caters to init for all types of cards. I can read the MBR of all types of cards...but when i tried to read the LBR of the SDHC card, it is all "0"s. :cry:
My coding to read sd card is SPI CMD17 (read single block)

What i have done during troubleshooting is to 1st read MBR follow by LBR;
16MB card - pass
1G card - pass
2G card - pass
4G card - fail (LBR at 0x2000)
32G card - fail (LBR at 0x2000)
Thinking that it might be my coding issue reading sector location 0x2000, i tried reading this sector of my 1G ver2.00 sdcard and it is able to read the data inside correctly.

Is there any thing special to configure for SDHC?
Pls help me if you have encounter similar issues before. I have been looking at the sample codes and searching the net... but could not find an answer yet. Thanks.
 
Is there any thing special to configure for SDHC?
Did you notice the different address format between standard SD and SDHC in READ and WRITE_BLOCK commands?
 
  • Like
Reactions: mbwin

    mbwin

    Points: 2
    Helpful Answer Positive Rating
Thank you very much!!!
My problem is solved. Now i can read the LBR of SDHC.
I fail to notice the different address format! :oops:
 

so go read address location (0x39 * 512) for LBR
This 512 multiplication was creating a problem.
my sector read write wasnt having this line of code.
now everything is working perfectly. thanks mbwin.

i would like to know is this multiplication always necessary in all the cases?

- - - Updated - - -

what i also came to know is that the WINHEX reads the LBA begin sector as 0 and not the MBR sector.
is this what a physical drive and logical drive differs in?
i mean is it like that the MBR sector is 0 is actually sector 0 of physical drive and LBA is sector 0 of a logical drive?
 

i would like to know is this multiplication always necessary in all the cases?
As FvM have help point out, there is a difference in address format between standard HC and SDHC. I guess ur card is SDHC, thus do not need to *512.
From physical layer simplified spec v4.1(pg60) it says :
"SDHC and SDXC use the 32-bit argument of memory access commands as block address format. Block length is fixed to 512 bytes regardless CMD16,
SDSC uses the 32-bit argument of memory access commands as byte address format. Block length is determined by CMD16,"



This is the guide i read to understand MBR, LBA. **broken link removed**

Hope this helps.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top