mirror of
https://github.com/Scandal-UK/Incognito_RCM.git
synced 2024-11-08 13:11:52 +00:00
Extracted crc writing into its own method
This commit is contained in:
parent
02ab328e1c
commit
9d0149ad28
2 changed files with 25 additions and 19 deletions
|
@ -376,22 +376,29 @@ bool writeSerial()
|
||||||
}
|
}
|
||||||
|
|
||||||
const u32 serialOffset = 0x250;
|
const u32 serialOffset = 0x250;
|
||||||
const u32 serialBlockSize = 0x1E;
|
|
||||||
|
|
||||||
if (!writeData((u8 *)junkSerial, serialOffset, 14, NULL))
|
if (!writeData((u8 *)junkSerial, serialOffset, 14, NULL))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// write crc at end of serial-number block
|
// write crc at end of serial-number block
|
||||||
char serial[31] = "";
|
return writeCrc(serialOffset, 0x1E);
|
||||||
readData((u8 *)serial, serialOffset, serialBlockSize, NULL);
|
|
||||||
|
|
||||||
const char *serialBytes = serial;
|
|
||||||
u16 crcValue = get_crc_16(serialBytes, serialBlockSize);
|
|
||||||
u8 crc[2] = { crcValue & 0xff, crcValue >> 8 }; // bytes of u16
|
|
||||||
|
|
||||||
return writeData(crc, serialOffset + serialBlockSize, 2, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool writeCrc(u32 offset, u32 size)
|
||||||
|
{
|
||||||
|
char buffer[size + 1];
|
||||||
|
if (!readData((u8 *)buffer, offset, size, NULL))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const char *bytes = buffer;
|
||||||
|
free(buffer);
|
||||||
|
u16 crcValue = get_crc_16(bytes, size);
|
||||||
|
u8 crc[2] = { crcValue & 0xff, crcValue >> 8 }; // bytes of u16
|
||||||
|
|
||||||
|
return writeData(crc, offset + size, 2, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo: write a method to add a crc!
|
||||||
|
// todo: include crc block in sizes
|
||||||
bool incognito()
|
bool incognito()
|
||||||
{
|
{
|
||||||
gfx_printf("%kChecking if backup exists...\n", COLOR_YELLOW);
|
gfx_printf("%kChecking if backup exists...\n", COLOR_YELLOW);
|
||||||
|
|
|
@ -77,6 +77,14 @@ out:;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// replacement for nx_emmc_part_write in storage/nx_emmc, which uses sdmmc_storage_write
|
||||||
|
int nx_emummc_part_write(sdmmc_storage_t *storage, emmc_part_t *part, u32 sector_off, u32 num_sectors, void *buf)
|
||||||
|
{
|
||||||
|
// The last LBA is inclusive.
|
||||||
|
if (part->lba_start + sector_off > part->lba_end)
|
||||||
|
return 0;
|
||||||
|
return emummc_storage_write(storage, part->lba_start + sector_off, num_sectors, buf);
|
||||||
|
}
|
||||||
|
|
||||||
bool prodinfo_read(
|
bool prodinfo_read(
|
||||||
u8 *buff, /* Data buffer to store read data */
|
u8 *buff, /* Data buffer to store read data */
|
||||||
|
@ -157,12 +165,3 @@ bool prodinfo_write(
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// replacement for nx_emmc_part_write in storage/nx_emmc, which uses sdmmc_storage_write
|
|
||||||
int nx_emummc_part_write(sdmmc_storage_t *storage, emmc_part_t *part, u32 sector_off, u32 num_sectors, void *buf)
|
|
||||||
{
|
|
||||||
// The last LBA is inclusive.
|
|
||||||
if (part->lba_start + sector_off > part->lba_end)
|
|
||||||
return 0;
|
|
||||||
return emummc_storage_write(storage, part->lba_start + sector_off, num_sectors, buf);
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue