drivers/sdcard: Make ioctl(4), ioctl(5) return num blocks, block size.

For CSD v1.0 the computed size is in bytes, so convert it to number of
512-byte blocks, and then ioctl(4) will return the correct value.

Also implement ioctl(5) to return the block size, which is always 512.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2022-06-10 12:48:14 +10:00
parent ab6ad86793
commit 203b98c42b

View File

@ -103,7 +103,8 @@ class SDCard:
c_size = (csd[6] & 0b11) << 10 | csd[7] << 2 | csd[8] >> 6 c_size = (csd[6] & 0b11) << 10 | csd[7] << 2 | csd[8] >> 6
c_size_mult = (csd[9] & 0b11) << 1 | csd[10] >> 7 c_size_mult = (csd[9] & 0b11) << 1 | csd[10] >> 7
read_bl_len = csd[5] & 0b1111 read_bl_len = csd[5] & 0b1111
self.sectors = (c_size + 1) * (2 ** (c_size_mult + 2)) * (2**read_bl_len) capacity = (c_size + 1) * (2 ** (c_size_mult + 2)) * (2**read_bl_len)
self.sectors = capacity // 512
else: else:
raise OSError("SD card CSD format not supported") raise OSError("SD card CSD format not supported")
# print('sectors', self.sectors) # print('sectors', self.sectors)
@ -282,3 +283,5 @@ class SDCard:
def ioctl(self, op, arg): def ioctl(self, op, arg):
if op == 4: # get number of blocks if op == 4: # get number of blocks
return self.sectors return self.sectors
if op == 5: # get block size in bytes
return 512