cancel
Showing results for 
Search instead for 
Did you mean: 

CHS to LBA conversion - How to get CHS and SPT on uSD card?

Zaher
Senior II

I need to do conversion between CHS addressing to LBA using the following formula:

LBA = (( C x HPC ) + H ) x SPT + S - 1

where,

  • C, H and S are the cylinder number, head number, and the sector number
  • LBA is the logical block address
  • HPC is the number of heads per cylinder
  • SPT is the number of sectors per track

but I just don't know where and how to get those from a uSD card? Is there any way to get them using the MMC/SDIO HAL library or FATFS?

17 REPLIES 17

What are you doing that needs CHS addressing? Pretending to be an old IDE adapter?

For an LBA device just multiply out by maximal head and sector counts.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I'm working on a SCSI Disk (target).

Zaher
Senior II

@Community member​ 

Clive,

You're right, and I might not need it after all. But if you don't mind me asking, back in the day when you were working on a SCSI project, how you were handling the addressing of storage device (probably a hard drive) in commands like Read Capacity(10) , Read/write, Format Unit? Also when you need to provide parameters for disk geometry, like those you find on format page, how you would specify them?

You know, I started this project almost two years ago. At the time, I had thousands of questions and I had to spend months reading tons of material about SCSI, as well as, the SPC I'm using, until I became well-founded in the subject. Now, all I need to get done is to adopt the functions needed to format/read/write the medium.

Any input is highly appreciated!

SCSI and SASI before that always used BLOCK addresses. You could often program the geometry into the controller and it would store the configuration and bad block lists onto a maintenance cylinder, ie -1

I think the constraints you are labouring under are a result of register sizes used by the PC BIOS INT13 parameter.

The concept of cylinder, heads and records/sectors died a long while ago, storage media isn't that uniform, you can store far more data on the outer tracks than the inner ones.

I've worked with HD, TAPE, CD, DVD, etc and in more recent years with SD cards, NAND and eMMC devices.

READ/GET CAPACITY just tells you the number and size of blocks. FORMAT would lay down header and sector data on the blank media, which would otherwise be randomly magnetized.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
I think the constraints you are labouring under are a result of register sizes used by the PC BIOS INT13 parameter.

But what the PC BIOS had to do about it and what was the INT13 parameter?

Zaher
Senior II

@Community member​ 

Turns out it's not needed for read/write accesses. It's only needed for format mode page.

@Community member​ 

By the way, the target-mode device I'm working on is not intended for vintage computers, so I'm sorry if I made you understand that because I needed to get CHS values. Anyways, thank you always for your excellent backup over here!

Zaher
Senior II

Well, for some reason non of the following returns a correct value: SDCardInfo.CardCapacity and SDCardInfo.CardBlockSize

Any idea?