|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
examples/ek_ra8d2/hw_validated/manual/usb_host_file_ops/src/usb_host_file_ops_steps.c More...
#include "usb_host_file_ops_steps.h"#include <stdint.h>#include "ra8_board_ek_ra8d2.h"#include "ra8_err.h"#include "ra8_fs.h"#include "ra8_io_blockdev.h"#include "ra8_io_blockdev_usbmsc.h"Go to the source code of this file.
Data Structures | |
| struct | fileops_listdir_ctx_t |
| Cookie carried through ra8_fs_listdir for printing + matching. More... | |
Functions | |
| static uint8_t | fileops_nibble_to_hex (uint32_t nibble) |
| Format one nibble (0..15) into an uppercase hex character. | |
| static uint32_t | fileops_str_len (const char *text) |
| Bounded ASCII string length (cap k_fileops_print_cap). | |
| static bool | fileops_name_eq (const char *a, const char *b) |
| Bounded ASCII string equality (cap k_fileops_name_cap). | |
| static ra8_err_t | fileops_sci_write (const uint8_t *data, uint32_t len) |
| Push a literal block over SCI8 polled. | |
| ra8_err_t | fileops_print (const char *text) |
| Print a NUL-terminated ASCII string over the console. | |
| ra8_err_t | fileops_print_dec (uint64_t value) |
| Print a uint32_t as ASCII decimal. | |
| ra8_err_t | fileops_print_hex (uint32_t value, uint8_t digits) |
| Print a value as fixed-width uppercase hex. | |
| ra8_err_t | fileops_print_fail (const char *what, ra8_err_t err) |
| Print "FAIL <what> err=0xNNNNNNNN" on its own line. | |
| static const char * | fileops_fs_type_name (ra8_fs_type_t type) |
| Map a detected filesystem type to a printable name. | |
| ra8_err_t | fileops_mount_volume (ra8_fs_mount_t **out_mount) |
| Mount the attached drive through the USB-MSC backend. | |
| static void | fileops_listdir_cb (const char *name, uint8_t attr, uint64_t size, void *ctx) |
| Listdir callback: print one entry, match the expectation names. | |
| static ra8_err_t | fileops_step_listdir (ra8_fs_mount_t *mount, const char *want, const char *avoid) |
| List the root directory and check presence/absence expectations. | |
| static ra8_err_t | fileops_read_back (ra8_fs_mount_t *mount, const char *path) |
Open path and verify it reads back the known payload. | |
| static ra8_err_t | fileops_expect_absent (ra8_fs_mount_t *mount, const char *path) |
Require that path no longer resolves on the volume. | |
| static ra8_err_t | fileops_step_write (ra8_fs_mount_t *mount) |
| Step 3: print the banner and write the payload file. | |
| ra8_err_t | fileops_suite_create (ra8_fs_mount_t *mount) |
| Suite steps 1..5: cleanup, baseline listdir, write, verify, list. | |
| ra8_err_t | fileops_suite_mutate (ra8_fs_mount_t *mount) |
| Suite steps 6..9: rename, old-gone/new-intact, list, delete. | |
| static void | fileops_dump_rows (const uint8_t *data, uint32_t offset, uint32_t len) |
Hex-dump len bytes of data starting at offset. | |
| void | fileops_probe_layout (void) |
| Dump the partition table + LBA1/LBA2 heads after a mount failure. | |
Variables | |
| static const char | k_fileops_name_a [] = "USBTEST.TXT" |
| Name the payload file is created under (8.3-safe, <= 15 chars). | |
| static const char | k_fileops_name_b [] = "USBDONE.TXT" |
| Name the payload file is renamed to (8.3-safe, <= 15 chars). | |
| static const uint8_t | k_fileops_payload [] |
| Known payload written to and read back from the drive. | |
| static ra8_io_blockdev_t | s_fileops_usb_dev |
| Block device fronting the hosted MSC volume for this ladder. | |
| static ra8_io_blockdev_usbmsc_state_t | s_fileops_usb_state |
| Caller-owned backend state for s_fileops_usb_dev. | |
examples/ek_ra8d2/hw_validated/manual/usb_host_file_ops/src/usb_host_file_ops_steps.c
Console helpers + ra8_fs file-op suite for the USB host file-ops app.
Implements the polled-console print helpers, the ra8_io USB-MSC block device the ra8_fs mount runs on, the root-directory listing, the nine file-operation steps, and the on-mount-failure disk-layout probe. These routines were split out of main.c so every translation unit stays under the repository file-size cap; the boot/bring-up code and the retry ladder remain in main.c.
Definition in file usb_host_file_ops_steps.c.
|
static |
Hex-dump len bytes of data starting at offset.
| [in] | data | Sector buffer. |
| [in] | offset | First byte index to print. |
| [in] | len | Byte count to print. |
data holds at least offset + len bytes. Definition at line 672 of file usb_host_file_ops_steps.c.
References fileops_print(), fileops_print_hex(), k_fileops_hex_chars_u16, and k_fileops_probe_row.
Referenced by fileops_probe_layout().
|
staticnodiscard |
Require that path no longer resolves on the volume.
| [in] | mount | Live mount handle. |
| [in] | path | Name that must not exist. |
| k_ra8_err_exists | The name still opened successfully. |
mount is a live handle from ra8_fs_mount. path was unlinked or renamed away. Definition at line 494 of file usb_host_file_ops_steps.c.
References fileops_print_fail(), k_ra8_err_exists, k_ra8_err_not_found, k_ra8_fs_mode_read, k_ra8_ok, ra8_fs_close(), and ra8_fs_open().
Referenced by fileops_suite_mutate().
|
static |
Map a detected filesystem type to a printable name.
| [in] | type | Mount-time detection result. |
| exfat | For k_ra8_fs_type_exfat. |
type came from a populated mount struct. Definition at line 255 of file usb_host_file_ops_steps.c.
References k_ra8_fs_type_exfat, k_ra8_fs_type_fat12, k_ra8_fs_type_fat16, k_ra8_fs_type_fat32, and k_ra8_fs_type_unknown.
Referenced by fileops_mount_volume().
|
static |
Listdir callback: print one entry, match the expectation names.
| [in] | name | NUL-terminated entry name. |
| [in] | attr | FAT attribute byte. |
| [in] | size | File size in bytes (0 for directories). |
| [in,out] | ctx | fileops_listdir_ctx_t cookie. |
Definition at line 342 of file usb_host_file_ops_steps.c.
References fileops_listdir_ctx_t::avoid, fileops_listdir_ctx_t::count, fileops_name_eq(), fileops_print(), fileops_print_dec(), fileops_listdir_ctx_t::found_avoid, fileops_listdir_ctx_t::found_want, k_ra8_fs_attr_directory, and fileops_listdir_ctx_t::want.
Referenced by fileops_step_listdir().
|
nodiscard |
Mount the attached drive through the USB-MSC backend.
| [out] | out_mount | Receives the mount handle on success. |
| k_ra8_ok | Volume mounted; the type line was printed. |
out_mount is non-NULL. Definition at line 272 of file usb_host_file_ops_steps.c.
References fileops_fs_type_name(), fileops_print(), fileops_print_dec(), fileops_print_fail(), k_fileops_target_lun, k_ra8_ok, ra8_fs_mount(), ra8_io_blockdev_as_fs_backend(), ra8_io_blockdev_usbmsc_init(), s_fileops_usb_dev, and s_fileops_usb_state.
Referenced by fileops_run_ladder().
|
static |
Bounded ASCII string equality (cap k_fileops_name_cap).
| [in] | a | First NUL-terminated string. |
| [in] | b | Second NUL-terminated string. |
| false | On the first differing byte. |
a and b are non-NULL. Definition at line 114 of file usb_host_file_ops_steps.c.
References k_fileops_name_cap.
Referenced by fileops_listdir_cb().
|
static |
Format one nibble (0..15) into an uppercase hex character.
| [in] | nibble | 4-bit value. |
| '0' | For a zero nibble. |
Definition at line 67 of file usb_host_file_ops_steps.c.
References k_fileops_hex_digit_split.
Referenced by fileops_print_hex().
|
nodiscard |
Print a NUL-terminated ASCII string over the console.
| [in] | text | String to print (CR/LF included by the caller). |
| k_ra8_ok | All bytes queued. |
text is non-NULL. text is NUL-terminated within k_fileops_print_cap bytes. Definition at line 146 of file usb_host_file_ops_steps.c.
References fileops_sci_write(), and fileops_str_len().
Referenced by fileops_dump_rows(), fileops_listdir_cb(), fileops_mount_volume(), fileops_print_attach(), fileops_print_fail(), fileops_probe_layout(), fileops_run_ladder(), fileops_step_listdir(), fileops_step_write(), fileops_suite_create(), fileops_suite_mutate(), and main().
|
nodiscard |
Print a uint32_t as ASCII decimal.
| [in] | value | Value to print. |
| k_ra8_ok | All bytes queued. |
Definition at line 151 of file usb_host_file_ops_steps.c.
References fileops_sci_write(), k_fileops_dec_chars_u64, and k_fileops_dec_radix.
Referenced by fileops_listdir_cb(), fileops_mount_volume(), fileops_probe_layout(), fileops_step_listdir(), and fileops_step_write().
Print "FAIL <what> err=0xNNNNNNNN" on its own line.
| [in] | what | Short description of the failed step. |
| [in] | err | Error code returned by the step. |
| k_ra8_ok | The diagnostic line is queued. |
what is NUL-terminated within the print cap. Definition at line 186 of file usb_host_file_ops_steps.c.
References fileops_print(), fileops_print_hex(), k_fileops_hex_chars_u32, and k_ra8_ok.
Referenced by fileops_expect_absent(), fileops_mount_volume(), fileops_read_back(), fileops_run_ladder(), fileops_step_listdir(), fileops_step_write(), fileops_suite_mutate(), and main().
|
nodiscard |
Print a value as fixed-width uppercase hex.
| [in] | value | Value to print. |
| [in] | digits | Hex digit count (4 for u16, 8 for u32). |
| k_ra8_ok | All bytes queued. |
digits is at most k_fileops_hex_chars_u32. Definition at line 172 of file usb_host_file_ops_steps.c.
References fileops_nibble_to_hex(), fileops_sci_write(), k_fileops_hex_chars_u32, k_fileops_nibble_bits, and k_fileops_nibble_mask.
Referenced by fileops_dump_rows(), fileops_print_attach(), and fileops_print_fail().
| void fileops_probe_layout | ( | void | ) |
Dump the partition table + LBA1/LBA2 heads after a mount failure.
Reads LBA 0 (MBR partition entries at 0x1BE), LBA 1, and LBA 2 straight through the USB backend and prints hex excerpts, so an unrecognized disk layout (e.g. GPT) can be identified from the log.
Definition at line 688 of file usb_host_file_ops_steps.c.
References fileops_dump_rows(), fileops_print(), fileops_print_dec(), k_fileops_probe_head_len, k_fileops_probe_lba_max, k_fileops_probe_tbl_len, k_fileops_probe_tbl_off, k_fileops_sector_bytes, k_ra8_ok, ra8_io_blockdev_read(), and s_fileops_usb_dev.
Referenced by fileops_run_ladder().
|
staticnodiscard |
Open path and verify it reads back the known payload.
| [in] | mount | Live mount handle. |
| [in] | path | File expected to hold k_fileops_payload. |
| k_ra8_err_invalid_size | Read length differs from the payload. |
| k_ra8_err_invalid_state | A payload byte differs. |
mount is a live handle from ra8_fs_mount. path names a file written with the payload. Definition at line 449 of file usb_host_file_ops_steps.c.
References fileops_print_fail(), k_fileops_payload, k_fileops_sector_bytes, k_ra8_err_invalid_size, k_ra8_err_invalid_state, k_ra8_fs_mode_read, k_ra8_ok, ra8_fs_close(), ra8_fs_open(), and ra8_fs_read().
Referenced by fileops_suite_create(), and fileops_suite_mutate().
|
staticnodiscard |
Push a literal block over SCI8 polled.
| [in] | data | Buffer to send. |
| [in] | len | Byte count. |
| k_ra8_ok | All bytes queued. |
data is non-NULL; SCI8 init already ran. len excludes any NUL terminator. Definition at line 141 of file usb_host_file_ops_steps.c.
References ra8_board_uart_console_write().
Referenced by fileops_print(), fileops_print_dec(), and fileops_print_hex().
|
staticnodiscard |
List the root directory and check presence/absence expectations.
| [in] | mount | Live mount handle. |
| [in] | want | Name that must appear (nullptr = no check). |
| [in] | avoid | Name that must not appear (nullptr = no check). |
| k_ra8_err_not_found | want was not listed. |
| k_ra8_err_exists | avoid was listed. |
mount is a live handle from ra8_fs_mount. Definition at line 384 of file usb_host_file_ops_steps.c.
References fileops_listdir_ctx_t::count, fileops_listdir_cb(), fileops_print(), fileops_print_dec(), fileops_print_fail(), fileops_listdir_ctx_t::found_avoid, fileops_listdir_ctx_t::found_want, k_ra8_err_exists, k_ra8_err_not_found, k_ra8_ok, and ra8_fs_listdir().
Referenced by fileops_suite_create(), and fileops_suite_mutate().
|
staticnodiscard |
Step 3: print the banner and write the payload file.
| [in] | mount | Live mount handle. |
| k_ra8_ok | k_fileops_name_a holds the payload. |
mount is a live handle from ra8_fs_mount. Definition at line 523 of file usb_host_file_ops_steps.c.
References fileops_print(), fileops_print_dec(), fileops_print_fail(), k_fileops_name_a, k_fileops_payload, k_ra8_ok, and ra8_fs_write_file().
Referenced by fileops_suite_create().
|
static |
Bounded ASCII string length (cap k_fileops_print_cap).
| [in] | text | NUL-terminated string. |
| 0 | For an empty string. |
text is non-NULL. text points to readable storage of at least the returned length. Definition at line 88 of file usb_host_file_ops_steps.c.
References k_fileops_print_cap.
Referenced by fileops_print().
|
nodiscard |
Suite steps 1..5: cleanup, baseline listdir, write, verify, list.
| [in] | mount | Live mount handle. |
| k_ra8_ok | Steps 1-5 all passed and printed their verdicts. |
mount is a live handle from ra8_fs_mount. Definition at line 548 of file usb_host_file_ops_steps.c.
References fileops_print(), fileops_read_back(), fileops_step_listdir(), fileops_step_write(), k_fileops_name_a, k_fileops_name_b, k_ra8_board_led2, k_ra8_ok, ra8_board_led_toggle(), and ra8_fs_unlink().
Referenced by fileops_run_ladder().
|
nodiscard |
Suite steps 6..9: rename, old-gone/new-intact, list, delete.
| [in] | mount | Live mount handle. |
| k_ra8_ok | Steps 6-9 all passed and printed their verdicts. |
Definition at line 596 of file usb_host_file_ops_steps.c.
References fileops_expect_absent(), fileops_print(), fileops_print_fail(), fileops_read_back(), fileops_step_listdir(), k_fileops_name_a, k_fileops_name_b, k_ra8_board_led2, k_ra8_ok, ra8_board_led_toggle(), ra8_fs_rename(), and ra8_fs_unlink().
Referenced by fileops_run_ladder().
|
static |
Name the payload file is created under (8.3-safe, <= 15 chars).
Definition at line 40 of file usb_host_file_ops_steps.c.
Referenced by fileops_step_write(), fileops_suite_create(), and fileops_suite_mutate().
|
static |
Name the payload file is renamed to (8.3-safe, <= 15 chars).
Definition at line 43 of file usb_host_file_ops_steps.c.
Referenced by fileops_suite_create(), and fileops_suite_mutate().
|
static |
Known payload written to and read back from the drive.
Definition at line 46 of file usb_host_file_ops_steps.c.
Referenced by fileops_read_back(), and fileops_step_write().
|
static |
Block device fronting the hosted MSC volume for this ladder.
Bound once in fileops_mount_volume by ra8_io_blockdev_usbmsc_init, which wires the ra8_io USB-MSC backend over the polled host-MSC class. File scope because ra8_io_blockdev_as_fs_backend keeps a pointer to this handle for the whole life of the mount.
Definition at line 226 of file usb_host_file_ops_steps.c.
Referenced by fileops_mount_volume(), and fileops_probe_layout().
|
static |
Caller-owned backend state for s_fileops_usb_dev.
Records the logical unit the backend addresses. Private to the ra8_io USB-MSC backend and must out-live every call made through the device.
Definition at line 240 of file usb_host_file_ops_steps.c.
Referenced by fileops_mount_volume().