@@ -61,6 +61,7 @@ static int g_cmd8_never; /* v1.x: CMD8 is never answered */
6161static int g_cmd8_needs_18v ; /* left in UHS: answered only at 1.8V */
6262static int g_cicmd_stuck ; /* the command line never goes idle */
6363static int g_cmd8_mangled ; /* CMD8 IS answered, but the link corrupts it */
64+ static int g_cmd8_mangled_once ; /* first CMD8 response is corrupted */
6465static int g_reset_never ; /* the reset bit itself never self-clears */
6566static int g_inhibit_sticky ; /* reset completes, but CICMD stays set */
6667static unsigned int g_cmd8_attempts ;
@@ -116,7 +117,8 @@ void sdhci_reg_write(uint32_t offset, uint32_t val)
116117 & SDHCI_SRS15_V18SE ) != 0 ;
117118
118119 g_cmd8_attempts ++ ;
119- if (g_cmd8_mangled ) {
120+ if (g_cmd8_mangled ||
121+ (g_cmd8_mangled_once && g_cmd8_attempts == 1 )) {
120122 /* The card DID answer; the link mangled the response. Not a
121123 * timeout, so not a legacy card. */
122124 g_sdhci_regs [SDHCI_SRS12 / sizeof (uint32_t )] |=
@@ -184,6 +186,7 @@ static void setup(void)
184186 g_cmd8_never = 0 ;
185187 g_cmd8_needs_18v = 0 ;
186188 g_cmd8_mangled = 0 ;
189+ g_cmd8_mangled_once = 0 ;
187190 g_reset_never = 0 ;
188191 g_inhibit_sticky = 0 ;
189192 g_wdt_pets = 0 ;
@@ -275,6 +278,20 @@ START_TEST(test_uhs_recover_rolls_back)
275278END_TEST
276279#endif
277280
281+ /* A transient response error is retried; a working card still reaches
282+ * ACMD41 after its next CMD8 answer. */
283+ START_TEST (test_cmd8_transient_error_retries )
284+ {
285+ script_card_present ();
286+ g_cmd8_mangled_once = 1 ;
287+
288+ (void )sdcard_card_full_init ();
289+
290+ ck_assert_uint_eq (g_cmd8_attempts , 2 );
291+ ck_assert_uint_gt (g_acmd41_polls , 0 );
292+ }
293+ END_TEST
294+
278295/* A mangled CMD8 response is NOT a legacy card.
279296 *
280297 * Silence means the card does not implement CMD8; a CRC or index error means
@@ -345,6 +362,7 @@ Suite *sdhci_cmd_inhibit_suite(void)
345362 tcase_add_test (tc , test_command_inhibit_does_not_hang );
346363 tcase_add_test (tc , test_cmd8_absent_is_not_fatal );
347364 tcase_add_test (tc , test_cmd8_answered_normally );
365+ tcase_add_test (tc , test_cmd8_transient_error_retries );
348366 tcase_add_test (tc , test_cmd8_bus_error_is_still_fatal );
349367 tcase_add_test (tc , test_inhibit_that_survives_reset_does_not_hang );
350368 tcase_add_test (tc , test_reset_that_never_clears_does_not_hang );
0 commit comments