diff --git a/bdk/storage/ramdisk.c b/bdk/storage/ramdisk.c index e7b7c01..315075d 100644 --- a/bdk/storage/ramdisk.c +++ b/bdk/storage/ramdisk.c @@ -1,7 +1,7 @@ /* * Ramdisk driver for Tegra X1 * - * Copyright (c) 2019 CTCaer + * Copyright (c) 2019-2021 CTCaer * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -19,23 +19,40 @@ #include #include "ramdisk.h" +#include #include #include #include -int ram_disk_init(FATFS *ram_fs) +static u32 disk_size = 0; + +int ram_disk_init(FATFS *ram_fs, u32 ramdisk_size) { - int res; - u8 *buf = malloc(0x400000); + int res = 0; + disk_size = ramdisk_size; - f_mount(NULL, "ram:", 1); // Unmount ramdisk. + // If ramdisk is not raw, format it. + if (ram_fs) + { + u8 *buf = malloc(0x400000); - res = f_mkfs("ram:", FM_EXFAT, RAMDISK_CLUSTER_SZ, buf, 0x400000); // Format as exFAT w/ 32KB cluster. - if (!res) - res = f_mount(ram_fs, "ram:", 1); // Mount ramdisk. + // Set ramdisk size. + ramdisk_size >>= 9; + disk_set_info(DRIVE_RAM, SET_SECTOR_COUNT, &ramdisk_size); - free(buf); + // Unmount ramdisk. + f_mount(NULL, "ram:", 1); + + // Format as exFAT w/ 32KB cluster with no MBR. + res = f_mkfs("ram:", FM_EXFAT | FM_SFD, RAMDISK_CLUSTER_SZ, buf, 0x400000); + + // Mount ramdisk. + if (!res) + res = f_mount(ram_fs, "ram:", 1); + + free(buf); + } return res; } @@ -45,7 +62,7 @@ int ram_disk_read(u32 sector, u32 sector_count, void *buf) u32 sector_off = RAM_DISK_ADDR + (sector << 9); u32 bytes_count = sector_count << 9; - if ((sector_off - RAM_DISK_ADDR) > RAM_DISK_SZ) + if ((sector_off - RAM_DISK_ADDR) > disk_size) return 1; memcpy(buf, (void *)sector_off, bytes_count); @@ -58,7 +75,7 @@ int ram_disk_write(u32 sector, u32 sector_count, const void *buf) u32 sector_off = RAM_DISK_ADDR + (sector << 9); u32 bytes_count = sector_count << 9; - if ((sector_off - RAM_DISK_ADDR) > RAM_DISK_SZ) + if ((sector_off - RAM_DISK_ADDR) > disk_size) return 1; memcpy((void *)sector_off, buf, bytes_count); diff --git a/bdk/storage/ramdisk.h b/bdk/storage/ramdisk.h index ef43bb5..e625235 100644 --- a/bdk/storage/ramdisk.h +++ b/bdk/storage/ramdisk.h @@ -1,7 +1,7 @@ /* * Ramdisk driver for Tegra X1 * - * Copyright (c) 2019 CTCaer + * Copyright (c) 2019-2021 CTCaer * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -23,7 +23,7 @@ #define RAMDISK_CLUSTER_SZ 32768 -int ram_disk_init(FATFS *ram_fs); +int ram_disk_init(FATFS *ram_fs, u32 ramdisk_size); int ram_disk_read(u32 sector, u32 sector_count, void *buf); int ram_disk_write(u32 sector, u32 sector_count, const void *buf); diff --git a/nyx/nyx_gui/frontend/gui_options.c b/nyx/nyx_gui/frontend/gui_options.c index 277174d..8da550a 100644 --- a/nyx/nyx_gui/frontend/gui_options.c +++ b/nyx/nyx_gui/frontend/gui_options.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 CTCaer + * Copyright (c) 2018-2021 CTCaer * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, diff --git a/nyx/nyx_gui/frontend/gui_tools_partition_manager.c b/nyx/nyx_gui/frontend/gui_tools_partition_manager.c index 263dc5d..7ab4709 100644 --- a/nyx/nyx_gui/frontend/gui_tools_partition_manager.c +++ b/nyx/nyx_gui/frontend/gui_tools_partition_manager.c @@ -1366,7 +1366,7 @@ static lv_res_t _create_mbox_start_partitioning(lv_obj_t *btn) lv_label_set_text(lbl_paths[0], "Please wait..."); lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); manual_system_maintenance(true); - if (ram_disk_init(&ram_fs)) + if (ram_disk_init(&ram_fs, RAM_DISK_SZ)) { lv_label_set_text(lbl_status, "#FFDD00 Error:# Failed to initialize Ramdisk!"); goto error; diff --git a/nyx/nyx_gui/libs/fatfs/diskio.c b/nyx/nyx_gui/libs/fatfs/diskio.c index f2f52b0..5e3a47b 100644 --- a/nyx/nyx_gui/libs/fatfs/diskio.c +++ b/nyx/nyx_gui/libs/fatfs/diskio.c @@ -16,6 +16,8 @@ #include #include +static u32 sd_rsvd_sectors = 0; +static u32 ramdisk_sectors = 0; /*-----------------------------------------------------------------------*/ /* Get Drive Status */ /*-----------------------------------------------------------------------*/ @@ -88,7 +90,6 @@ DRESULT disk_write ( /*-----------------------------------------------------------------------*/ /* Miscellaneous Functions */ /*-----------------------------------------------------------------------*/ -static u32 part_rsvd_size = 0; DRESULT disk_ioctl ( BYTE pdrv, /* Physical drive nmuber (0..) */ BYTE cmd, /* Control code */ @@ -102,7 +103,7 @@ DRESULT disk_ioctl ( switch (cmd) { case GET_SECTOR_COUNT: - *buf = sd_storage.sec_cnt - part_rsvd_size; + *buf = sd_storage.sec_cnt - sd_rsvd_sectors; break; case GET_BLOCK_SIZE: *buf = 32768; // Align to 16MB. @@ -114,7 +115,7 @@ DRESULT disk_ioctl ( switch (cmd) { case GET_SECTOR_COUNT: - *buf = RAM_DISK_SZ >> 9; // 1GB. + *buf = ramdisk_sectors; break; case GET_BLOCK_SIZE: *buf = 2048; // Align to 1MB. @@ -133,12 +134,15 @@ DRESULT disk_set_info ( { DWORD *buf = (DWORD *)buff; - if (pdrv == DRIVE_SD) + if (cmd == SET_SECTOR_COUNT) { - switch (cmd) + switch (pdrv) { - case SET_SECTOR_COUNT: - part_rsvd_size = *buf; + case DRIVE_SD: + sd_rsvd_sectors = *buf; + break; + case DRIVE_RAM: + ramdisk_sectors = *buf; break; } } diff --git a/nyx/nyx_gui/storage/nx_sd.c b/nyx/nyx_gui/storage/nx_sd.c index a8f67ce..3251b13 100644 --- a/nyx/nyx_gui/storage/nx_sd.c +++ b/nyx/nyx_gui/storage/nx_sd.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2018 naehrwert - * Copyright (c) 2018-2019 CTCaer + * Copyright (c) 2018-2021 CTCaer * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License,