ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
board_periph_sd_format.c File Reference

Blank-card FAT16/FAT32 sparse-sector formatters (–sd-new). More...

#include <string.h>
#include "board_periph_sd_internal.h"
#include "emu_host_io_internal.h"
Include dependency graph for board_periph_sd_format.c:

Go to the source code of this file.

Enumerations

enum  sd_le_const_t : uint8_t {
  k_le_byte0 = 0U ,
  k_le_byte1 = 1U ,
  k_le_byte2 = 2U ,
  k_le_byte3 = 3U ,
  k_le_shift_b1 = 8U ,
  k_le_shift_b2 = 16U ,
  k_le_shift_b3 = 24U ,
  k_le_byte_mask = 0xFFU
}
 Little-endian byte offsets, shifts, and mask for image serialization. More...
enum  sd_bpb_off_t : uint16_t {
  k_bpb_jmp0 = 0U ,
  k_bpb_jmp1 = 1U ,
  k_bpb_jmp2 = 2U ,
  k_bpb_oem = 3U ,
  k_bpb_bytes_per_sec = 11U ,
  k_bpb_sec_per_clus = 13U ,
  k_bpb_resv_sec = 14U ,
  k_bpb_num_fats = 16U ,
  k_bpb_root_ents = 17U ,
  k_bpb_totsec16 = 19U ,
  k_bpb_media = 21U ,
  k_bpb_fatsz16 = 22U ,
  k_bpb_sec_per_trk = 24U ,
  k_bpb_num_heads = 26U ,
  k_bpb_totsec32 = 32U ,
  k_bpb_fatsz32 = 36U ,
  k_bpb16_drive_num = 36U ,
  k_bpb16_boot_sig = 38U ,
  k_bpb16_volid = 39U ,
  k_bpb16_vol_label = 43U ,
  k_bpb32_root_clus = 44U ,
  k_bpb32_fsinfo_sec = 48U ,
  k_bpb32_bkboot_sec = 50U ,
  k_bpb16_fstype = 54U ,
  k_bpb32_drive_num = 64U ,
  k_bpb32_boot_sig = 66U ,
  k_bpb32_volid = 67U ,
  k_bpb32_vol_label = 71U ,
  k_bpb32_fstype = 82U ,
  k_bpb_sig_lo = 510U ,
  k_bpb_sig_hi = 511U
}
 FAT BPB byte offsets within a sector (FAT16 + FAT32 layouts). More...
enum  sd_bpb_val_t : uint32_t {
  k_bpb_jmp_b0 = 0xEBU ,
  k_bpb_jmp_b1 = 0x58U ,
  k_bpb_jmp_b2 = 0x90U ,
  k_bpb_oem_len = 8U ,
  k_bpb_fstype_len = 8U ,
  k_bpb_sig_byte_lo = 0x55U ,
  k_bpb_sig_byte_hi = 0xAAU ,
  k_bpb_num_fats_val = 2U ,
  k_bpb_media_fixed = 0xF8U ,
  k_bpb_sec_per_trk_val = 63U ,
  k_bpb_num_heads_val = 255U ,
  k_bpb_drive_num_val = 0x80U ,
  k_bpb_ext_boot_sig = 0x29U ,
  k_bpb_dir_ent_size = 32U ,
  k_bpb_fat16_div = 256U ,
  k_bpb_fat32_div = 128U ,
  k_fat16_eoc_clus0 = 0xFFF8U ,
  k_fat16_eoc_clus1 = 0xFFFFU ,
  k_fat32_eoc_media = 0x0FFFFFF8U ,
  k_fat32_eoc = 0x0FFFFFFFU ,
  k_fat32_root_clus = 2U ,
  k_fat32_fsinfo_sec = 1U ,
  k_fat32_bkboot_sec = 6U ,
  k_fsi_lead_sig = 0x41615252U ,
  k_fsi_struc_sig = 0x61417272U ,
  k_fsi_trail_sig = 0xAA550000U ,
  k_fsi_off_lead = 0U ,
  k_fsi_off_struc = 484U ,
  k_fsi_off_free = 488U ,
  k_fsi_off_nxtfree = 492U ,
  k_fsi_off_trail = 508U ,
  k_fsi_free_unknown = 0xFFFFFFFFU ,
  k_fsi_nxt_free = 3U ,
  k_fat_ent1_off = 2U ,
  k_fat32_ent1_off = 4U ,
  k_fat32_ent2_off = 8U
}
 FAT BPB literal field values + the FSInfo signatures. More...

