diff --git a/bdk/libs/fatfs/ff.c b/bdk/libs/fatfs/ff.c index 9035f35..e6a6c56 100644 --- a/bdk/libs/fatfs/ff.c +++ b/bdk/libs/fatfs/ff.c @@ -38,6 +38,7 @@ #include "ff.h" /* Declarations of FatFs API */ #include "diskio.h" /* Declarations of device I/O functions */ +#include #include #define EFSPRINTF(text, ...) print_error(); gfx_printf("%k"text"%k\n", 0xFFFFFF00, 0xFFFFFFFF); @@ -3284,6 +3285,7 @@ static FRESULT find_volume ( /* FR_OK(0): successful, !=0: an error occurred */ /* Following code attempts to mount the volume. (analyze BPB and initialize the filesystem object) */ fs->fs_type = 0; /* Clear the filesystem object */ + fs->part_type = 0; /* Clear the Partition object */ fs->pdrv = LD2PD(vol); /* Bind the logical drive and a physical drive */ stat = disk_initialize(fs->pdrv); /* Initialize the physical drive */ if (stat & STA_NOINIT) { /* Check if the initialization succeeded */ @@ -3318,6 +3320,18 @@ static FRESULT find_volume ( /* FR_OK(0): successful, !=0: an error occurred */ EFSPRINTF("BRNL"); return FR_DISK_ERR; /* An error occured in the disk I/O layer */ } +#if FF_SIMPLE_GPT + if (fmt >= 2) { + /* If GPT Check the first partition */ + gpt_t gpt; + if (disk_read(fs->pdrv, (BYTE *)&gpt, 1, sizeof(gpt_t) / SS(fs))) return FR_DISK_ERR; + if (!mem_cmp(&gpt.header.signature, "EFI PART", 8)) { + fs->part_type = 1; + bsect = gpt.entries[0].lba_start; + fmt = bsect ? check_fs(fs, bsect) : 3; /* Check the partition */ + } + } +#endif if (fmt >= 2) { EFSPRINTF("NOFAT"); return FR_NO_FILESYSTEM; /* No FAT volume is found */ diff --git a/bdk/libs/fatfs/ff.h b/bdk/libs/fatfs/ff.h index a83cf63..48ca614 100644 --- a/bdk/libs/fatfs/ff.h +++ b/bdk/libs/fatfs/ff.h @@ -97,6 +97,7 @@ typedef DWORD FSIZE_t; typedef struct { BYTE win[FF_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */ BYTE fs_type; /* Filesystem type (0:not mounted) */ + BYTE part_type; /* Partition type (0:MBR, 1:GPT) */ BYTE pdrv; /* Associated physical drive */ BYTE n_fats; /* Number of FATs (1 or 2) */ BYTE wflag; /* win[] flag (b0:dirty) */ diff --git a/bdk/storage/nx_sd.h b/bdk/storage/nx_sd.h index bc4c2d4..81a5154 100644 --- a/bdk/storage/nx_sd.h +++ b/bdk/storage/nx_sd.h @@ -51,6 +51,7 @@ bool sd_initialize(bool power_cycle); bool sd_mount(); void sd_unmount(); void sd_end(); +bool sd_is_gpt(); void *sd_file_read(const char *path, u32 *fsize); int sd_save_to_file(void *buf, u32 size, const char *filename); diff --git a/bootloader/hos/hos.c b/bootloader/hos/hos.c index 6c202c5..b208013 100644 --- a/bootloader/hos/hos.c +++ b/bootloader/hos/hos.c @@ -721,6 +721,10 @@ int hos_launch(ini_sec_t *cfg) goto error; } + // Check if SD Card is GPT. + if (sd_is_gpt()) + _hos_crit_error("SD has GPT only!"); + // Read package1 and the correct keyblob. if (!_read_emmc_pkg1(&ctxt)) goto error; diff --git a/bootloader/libs/fatfs/ffconf.h b/bootloader/libs/fatfs/ffconf.h index ee536ef..670be69 100644 --- a/bootloader/libs/fatfs/ffconf.h +++ b/bootloader/libs/fatfs/ffconf.h @@ -46,11 +46,15 @@ /* This option switches fast seek function. (0:Disable or 1:Enable) */ #define FF_FASTFS 0 - #if FF_FASTFS #undef FF_USE_FASTSEEK #define FF_USE_FASTSEEK 1 #endif +/* This option switches fast access to chained clusters. (0:Disable or 1:Enable) */ + + +#define FF_SIMPLE_GPT 1 +/* This option switches support for the first GPT partition. (0:Disable or 1:Enable) */ #define FF_USE_EXPAND 0 @@ -185,6 +189,7 @@ / not defined, a user defined volume string table needs to be defined as: / / const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb",... +/ Order is important. Any change to order, must also be reflected to diskio drive enum. */ @@ -246,7 +251,7 @@ #define FF_FS_NORTC 1 #define FF_NORTC_MON 1 #define FF_NORTC_MDAY 1 -#define FF_NORTC_YEAR 2020 +#define FF_NORTC_YEAR 2021 /* The option FF_FS_NORTC switches timestamp function. If the system does not have / any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable / the timestamp function. Every object modified by FatFs will have a fixed timestamp diff --git a/bootloader/storage/nx_sd.c b/bootloader/storage/nx_sd.c index fa284fa..69f0c50 100644 --- a/bootloader/storage/nx_sd.c +++ b/bootloader/storage/nx_sd.c @@ -180,6 +180,11 @@ static void _sd_deinit() void sd_unmount() { _sd_deinit(); } void sd_end() { _sd_deinit(); } +bool sd_is_gpt() +{ + return sd_fs.part_type; +} + void *sd_file_read(const char *path, u32 *fsize) { FIL fp; diff --git a/nyx/nyx_gui/libs/fatfs/ffconf.h b/nyx/nyx_gui/libs/fatfs/ffconf.h index 1f79990..08bee44 100644 --- a/nyx/nyx_gui/libs/fatfs/ffconf.h +++ b/nyx/nyx_gui/libs/fatfs/ffconf.h @@ -41,16 +41,25 @@ #define FF_USE_MKFS 1 /* This option switches f_mkfs() function. (0:Disable or 1:Enable) */ +#if FF_USE_MKFS +#define FF_MKFS_LABEL "SWITCH SD " +#endif +/* This sets FAT/FAT32 label. Exactly 11 characters, all caps. */ + #define FF_USE_FASTSEEK 0 /* This option switches fast seek function. (0:Disable or 1:Enable) */ #define FF_FASTFS 1 - #if FF_FASTFS #undef FF_USE_FASTSEEK #define FF_USE_FASTSEEK 1 #endif +/* This option switches fast access to chained clusters. (0:Disable or 1:Enable) */ + + +#define FF_SIMPLE_GPT 1 +/* This option switches support for the first GPT partition. (0:Disable or 1:Enable) */ #define FF_USE_EXPAND 0 @@ -186,6 +195,7 @@ / not defined, a user defined volume string table needs to be defined as: / / const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb",... +/ Order is important. Any change to order, must also be reflected to diskio drive enum. */ @@ -247,7 +257,7 @@ #define FF_FS_NORTC 0 #define FF_NORTC_MON 1 #define FF_NORTC_MDAY 1 -#define FF_NORTC_YEAR 2020 +#define FF_NORTC_YEAR 2021 /* The option FF_FS_NORTC switches timestamp function. If the system does not have / any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable / the timestamp function. Every object modified by FatFs will have a fixed timestamp