Bug fixes, wording, etc

This commit is contained in:
Kostas Missos 2018-06-01 19:02:13 +03:00 committed by nwert
parent d8251ab28b
commit 54a0a353bc
5 changed files with 76 additions and 76 deletions

View file

@ -26,7 +26,7 @@
#include "gfx.h" #include "gfx.h"
extern gfx_ctxt_t gfx_ctxt; extern gfx_ctxt_t gfx_ctxt;
extern gfx_con_t gfx_con; extern gfx_con_t gfx_con;
#define EFSPRINTF(text, ...) gfx_printf(&gfx_con, "\n\n\n%k[FatFS] "text"%k\n", 0xFF00FFFF, 0xFFFFFFFF) #define EFSPRINTF(text, ...) gfx_printf(&gfx_con, "\n\n\n%k[FatFS] Error: "text"%k\n", 0xFF00FFFF, 0xFFFFFFFF)
//#define EFSPRINTF(...) //#define EFSPRINTF(...)
/*-------------------------------------------------------------------------- /*--------------------------------------------------------------------------
@ -3259,7 +3259,7 @@ FRESULT find_volume ( /* FR_OK(0): successful, !=0: any error occurred */
stat = disk_status(fs->pdrv); stat = disk_status(fs->pdrv);
if (!(stat & STA_NOINIT)) { /* and the physical drive is kept initialized */ if (!(stat & STA_NOINIT)) { /* and the physical drive is kept initialized */
if (!FF_FS_READONLY && mode && (stat & STA_PROTECT)) { /* Check write protection if needed */ if (!FF_FS_READONLY && mode && (stat & STA_PROTECT)) { /* Check write protection if needed */
EFSPRINTF("Error: Write protected!"); EFSPRINTF("Write protected!");
return FR_WRITE_PROTECTED; return FR_WRITE_PROTECTED;
} }
return FR_OK; /* The filesystem object is valid */ return FR_OK; /* The filesystem object is valid */
@ -3273,11 +3273,11 @@ FRESULT find_volume ( /* FR_OK(0): successful, !=0: any error occurred */
fs->pdrv = LD2PD(vol); /* Bind the logical drive and a physical drive */ fs->pdrv = LD2PD(vol); /* Bind the logical drive and a physical drive */
stat = disk_initialize(fs->pdrv); /* Initialize the physical drive */ stat = disk_initialize(fs->pdrv); /* Initialize the physical drive */
if (stat & STA_NOINIT) { /* Check if the initialization succeeded */ if (stat & STA_NOINIT) { /* Check if the initialization succeeded */
EFSPRINTF("Error: Medium not ready or hard error!"); EFSPRINTF("Medium not ready or hard error!");
return FR_NOT_READY; /* Failed to initialize due to no medium or hard error */ return FR_NOT_READY; /* Failed to initialize due to no medium or hard error */
} }
if (!FF_FS_READONLY && mode && (stat & STA_PROTECT)) { /* Check disk write protection if needed */ if (!FF_FS_READONLY && mode && (stat & STA_PROTECT)) { /* Check disk write protection if needed */
EFSPRINTF("Error: Write protected!"); EFSPRINTF("Write protected!");
return FR_WRITE_PROTECTED; return FR_WRITE_PROTECTED;
} }
#if FF_MAX_SS != FF_MIN_SS /* Get sector size (multiple sector size cfg only) */ #if FF_MAX_SS != FF_MIN_SS /* Get sector size (multiple sector size cfg only) */
@ -3301,11 +3301,11 @@ FRESULT find_volume ( /* FR_OK(0): successful, !=0: any error occurred */
} while (LD2PT(vol) == 0 && fmt >= 2 && ++i < 4); } while (LD2PT(vol) == 0 && fmt >= 2 && ++i < 4);
} }
if (fmt == 4) { if (fmt == 4) {
EFSPRINTF("Error: Disk I/O error - Could not load boot record!"); EFSPRINTF("Disk I/O error - Could not load boot record!");
return FR_DISK_ERR; /* An error occured in the disk I/O layer */ return FR_DISK_ERR; /* An error occured in the disk I/O layer */
} }
if (fmt >= 2) { if (fmt >= 2) {
EFSPRINTF("Error: No FAT/FAT32/exFAT filesystem found!"); EFSPRINTF("No FAT/FAT32/exFAT filesystem found!");
return FR_NO_FILESYSTEM; /* No FAT volume is found */ return FR_NO_FILESYSTEM; /* No FAT volume is found */
} }
@ -3316,21 +3316,24 @@ FRESULT find_volume ( /* FR_OK(0): successful, !=0: any error occurred */
QWORD maxlba; QWORD maxlba;
for (i = BPB_ZeroedEx; i < BPB_ZeroedEx + 53 && fs->win[i] == 0; i++) ; /* Check zero filler */ for (i = BPB_ZeroedEx; i < BPB_ZeroedEx + 53 && fs->win[i] == 0; i++) ; /* Check zero filler */
if (i < BPB_ZeroedEx + 53) return FR_NO_FILESYSTEM; if (i < BPB_ZeroedEx + 53) {
EFSPRINTF("exFAT - Zero filler check failed!");
return FR_NO_FILESYSTEM;
}
if (ld_word(fs->win + BPB_FSVerEx) != 0x100) { if (ld_word(fs->win + BPB_FSVerEx) != 0x100) {
EFSPRINTF("Error: exFAT - Version check failed!"); EFSPRINTF("exFAT - Version check failed!");
return FR_NO_FILESYSTEM; /* Check exFAT version (must be version 1.0) */ return FR_NO_FILESYSTEM; /* Check exFAT version (must be version 1.0) */
} }
if (1 << fs->win[BPB_BytsPerSecEx] != SS(fs)) { /* (BPB_BytsPerSecEx must be equal to the physical sector size) */ if (1 << fs->win[BPB_BytsPerSecEx] != SS(fs)) { /* (BPB_BytsPerSecEx must be equal to the physical sector size) */
EFSPRINTF("Error: exFAT - Bytes per sector does not match physical sector size!"); EFSPRINTF("exFAT - Bytes per sector does not match physical sector size!");
return FR_NO_FILESYSTEM; return FR_NO_FILESYSTEM;
} }
maxlba = ld_qword(fs->win + BPB_TotSecEx) + bsect; /* Last LBA + 1 of the volume */ maxlba = ld_qword(fs->win + BPB_TotSecEx) + bsect; /* Last LBA + 1 of the volume */
if (maxlba >= 0x100000000) { if (maxlba >= 0x100000000) {
EFSPRINTF("Error: exFAT - Cannot handle volume LBA with 32-bit LBA!"); EFSPRINTF("exFAT - Cannot handle volume LBA with 32-bit LBA!");
return FR_NO_FILESYSTEM; /* (It cannot be handled in 32-bit LBA) */ return FR_NO_FILESYSTEM; /* (It cannot be handled in 32-bit LBA) */
} }
@ -3338,19 +3341,19 @@ FRESULT find_volume ( /* FR_OK(0): successful, !=0: any error occurred */
fs->n_fats = fs->win[BPB_NumFATsEx]; /* Number of FATs */ fs->n_fats = fs->win[BPB_NumFATsEx]; /* Number of FATs */
if (fs->n_fats != 1) { if (fs->n_fats != 1) {
EFSPRINTF("Error: exFAT - Multiple or no file allocation tables found!"); EFSPRINTF("exFAT - Multiple or no file allocation tables found!");
return FR_NO_FILESYSTEM; /* (Supports only 1 FAT) */ return FR_NO_FILESYSTEM; /* (Supports only 1 FAT) */
} }
fs->csize = 1 << fs->win[BPB_SecPerClusEx]; /* Cluster size */ fs->csize = 1 << fs->win[BPB_SecPerClusEx]; /* Cluster size */
if (fs->csize == 0) { if (fs->csize == 0) {
EFSPRINTF("Error: exFAT - Cluster size is not between 1KB - 32KB!"); EFSPRINTF("exFAT - Cluster size is not between 1KB - 32KB!");
return FR_NO_FILESYSTEM; /* (Must be 1..32768) */ return FR_NO_FILESYSTEM; /* (Must be 1..32768) */
} }
nclst = ld_dword(fs->win + BPB_NumClusEx); /* Number of clusters */ nclst = ld_dword(fs->win + BPB_NumClusEx); /* Number of clusters */
if (nclst > MAX_EXFAT) { if (nclst > MAX_EXFAT) {
EFSPRINTF("Error: exFAT - Total clusters exceed allowed!"); EFSPRINTF("exFAT - Total clusters exceed allowed!");
return FR_NO_FILESYSTEM; /* (Too many clusters) */ return FR_NO_FILESYSTEM; /* (Too many clusters) */
} }
fs->n_fatent = nclst + 2; fs->n_fatent = nclst + 2;
@ -3360,20 +3363,23 @@ FRESULT find_volume ( /* FR_OK(0): successful, !=0: any error occurred */
fs->database = bsect + ld_dword(fs->win + BPB_DataOfsEx); fs->database = bsect + ld_dword(fs->win + BPB_DataOfsEx);
fs->fatbase = bsect + ld_dword(fs->win + BPB_FatOfsEx); fs->fatbase = bsect + ld_dword(fs->win + BPB_FatOfsEx);
if (maxlba < (QWORD)fs->database + nclst * fs->csize) { if (maxlba < (QWORD)fs->database + nclst * fs->csize) {
EFSPRINTF("Error: exFAT - Volume size is lower than required!"); EFSPRINTF("exFAT - Volume size is lower than required!");
return FR_NO_FILESYSTEM; /* (Volume size must not be smaller than the size required) */ return FR_NO_FILESYSTEM; /* (Volume size must not be smaller than the size required) */
} }
fs->dirbase = ld_dword(fs->win + BPB_RootClusEx); fs->dirbase = ld_dword(fs->win + BPB_RootClusEx);
/* Check if bitmap location is in assumption (at the first cluster) */ /* Check if bitmap location is in assumption (at the first cluster) */
if (move_window(fs, clst2sect(fs, fs->dirbase)) != FR_OK) { if (move_window(fs, clst2sect(fs, fs->dirbase)) != FR_OK) {
EFSPRINTF("Error: exFAT - Bitmap location not at first cluster!"); EFSPRINTF("exFAT - Bitmap location not at first cluster!");
return FR_DISK_ERR; return FR_DISK_ERR;
} }
for (i = 0; i < SS(fs); i += SZDIRE) { for (i = 0; i < SS(fs); i += SZDIRE) {
if (fs->win[i] == 0x81 && ld_dword(fs->win + i + 20) == 2) break; /* 81 entry with cluster #2? */ if (fs->win[i] == 0x81 && ld_dword(fs->win + i + 20) == 2) break; /* 81 entry with cluster #2? */
} }
if (i == SS(fs)) return FR_NO_FILESYSTEM; if (i == SS(fs)) {
EFSPRINTF("exFAT - Bitmap allocation is missing!");
return FR_NO_FILESYSTEM;
}
#if !FF_FS_READONLY #if !FF_FS_READONLY
fs->last_clst = fs->free_clst = 0xFFFFFFFF; /* Initialize cluster allocation information */ fs->last_clst = fs->free_clst = 0xFFFFFFFF; /* Initialize cluster allocation information */
#endif #endif
@ -3382,7 +3388,7 @@ FRESULT find_volume ( /* FR_OK(0): successful, !=0: any error occurred */
#endif /* FF_FS_EXFAT */ #endif /* FF_FS_EXFAT */
{ {
if (ld_word(fs->win + BPB_BytsPerSec) != SS(fs)) { if (ld_word(fs->win + BPB_BytsPerSec) != SS(fs)) {
EFSPRINTF("Error: FAT - Bytes per sector does not match physical sector size!"); EFSPRINTF("FAT - Bytes per sector does not match physical sector size!");
return FR_NO_FILESYSTEM; /* (BPB_BytsPerSec must be equal to the physical sector size) */ return FR_NO_FILESYSTEM; /* (BPB_BytsPerSec must be equal to the physical sector size) */
} }
@ -3392,20 +3398,20 @@ FRESULT find_volume ( /* FR_OK(0): successful, !=0: any error occurred */
fs->n_fats = fs->win[BPB_NumFATs]; /* Number of FATs */ fs->n_fats = fs->win[BPB_NumFATs]; /* Number of FATs */
if (fs->n_fats != 1 && fs->n_fats != 2) { if (fs->n_fats != 1 && fs->n_fats != 2) {
EFSPRINTF("Error: FAT - No or more than 2 file allocation tables found!"); EFSPRINTF("FAT - No or more than 2 file allocation tables found!");
return FR_NO_FILESYSTEM; /* (Must be 1 or 2) */ return FR_NO_FILESYSTEM; /* (Must be 1 or 2) */
} }
fasize *= fs->n_fats; /* Number of sectors for FAT area */ fasize *= fs->n_fats; /* Number of sectors for FAT area */
fs->csize = fs->win[BPB_SecPerClus]; /* Cluster size */ fs->csize = fs->win[BPB_SecPerClus]; /* Cluster size */
if (fs->csize == 0 || (fs->csize & (fs->csize - 1))) { if (fs->csize == 0 || (fs->csize & (fs->csize - 1))) {
EFSPRINTF("Error: FAT - Cluster size is not a power of 2!"); EFSPRINTF("FAT - Cluster size is not a power of 2!");
return FR_NO_FILESYSTEM; /* (Must be power of 2) */ return FR_NO_FILESYSTEM; /* (Must be power of 2) */
} }
fs->n_rootdir = ld_word(fs->win + BPB_RootEntCnt); /* Number of root directory entries */ fs->n_rootdir = ld_word(fs->win + BPB_RootEntCnt); /* Number of root directory entries */
if (fs->n_rootdir % (SS(fs) / SZDIRE)) { if (fs->n_rootdir % (SS(fs) / SZDIRE)) {
EFSPRINTF("Error: FAT - Root directory entries are not sector aligned!"); EFSPRINTF("FAT - Root directory entries are not sector aligned!");
return FR_NO_FILESYSTEM; /* (Must be sector aligned) */ return FR_NO_FILESYSTEM; /* (Must be sector aligned) */
} }
@ -3414,19 +3420,19 @@ FRESULT find_volume ( /* FR_OK(0): successful, !=0: any error occurred */
nrsv = ld_word(fs->win + BPB_RsvdSecCnt); /* Number of reserved sectors */ nrsv = ld_word(fs->win + BPB_RsvdSecCnt); /* Number of reserved sectors */
if (nrsv == 0) { if (nrsv == 0) {
EFSPRINTF("Error: FAT - Zero reserved sectors!"); EFSPRINTF("FAT - Zero reserved sectors!");
return FR_NO_FILESYSTEM; /* (Must not be 0) */ return FR_NO_FILESYSTEM; /* (Must not be 0) */
} }
/* Determine the FAT sub type */ /* Determine the FAT sub type */
sysect = nrsv + fasize + fs->n_rootdir / (SS(fs) / SZDIRE); /* RSV + FAT + DIR */ sysect = nrsv + fasize + fs->n_rootdir / (SS(fs) / SZDIRE); /* RSV + FAT + DIR */
if (tsect < sysect) { if (tsect < sysect) {
EFSPRINTF("Error: FAT - Invalid volume size!"); EFSPRINTF("FAT - Invalid volume size!");
return FR_NO_FILESYSTEM; /* (Invalid volume size) */ return FR_NO_FILESYSTEM; /* (Invalid volume size) */
} }
nclst = (tsect - sysect) / fs->csize; /* Number of clusters */ nclst = (tsect - sysect) / fs->csize; /* Number of clusters */
if (nclst == 0) { if (nclst == 0) {
EFSPRINTF("Error: FAT - Invalid volume size!"); EFSPRINTF("FAT - Invalid volume size!");
return FR_NO_FILESYSTEM; /* (Invalid volume size) */ return FR_NO_FILESYSTEM; /* (Invalid volume size) */
} }
fmt = 0; fmt = 0;
@ -3434,7 +3440,7 @@ FRESULT find_volume ( /* FR_OK(0): successful, !=0: any error occurred */
if (nclst <= MAX_FAT16) fmt = FS_FAT16; if (nclst <= MAX_FAT16) fmt = FS_FAT16;
if (nclst <= MAX_FAT12) fmt = FS_FAT12; if (nclst <= MAX_FAT12) fmt = FS_FAT12;
if (fmt == 0) { if (fmt == 0) {
EFSPRINTF("Error: FAT - Not compatible FAT12/16/32 filesystem!"); EFSPRINTF("FAT - Not compatible FAT12/16/32 filesystem!");
return FR_NO_FILESYSTEM; return FR_NO_FILESYSTEM;
} }
@ -3445,18 +3451,18 @@ FRESULT find_volume ( /* FR_OK(0): successful, !=0: any error occurred */
fs->database = bsect + sysect; /* Data start sector */ fs->database = bsect + sysect; /* Data start sector */
if (fmt == FS_FAT32) { if (fmt == FS_FAT32) {
if (ld_word(fs->win + BPB_FSVer32) != 0) { if (ld_word(fs->win + BPB_FSVer32) != 0) {
EFSPRINTF("Error: FAT32 - Not a 0.0 revision!"); EFSPRINTF("FAT32 - Not a 0.0 revision!");
return FR_NO_FILESYSTEM; /* (Must be FAT32 revision 0.0) */ return FR_NO_FILESYSTEM; /* (Must be FAT32 revision 0.0) */
} }
if (fs->n_rootdir != 0) { if (fs->n_rootdir != 0) {
EFSPRINTF("Error: FAT32 - Root entry sector is not 0!"); EFSPRINTF("FAT32 - Root entry sector is not 0!");
return FR_NO_FILESYSTEM; /* (BPB_RootEntCnt must be 0) */ return FR_NO_FILESYSTEM; /* (BPB_RootEntCnt must be 0) */
} }
fs->dirbase = ld_dword(fs->win + BPB_RootClus32); /* Root directory start cluster */ fs->dirbase = ld_dword(fs->win + BPB_RootClus32); /* Root directory start cluster */
szbfat = fs->n_fatent * 4; /* (Needed FAT size) */ szbfat = fs->n_fatent * 4; /* (Needed FAT size) */
} else { } else {
if (fs->n_rootdir == 0) { if (fs->n_rootdir == 0) {
EFSPRINTF("Error: FAT - Root entry sector is 0!"); EFSPRINTF("FAT - Root entry sector is 0!");
return FR_NO_FILESYSTEM; /* (BPB_RootEntCnt must not be 0) */ return FR_NO_FILESYSTEM; /* (BPB_RootEntCnt must not be 0) */
} }
fs->dirbase = fs->fatbase + fasize; /* Root directory start sector */ fs->dirbase = fs->fatbase + fasize; /* Root directory start sector */
@ -3464,7 +3470,7 @@ FRESULT find_volume ( /* FR_OK(0): successful, !=0: any error occurred */
fs->n_fatent * 2 : fs->n_fatent * 3 / 2 + (fs->n_fatent & 1); fs->n_fatent * 2 : fs->n_fatent * 3 / 2 + (fs->n_fatent & 1);
} }
if (fs->fsize < (szbfat + (SS(fs) - 1)) / SS(fs)) { if (fs->fsize < (szbfat + (SS(fs) - 1)) / SS(fs)) {
EFSPRINTF("Error: FAT - FAT size is not the required size!"); EFSPRINTF("FAT - FAT size is not the required size!");
return FR_NO_FILESYSTEM; /* (BPB_FATSz must not be less than the size needed) */ return FR_NO_FILESYSTEM; /* (BPB_FATSz must not be less than the size needed) */
} }
@ -3578,7 +3584,7 @@ FRESULT f_mount (
/* Get logical drive number */ /* Get logical drive number */
vol = get_ldnumber(&rp); vol = get_ldnumber(&rp);
if (vol < 0) { if (vol < 0) {
EFSPRINTF("Error: Invalid drive!"); EFSPRINTF("Invalid drive!");
return FR_INVALID_DRIVE; return FR_INVALID_DRIVE;
} }
cfs = FatFs[vol]; /* Pointer to fs object */ cfs = FatFs[vol]; /* Pointer to fs object */
@ -3822,11 +3828,11 @@ FRESULT f_read (
*br = 0; /* Clear read byte counter */ *br = 0; /* Clear read byte counter */
res = validate(&fp->obj, &fs); /* Check validity of the file object */ res = validate(&fp->obj, &fs); /* Check validity of the file object */
if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) { if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) {
EFSPRINTF("Error: File object Validation!"); EFSPRINTF("File object Validation!");
LEAVE_FF(fs, res); /* Check validity */ LEAVE_FF(fs, res); /* Check validity */
} }
if (!(fp->flag & FA_READ)) { if (!(fp->flag & FA_READ)) {
EFSPRINTF("Error: Access denied!"); EFSPRINTF("Access denied!");
LEAVE_FF(fs, FR_DENIED); /* Check access mode */ LEAVE_FF(fs, FR_DENIED); /* Check access mode */
} }
remain = fp->obj.objsize - fp->fptr; remain = fp->obj.objsize - fp->fptr;
@ -3850,18 +3856,18 @@ FRESULT f_read (
} }
} }
if (clst < 2) { if (clst < 2) {
EFSPRINTF("Error: Cluster status check or Internal error!"); EFSPRINTF("Cluster status check or Internal error!");
ABORT(fs, FR_INT_ERR); ABORT(fs, FR_INT_ERR);
} }
if (clst == 0xFFFFFFFF) { if (clst == 0xFFFFFFFF) {
EFSPRINTF("Error: Disk error (cluster hard error)!"); EFSPRINTF("Disk error (cluster hard error)!");
ABORT(fs, FR_DISK_ERR); ABORT(fs, FR_DISK_ERR);
} }
fp->clust = clst; /* Update current cluster */ fp->clust = clst; /* Update current cluster */
} }
sect = clst2sect(fs, fp->clust); /* Get current sector */ sect = clst2sect(fs, fp->clust); /* Get current sector */
if (sect == 0) { if (sect == 0) {
EFSPRINTF("Error: Get current sector error!"); EFSPRINTF("Get current sector error!");
ABORT(fs, FR_INT_ERR); ABORT(fs, FR_INT_ERR);
} }
sect += csect; sect += csect;
@ -3871,7 +3877,7 @@ FRESULT f_read (
cc = fs->csize - csect; cc = fs->csize - csect;
} }
if (disk_read(fs->pdrv, rbuff, sect, cc) != RES_OK) { if (disk_read(fs->pdrv, rbuff, sect, cc) != RES_OK) {
EFSPRINTF("Error: Read - Low level disk I/O!"); EFSPRINTF("Read - Low level disk I/O!");
ABORT(fs, FR_DISK_ERR); ABORT(fs, FR_DISK_ERR);
} }
#if !FF_FS_READONLY && FF_FS_MINIMIZE <= 2 /* Replace one of the read sectors with cached data if it contains a dirty sector */ #if !FF_FS_READONLY && FF_FS_MINIMIZE <= 2 /* Replace one of the read sectors with cached data if it contains a dirty sector */
@ -3893,14 +3899,14 @@ FRESULT f_read (
#if !FF_FS_READONLY #if !FF_FS_READONLY
if (fp->flag & FA_DIRTY) { /* Write-back dirty sector cache */ if (fp->flag & FA_DIRTY) { /* Write-back dirty sector cache */
if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) { if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) {
EFSPRINTF("Error: Write-back dirty sector cache!"); EFSPRINTF("Write-back dirty sector cache!");
ABORT(fs, FR_DISK_ERR); ABORT(fs, FR_DISK_ERR);
} }
fp->flag &= (BYTE)~FA_DIRTY; fp->flag &= (BYTE)~FA_DIRTY;
} }
#endif #endif
if (disk_read(fs->pdrv, fp->buf, sect, 1) != RES_OK) { if (disk_read(fs->pdrv, fp->buf, sect, 1) != RES_OK) {
EFSPRINTF("Error: Read - Low level disk I/O!\n(fill sector cache)"); EFSPRINTF("Read - Low level disk I/O!\n(fill sector cache)");
ABORT(fs, FR_DISK_ERR); /* Fill sector cache */ ABORT(fs, FR_DISK_ERR); /* Fill sector cache */
} }
} }
@ -3945,11 +3951,11 @@ FRESULT f_write (
*bw = 0; /* Clear write byte counter */ *bw = 0; /* Clear write byte counter */
res = validate(&fp->obj, &fs); /* Check validity of the file object */ res = validate(&fp->obj, &fs); /* Check validity of the file object */
if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) { if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) {
EFSPRINTF("Error: File object Validation!"); EFSPRINTF("File object Validation!");
LEAVE_FF(fs, res); /* Check validity */ LEAVE_FF(fs, res); /* Check validity */
} }
if (!(fp->flag & FA_WRITE)) { if (!(fp->flag & FA_WRITE)) {
EFSPRINTF("Error: Access denied!"); EFSPRINTF("Access denied!");
LEAVE_FF(fs, FR_DENIED); /* Check access mode */ LEAVE_FF(fs, FR_DENIED); /* Check access mode */
} }
@ -3979,15 +3985,15 @@ FRESULT f_write (
} }
} }
if (clst == 0) { if (clst == 0) {
EFSPRINTF("Error: Could not allocate a new cluster\n(disk full or low level disk I/O error)!"); EFSPRINTF("Could not allocate a new cluster\n(disk full or low level disk I/O error)!");
break; /* Could not allocate a new cluster (disk full) */ break; /* Could not allocate a new cluster (disk full) */
} }
if (clst == 1) { if (clst == 1) {
EFSPRINTF("Error: Cluster status check or Internal error!"); EFSPRINTF("Cluster status check or Internal error!");
ABORT(fs, FR_INT_ERR); ABORT(fs, FR_INT_ERR);
} }
if (clst == 0xFFFFFFFF) { if (clst == 0xFFFFFFFF) {
EFSPRINTF("Error: Disk error (cluster hard error)!"); EFSPRINTF("Disk error (cluster hard error)!");
ABORT(fs, FR_DISK_ERR); ABORT(fs, FR_DISK_ERR);
} }
fp->clust = clst; /* Update current cluster */ fp->clust = clst; /* Update current cluster */
@ -3998,7 +4004,7 @@ FRESULT f_write (
#else #else
if (fp->flag & FA_DIRTY) { /* Write-back sector cache */ if (fp->flag & FA_DIRTY) { /* Write-back sector cache */
if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) { if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) {
EFSPRINTF("Error: Write-back sector cache!"); EFSPRINTF("Write-back sector cache!");
ABORT(fs, FR_DISK_ERR); ABORT(fs, FR_DISK_ERR);
} }
fp->flag &= (BYTE)~FA_DIRTY; fp->flag &= (BYTE)~FA_DIRTY;
@ -4006,7 +4012,7 @@ FRESULT f_write (
#endif #endif
sect = clst2sect(fs, fp->clust); /* Get current sector */ sect = clst2sect(fs, fp->clust); /* Get current sector */
if (sect == 0) { if (sect == 0) {
EFSPRINTF("Error: Get current sector error!"); EFSPRINTF("Get current sector error!");
ABORT(fs, FR_INT_ERR); ABORT(fs, FR_INT_ERR);
} }
sect += csect; sect += csect;
@ -4016,7 +4022,7 @@ FRESULT f_write (
cc = fs->csize - csect; cc = fs->csize - csect;
} }
if (disk_write(fs->pdrv, wbuff, sect, cc) != RES_OK) { if (disk_write(fs->pdrv, wbuff, sect, cc) != RES_OK) {
EFSPRINTF("Error: Write - Low level disk I/O!"); EFSPRINTF("Write - Low level disk I/O!");
ABORT(fs, FR_DISK_ERR); ABORT(fs, FR_DISK_ERR);
} }
#if FF_FS_MINIMIZE <= 2 #if FF_FS_MINIMIZE <= 2
@ -4044,7 +4050,7 @@ FRESULT f_write (
if (fp->sect != sect && /* Fill sector cache with file data */ if (fp->sect != sect && /* Fill sector cache with file data */
fp->fptr < fp->obj.objsize && fp->fptr < fp->obj.objsize &&
disk_read(fs->pdrv, fp->buf, sect, 1) != RES_OK) { disk_read(fs->pdrv, fp->buf, sect, 1) != RES_OK) {
EFSPRINTF("Error: Read - Low level disk I/O!\n(Could not fill sector cache with file data)"); EFSPRINTF("Read - Low level disk I/O!\n(Could not fill sector cache with file data)");
ABORT(fs, FR_DISK_ERR); ABORT(fs, FR_DISK_ERR);
} }
#endif #endif

View file

@ -35,8 +35,8 @@
#include "gfx.h" #include "gfx.h"
extern gfx_ctxt_t gfx_ctxt; extern gfx_ctxt_t gfx_ctxt;
extern gfx_con_t gfx_con; extern gfx_con_t gfx_con;
#define DPRINTF(...) gfx_printf(&gfx_con, __VA_ARGS__) //#define DPRINTF(...) gfx_printf(&gfx_con, __VA_ARGS__)
//#define DPRINTF(...) #define DPRINTF(...)
enum KB_FIRMWARE_VERSION { enum KB_FIRMWARE_VERSION {
KB_FIRMWARE_VERSION_100_200 = 0, KB_FIRMWARE_VERSION_100_200 = 0,
@ -213,10 +213,10 @@ static int _read_emmc_pkg1(launch_ctxt_t *ctxt)
ctxt->pkg1_id = pkg1_identify(ctxt->pkg1); ctxt->pkg1_id = pkg1_identify(ctxt->pkg1);
if (!ctxt->pkg1_id) if (!ctxt->pkg1_id)
{ {
DPRINTF("%kCould not identify package1 version (= '%s').%k\n", 0xFF0000FF, (char *)ctxt->pkg1 + 0x10, 0xFFFFFFFF); gfx_printf(&gfx_con, "%kCould not identify package1 version (= '%s').%k\n", 0xFF0000FF, (char *)ctxt->pkg1 + 0x10, 0xFFFFFFFF);
goto out; goto out;
} }
DPRINTF("Identified package1 ('%s'), keyblob version %d\n", (char *)(ctxt->pkg1 + 0x10), ctxt->pkg1_id->kb); gfx_printf(&gfx_con, "Identified package1 ('%s'), Keyblob version %d\n\n", (char *)(ctxt->pkg1 + 0x10), ctxt->pkg1_id->kb);
//Read the correct keyblob. //Read the correct keyblob.
ctxt->keyblob = (u8 *)malloc(NX_EMMC_BLOCKSIZE); ctxt->keyblob = (u8 *)malloc(NX_EMMC_BLOCKSIZE);
@ -241,7 +241,7 @@ static int _read_emmc_pkg2(launch_ctxt_t *ctxt)
//Parse eMMC GPT. //Parse eMMC GPT.
LIST_INIT(gpt); LIST_INIT(gpt);
nx_emmc_gpt_parse(&gpt, &storage); nx_emmc_gpt_parse(&gpt, &storage);
DPRINTF("parsed GPT\n"); DPRINTF("Parsed GPT\n");
//Find package2 partition. //Find package2 partition.
emmc_part_t *pkg2_part = nx_emmc_part_find(&gpt, "BCPKG2-1-Normal-Main"); emmc_part_t *pkg2_part = nx_emmc_part_find(&gpt, "BCPKG2-1-Normal-Main");
if (!pkg2_part) if (!pkg2_part)
@ -315,7 +315,7 @@ static int _config_kip1(launch_ctxt_t *ctxt, const char *value)
merge_kip_t *mkip1 = (merge_kip_t *)malloc(sizeof(merge_kip_t)); merge_kip_t *mkip1 = (merge_kip_t *)malloc(sizeof(merge_kip_t));
mkip1->kip1 = malloc(f_size(&fp)); mkip1->kip1 = malloc(f_size(&fp));
f_read(&fp, mkip1->kip1, f_size(&fp), NULL); f_read(&fp, mkip1->kip1, f_size(&fp), NULL);
DPRINTF("loaded kip from SD (size %08X)\n", f_size(&fp)); DPRINTF("Loaded kip1 from SD (size %08X)\n", f_size(&fp));
f_close(&fp); f_close(&fp);
list_append(&ctxt->kip1_list, &mkip1->link); list_append(&ctxt->kip1_list, &mkip1->link);
return 1; return 1;
@ -358,11 +358,7 @@ int hos_launch(ini_sec_t *cfg)
if (!_read_emmc_pkg1(&ctxt)) if (!_read_emmc_pkg1(&ctxt))
return 0; return 0;
//XXX: remove this once we support 3+. gfx_printf(&gfx_con, "Loaded package1 and keyblob\n");
//if (ctxt.pkg1_id->kb > 0)
// return 0;
DPRINTF("loaded pkg1 and keyblob\n");
//Generate keys. //Generate keys.
keygen(ctxt.keyblob, ctxt.pkg1_id->kb, (u8 *)ctxt.pkg1 + ctxt.pkg1_id->tsec_off); keygen(ctxt.keyblob, ctxt.pkg1_id->kb, (u8 *)ctxt.pkg1 + ctxt.pkg1_id->tsec_off);
DPRINTF("generated keys\n"); DPRINTF("generated keys\n");
@ -373,7 +369,7 @@ DPRINTF("generated keys\n");
pkg1_unpack((void *)0x8000D000, (void *)ctxt.pkg1_id->secmon_base, ctxt.pkg1_id, ctxt.pkg1); pkg1_unpack((void *)0x8000D000, (void *)ctxt.pkg1_id->secmon_base, ctxt.pkg1_id, ctxt.pkg1);
//gfx_hexdump(&gfx_con, 0x8000D000, (void *)0x8000D000, 0x100); //gfx_hexdump(&gfx_con, 0x8000D000, (void *)0x8000D000, 0x100);
//gfx_hexdump(&gfx_con, ctxt.pkg1_id->secmon_base, (void *)ctxt.pkg1_id->secmon_base, 0x100); //gfx_hexdump(&gfx_con, ctxt.pkg1_id->secmon_base, (void *)ctxt.pkg1_id->secmon_base, 0x100);
DPRINTF("decrypted and unpacked pkg1\n"); gfx_printf(&gfx_con, "Decrypted and unpacked package1\n");
} }
//Replace 'warmboot.bin' if requested. //Replace 'warmboot.bin' if requested.
if (ctxt.warmboot) if (ctxt.warmboot)
@ -399,14 +395,14 @@ DPRINTF("decrypted and unpacked pkg1\n");
if (!_read_emmc_pkg2(&ctxt)) if (!_read_emmc_pkg2(&ctxt))
return 0; return 0;
DPRINTF("read pkg2\n"); gfx_printf(&gfx_con, "Read package2\n");
//Decrypt package2 and parse KIP1 blobs in INI1 section. //Decrypt package2 and parse KIP1 blobs in INI1 section.
pkg2_hdr_t *pkg2_hdr = pkg2_decrypt(ctxt.pkg2); pkg2_hdr_t *pkg2_hdr = pkg2_decrypt(ctxt.pkg2);
LIST_INIT(kip1_info); LIST_INIT(kip1_info);
pkg2_parse_kips(&kip1_info, pkg2_hdr); pkg2_parse_kips(&kip1_info, pkg2_hdr);
DPRINTF("parsed ini1\n"); gfx_printf(&gfx_con, "Parsed ini1\n");
//Use the kernel included in package2 in case we didn't load one already. //Use the kernel included in package2 in case we didn't load one already.
if (!ctxt.kernel) if (!ctxt.kernel)
@ -421,13 +417,13 @@ DPRINTF("decrypted and unpacked pkg1\n");
//Rebuild and encrypt package2. //Rebuild and encrypt package2.
pkg2_build_encrypt((void *)0xA9800000, ctxt.kernel, ctxt.kernel_size, &kip1_info); pkg2_build_encrypt((void *)0xA9800000, ctxt.kernel, ctxt.kernel_size, &kip1_info);
DPRINTF("rebuilt pkg2\n"); gfx_printf(&gfx_con, "Rebuilt and loaded package2\n");
} else { } else {
//Read package2. //Read package2.
if (!_read_emmc_pkg2(&ctxt)) if (!_read_emmc_pkg2(&ctxt))
return 0; return 0;
DPRINTF("read pkg2\n"); gfx_printf(&gfx_con, "Loaded package2\n");
memcpy((void *)0xA9800000, ctxt.pkg2, ctxt.pkg2_size); memcpy((void *)0xA9800000, ctxt.pkg2, ctxt.pkg2_size);
} }
} }
@ -446,8 +442,6 @@ DPRINTF("decrypted and unpacked pkg1\n");
case KB_FIRMWARE_VERSION_400: case KB_FIRMWARE_VERSION_400:
case KB_FIRMWARE_VERSION_500: case KB_FIRMWARE_VERSION_500:
se_key_acc_ctrl(0xC, 0xFF); se_key_acc_ctrl(0xC, 0xFF);
//se_key_acc_ctrl(0xD, 0xFF);
//se_key_acc_ctrl(0xE, 0xFF);
se_key_acc_ctrl(0xF, 0xFF); se_key_acc_ctrl(0xF, 0xFF);
break; break;
} }