Functions

static RA8_INTERNAL void internal_sd_put16 (uint8_t *p, uint16_t v)
 Store one 16-bit image field in little-endian order.
static RA8_INTERNAL void internal_sd_put32 (uint8_t *p, uint32_t v)
 Store one 32-bit image field in little-endian order.
static RA8_INTERNAL void internal_sd_boot_frame (uint8_t *img, const char *oem)
 Write the shared boot prologue and trailing boot signature.
void priv_board_sd_label_field (uint8_t *dst, const char *label)
 Pad an ASCII volume label to the 11-byte 8.3 field (space-filled).
static RA8_INTERNAL uint32_t internal_fat16_solve_geometry (uint32_t total_sectors, uint32_t root_sectors, uint32_t *fatsz)
 Solve the FAT16 cluster size and FAT length for total_sectors.
static RA8_INTERNAL void internal_fat16_write_bpb (uint8_t *img, uint32_t total_sectors, uint32_t spc, uint32_t fatsz, const char *label)
 Write the FAT16 BIOS Parameter Block into sector 0 of img.
static RA8_INTERNAL bool internal_write_sector (int image_fd, uint32_t sector, const uint8_t *data)
 Write one complete sector at its checked positioned offset.
bool priv_board_sd_format_fat16 (int image_fd, uint32_t total_sectors, const char *label, uint32_t *out_spc)
 Format the attached sparse backend as a FAT16 volume.
static RA8_INTERNAL uint32_t internal_sd_fat32_geometry (uint32_t total_sectors, uint32_t *out_fatsz, uint32_t *out_clusters)
 Compute FAT32 volume geometry for a card of total_sectors.
static RA8_INTERNAL void internal_fat32_write_bpb (uint8_t *img, uint32_t total_sectors, uint32_t spc, uint32_t fatsz, const char *label)
 Serialize one deterministic FAT32 BIOS Parameter Block.
bool priv_board_sd_format_fat32 (int image_fd, uint32_t total_sectors, const char *label, uint32_t *out_spc)
 Format the attached sparse backend as a FAT32 volume.

Detailed Description

Blank-card FAT16/FAT32 sparse-sector formatters (–sd-new).

The bounded sector formatters board_sd_attach_blank uses to build an empty FAT volume in an anonymous sparse file. No peripheral block is registered here (registration is constructor-based and stays with the card model), so this helper TU rides the board_periph_*.c build glob with no CMake edit.

Since
0.1.0

Definition in file board_periph_sd_format.c.

Enumeration Type Documentation

◆ sd_bpb_off_t

enum sd_bpb_off_t : uint16_t

FAT BPB byte offsets within a sector (FAT16 + FAT32 layouts).

Enumerator
k_bpb_jmp0 

Jump instruction byte 0.

k_bpb_jmp1 

Jump instruction byte 1.

k_bpb_jmp2 

Jump instruction byte 2.

k_bpb_oem 

OEM name (8 bytes).

k_bpb_bytes_per_sec 

BPB_BytsPerSec.

k_bpb_sec_per_clus 

BPB_SecPerClus.

k_bpb_resv_sec 

BPB_RsvdSecCnt.

k_bpb_num_fats 

BPB_NumFATs.

k_bpb_root_ents 

BPB_RootEntCnt.

k_bpb_totsec16 

BPB_TotSec16.

k_bpb_media 

BPB_Media.

k_bpb_fatsz16 

BPB_FATSz16.

k_bpb_sec_per_trk 

BPB_SecPerTrk.

k_bpb_num_heads 

BPB_NumHeads.

k_bpb_totsec32 

BPB_TotSec32.

k_bpb_fatsz32 

