1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-29 23:32:23 +00:00

[stage2] Accomodate raw_mmc_dev to latest sdmmc driver changes

This commit is contained in:
TuxSH 2018-05-12 12:23:07 +02:00
parent 75169790ff
commit 00f08321c7

View file

@ -205,8 +205,7 @@ static int rawmmcdev_close(struct _reent *r, void *fd) {
return 0; return 0;
} }
/* Keep this <= the size of the DMA bounce buffer in sdmmc.c */ static __attribute__((aligned(16))) uint8_t g_crypto_buffer[512 * 16] = {0};
static __attribute__((aligned(16))) uint8_t g_crypto_buffer[512] = {0};
static ssize_t rawmmcdev_write(struct _reent *r, void *fd, const char *ptr, size_t len) { static ssize_t rawmmcdev_write(struct _reent *r, void *fd, const char *ptr, size_t len) {
rawmmcdev_file_t *f = (rawmmcdev_file_t *)fd; rawmmcdev_file_t *f = (rawmmcdev_file_t *)fd;
@ -262,17 +261,14 @@ static ssize_t rawmmcdev_write(struct _reent *r, void *fd, const char *ptr, size
return len; return len;
} }
if (device->encrypted) {
size_t sectors_remaining = sector_end_aligned - current_sector; size_t sectors_remaining = sector_end_aligned - current_sector;
for (size_t i = 0; i < len; i += sizeof(g_crypto_buffer)/512) { for (size_t i = 0; i < len; i += sizeof(g_crypto_buffer)/512) {
size_t n = sectors_remaining <= sizeof(g_crypto_buffer)/512 ? sectors_remaining : sizeof(g_crypto_buffer)/512; size_t n = sectors_remaining <= sizeof(g_crypto_buffer)/512 ? sectors_remaining : sizeof(g_crypto_buffer)/512;
if (device->encrypted) {
memcpy(g_crypto_buffer, data, 512 * n); memcpy(g_crypto_buffer, data, 512 * n);
device->write_crypt_func(g_crypto_buffer, g_crypto_buffer, current_sector - device_sector_offset, 512 * n, device->iv, device->crypt_flags); device->write_crypt_func(g_crypto_buffer, g_crypto_buffer, current_sector - device_sector_offset, 512 * n, device->iv, device->crypt_flags);
no = sdmmc_write(device->mmc, g_crypto_buffer, current_sector, n); no = sdmmc_write(device->mmc, g_crypto_buffer, current_sector, n);
} else {
no = sdmmc_write(device->mmc, data, current_sector, n);
}
if (no != 0) { if (no != 0) {
r->_errno = no; r->_errno = no;
@ -282,6 +278,19 @@ static ssize_t rawmmcdev_write(struct _reent *r, void *fd, const char *ptr, size
data += 512 * n; data += 512 * n;
current_sector += n; current_sector += n;
} }
} else {
/* We can write everything aligned at once. */
size_t sectors_remaining = sector_end_aligned - current_sector;
no = sdmmc_write(device->mmc, data, current_sector, sectors_remaining);
if (no != 0) {
r->_errno = no;
return -1;
}
data += 512 * sectors_remaining;
current_sector += sectors_remaining;
}
/* Unaligned at the end, we need to read the sector and incorporate the data. */ /* Unaligned at the end, we need to read the sector and incorporate the data. */
if (sector_end != sector_end_aligned) { if (sector_end != sector_end_aligned) {
@ -357,11 +366,11 @@ static ssize_t rawmmcdev_read(struct _reent *r, void *fd, char *ptr, size_t len)
return 0; return 0;
} }
if (device->encrypted) {
size_t sectors_remaining = sector_end_aligned - current_sector; size_t sectors_remaining = sector_end_aligned - current_sector;
for (size_t i = 0; i < len; i += sizeof(g_crypto_buffer)/512) { for (size_t i = 0; i < len; i += sizeof(g_crypto_buffer)/512) {
size_t n = sectors_remaining <= sizeof(g_crypto_buffer)/512 ? sectors_remaining : sizeof(g_crypto_buffer)/512; size_t n = sectors_remaining <= sizeof(g_crypto_buffer)/512 ? sectors_remaining : sizeof(g_crypto_buffer)/512;
if (device->encrypted) {
no = sdmmc_read(device->mmc, g_crypto_buffer, current_sector, n); no = sdmmc_read(device->mmc, g_crypto_buffer, current_sector, n);
if (no != 0) { if (no != 0) {
r->_errno = no; r->_errno = no;
@ -369,16 +378,22 @@ static ssize_t rawmmcdev_read(struct _reent *r, void *fd, char *ptr, size_t len)
} }
device->read_crypt_func(g_crypto_buffer, g_crypto_buffer, current_sector - device_sector_offset, 512 * n, device->iv, device->crypt_flags); device->read_crypt_func(g_crypto_buffer, g_crypto_buffer, current_sector - device_sector_offset, 512 * n, device->iv, device->crypt_flags);
memcpy(data, g_crypto_buffer, 512 * n); memcpy(data, g_crypto_buffer, 512 * n);
data += 512 * n;
current_sector += n;
}
} else { } else {
no = sdmmc_read(device->mmc, data, current_sector, n); /* We can read everything aligned at once. */
size_t sectors_remaining = sector_end_aligned - current_sector;
no = sdmmc_read(device->mmc, data, current_sector, sectors_remaining);
if (no != 0) { if (no != 0) {
r->_errno = no; r->_errno = no;
return -1; return -1;
} }
}
data += 512 * n; data += 512 * sectors_remaining;
current_sector += n; current_sector += sectors_remaining;
} }
/* Unaligned at the end, we need to read the sector and incorporate the data. */ /* Unaligned at the end, we need to read the sector and incorporate the data. */