View file

@ -516,7 +516,7 @@ void print_mmc_info()
boot_size / 1024, boot_size / 1024 / 512); boot_size / 1024, boot_size / 1024 / 512);
gfx_printf(&gfx_con, " 3: %kRPMB %kSize: %5d KiB (LBA Sectors: 0x%07X)\n", 0xFF00FF96, 0xFFCCCCCC, gfx_printf(&gfx_con, " 3: %kRPMB %kSize: %5d KiB (LBA Sectors: 0x%07X)\n", 0xFF00FF96, 0xFFCCCCCC,
rpmb_size / 1024, rpmb_size / 1024 / 512); rpmb_size / 1024, rpmb_size / 1024 / 512);
gfx_printf(&gfx_con, " 0: %kGPP (USER) %kSize: %05d MiB (LBA Sectors: 0x%07X)\n\n", 0xFF00FF96, 0xFFCCCCCC, gfx_printf(&gfx_con, " 0: %kGPP (USER) %kSize: %5d MiB (LBA Sectors: 0x%07X)\n\n", 0xFF00FF96, 0xFFCCCCCC,
storage.sec_cnt >> SECTORS_TO_MIB_COEFF, storage.sec_cnt); storage.sec_cnt >> SECTORS_TO_MIB_COEFF, storage.sec_cnt);
gfx_printf(&gfx_con, "%kGPP (eMMC USER) partition table:%k\n", 0xFFFFDD00, 0xFFCCCCCC); gfx_printf(&gfx_con, "%kGPP (eMMC USER) partition table:%k\n", 0xFFFFDD00, 0xFFCCCCCC);
@ -1287,12 +1287,12 @@ out:;
void about() void about()
{ {
static const char octopus[] = static const char octopus[] =
"hekate (c) 2018 naehrwert, st4rk\n\n" "hekate (C) 2018 naehrwert, st4rk\n\n"
"Thanks to: %kderrek, nedwill, plutoo, shuffle2, smea, thexyz, yellows8%k\n\n" "Thanks to: %kderrek, nedwill, plutoo, shuffle2, smea, thexyz, yellows8%k\n\n"
"Greetings to: fincs, hexkyz, SciresM, Shiny Quagsire, WinterMute\n\n" "Greetings to: fincs, hexkyz, SciresM, Shiny Quagsire, WinterMute\n\n"
"Open source and free packages used:\n" "Open source and free packages used:\n"
" - FatFs R0.13a (Copyright (C) 2017, ChaN)\n" " - FatFs R0.13a, (Copyright (C) 2017, ChaN)\n"
" - bcl-1.2.0 (Copyright (c) 2003-2006 Marcus Geelnard)\n\n" " - bcl-1.2.0, (Copyright (C) 2003-2006, Marcus Geelnard)\n\n"
" %k___\n" " %k___\n"
" .-' `'.\n" " .-' `'.\n"
" / \\\n" " / \\\n"

View file

@ -17,7 +17,7 @@
#include "tui.h" #include "tui.h"
#include "btn.h" #include "btn.h"
void tui_pbar(gfx_con_t *con, int x, int y, u32 val) void tui_pbar(gfx_con_t *con, int x, int y, u32 val, u32 fgcol, u32 bgcol)
{ {
u32 cx, cy; u32 cx, cy;
@ -25,14 +25,14 @@ void tui_pbar(gfx_con_t *con, int x, int y, u32 val)
gfx_con_setpos(con, x, y); gfx_con_setpos(con, x, y);
gfx_printf(con, "[%3d%%]", val); gfx_printf(con, "%k[%3d%%]%k", fgcol, val, bgcol);
x += 7 * 8; x += 7 * 8;
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
gfx_line(con->gfx_ctxt, x, y + i + 1, x + 3 * val, y + i + 1, 0xFFCCCCCC); gfx_line(con->gfx_ctxt, x, y + i + 1, x + 3 * val, y + i + 1, fgcol);
gfx_line(con->gfx_ctxt, x + 3 * val, y + i + 1, x + 3 * 100, y + i + 1, 0xFF555555); gfx_line(con->gfx_ctxt, x + 3 * val, y + i + 1, x + 3 * 100, y + i + 1, bgcol);
} }
gfx_con_setpos(con, cx, cy); gfx_con_setpos(con, cx, cy);

View file

@ -57,7 +57,7 @@ typedef struct _menu_t
#define MDEF_CAPTION(caption, color) { MENT_CAPTION, caption, color } #define MDEF_CAPTION(caption, color) { MENT_CAPTION, caption, color }
#define MDEF_CHGLINE() {MENT_CHGLINE} #define MDEF_CHGLINE() {MENT_CHGLINE}
void tui_pbar(gfx_con_t *con, int x, int y, u32 val); void tui_pbar(gfx_con_t *con, int x, int y, u32 val, u32 fgcol, u32 bgcol);
void *tui_do_menu(gfx_con_t *con, menu_t *menu); void *tui_do_menu(gfx_con_t *con, menu_t *menu);
#endif #endif