BPB_FATSz32 (FAT32 only).

k_bpb16_drive_num 

BS_DrvNum (FAT16).

k_bpb16_boot_sig 

BS_BootSig (FAT16).

k_bpb16_volid 

BS_VolID (FAT16).

k_bpb16_vol_label 

BS_VolLab (FAT16, 11 bytes).

k_bpb32_root_clus 

BPB_RootClus (FAT32).

k_bpb32_fsinfo_sec 

BPB_FSInfo (FAT32).

k_bpb32_bkboot_sec 

BPB_BkBootSec (FAT32).

k_bpb16_fstype 

BS_FilSysType (FAT16, 8 bytes).

k_bpb32_drive_num 

BS_DrvNum (FAT32).

k_bpb32_boot_sig 

BS_BootSig (FAT32).

k_bpb32_volid 

BS_VolID (FAT32).

k_bpb32_vol_label 

BS_VolLab (FAT32, 11 bytes).

k_bpb32_fstype 

BS_FilSysType (FAT32, 8 bytes).

k_bpb_sig_lo 

0x55 boot-signature byte.

k_bpb_sig_hi 

0xAA boot-signature byte.

Definition at line 79 of file board_periph_sd_format.c.

◆ sd_bpb_val_t

enum sd_bpb_val_t : uint32_t

FAT BPB literal field values + the FSInfo signatures.

Enumerator
k_bpb_jmp_b0 

Boot jump byte 0 (JMP short).

k_bpb_jmp_b1 

Boot jump byte 1 (offset).

k_bpb_jmp_b2 

Boot jump byte 2 (NOP).

k_bpb_oem_len 

OEM-name field length.

k_bpb_fstype_len 

FilSysType field length.

k_bpb_sig_byte_lo 

Boot signature low byte.

k_bpb_sig_byte_hi 

Boot signature high byte.

k_bpb_num_fats_val 

Number of FAT copies.

k_bpb_media_fixed 

Media descriptor: fixed disk.

k_bpb_sec_per_trk_val 

Sectors per track.

k_bpb_num_heads_val 

Number of heads.

k_bpb_drive_num_val 

Drive number (hard disk).

k_bpb_ext_boot_sig 

Extended boot signature present.

k_bpb_dir_ent_size 

Bytes per directory entry.

k_bpb_fat16_div 

512-byte sector / 2-byte FAT16 ent.

k_bpb_fat32_div 

FAT32 FAT-size divisor multiplier.

k_fat16_eoc_clus0 

FAT16 entry 0: media + EOC bits.

k_fat16_eoc_clus1 

FAT16 entry 1: end-of-chain.

k_fat32_eoc_media 

FAT32 entry 0: media + EOC.

k_fat32_eoc 

FAT32 end-of-chain marker.

k_fat32_root_clus 

FAT32 root directory cluster.

k_fat32_fsinfo_sec 

FSInfo sector index.

k_fat32_bkboot_sec 

Backup boot-sector index.

k_fsi_lead_sig 

FSInfo lead signature "RRaA".

k_fsi_struc_sig 

FSInfo struct signature "rrAa".

k_fsi_trail_sig 

FSInfo trailing signature.

k_fsi_off_lead 

FSInfo lead-sig offset.

k_fsi_off_struc 

FSInfo struct-sig offset.

k_fsi_off_free 

FSInfo free-cluster-count off.

k_fsi_off_nxtfree 

FSInfo next-free-cluster off.

k_fsi_off_trail 

FSInfo trailing-sig offset.

k_fsi_free_unknown 

Free-cluster count unknown.

k_fsi_nxt_free 

Next-free cluster hint.

k_fat_ent1_off 

FAT16 entry-1 byte offset.

k_fat32_ent1_off 

FAT32 entry-1 byte offset.

k_fat32_ent2_off 

FAT32 entry-2 byte offset.

Definition at line 114 of file board_periph_sd_format.c.

◆ sd_le_const_t

enum sd_le_const_t : uint8_t

Little-endian byte offsets, shifts, and mask for image serialization.

Enumerator
k_le_byte0 

