diff options
Diffstat (limited to 'lib/fatfs/fatfs_utils/utils.py')
| -rw-r--r-- | lib/fatfs/fatfs_utils/utils.py | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/lib/fatfs/fatfs_utils/utils.py b/lib/fatfs/fatfs_utils/utils.py index d2180c76..662586a5 100644 --- a/lib/fatfs/fatfs_utils/utils.py +++ b/lib/fatfs/fatfs_utils/utils.py @@ -1,15 +1,18 @@ -# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Apache-2.0 - import argparse import binascii import os import re import uuid from datetime import datetime -from typing import List, Optional, Tuple +from typing import List +from typing import Optional +from typing import Tuple -from construct import BitsInteger, BitStruct, Int16ul +from construct import BitsInteger +from construct import BitStruct +from construct import Int16ul # the regex pattern defines symbols that are allowed by long file names but not by short file names INVALID_SFN_CHARS_PATTERN = re.compile(r'[.+,;=\[\]]') @@ -68,8 +71,8 @@ def number_of_clusters(number_of_sectors: int, sectors_per_cluster: int) -> int: return number_of_sectors // sectors_per_cluster -def get_non_data_sectors_cnt(reserved_sectors_cnt: int, sectors_per_fat_cnt: int, root_dir_sectors_cnt: int) -> int: - return reserved_sectors_cnt + sectors_per_fat_cnt + root_dir_sectors_cnt +def get_non_data_sectors_cnt(reserved_sectors_cnt: int, sectors_per_fat_cnt: int, fat_tables_cnt: int, root_dir_sectors_cnt: int) -> int: + return reserved_sectors_cnt + sectors_per_fat_cnt * fat_tables_cnt + root_dir_sectors_cnt def get_fatfs_type(clusters_count: int) -> int: @@ -203,9 +206,19 @@ def get_args_for_partition_generator(desc: str, wl: bool) -> argparse.Namespace: type=int, choices=[FAT12, FAT16, 0], help=""" - Type of fat. Select 12 for fat12, 16 for fat16. Don't set, or set to 0 for automatic - calculation using cluster size and partition size. + Type of the FAT file-system. Select '12' for FAT12, '16' for FAT16. + Leave unset or select 0 for automatic file-system type detection. """) + parser.add_argument('--fat_count', + default=FATDefaults.FAT_TABLES_COUNT, + type=int, + choices=[1, 2], + help='Number of file allocation tables (FATs) in the filesystem.') + parser.add_argument('--wl_mode', + default=None, + type=str, + choices=['safe', 'perf'], + help='Wear levelling mode to use. Safe or performance. Only for sector size of 512') args = parser.parse_args() if args.fat_type == 0: @@ -215,6 +228,9 @@ def get_args_for_partition_generator(desc: str, wl: bool) -> argparse.Namespace: args.partition_size = int(str(args.partition_size), 0) if not os.path.isdir(args.input_directory): raise NotADirectoryError(f'The target directory `{args.input_directory}` does not exist!') + if args.wl_mode is not None: + if args.sector_size != 512: + raise ValueError('Wear levelling mode can be set only for sector size 512') return args @@ -276,7 +292,7 @@ class FATDefaults: # FATFS defaults SIZE: int = 1024 * 1024 RESERVED_SECTORS_COUNT: int = 1 - FAT_TABLES_COUNT: int = 1 + FAT_TABLES_COUNT: int = 2 SECTORS_PER_CLUSTER: int = 1 SECTOR_SIZE: int = 0x1000 HIDDEN_SECTORS: int = 0 |
