I think I may have (finally) found the fix. I had to remove the entire reset logic for it to work i.e.
- remove hardware reset or power-cycling logic (this was done by muxing the uSDHC2’s RESET line to gpio-mode and toggling gpio pin 19 to power-cycle the sd-card) and
- remove software reset logic (performed by setting RSTA)
- and set the reset line’s mux-mode to uSDHC-mode.
and it magically started working.
I still have to no idea why this works? I hope NXP can explain why this works? But until then, my best guess is that the i.MX 8M Nano EVK board deviates from both the SD spec and the reference manual.
If anyone wants to test this. Please clone the latest (master) commit, build and flash. You should see debug output below
[ 0.000005] imx8mn-rs version 0.1.0
[ 0.003617] Booting on: [i.MX](https://i.mx/) 8M Nano EVK
[ 0.007682] Current privilege level: EL3
[ 0.011755] Exception handling state:
[ 0.015561] Debug: Masked
[ 0.018894] SError: Unmasked
[ 0.022413] IRQ: Masked
[ 0.025746] FIQ: Masked
[ 0.028993] Drivers loaded:
[ 0.031841] 1. i.MX8M Uart2
[ 0.035289] Chars written: 382
[ 0.038436] uSDHC2 supports 1.8v, 3.0v, 3.3v ...
[ 0.043311] NO RESET, PRES_STAT: 0xff8d8088
...
[ 0.050676] NO RSTA, PRES_STAT: 0xff8d8088
...
[ 0.082844] Sd clock stablized in 37us
[ 0.086777] Prescaler = 64, Divisor = 16, Freq = 390625 Hz
...
[ 0.108591] before CMD0 sent, PRES_STAT: 0xff8d8088
[ 0.113783] Sd: sending command, CMD_NAME: "GO_IDLE_STATE", CMD_CODE: 0x00000000, CMD_ARG: 0x00000000
[ 0.126803] Sd: sending command, CMD_NAME: "SEND_IF_COND", CMD_CODE: 0x081a0000, CMD_ARG: 0x000001aa
[ 0.137920] Sd: sending command, CMD_NAME: "APP_CMD", CMD_CODE: 0x371a0000, CMD_ARG: 0x00000000
[ 0.148645] Sd: sending command, CMD_NAME: "APP_SEND_OP_COND", CMD_CODE: 0x29020000, CMD_ARG: 0x50ff8000
[ 0.560598] Sd: sending command, CMD_NAME: "APP_CMD", CMD_CODE: 0x371a0000, CMD_ARG: 0x00000000
[ 0.571475] Sd: sending command, CMD_NAME: "APP_SEND_OP_COND", CMD_CODE: 0x29020000, CMD_ARG: 0x50ff8000
[ 0.583475] Sd: sending command, CMD_NAME: "ALL_SEND_CID", CMD_CODE: 0x02090000, CMD_ARG: 0x00000000
[ 0.595085] Sd: sending command, CMD_NAME: "SEND_REL_ADDR", CMD_CODE: 0x03020000, CMD_ARG: 0x00000000
[ 0.606431] Sd: sending command, CMD_NAME: "SEND_CSD", CMD_CODE: 0x09010000, CMD_ARG: 0x00010000
[ 0.617763] CSD Contents : 00 40 0e 00 32 5b 59 00 003b 83 7f 80 0a 40 00
[ 0.624947] cemmc_structure=1, spec_vers=0, taac=0x0E, nsac=0x00, tran_speed=0x32,ccc=0x05B5, read_bl_len=0x09, read_bl_partial=0b, write_blk_misalign=0b,read_blk_mi
salign=0b, dsr_imp=0b, sector_size =0x7F, erase_blk_en=1b
[ 0.645753] CSD 2.0: ver2_c_size = 0x3BFF, card capacity: 7987527680 bytes or 7.99GiB
[ 0.654006] wp_grp_size=0x0000000b, wp_grp_enable=0b, default_ecc=00b, r2w_factor=010b, write_bl_len=0x09, write_bl_partial=0b, file_format_grp=0, copy=0b, perm_writ
e_protect=0b, tmp_write_protect=0b, file_format=0b ecc=00b