Least-significant byte offset.

k_le_byte1 

Second byte offset.

k_le_byte2 

Third byte offset.

k_le_byte3 

Most-significant byte offset.

k_le_shift_b1 

Shift to extract byte 1.

k_le_shift_b2 

Shift to extract byte 2.

k_le_shift_b3 

Shift to extract byte 3.

k_le_byte_mask 

Low-byte mask.

Definition at line 29 of file board_periph_sd_format.c.

Function Documentation

◆ internal_fat16_solve_geometry()

RA8_INTERNAL uint32_t internal_fat16_solve_geometry ( uint32_t total_sectors,
uint32_t root_sectors,
uint32_t * fatsz )
static

Solve the FAT16 cluster size and FAT length for total_sectors.

Doubles sectors-per-cluster until the cluster count fits under the FAT16 ceiling, recomputing the FAT length each round because the two depend on each other. Stops at k_fmt_spc_max, the largest cluster the format allows.

Parameters
[in]total_sectorsCard size in 512-byte sectors.
[in]root_sectorsSectors the fixed root directory occupies.
[out]fatszReceives the per-copy FAT length in sectors.
Returns
Sectors per cluster.
Return values
spcPower-of-two sectors per cluster, at most k_fmt_spc_max.
Precondition
fatsz is non-NULL.
total_sectors leaves room for the reserved and root regions.
Postcondition
The returned cluster size is a power of two, at most k_fmt_spc_max.
*fatsz covers every cluster the returned size yields.
Note
Thread-safe: pure arithmetic over its arguments.
Since
0.1.0

Definition at line 213 of file board_periph_sd_format.c.

References k_bpb_fat16_div, k_bpb_num_fats_val, k_fmt_fat16_max, k_fmt_resv_f16, and k_fmt_spc_max.

Referenced by priv_board_sd_format_fat16().

◆ internal_fat16_write_bpb()

RA8_INTERNAL void internal_fat16_write_bpb ( uint8_t * img,
uint32_t total_sectors,
uint32_t spc,
uint32_t fatsz,
const char * label )
static

Write the FAT16 BIOS Parameter Block into sector 0 of img.

Serializes deterministic geometry, identifiers, label, and FAT16 type fields into the already zeroed sector without touching another sector.

Parameters
[out]imgCard image.
[in]total_sectorsCard size in sectors.
[in]spcSectors per cluster.
[in]fatszPer-copy FAT length in sectors.
[in]labelVolume label for the boot-sector field.
Precondition
img covers at least one sector.
spc and fatsz came from fat16_solve_geometry().
Postcondition
The sector count lands in the 16- or 32-bit field as its size requires.
The label and "FAT16 " type string are space-padded to width.
Note
Not thread-safe with respect to img.
Since
0.1.0

Definition at line 254 of file board_periph_sd_format.c.

References internal_sd_boot_frame(), internal_sd_put16(), internal_sd_put32(), k_bpb16_boot_sig, k_bpb16_drive_num, k_bpb16_fstype, k_bpb16_vol_label, k_bpb16_volid, k_bpb_bytes_per_sec, k_bpb_drive_num_val, k_bpb_ext_boot_sig, k_bpb_fatsz16, k_bpb_fstype_len, k_bpb_media, k_bpb_media_fixed, k_bpb_num_fats, k_bpb_num_fats_val, k_bpb_num_heads, k_bpb_num_heads_val, k_bpb_resv_sec, k_bpb_root_ents, k_bpb_sec_per_clus, k_bpb_sec_per_trk, k_bpb_sec_per_trk_val, k_bpb_totsec16, k_bpb_totsec32, k_fmt_resv_f16, k_fmt_root_ents, k_fmt_sec_bytes, k_fmt_totsec16_max, k_fmt_volid, memcpy(), priv_board_sd_label_field(), and RA8_INTERNAL.

Referenced by priv_board_sd_format_fat16().

◆ internal_fat32_write_bpb()

RA8_INTERNAL void internal_fat32_write_bpb ( uint8_t * img,
uint32_t total_sectors,
uint32_t spc,
uint32_t fatsz,
const char * label )
static

