handsomematt / gmp-z003

Information on the M3i Zero (GMP-Z003)
13 stars 2 forks source link

`ioM3LogicCardRead` and `ioM3LogicCardWrite` have incorrect CARD_COMMAND order #4

Open lifehackerhansol opened 1 year ago

lifehackerhansol commented 1 year ago

For SDIO (uncertain about flash IO), the MSByte of the sector address is actually CARD_COMMAND[7]. CARD_COMMAND[1-3] are the following bits.

So it should in fact be:

  command[7] = 0xC9; // GMP-Z003
  command[6] = (address >> 16) & 0xff;
  command[5] = (address >> 8)  & 0xff;
  command[4] =  address        & 0xff;
  command[3] = 0;
  command[2] = 0;
  command[1] = 0;
  command[0] = (address >> 24) & 0xff;

Alternatively:

u64 command = (0xC9ull << 56) | ((u64)(sector & 0xFFFFFF) << 32) | ((u64)sector >> 24 & 0xFF);
lifehackerhansol commented 1 year ago

It should be noted that the G003 does not double check the commands here; it will read and write to the SD, no questions asked, proceeding to corrupt the file system to oblivion.

lifehackerhansol commented 1 year ago

Also, sector addresses should be shifted <<1, not <<9.