mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-12 08:20:56 +00:00
core/embed: update fatfs to 0.14; use upstream version
This commit is contained in:
parent
1480f5a25c
commit
32f8f1cb61
@ -1,11 +1,7 @@
|
||||
// clang-format off
|
||||
|
||||
/* This file is part of ooFatFs, a customised version of FatFs
|
||||
* See https://github.com/micropython/oofatfs for details
|
||||
*/
|
||||
|
||||
/*-----------------------------------------------------------------------/
|
||||
/ Low level disk interface modlue include file (C)ChaN, 2014 /
|
||||
/ Low level disk interface modlue include file (C)ChaN, 2019 /
|
||||
/-----------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _DISKIO_DEFINED
|
||||
@ -32,9 +28,11 @@ typedef enum {
|
||||
/* Prototypes for disk control functions */
|
||||
|
||||
|
||||
DRESULT disk_read (void *drv, BYTE* buff, DWORD sector, UINT count);
|
||||
DRESULT disk_write (void *drv, const BYTE* buff, DWORD sector, UINT count);
|
||||
DRESULT disk_ioctl (void *drv, BYTE cmd, void* buff);
|
||||
DSTATUS disk_initialize (BYTE pdrv);
|
||||
DSTATUS disk_status (BYTE pdrv);
|
||||
DRESULT disk_read (BYTE pdrv, BYTE* buff, LBA_t sector, UINT count);
|
||||
DRESULT disk_write (BYTE pdrv, const BYTE* buff, LBA_t sector, UINT count);
|
||||
DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
|
||||
|
||||
|
||||
/* Disk Status Bits (DSTATUS) */
|
||||
@ -52,8 +50,6 @@ DRESULT disk_ioctl (void *drv, BYTE cmd, void* buff);
|
||||
#define GET_SECTOR_SIZE 2 /* Get sector size (needed at FF_MAX_SS != FF_MIN_SS) */
|
||||
#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at FF_USE_MKFS == 1) */
|
||||
#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at FF_USE_TRIM == 1) */
|
||||
#define IOCTL_INIT 5
|
||||
#define IOCTL_STATUS 6
|
||||
|
||||
/* Generic command (Not used by FatFs) */
|
||||
#define CTRL_POWER 5 /* Get/Set power status */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,14 +1,10 @@
|
||||
// clang-format off
|
||||
|
||||
/* This file is part of ooFatFs, a customised version of FatFs
|
||||
* See https://github.com/micropython/oofatfs for details
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------/
|
||||
/ FatFs - Generic FAT Filesystem module R0.13c /
|
||||
/ FatFs - Generic FAT Filesystem module R0.14 /
|
||||
/-----------------------------------------------------------------------------/
|
||||
/
|
||||
/ Copyright (C) 2018, ChaN, all right reserved.
|
||||
/ Copyright (C) 2019, ChaN, all right reserved.
|
||||
/
|
||||
/ FatFs module is an open source software. Redistribution and use of FatFs in
|
||||
/ source and binary forms, with or without modification, are permitted provided
|
||||
@ -26,7 +22,7 @@
|
||||
|
||||
|
||||
#ifndef FF_DEFINED
|
||||
#define FF_DEFINED 86604 /* Revision ID */
|
||||
#define FF_DEFINED 86606 /* Revision ID */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -51,21 +47,29 @@ typedef unsigned __int64 QWORD;
|
||||
typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
|
||||
typedef unsigned char BYTE; /* char must be 8-bit */
|
||||
typedef uint16_t WORD; /* 16-bit unsigned integer */
|
||||
typedef uint16_t WCHAR; /* 16-bit unsigned integer */
|
||||
typedef uint32_t DWORD; /* 32-bit unsigned integer */
|
||||
typedef uint64_t QWORD; /* 64-bit unsigned integer */
|
||||
typedef WORD WCHAR; /* UTF-16 character type */
|
||||
#else /* Earlier than C99 */
|
||||
#define FF_INTDEF 1
|
||||
typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
|
||||
typedef unsigned char BYTE; /* char must be 8-bit */
|
||||
typedef unsigned short WORD; /* 16-bit unsigned integer */
|
||||
typedef unsigned short WCHAR; /* 16-bit unsigned integer */
|
||||
typedef unsigned long DWORD; /* 32-bit unsigned integer */
|
||||
typedef WORD WCHAR; /* UTF-16 character type */
|
||||
#endif
|
||||
|
||||
|
||||
/* Definitions of volume management */
|
||||
|
||||
#if FF_MULTI_PARTITION /* Multiple partition configuration */
|
||||
typedef struct {
|
||||
BYTE pd; /* Physical drive number */
|
||||
BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
|
||||
} PARTITION;
|
||||
extern PARTITION VolToPart[]; /* Volume - Partition mapping table */
|
||||
#endif
|
||||
|
||||
#if FF_STR_VOLUME_ID
|
||||
#ifndef FF_VOLUME_STRS
|
||||
extern const char* VolumeStr[FF_VOLUMES]; /* User defied volume ID */
|
||||
@ -103,15 +107,24 @@ typedef char TCHAR;
|
||||
|
||||
|
||||
|
||||
/* Type of file size variables */
|
||||
/* Type of file size and LBA variables */
|
||||
|
||||
#if FF_FS_EXFAT
|
||||
#if FF_INTDEF != 2
|
||||
#error exFAT feature wants C99 or later
|
||||
#endif
|
||||
typedef QWORD FSIZE_t;
|
||||
#if FF_LBA64
|
||||
typedef QWORD LBA_t;
|
||||
#else
|
||||
typedef DWORD LBA_t;
|
||||
#endif
|
||||
#else
|
||||
#if FF_LBA64
|
||||
#error exFAT needs to be enabled when enable 64-bit LBA
|
||||
#endif
|
||||
typedef DWORD FSIZE_t;
|
||||
typedef DWORD LBA_t;
|
||||
#endif
|
||||
|
||||
|
||||
@ -119,11 +132,8 @@ typedef DWORD FSIZE_t;
|
||||
/* Filesystem object structure (FATFS) */
|
||||
|
||||
typedef struct {
|
||||
void *drv; // block device underlying this filesystem
|
||||
#if FF_MULTI_PARTITION /* Multiple partition configuration */
|
||||
BYTE part; // Partition: 0:Auto detect, 1-4:Forced partition
|
||||
#endif
|
||||
BYTE fs_type; /* Filesystem type (0:not mounted) */
|
||||
BYTE pdrv; /* Associated physical drive */
|
||||
BYTE n_fats; /* Number of FATs (1 or 2) */
|
||||
BYTE wflag; /* win[] flag (b0:dirty) */
|
||||
BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */
|
||||
@ -156,14 +166,14 @@ typedef struct {
|
||||
#endif
|
||||
DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */
|
||||
DWORD fsize; /* Size of an FAT [sectors] */
|
||||
DWORD volbase; /* Volume base sector */
|
||||
DWORD fatbase; /* FAT base sector */
|
||||
DWORD dirbase; /* Root directory base sector/cluster */
|
||||
DWORD database; /* Data base sector */
|
||||
LBA_t volbase; /* Volume base sector */
|
||||
LBA_t fatbase; /* FAT base sector */
|
||||
LBA_t dirbase; /* Root directory base sector/cluster */
|
||||
LBA_t database; /* Data base sector */
|
||||
#if FF_FS_EXFAT
|
||||
DWORD bitbase; /* Allocation bitmap base sector */
|
||||
LBA_t bitbase; /* Allocation bitmap base sector */
|
||||
#endif
|
||||
DWORD winsect; /* Current sector appearing in the win[] */
|
||||
LBA_t winsect; /* Current sector appearing in the win[] */
|
||||
BYTE win[FF_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */
|
||||
} FATFS;
|
||||
|
||||
@ -200,9 +210,9 @@ typedef struct {
|
||||
BYTE err; /* Abort flag (error code) */
|
||||
FSIZE_t fptr; /* File read/write pointer (Zeroed on file open) */
|
||||
DWORD clust; /* Current cluster of fpter (invalid when fptr is 0) */
|
||||
DWORD sect; /* Sector number appearing in buf[] (0:invalid) */
|
||||
LBA_t sect; /* Sector number appearing in buf[] (0:invalid) */
|
||||
#if !FF_FS_READONLY
|
||||
DWORD dir_sect; /* Sector number containing the directory entry (not used at exFAT) */
|
||||
LBA_t dir_sect; /* Sector number containing the directory entry (not used at exFAT) */
|
||||
BYTE* dir_ptr; /* Pointer to the directory entry in the win[] (not used at exFAT) */
|
||||
#endif
|
||||
#if FF_USE_FASTSEEK
|
||||
@ -215,13 +225,13 @@ typedef struct {
|
||||
|
||||
|
||||
|
||||
/* Directory object structure (FF_DIR) */
|
||||
/* Directory object structure (DIR) */
|
||||
|
||||
typedef struct {
|
||||
FFOBJID obj; /* Object identifier */
|
||||
DWORD dptr; /* Current read/write offset */
|
||||
DWORD clust; /* Current cluster */
|
||||
DWORD sect; /* Current sector (0:Read operation has terminated) */
|
||||
LBA_t sect; /* Current sector (0:Read operation has terminated) */
|
||||
BYTE* dir; /* Pointer to the directory item in the win[] */
|
||||
BYTE fn[12]; /* SFN (in/out) {body[8],ext[3],status[1]} */
|
||||
#if FF_USE_LFN
|
||||
@ -230,7 +240,7 @@ typedef struct {
|
||||
#if FF_USE_FIND
|
||||
const TCHAR* pat; /* Pointer to the name matching pattern */
|
||||
#endif
|
||||
} FF_DIR;
|
||||
} DIR;
|
||||
|
||||
|
||||
|
||||
@ -251,6 +261,18 @@ typedef struct {
|
||||
|
||||
|
||||
|
||||
/* Format parameter structure (MKFS_PARM) */
|
||||
|
||||
typedef struct {
|
||||
BYTE fmt; /* Format option (FM_FAT, FM_FAT32, FM_EXFAT and FM_SFD) */
|
||||
BYTE n_fat; /* Number of FATs */
|
||||
UINT align; /* Data area alignment (sector) */
|
||||
UINT n_root; /* Number of root directory entries */
|
||||
DWORD au_size; /* Cluster size (byte) */
|
||||
} MKFS_PARM;
|
||||
|
||||
|
||||
|
||||
/* File function return code (FRESULT) */
|
||||
|
||||
typedef enum {
|
||||
@ -281,37 +303,40 @@ typedef enum {
|
||||
/*--------------------------------------------------------------*/
|
||||
/* FatFs module application interface */
|
||||
|
||||
FRESULT f_open (FATFS *fs, FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */
|
||||
FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */
|
||||
FRESULT f_close (FIL* fp); /* Close an open file object */
|
||||
FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from the file */
|
||||
FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to the file */
|
||||
FRESULT f_lseek (FIL* fp, FSIZE_t ofs); /* Move file pointer of the file object */
|
||||
FRESULT f_truncate (FIL* fp); /* Truncate the file */
|
||||
FRESULT f_sync (FIL* fp); /* Flush cached data of the writing file */
|
||||
FRESULT f_opendir (FATFS *fs, FF_DIR* dp, const TCHAR* path); /* Open a directory */
|
||||
FRESULT f_closedir (FF_DIR* dp); /* Close an open directory */
|
||||
FRESULT f_readdir (FF_DIR* dp, FILINFO* fno); /* Read a directory item */
|
||||
FRESULT f_findfirst (FF_DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */
|
||||
FRESULT f_findnext (FF_DIR* dp, FILINFO* fno); /* Find next file */
|
||||
FRESULT f_mkdir (FATFS *fs, const TCHAR* path); /* Create a sub directory */
|
||||
FRESULT f_unlink (FATFS *fs, const TCHAR* path); /* Delete an existing file or directory */
|
||||
FRESULT f_rename (FATFS *fs, const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */
|
||||
FRESULT f_stat (FATFS *fs, const TCHAR* path, FILINFO* fno); /* Get file status */
|
||||
FRESULT f_chmod (FATFS *fs, const TCHAR* path, BYTE attr, BYTE mask); /* Change attribute of a file/dir */
|
||||
FRESULT f_utime (FATFS *fs, const TCHAR* path, const FILINFO* fno); /* Change timestamp of a file/dir */
|
||||
FRESULT f_chdir (FATFS *fs, const TCHAR* path); /* Change current directory */
|
||||
FRESULT f_getcwd (FATFS *fs, TCHAR* buff, UINT len); /* Get current directory */
|
||||
FRESULT f_getfree (FATFS *fs, DWORD* nclst); /* Get number of free clusters on the drive */
|
||||
FRESULT f_getlabel (FATFS *fs, TCHAR* label, DWORD* vsn); /* Get volume label */
|
||||
FRESULT f_setlabel (FATFS *fs, const TCHAR* label); /* Set volume label */
|
||||
FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */
|
||||
FRESULT f_closedir (DIR* dp); /* Close an open directory */
|
||||
FRESULT f_readdir (DIR* dp, FILINFO* fno); /* Read a directory item */
|
||||
FRESULT f_findfirst (DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */
|
||||
FRESULT f_findnext (DIR* dp, FILINFO* fno); /* Find next file */
|
||||
FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */
|
||||
FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */
|
||||
FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */
|
||||
FRESULT f_stat (const TCHAR* path, FILINFO* fno); /* Get file status */
|
||||
FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask); /* Change attribute of a file/dir */
|
||||
FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change timestamp of a file/dir */
|
||||
FRESULT f_chdir (const TCHAR* path); /* Change current directory */
|
||||
FRESULT f_chdrive (const TCHAR* path); /* Change current drive */
|
||||
FRESULT f_getcwd (TCHAR* buff, UINT len); /* Get current directory */
|
||||
FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get number of free clusters on the drive */
|
||||
FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */
|
||||
FRESULT f_setlabel (const TCHAR* label); /* Set volume label */
|
||||
FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */
|
||||
FRESULT f_expand (FIL* fp, FSIZE_t szf, BYTE opt); /* Allocate a contiguous block to the file */
|
||||
FRESULT f_mount (FATFS* fs); /* Mount/Unmount a logical drive */
|
||||
FRESULT f_umount (FATFS* fs); /* Unmount a logical drive */
|
||||
FRESULT f_mkfs (FATFS *fs, BYTE opt, DWORD au, void* work, UINT len); /* Create a FAT volume */
|
||||
FRESULT f_fdisk (void *pdrv, const DWORD* szt, void* work); /* Divide a physical drive into some partitions */
|
||||
FRESULT f_expand (FIL* fp, FSIZE_t fsz, BYTE opt); /* Allocate a contiguous block to the file */
|
||||
FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */
|
||||
FRESULT f_mkfs (const TCHAR* path, const MKFS_PARM* opt, void* work, UINT len); /* Create a FAT volume */
|
||||
FRESULT f_fdisk (BYTE pdrv, const LBA_t ptbl[], void* work); /* Divide a physical drive into some partitions */
|
||||
FRESULT f_setcp (WORD cp); /* Set current code page */
|
||||
FRESULT f_repair (FATFS* fs, void* work, UINT len); /* Free unreferenced clusters from the FAT */
|
||||
int f_putc (TCHAR c, FIL* fp); /* Put a character to the file */
|
||||
int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
|
||||
int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */
|
||||
TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
|
||||
|
||||
#define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize))
|
||||
#define f_error(fp) ((fp)->err)
|
||||
@ -350,7 +375,7 @@ void ff_memfree (void* mblock); /* Free memory block */
|
||||
|
||||
/* Sync functions */
|
||||
#if FF_FS_REENTRANT
|
||||
int ff_cre_syncobj (FATFS *fatfs, FF_SYNC_t* sobj); /* Create a sync object */
|
||||
int ff_cre_syncobj (BYTE vol, FF_SYNC_t* sobj); /* Create a sync object */
|
||||
int ff_req_grant (FF_SYNC_t sobj); /* Lock sync object */
|
||||
void ff_rel_grant (FF_SYNC_t sobj); /* Unlock sync object */
|
||||
int ff_del_syncobj (FF_SYNC_t sobj); /* Delete a sync object */
|
||||
|
@ -6,9 +6,8 @@ unifdef \
|
||||
-DFF_USE_FASTSEEK=0 \
|
||||
-DFF_USE_EXPAND=0 \
|
||||
-DFF_USE_CHMOD=0 \
|
||||
-DFF_USE_LABEL=0 \
|
||||
-DFF_USE_LABEL=1 \
|
||||
-DFF_USE_FORWARD=0 \
|
||||
-DFF_USE_REPAIR=0 \
|
||||
-DFF_CODE_PAGE=437 \
|
||||
-DFF_USE_LFN=1 \
|
||||
-DFF_LFN_UNICODE=2 \
|
||||
@ -24,6 +23,8 @@ unifdef \
|
||||
-DFF_FS_NORTC=1 \
|
||||
-DFF_FS_LOCK=0 \
|
||||
-DFF_FS_REENTRANT=0 \
|
||||
-DFF_LBA64=0 \
|
||||
-DFF_MULTI_PARTITION=0 \
|
||||
ff.c -o ff.c
|
||||
|
||||
unifdef \
|
||||
|
@ -1,14 +1,10 @@
|
||||
// clang-format off
|
||||
|
||||
/* This file is part of ooFatFs, a customised version of FatFs
|
||||
* See https://github.com/micropython/oofatfs for details
|
||||
*/
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ FatFs Functional Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#define FFCONF_DEF 86604 /* Revision ID */
|
||||
#define FFCONF_DEF 86606 /* Revision ID */
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ Function Configurations
|
||||
@ -44,11 +40,7 @@
|
||||
/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */
|
||||
|
||||
|
||||
#ifdef TREZOR_EMULATOR
|
||||
#define FF_USE_MKFS 1
|
||||
#else
|
||||
#define FF_USE_MKFS 0
|
||||
#endif
|
||||
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
@ -65,7 +57,7 @@
|
||||
/ (0:Disable or 1:Enable) Also FF_FS_READONLY needs to be 0 to enable this option. */
|
||||
|
||||
|
||||
#define FF_USE_LABEL 0
|
||||
#define FF_USE_LABEL 1
|
||||
/* This option switches volume label functions, f_getlabel() and f_setlabel().
|
||||
/ (0:Disable or 1:Enable) */
|
||||
|
||||
@ -74,10 +66,6 @@
|
||||
/* This option switches f_forward() function. (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
#define FF_USE_REPAIR 0
|
||||
/* This option switches f_repair() function. (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ Locale and Namespace Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
@ -124,11 +112,11 @@
|
||||
/ requiers certain internal working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and
|
||||
/ additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled.
|
||||
/ The FF_MAX_LFN defines size of the working buffer in UTF-16 code unit and it can
|
||||
/ be in range of 12 to 255. It is recommended to be set 255 to fully support LFN
|
||||
/ be in range of 12 to 255. It is recommended to be set it 255 to fully support LFN
|
||||
/ specification.
|
||||
/ When use stack for the working buffer, take care on stack overflow. When use heap
|
||||
/ memory for the working buffer, memory management functions, ff_memalloc() and
|
||||
/ ff_memfree() in ffsystem.c, need to be added to the project. */
|
||||
/ ff_memfree() exemplified in ffsystem.c, need to be added to the project. */
|
||||
|
||||
|
||||
#define FF_LFN_UNICODE 2
|
||||
@ -214,24 +202,22 @@
|
||||
/ GET_SECTOR_SIZE command. */
|
||||
|
||||
|
||||
#define FF_LBA64 0
|
||||
/* This option switches support for 64-bit LBA. (0:Disable or 1:Enable)
|
||||
/ To enable the 64-bit LBA, also exFAT needs to be enabled. (FF_FS_EXFAT == 1) */
|
||||
|
||||
|
||||
#define FF_MIN_GPT 0x100000000
|
||||
/* Minimum number of sectors to switch GPT format to create partition in f_mkfs and
|
||||
/ f_fdisk function. 0x100000000 max. This option has no effect when FF_LBA64 == 0. */
|
||||
|
||||
|
||||
#define FF_USE_TRIM 0
|
||||
/* This option switches support for ATA-TRIM. (0:Disable or 1:Enable)
|
||||
/ To enable Trim function, also CTRL_TRIM command should be implemented to the
|
||||
/ disk_ioctl() function. */
|
||||
|
||||
|
||||
#define FF_FS_NOFSINFO 0
|
||||
/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
|
||||
/ option, and f_getfree() function at first time after volume mount will force
|
||||
/ a full FAT scan. Bit 1 controls the use of last allocated cluster number.
|
||||
/
|
||||
/ bit0=0: Use free cluster count in the FSINFO if available.
|
||||
/ bit0=1: Do not trust free cluster count in the FSINFO.
|
||||
/ bit1=0: Use last allocated cluster number in the FSINFO if available.
|
||||
/ bit1=1: Do not trust last allocated cluster number in the FSINFO.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ System Configurations
|
||||
@ -261,7 +247,19 @@
|
||||
/ To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be
|
||||
/ added to the project to read current time form real-time clock. FF_NORTC_MON,
|
||||
/ FF_NORTC_MDAY and FF_NORTC_YEAR have no effect.
|
||||
/ These options have no effect at read-only configuration (FF_FS_READONLY = 1). */
|
||||
/ These options have no effect in read-only configuration (FF_FS_READONLY = 1). */
|
||||
|
||||
|
||||
#define FF_FS_NOFSINFO 0
|
||||
/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
|
||||
/ option, and f_getfree() function at first time after volume mount will force
|
||||
/ a full FAT scan. Bit 1 controls the use of last allocated cluster number.
|
||||
/
|
||||
/ bit0=0: Use free cluster count in the FSINFO if available.
|
||||
/ bit0=1: Do not trust free cluster count in the FSINFO.
|
||||
/ bit1=0: Use last allocated cluster number in the FSINFO if available.
|
||||
/ bit1=1: Do not trust last allocated cluster number in the FSINFO.
|
||||
*/
|
||||
|
||||
|
||||
#define FF_FS_LOCK 0
|
||||
|
@ -1,7 +1,7 @@
|
||||
// clang-format off
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Unicode handling functions for FatFs R0.13c */
|
||||
/* Unicode handling functions for FatFs R0.13+ */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This module will occupy a huge memory in the .const section when the /
|
||||
/ FatFs is configured for LFN with DBCS. If the system has any Unicode /
|
||||
@ -9,7 +9,7 @@
|
||||
/ that function to avoid silly memory consumption. /
|
||||
/-------------------------------------------------------------------------*/
|
||||
/*
|
||||
/ Copyright (C) 2018, ChaN, all right reserved.
|
||||
/ Copyright (C) 2014, ChaN, all right reserved.
|
||||
/
|
||||
/ FatFs module is an open source software. Redistribution and use of FatFs in
|
||||
/ source and binary forms, with or without modification, are permitted provided
|
||||
@ -27,11 +27,7 @@
|
||||
|
||||
#include "ff.h"
|
||||
|
||||
#if FF_USE_LFN /* This module will be blanked at non-LFN configuration */
|
||||
|
||||
#if FF_DEFINED != 86604 /* Revision ID */
|
||||
#error Wrong include file (ff.h).
|
||||
#endif
|
||||
#if FF_USE_LFN /* This module will be blanked if non-LFN configuration */
|
||||
|
||||
#define MERGE2(a, b) a ## b
|
||||
#define CVTBL(tbl, cp) MERGE2(tbl, cp)
|
||||
@ -86,7 +82,7 @@ WCHAR ff_uni2oem ( /* Returns OEM code character, zero on error */
|
||||
return c;
|
||||
}
|
||||
|
||||
WCHAR ff_oem2uni ( /* Returns Unicode character, zero on error */
|
||||
WCHAR ff_oem2uni ( /* Returns Unicode character in UTF-16, zero on error */
|
||||
WCHAR oem, /* OEM code to be converted */
|
||||
WORD cp /* Code page for the conversion */
|
||||
)
|
||||
|
@ -27,7 +27,16 @@
|
||||
#include "sdcard.h"
|
||||
// clang-format on
|
||||
|
||||
DRESULT disk_read(void *drv, BYTE *buff, DWORD sector, UINT count) {
|
||||
DSTATUS disk_initialize(BYTE pdrv) {
|
||||
return (sectrue == sdcard_is_present()) ? 0 : STA_NODISK;
|
||||
}
|
||||
|
||||
DSTATUS disk_status(BYTE pdrv) {
|
||||
return (sectrue == sdcard_is_present()) ? 0 : STA_NODISK;
|
||||
}
|
||||
|
||||
DRESULT disk_read(BYTE pdrv, BYTE *buff, LBA_t sector, UINT count) {
|
||||
(void)pdrv;
|
||||
if (sectrue == sdcard_read_blocks((uint32_t *)buff, sector, count)) {
|
||||
return RES_OK;
|
||||
} else {
|
||||
@ -35,7 +44,8 @@ DRESULT disk_read(void *drv, BYTE *buff, DWORD sector, UINT count) {
|
||||
}
|
||||
}
|
||||
|
||||
DRESULT disk_write(void *drv, const BYTE *buff, DWORD sector, UINT count) {
|
||||
DRESULT disk_write(BYTE pdrv, const BYTE *buff, LBA_t sector, UINT count) {
|
||||
(void)pdrv;
|
||||
if (sectrue == sdcard_write_blocks((const uint32_t *)buff, sector, count)) {
|
||||
return RES_OK;
|
||||
} else {
|
||||
@ -43,8 +53,8 @@ DRESULT disk_write(void *drv, const BYTE *buff, DWORD sector, UINT count) {
|
||||
}
|
||||
}
|
||||
|
||||
DRESULT disk_ioctl(void *drv, BYTE cmd, void *buff) {
|
||||
(void)drv;
|
||||
DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff) {
|
||||
(void)pdrv;
|
||||
switch (cmd) {
|
||||
case CTRL_SYNC:
|
||||
return RES_OK;
|
||||
@ -57,12 +67,6 @@ DRESULT disk_ioctl(void *drv, BYTE cmd, void *buff) {
|
||||
case GET_BLOCK_SIZE:
|
||||
*((DWORD *)buff) = 1;
|
||||
return RES_OK;
|
||||
case IOCTL_INIT:
|
||||
*((DSTATUS *)buff) = (sectrue == sdcard_is_present()) ? 0 : STA_NODISK;
|
||||
return RES_OK;
|
||||
case IOCTL_STATUS:
|
||||
*((DSTATUS *)buff) = (sectrue == sdcard_is_present()) ? 0 : STA_NODISK;
|
||||
return RES_OK;
|
||||
default:
|
||||
return RES_PARERR;
|
||||
}
|
||||
@ -280,7 +284,7 @@ STATIC const mp_obj_type_t mod_trezorio_FatFSFile_type = {
|
||||
/// """
|
||||
typedef struct _mp_obj_FatFSDir_t {
|
||||
mp_obj_base_t base;
|
||||
FF_DIR dp;
|
||||
DIR dp;
|
||||
} mp_obj_FatFSDir_t;
|
||||
|
||||
/// def __next__(self) -> Tuple[int, str, str]:
|
||||
@ -338,7 +342,6 @@ STATIC mp_obj_t mod_trezorio_FatFS_make_new(const mp_obj_type_t *type,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_FatFS_open(mp_obj_t self, mp_obj_t path,
|
||||
mp_obj_t flags) {
|
||||
mp_obj_FatFS_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t _path, _flags;
|
||||
mp_get_buffer_raise(path, &_path, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(flags, &_flags, MP_BUFFER_READ);
|
||||
@ -364,7 +367,7 @@ STATIC mp_obj_t mod_trezorio_FatFS_open(mp_obj_t self, mp_obj_t path,
|
||||
}
|
||||
}
|
||||
FIL fp;
|
||||
FRESULT res = f_open(&(o->fs), &fp, _path.buf, mode);
|
||||
FRESULT res = f_open(&fp, _path.buf, mode);
|
||||
if (res != FR_OK) {
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
}
|
||||
@ -381,11 +384,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorio_FatFS_open_obj,
|
||||
/// List a directory (return generator)
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_FatFS_listdir(mp_obj_t self, mp_obj_t path) {
|
||||
mp_obj_FatFS_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t _path;
|
||||
mp_get_buffer_raise(path, &_path, MP_BUFFER_READ);
|
||||
FF_DIR dp;
|
||||
FRESULT res = f_opendir(&(o->fs), &dp, _path.buf);
|
||||
DIR dp;
|
||||
FRESULT res = f_opendir(&dp, _path.buf);
|
||||
if (res != FR_OK) {
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
}
|
||||
@ -402,10 +404,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_FatFS_listdir_obj,
|
||||
/// Create a sub directory
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_FatFS_mkdir(size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_FatFS_t *o = MP_OBJ_TO_PTR(args[0]);
|
||||
mp_buffer_info_t path;
|
||||
mp_get_buffer_raise(args[1], &path, MP_BUFFER_READ);
|
||||
FRESULT res = f_mkdir(&(o->fs), path.buf);
|
||||
FRESULT res = f_mkdir(path.buf);
|
||||
// directory exists and exist_ok is True, return without failure
|
||||
if (res == FR_EXIST && n_args > 2 && args[2] == mp_const_true) {
|
||||
return mp_const_none;
|
||||
@ -423,10 +424,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorio_FatFS_mkdir_obj, 2, 3,
|
||||
/// Delete an existing file or directory
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_FatFS_unlink(mp_obj_t self, mp_obj_t path) {
|
||||
mp_obj_FatFS_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t _path;
|
||||
mp_get_buffer_raise(path, &_path, MP_BUFFER_READ);
|
||||
FRESULT res = f_unlink(&(o->fs), _path.buf);
|
||||
FRESULT res = f_unlink(_path.buf);
|
||||
if (res != FR_OK) {
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
}
|
||||
@ -440,11 +440,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_FatFS_unlink_obj,
|
||||
/// Get file status
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_FatFS_stat(mp_obj_t self, mp_obj_t path) {
|
||||
mp_obj_FatFS_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t _path;
|
||||
mp_get_buffer_raise(path, &_path, MP_BUFFER_READ);
|
||||
FILINFO info;
|
||||
FRESULT res = f_stat(&(o->fs), _path.buf, &info);
|
||||
FRESULT res = f_stat(_path.buf, &info);
|
||||
if (res != FR_OK) {
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
}
|
||||
@ -459,11 +458,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_FatFS_stat_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_FatFS_rename(mp_obj_t self, mp_obj_t oldpath,
|
||||
mp_obj_t newpath) {
|
||||
mp_obj_FatFS_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t _oldpath, _newpath;
|
||||
mp_get_buffer_raise(oldpath, &_oldpath, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(newpath, &_newpath, MP_BUFFER_READ);
|
||||
FRESULT res = f_rename(&(o->fs), _oldpath.buf, _newpath.buf);
|
||||
FRESULT res = f_rename(_oldpath.buf, _newpath.buf);
|
||||
if (res != FR_OK) {
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
}
|
||||
@ -478,7 +476,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorio_FatFS_rename_obj,
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_FatFS_mount(mp_obj_t self) {
|
||||
mp_obj_FatFS_t *o = MP_OBJ_TO_PTR(self);
|
||||
FRESULT res = f_mount(&(o->fs));
|
||||
FRESULT res = f_mount(&(o->fs), "", 1);
|
||||
if (res != FR_OK) {
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
}
|
||||
@ -492,8 +490,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_FatFS_mount_obj,
|
||||
/// Unmount a logical drive
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_FatFS_unmount(mp_obj_t self) {
|
||||
mp_obj_FatFS_t *o = MP_OBJ_TO_PTR(self);
|
||||
FRESULT res = f_umount(&(o->fs));
|
||||
// to unmount we have to call mount with the first parameter NULL
|
||||
FRESULT res = f_mount(NULL, "", 0);
|
||||
if (res != FR_OK) {
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
}
|
||||
@ -502,16 +500,14 @@ STATIC mp_obj_t mod_trezorio_FatFS_unmount(mp_obj_t self) {
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_FatFS_unmount_obj,
|
||||
mod_trezorio_FatFS_unmount);
|
||||
|
||||
#ifdef TREZOR_EMULATOR
|
||||
|
||||
/// def mkfs(self) -> None:
|
||||
/// """
|
||||
/// Create a FAT volume
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_FatFS_mkfs(mp_obj_t self) {
|
||||
mp_obj_FatFS_t *o = MP_OBJ_TO_PTR(self);
|
||||
MKFS_PARM params = {FM_FAT32, 0, 0, 0, 0};
|
||||
uint8_t working_buf[FF_MAX_SS];
|
||||
FRESULT res = f_mkfs(&(o->fs), FM_FAT32, 0, working_buf, sizeof(working_buf));
|
||||
FRESULT res = f_mkfs("", ¶ms, working_buf, sizeof(working_buf));
|
||||
if (res != FR_OK) {
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
}
|
||||
@ -520,7 +516,21 @@ STATIC mp_obj_t mod_trezorio_FatFS_mkfs(mp_obj_t self) {
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_FatFS_mkfs_obj,
|
||||
mod_trezorio_FatFS_mkfs);
|
||||
|
||||
#endif
|
||||
/// def setlabel(self, label: str) -> None:
|
||||
/// """
|
||||
/// Set volume label
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_FatFS_setlabel(mp_obj_t self, mp_obj_t label) {
|
||||
mp_buffer_info_t _label;
|
||||
mp_get_buffer_raise(label, &_label, MP_BUFFER_READ);
|
||||
FRESULT res = f_setlabel(_label.buf);
|
||||
if (res != FR_OK) {
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_FatFS_setlabel_obj,
|
||||
mod_trezorio_FatFS_setlabel);
|
||||
|
||||
STATIC const mp_rom_map_elem_t mod_trezorio_FatFS_locals_dict_table[] = {
|
||||
{MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mod_trezorio_FatFS_open_obj)},
|
||||
@ -531,9 +541,9 @@ STATIC const mp_rom_map_elem_t mod_trezorio_FatFS_locals_dict_table[] = {
|
||||
{MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&mod_trezorio_FatFS_stat_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&mod_trezorio_FatFS_mount_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_unmount), MP_ROM_PTR(&mod_trezorio_FatFS_unmount_obj)},
|
||||
#ifdef TREZOR_EMULATOR
|
||||
{MP_ROM_QSTR(MP_QSTR_mkfs), MP_ROM_PTR(&mod_trezorio_FatFS_mkfs_obj)},
|
||||
#endif
|
||||
{MP_ROM_QSTR(MP_QSTR_setlabel),
|
||||
MP_ROM_PTR(&mod_trezorio_FatFS_setlabel_obj)},
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(mod_trezorio_FatFS_locals_dict,
|
||||
mod_trezorio_FatFS_locals_dict_table);
|
||||
|
@ -120,6 +120,11 @@ class FatFS:
|
||||
Create a FAT volume
|
||||
"""
|
||||
|
||||
def setlabel(self, label: str) -> None:
|
||||
"""
|
||||
Set volume label
|
||||
"""
|
||||
|
||||
|
||||
# extmod/modtrezorio/modtrezorio-flash.h
|
||||
class FlashOTP:
|
||||
|
Loading…
Reference in New Issue
Block a user