Serialize one deterministic FAT32 BIOS Parameter Block.

Writes common geometry, FAT32 root/FSInfo locations, volume identity, space-padded label, and type string into an already zeroed boot sector.

Parameters
[out]imgZeroed boot-sector buffer.
[in]total_sectorsExact card sector count.
[in]spcSolved sectors per cluster.
[in]fatszSolved sectors per FAT copy.
[in]labelOptional NUL-terminated volume label.
Precondition
img spans one writable k_fmt_sec_bytes sector.
spc and fatsz came from internal_sd_fat32_geometry.
Postcondition
FAT32 BPB, extended fields, signature, and label are initialized.
Bytes outside named fields remain zero.
Note
Pure apart from caller-owned sector; thread-safe for distinct buffers.
Since
0.1.0

Definition at line 406 of file board_periph_sd_format.c.

References internal_sd_boot_frame(), internal_sd_put16(), internal_sd_put32(), k_bpb32_bkboot_sec, k_bpb32_boot_sig, k_bpb32_drive_num, k_bpb32_fsinfo_sec, k_bpb32_fstype, k_bpb32_root_clus, k_bpb32_vol_label, k_bpb32_volid, k_bpb_bytes_per_sec, k_bpb_drive_num_val, k_bpb_ext_boot_sig, k_bpb_fatsz16, k_bpb_fatsz32, k_bpb_fstype_len, k_bpb_media, k_bpb_media_fixed, k_bpb_num_fats, k_bpb_num_fats_val, k_bpb_num_heads, k_bpb_num_heads_val, k_bpb_resv_sec, k_bpb_root_ents, k_bpb_sec_per_clus, k_bpb_sec_per_trk, k_bpb_sec_per_trk_val, k_bpb_totsec16, k_bpb_totsec32, k_fat32_bkboot_sec, k_fat32_fsinfo_sec, k_fat32_root_clus, k_fmt_resv_f32, k_fmt_sec_bytes, k_fmt_volid, memcpy(), priv_board_sd_label_field(), and RA8_INTERNAL.

Referenced by priv_board_sd_format_fat32().

◆ internal_sd_boot_frame()

RA8_INTERNAL void internal_sd_boot_frame ( uint8_t * img,
const char * oem )
static

Write the shared boot prologue and trailing boot signature.

Installs the deterministic jump, exact eight-byte OEM field, and 0x55AA marker.

Parameters
[out]imgZeroed boot-sector buffer.
[in]oemExact eight-byte OEM spelling.
Precondition
img spans one writable k_fmt_sec_bytes sector.
oem spans at least k_bpb_oem_len readable bytes.
Postcondition
Named prologue and signature bytes are initialized.
All bytes outside those fixed fields remain unchanged.
Note
Pure apart from caller-owned sector and thread-safe.
Since
0.1.0

Definition at line 165 of file board_periph_sd_format.c.

References k_bpb_jmp0, k_bpb_jmp1, k_bpb_jmp2, k_bpb_jmp_b0, k_bpb_jmp_b1, k_bpb_jmp_b2, k_bpb_oem, k_bpb_oem_len, k_bpb_sig_byte_hi, k_bpb_sig_byte_lo, k_bpb_sig_hi, k_bpb_sig_lo, memcpy(), and RA8_INTERNAL.

Referenced by internal_fat16_write_bpb(), and internal_fat32_write_bpb().

◆ internal_sd_fat32_geometry()

RA8_INTERNAL uint32_t internal_sd_fat32_geometry ( uint32_t total_sectors,
uint32_t * out_fatsz,
uint32_t * out_clusters )
static

Compute FAT32 volume geometry for a card of total_sectors.

Iteratively grows the sectors-per-cluster (spc) so the FAT stays bounded and the cluster size is realistic (8 KiB at ~2 GiB, 32 KiB at ~8 GiB+), capped at the FAT32 cluster ceiling k_fmt_spc_max; k_fmt_fat32_pref keeps small cards at 1 spc. For each candidate spc it derives the FAT size (in sectors) using the Microsoft FAT32 divisor ((256 * spc) + NumFATs) / 2 = 128 * spc + 1 and the resulting cluster count. Extracted verbatim from sd_format_fat32().

