feat(m1): storage info command and tf card identity record (#16)
## What - M1 firmware: new `storage info` console command printing the mounted TF card identity from `sdmmc_card_t` (CID: manufacturer/OEM/product name/revision/serial/date; CSD: capacity in MiB, sectors, sector size). `storage: no card` when not mounted. CID/CSD are copied out under a new mutex that also guards mount/unmount, so the console never dereferences a half-initialized or freed card. No other behavior changed. - Lab config `_doc/lab/board-c1810c76790e.json`: `tf.tf_card` upgraded from `pending-visual-read` to the values read on the real board (`SD16G`, 14910 MiB, serial `0x00000024`, mfg 2026-05), citing the in-repo transcript. - ADR-0003: TF record acceptance checkbox ticked with citation; blockers list updated. ## Evidence - `poc/evidence/tf-info-20260907/tf-cid-transcript-20260907.log`: RTS-reset boot, two identical `storage info` reads (L188-189, L192-193), `status --json` sanity (L197, `tf":"READY`), serial non-zero. - Board restored to PoC-A firmware after the read (`poca status` verified). Co-authored-by: ania-lain <[email protected]>
This commit is contained in:
@@ -75,7 +75,7 @@ esp_err_t console_service::start() {
|
||||
};
|
||||
const esp_console_cmd_t storage_cmd{
|
||||
.command = "storage",
|
||||
.help = "storage probe | storage status",
|
||||
.help = "storage probe | storage status | storage info (TF card CID/CSD)",
|
||||
.hint = nullptr,
|
||||
.func = &console_service::storage_command,
|
||||
.argtable = nullptr,
|
||||
@@ -248,7 +248,11 @@ int console_service::storage_command(int argc, char** argv) {
|
||||
instance_->print_status(false);
|
||||
return 0;
|
||||
}
|
||||
std::printf("usage: storage probe | storage status\n");
|
||||
if (argc == 2 && std::strcmp(argv[1], "info") == 0) {
|
||||
instance_->storage_.print_card_info();
|
||||
return 0;
|
||||
}
|
||||
std::printf("usage: storage probe | storage status | storage info\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,10 @@ constexpr int64_t kLogIntervalUs = 10LL * 1000LL * 1000LL;
|
||||
sd_service::~sd_service() { unmount(); }
|
||||
|
||||
esp_err_t sd_service::start() {
|
||||
card_lock_ = xSemaphoreCreateMutex();
|
||||
if (card_lock_ == nullptr) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
const BaseType_t created =
|
||||
xTaskCreatePinnedToCore(&sd_service::task_entry, "frame-sd", 6144, this, 7, &task_, 1);
|
||||
return created == pdPASS ? ESP_OK : ESP_ERR_NO_MEM;
|
||||
@@ -65,9 +69,16 @@ esp_err_t sd_service::mount_and_check() {
|
||||
mount.max_files = 8;
|
||||
mount.allocation_unit_size = 16 * 1024;
|
||||
|
||||
// Hold card_lock_ across the mount call: esp_vfs_fat_sdmmc_mount writes card_ via the
|
||||
// out-param while the card struct is still initializing, and print_card_info must not
|
||||
// observe that half-built state.
|
||||
xSemaphoreTake(card_lock_, portMAX_DELAY);
|
||||
esp_err_t result = esp_vfs_fat_sdmmc_mount(board::kSdMount, &host, &slot, &mount, &card_);
|
||||
if (result != ESP_OK) {
|
||||
card_ = nullptr;
|
||||
}
|
||||
xSemaphoreGive(card_lock_);
|
||||
if (result != ESP_OK) {
|
||||
const bool card_absent = result == ESP_ERR_NOT_FOUND || result == ESP_ERR_TIMEOUT;
|
||||
status_.update([&](status_snapshot& value) {
|
||||
value.storage = card_absent ? sd_state::absent : sd_state::failed;
|
||||
@@ -135,10 +146,54 @@ esp_err_t sd_service::health_check() {
|
||||
}
|
||||
|
||||
void sd_service::unmount() {
|
||||
if (card_lock_ != nullptr) {
|
||||
xSemaphoreTake(card_lock_, portMAX_DELAY);
|
||||
}
|
||||
if (card_ != nullptr) {
|
||||
esp_vfs_fat_sdcard_unmount(board::kSdMount, card_);
|
||||
card_ = nullptr;
|
||||
}
|
||||
if (card_lock_ != nullptr) {
|
||||
xSemaphoreGive(card_lock_);
|
||||
}
|
||||
}
|
||||
|
||||
void sd_service::print_card_info() const {
|
||||
if (card_lock_ == nullptr) {
|
||||
std::printf("storage: no card\n");
|
||||
return;
|
||||
}
|
||||
sdmmc_cid_t cid{};
|
||||
sdmmc_csd_t csd{};
|
||||
bool mounted = false;
|
||||
xSemaphoreTake(card_lock_, portMAX_DELAY);
|
||||
if (card_ != nullptr) {
|
||||
cid = card_->cid;
|
||||
csd = card_->csd;
|
||||
mounted = true;
|
||||
}
|
||||
xSemaphoreGive(card_lock_);
|
||||
if (!mounted) {
|
||||
std::printf("storage: no card\n");
|
||||
return;
|
||||
}
|
||||
|
||||
char name[sizeof(cid.name) + 1]{};
|
||||
std::memcpy(name, cid.name, sizeof(cid.name));
|
||||
const unsigned oem_high = static_cast<unsigned>(cid.oem_id >> 8) & 0xFFU;
|
||||
const unsigned oem_low = static_cast<unsigned>(cid.oem_id) & 0xFFU;
|
||||
const unsigned serial = static_cast<unsigned>(static_cast<uint32_t>(cid.serial));
|
||||
const unsigned long long sectors = static_cast<unsigned long long>(csd.capacity);
|
||||
const unsigned long long capacity_mib =
|
||||
sectors * static_cast<unsigned long long>(csd.sector_size) / (1024ULL * 1024ULL);
|
||||
std::printf(
|
||||
"cid: mfg=0x%02X oem=%c%c name=\"%s\" rev=%u.%u serial=0x%08X date=%u/%u\n",
|
||||
static_cast<unsigned>(cid.mfg_id) & 0xFFU, oem_high != 0U ? oem_high : '?',
|
||||
oem_low != 0U ? oem_low : '?', name, (static_cast<unsigned>(cid.revision) >> 4U) & 0xFU,
|
||||
static_cast<unsigned>(cid.revision) & 0xFU, serial, static_cast<unsigned>(cid.date) & 0xFU,
|
||||
2000U + ((static_cast<unsigned>(cid.date) >> 4U) & 0xFFU));
|
||||
std::printf("csd: capacity=%llu MiB (%llu sectors × %u B)\n", capacity_mib, sectors,
|
||||
static_cast<unsigned>(csd.sector_size));
|
||||
}
|
||||
|
||||
esp_err_t sd_service::append_status_log() {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/task.h"
|
||||
#include "sdmmc_cmd.h"
|
||||
|
||||
@@ -19,6 +20,7 @@ class sd_service {
|
||||
|
||||
esp_err_t start();
|
||||
void request_probe();
|
||||
void print_card_info() const;
|
||||
|
||||
private:
|
||||
static void task_entry(void* context);
|
||||
@@ -30,6 +32,9 @@ class sd_service {
|
||||
|
||||
hardware_status& status_;
|
||||
sdmmc_card_t* card_{};
|
||||
// Serializes card_ mutations (sd task mount/unmount) against print_card_info copy-out
|
||||
// (console task); CID/CSD are copied under the lock, printed outside it.
|
||||
SemaphoreHandle_t card_lock_{};
|
||||
TaskHandle_t task_{};
|
||||
uint64_t log_sequence_{};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user