From 203b98c42b535a9c76f914b18dec4e221294b78c Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 10 Jun 2022 12:48:14 +1000 Subject: [PATCH] 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 --- drivers/sdcard/sdcard.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/sdcard/sdcard.py b/drivers/sdcard/sdcard.py index 57800a43bd..edcf14cad8 100644 --- a/drivers/sdcard/sdcard.py +++ b/drivers/sdcard/sdcard.py @@ -103,7 +103,8 @@ class SDCard: c_size = (csd[6] & 0b11) << 10 | csd[7] << 2 | csd[8] >> 6 c_size_mult = (csd[9] & 0b11) << 1 | csd[10] >> 7 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: raise OSError("SD card CSD format not supported") # print('sectors', self.sectors) @@ -282,3 +283,5 @@ class SDCard: def ioctl(self, op, arg): if op == 4: # get number of blocks return self.sectors + if op == 5: # get block size in bytes + return 512