1
0
Fork 0
mirror of https://github.com/Scandal-UK/Incognito_RCM.git synced 2024-12-22 10:22:04 +00:00

Extracted crc writing into its own method

This commit is contained in:
Dan Ware 2020-06-06 10:23:43 +01:00
parent 02ab328e1c
commit 9d0149ad28
2 changed files with 25 additions and 19 deletions

View file

@ -376,22 +376,29 @@ bool writeSerial()
}
const u32 serialOffset = 0x250;
const u32 serialBlockSize = 0x1E;
if (!writeData((u8 *)junkSerial, serialOffset, 14, NULL))
return false;
// write crc at end of serial-number block
char serial[31] = "";
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);
return writeCrc(serialOffset, 0x1E);
}
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()
{
gfx_printf("%kChecking if backup exists...\n", COLOR_YELLOW);

View file

@ -77,6 +77,14 @@ out:;
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(
u8 *buff, /* Data buffer to store read data */
@ -157,12 +165,3 @@ bool prodinfo_write(
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);
}