|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Blank-card FAT16/FAT32 sparse-sector formatters (–sd-new). More...
Go to the source code of this file.
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. | |
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.
Definition in file board_periph_sd_format.c.
| enum sd_bpb_off_t : uint16_t |
FAT BPB byte offsets within a sector (FAT16 + FAT32 layouts).
Definition at line 79 of file board_periph_sd_format.c.
| enum sd_bpb_val_t : uint32_t |
FAT BPB literal field values + the FSInfo signatures.
Definition at line 114 of file board_periph_sd_format.c.
| enum sd_le_const_t : uint8_t |
Little-endian byte offsets, shifts, and mask for image serialization.
Definition at line 29 of file board_periph_sd_format.c.
|
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.
| [in] | total_sectors | Card size in 512-byte sectors. |
| [in] | root_sectors | Sectors the fixed root directory occupies. |
| [out] | fatsz | Receives the per-copy FAT length in sectors. |
| spc | Power-of-two sectors per cluster, at most k_fmt_spc_max. |
fatsz is non-NULL. total_sectors leaves room for the reserved and root regions. 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().
|
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.
| [out] | img | Card image. |
| [in] | total_sectors | Card size in sectors. |
| [in] | spc | Sectors per cluster. |
| [in] | fatsz | Per-copy FAT length in sectors. |
| [in] | label | Volume label for the boot-sector field. |
img covers at least one sector. spc and fatsz came from fat16_solve_geometry(). img. 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().
|
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.
| [out] | img | Zeroed boot-sector buffer. |
| [in] | total_sectors | Exact card sector count. |
| [in] | spc | Solved sectors per cluster. |
| [in] | fatsz | Solved sectors per FAT copy. |
| [in] | label | Optional NUL-terminated volume label. |
img spans one writable k_fmt_sec_bytes sector. spc and fatsz came from internal_sd_fat32_geometry. 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().
|
static |
Write the shared boot prologue and trailing boot signature.
Installs the deterministic jump, exact eight-byte OEM field, and 0x55AA marker.
| [out] | img | Zeroed boot-sector buffer. |
| [in] | oem | Exact eight-byte OEM spelling. |
img spans one writable k_fmt_sec_bytes sector. oem spans at least k_bpb_oem_len readable bytes. 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().
|
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().
| [in] | total_sectors | Card size in 512-byte sectors. |
| [out] | out_fatsz | Receives the chosen FAT size in sectors. |
| [out] | out_clusters | Receives the resulting data-cluster count. |
| spc | Sectors-per-cluster (power of two, 1 .. k_fmt_spc_max). |
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().
|
static |
Store one 16-bit image field in little-endian order.
Writes both bytes explicitly so serialization is host-independent.
| [out] | p | Destination spanning two bytes. |
| [in] | v | Value to encode. |
p is non-null and writable for two bytes. v may be any uint16_t value. v least-significant byte first. 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().
|
static |
Store one 32-bit image field in little-endian order.
Writes all four bytes explicitly so serialization is host-independent.
| [out] | p | Destination spanning four bytes. |
| [in] | v | Value to encode. |
p is non-null and writable for four bytes. v may be any uint32_t value. v least-significant byte first. 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().
|
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.
| [in] | image_fd | Open sparse working-image descriptor. |
| [in] | sector | Zero-based sector number. |
| [in] | data | Source spanning exactly k_fmt_sec_bytes bytes. |
| true | Complete sector was written. |
| false | Host positioned write failed. |
image_fd is open and writable. data is non-null and sector lies within prepared image geometry. 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().
|
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.
| [in] | image_fd | Sized sparse backing descriptor to format. |
| [in] | total_sectors | Card capacity in 512-byte sectors. |
| [in] | label | Volume label (space-padded to 11 chars). |
| [out] | out_spc | Receives the selected sectors per cluster. |
| true | The empty FAT16 volume was serialized. |
| false | A positioned backend write failed. |
image_fd is writable and sized for total_sectors sectors. total_sectors fits FAT16 cluster limits (caller picked FAT16). 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().
|
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.
| [in] | image_fd | Sized sparse backing descriptor to format. |
| [in] | total_sectors | Card capacity in 512-byte sectors. |
| [in] | label | Volume label (space-padded to 11 chars). |
| [out] | out_spc | Receives the selected sectors per cluster. |
| true | The empty FAT32 volume was serialized. |
| false | A positioned backend write failed. |
image_fd is writable and sized for total_sectors sectors. total_sectors warrants FAT32 (caller picked FAT32). 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().
| 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().