[sd tools] Utilize sd_file_read better

Additionally fix a long standing fread/fwrite bug, via a FatFS fix.
(Doesn't affect Tegra arch though)
This commit is contained in:
ctcaer@gmail.com
2019-03-16 23:35:43 +02:00
parent 491c4efe9c
commit 961768e14e
5 changed files with 48 additions and 56 deletions

View File

@@ -103,29 +103,24 @@ void sd_unmount()
}
}
void *sd_file_read(char *path)
void *sd_file_read(const char *path, u32 *fsize)
{
FIL fp;
if (f_open(&fp, path, FA_READ) != FR_OK)
return NULL;
u32 size = f_size(&fp);
if (fsize)
*fsize = size;
void *buf = malloc(size);
u8 *ptr = buf;
while (size > 0)
if (f_read(&fp, buf, size, NULL) != FR_OK)
{
u32 rsize = MIN(size, 512 * 8192);
if (f_read(&fp, ptr, rsize, NULL) != FR_OK)
{
free(buf);
f_close(&fp);
free(buf);
f_close(&fp);
return NULL;
}
ptr += rsize;
size -= rsize;
return NULL;
}
f_close(&fp);
@@ -847,10 +842,10 @@ void auto_launch_firmware()
if (!(b_cfg.boot_cfg & BOOT_CFG_FROM_LAUNCH) && h_cfg.bootwait)
{
if (bootlogoCustomEntry) // Check if user set custom logo path at the boot entry.
bitmap = (u8 *)sd_file_read(bootlogoCustomEntry);
bitmap = (u8 *)sd_file_read(bootlogoCustomEntry, NULL);
if (!bitmap) // Custom entry bootlogo not found, trying default custom one.
bitmap = (u8 *)sd_file_read("bootloader/bootlogo.bmp");
bitmap = (u8 *)sd_file_read("bootloader/bootlogo.bmp", NULL);
if (bitmap)
{