Parameters
[in]total_sectorsCard size in 512-byte sectors.
[out]out_fatszReceives the chosen FAT size in sectors.
[out]out_clustersReceives the resulting data-cluster count.
Returns
The chosen sectors-per-cluster value.
Return values
spcSectors-per-cluster (power of two, 1 .. k_fmt_spc_max).
Precondition
out_fatsz and out_clusters are non-null.
total_sectors exceeds the FAT32 reserved-sector count.
Postcondition
*out_fatsz and *out_clusters hold the geometry for the return value.
The returned spc is a power of two not exceeding k_fmt_spc_max.
Note
Pure computation; touches no image buffer. Not thread-safe by contract (operates only on caller-provided locals).
Since
0.1.0

Definition at line 360 of file board_periph_sd_format.c.

References k_bpb_fat32_div, k_fmt_fat32_pref, k_fmt_resv_f32, and k_fmt_spc_max.

Referenced by priv_board_sd_format_fat32().

◆ internal_sd_put16()

RA8_INTERNAL void internal_sd_put16 ( uint8_t * p,
uint16_t v )
static

Store one 16-bit image field in little-endian order.

Writes both bytes explicitly so serialization is host-independent.

Parameters
[out]pDestination spanning two bytes.
[in]vValue to encode.
Precondition
p is non-null and writable for two bytes.
v may be any uint16_t value.
Postcondition
Exactly two bytes contain v least-significant byte first.
No byte beyond the two-byte field is changed.
Note
Pure apart from caller output and thread-safe.
Since
0.1.0

Definition at line 52 of file board_periph_sd_format.c.

References k_le_byte0, k_le_byte1, k_le_byte_mask, k_le_shift_b1, and RA8_INTERNAL.

Referenced by internal_fat16_write_bpb(), internal_fat32_write_bpb(), and priv_board_sd_format_fat16().

◆ internal_sd_put32()

RA8_INTERNAL void internal_sd_put32 ( uint8_t * p,
uint32_t v )
static

Store one 32-bit image field in little-endian order.

Writes all four bytes explicitly so serialization is host-independent.

Parameters
[out]pDestination spanning four bytes.
[in]vValue to encode.
Precondition
p is non-null and writable for four bytes.
v may be any uint32_t value.
Postcondition
Exactly four bytes contain v least-significant byte first.
No byte beyond the four-byte field is changed.
Note
Pure apart from caller output and thread-safe.
Since
0.1.0

Definition at line 70 of file board_periph_sd_format.c.

References k_le_byte0, k_le_byte1, k_le_byte2, k_le_byte3, k_le_byte_mask, k_le_shift_b1, k_le_shift_b2, k_le_shift_b3, and RA8_INTERNAL.

Referenced by internal_fat16_write_bpb(), internal_fat32_write_bpb(), and priv_board_sd_format_fat32().

◆ internal_write_sector()

RA8_INTERNAL bool internal_write_sector ( int image_fd,
uint32_t sector,
const uint8_t * data )
static

Write one complete sector at its checked positioned offset.

Converts the sector number to a 64-bit byte offset and delegates exact host I/O.

Parameters
[in]image_fdOpen sparse working-image descriptor.
[in]sectorZero-based sector number.
[in]dataSource spanning exactly k_fmt_sec_bytes bytes.
Returns
Whether exact positioned I/O succeeded.
Return values
trueComplete sector was written.
falseHost positioned write failed.
Precondition
image_fd is open and writable.
data is non-null and sector lies within prepared image geometry.
Postcondition
Success replaces exactly the selected sector.
Descriptor stream position is unchanged.
Note
Not thread-safe for overlapping sector writes.
Since
0.1.0

Definition at line 298 of file board_periph_sd_format.c.

References k_emu_io_ok, k_fmt_sec_bytes, priv_emu_io_pwrite_exact(), RA8_INTERNAL, and emu_io_result_t::status.

Referenced by priv_board_sd_format_fat16(), and priv_board_sd_format_fat32().

◆ priv_board_sd_format_fat16()

bool priv_board_sd_format_fat16 ( int image_fd,
uint32_t total_sectors,
const char * label,
uint32_t * out_spc )
nodiscard

Format the attached sparse backend as a FAT16 volume.

Writes a complete BPB (boot frame, geometry, label, volume id), the signature bytes and the FAT[0]/FAT[1] reserved entries – enough to satisfy a host fsck_msdos and the firmware's ra8_fs mount alike.

Parameters
[in]image_fdSized sparse backing descriptor to format.
[in]total_sectorsCard capacity in 512-byte sectors.
[in]labelVolume label (space-padded to 11 chars).
[out]out_spcReceives the selected sectors per cluster.
Returns
Whether every required sector was written exactly.
Return values
trueThe empty FAT16 volume was serialized.
falseA positioned backend write failed.
Precondition
image_fd is writable and sized for total_sectors sectors.
total_sectors fits FAT16 cluster limits (caller picked FAT16).
Postcondition
The image mounts as an empty FAT16 volume.
Note
Uses only fixed one-sector buffers; not thread-safe.
Since
0.1.0

Definition at line 306 of file board_periph_sd_format.c.

References internal_fat16_solve_geometry(), internal_fat16_write_bpb(), internal_sd_put16(), internal_write_sector(), k_bpb_dir_ent_size, k_bpb_num_fats_val, k_fat16_eoc_clus0, k_fat16_eoc_clus1, k_fat_ent1_off, k_fmt_resv_f16, k_fmt_root_ents, k_fmt_sec_bytes, and k_le_byte0.

Referenced by board_sd_attach_blank().

◆ priv_board_sd_format_fat32()

bool priv_board_sd_format_fat32 ( int image_fd,
uint32_t total_sectors,
const char * label,
uint32_t * out_spc )
nodiscard

Format the attached sparse backend as a FAT32 volume.

Writes the FAT32 BPB (with FSInfo + backup boot sectors), the root-directory cluster chain and both FAT copies' reserved entries.

Parameters
[in]image_fdSized sparse backing descriptor to format.
[in]total_sectorsCard capacity in 512-byte sectors.
[in]labelVolume label (space-padded to 11 chars).
[out]out_spcReceives the selected sectors per cluster.
Returns
Whether every required sector was written exactly.
Return values
trueThe empty FAT32 volume was serialized.
falseA positioned backend write failed.
Precondition
image_fd is writable and sized for total_sectors sectors.
total_sectors warrants FAT32 (caller picked FAT32).
Postcondition
The image mounts as an empty FAT32 volume.
Note
Uses only fixed one-sector buffers; not thread-safe.
Since
0.1.0

Definition at line 435 of file board_periph_sd_format.c.

References internal_fat32_write_bpb(), internal_sd_fat32_geometry(), internal_sd_put32(), internal_write_sector(), k_bpb_num_fats_val, k_fat32_bkboot_sec, k_fat32_ent1_off, k_fat32_ent2_off, k_fat32_eoc, k_fat32_eoc_media, k_fat32_fsinfo_sec, k_fmt_resv_f32, k_fmt_sec_bytes, k_fsi_free_unknown, k_fsi_lead_sig, k_fsi_nxt_free, k_fsi_off_free, k_fsi_off_lead, k_fsi_off_nxtfree, k_fsi_off_struc, k_fsi_off_trail, k_fsi_struc_sig, k_fsi_trail_sig, and k_le_byte0.

Referenced by board_sd_attach_blank().

◆ priv_board_sd_label_field()

void priv_board_sd_label_field ( uint8_t * dst,
const char * label )

Pad an ASCII volume label to the 11-byte 8.3 field (space-filled).

Copy a volume label into an 11-char space-padded 8.3 field.

Definition at line 176 of file board_periph_sd_format.c.

References k_fmt_label_len.

Referenced by board_sd_attach_blank(), internal_fat16_write_bpb(), and internal_fat32_write_bpb().