scripts: P4-Nano probe app and C6 esp-hosted OTA tools

p4-probe identifies the P4 and its C6 over esp-hosted SDIO. c6-ota holds the
C6 coprocessor build and the two host updaters (3.1 and the 2.x one that moved
the factory C6 firmware to esp-hosted 3.1). Also the pending graphify output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Opus 5.5 committed 2026-11-24 13:52:12 +13:00
1 parent edf35e9c71
commit ba8e160aee
104 files changed
+8674 -204

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(c6_ota_v2)
@@ -0,0 +1,2 @@
idf_component_register(SRCS "main.c" INCLUDE_DIRS "."
PRIV_REQUIRES esp_partition esp_app_format bootloader_support nvs_flash esp_netif esp_event esp_wifi)
@@ -0,0 +1,3 @@
dependencies:
espressif/esp_hosted: "~2"
espressif/esp_wifi_remote: "*"
+87
View File
@@ -0,0 +1,87 @@
// One-shot C6 updater for the Waveshare ESP32-P4-Nano, built on esp-hosted 2.x so it speaks the
// RPC protocol of the C6's old factory firmware. Streams the C6 image that is already in the
// P4's "slave_fw" flash partition (written by ../mcu_host's flash step) and then reboots.
#include <string.h>
#include "esp_log.h"
#include "esp_partition.h"
#include "esp_app_desc.h"
#include "esp_image_format.h"
#include "esp_event.h"
#include "esp_netif.h"
#include "nvs_flash.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_hosted.h"
#include "esp_hosted_ota.h"
static const char *TAG = "c6-ota";
#define CHUNK 1400
// Size of an ESP app image: header, segments, checksum padded to 16, optional SHA-256.
static uint32_t image_size(const esp_partition_t *p)
{
esp_image_header_t h;
if (esp_partition_read(p, 0, &h, sizeof h) != ESP_OK || h.magic != ESP_IMAGE_HEADER_MAGIC)
return 0;
uint32_t off = sizeof h;
for (int i = 0; i < h.segment_count; i++) {
esp_image_segment_header_t s;
if (esp_partition_read(p, off, &s, sizeof s) != ESP_OK) return 0;
off += sizeof s + s.data_len;
}
off = (off + 1 + 15) & ~15u; // checksum byte, then pad to 16
if (h.hash_appended) off += 32;
return off <= p->size ? off : 0;
}
static void halt(const char *why)
{
ESP_LOGE(TAG, "%s", why);
for (;;) { ESP_LOGE(TAG, "RESULT FAIL: %s", why); vTaskDelay(pdMS_TO_TICKS(5000)); }
}
void app_main(void)
{
nvs_flash_init();
esp_netif_init();
esp_event_loop_create_default();
if (esp_hosted_connect_to_slave() != 0) halt("cannot connect to C6");
esp_hosted_coprocessor_fwver_t v = {0};
if (esp_hosted_get_coprocessor_fwversion(&v) == ESP_OK)
ESP_LOGI(TAG, "C6 firmware before update: %lu.%lu.%lu", (unsigned long)v.major1,
(unsigned long)v.minor1, (unsigned long)v.patch1);
else
ESP_LOGW(TAG, "C6 did not report a version (old firmware)");
const esp_partition_t *p = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, 0x40, "slave_fw");
if (!p) halt("no slave_fw partition");
uint32_t size = image_size(p);
if (!size) halt("slave_fw does not hold a valid image");
esp_app_desc_t d;
esp_partition_read(p, sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t), &d, sizeof d);
ESP_LOGI(TAG, "New C6 image: %u bytes, project '%s', IDF %s", (unsigned)size, d.project_name, d.idf_ver);
if (esp_hosted_slave_ota_begin() != ESP_OK) halt("OTA begin failed");
static uint8_t buf[CHUNK];
for (uint32_t off = 0; off < size;) {
uint32_t n = size - off > CHUNK ? CHUNK : size - off;
esp_partition_read(p, off, buf, n);
if (esp_hosted_slave_ota_write(buf, n) != ESP_OK) {
ESP_LOGE(TAG, "write failed at offset %u", (unsigned)off);
halt("OTA write failed");
}
off += n;
if ((off / CHUNK) % 100 == 0 || off == size)
ESP_LOGI(TAG, "sent %u / %u bytes", (unsigned)off, (unsigned)size);
}
if (esp_hosted_slave_ota_end() != ESP_OK) halt("OTA end failed (image rejected)");
ESP_LOGI(TAG, "OTA end OK");
esp_err_t a = esp_hosted_slave_ota_activate(); // only on C6 fw 2.6+; older ones switch at end
ESP_LOGI(TAG, "activate: %s", esp_err_to_name(a));
for (int i = 0; i < 3; i++) { ESP_LOGI(TAG, "RESULT OK: C6 updated, rebooting"); vTaskDelay(pdMS_TO_TICKS(1000)); }
esp_restart(); // reboots the P4, which resets the C6 into the new image
}
+23
View File
@@ -0,0 +1,23 @@
# Universal partition table for all OTA methods (HTTPS / LittleFS / Partition).
# Mirrors upstream esp_hosted/examples/host_performs_slave_ota/partitions.csv.
#
# Layout (8 MB flash, host = ESP32-P4):
# nvs 16K — config / Wi-Fi credentials
# otadata 8K — IDF OTA bookkeeping (which slot is active)
# phy_init 4K — RF calibration data
# ota_0 2M @ 0x010000 — host firmware A
# ota_1 2M @ 0x210000 — host firmware B
# storage 1920K @ 0x410000 — LittleFS partition (used by OTA_METHOD_LITTLEFS:
# the host stages the slave .bin into this FS,
# then streams it over RPC).
# slave_fw 2M @ 0x5F0000 — raw partition (used by OTA_METHOD_PARTITION:
# host reads slave .bin straight from flash).
#
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 16K,
otadata, data, ota, 0xd000, 8K,
phy_init, data, phy, 0xf000, 4K,
ota_0, app, ota_0, 0x10000, 2M,
ota_1, app, ota_1, 0x210000, 2M,
storage, data, littlefs, 0x410000, 0x1E0000,
slave_fw, data, 0x40, 0x5F0000, 0x200000,
1 # Universal partition table for all OTA methods (HTTPS / LittleFS / Partition).
2 # Mirrors upstream esp_hosted/examples/host_performs_slave_ota/partitions.csv.
3 #
4 # Layout (8 MB flash, host = ESP32-P4):
5 # nvs 16K — config / Wi-Fi credentials
6 # otadata 8K — IDF OTA bookkeeping (which slot is active)
7 # phy_init 4K — RF calibration data
8 # ota_0 2M @ 0x010000 — host firmware A
9 # ota_1 2M @ 0x210000 — host firmware B
10 # storage 1920K @ 0x410000 — LittleFS partition (used by OTA_METHOD_LITTLEFS:
11 # the host stages the slave .bin into this FS,
12 # then streams it over RPC).
13 # slave_fw 2M @ 0x5F0000 — raw partition (used by OTA_METHOD_PARTITION:
14 # host reads slave .bin straight from flash).
15 #
16 # Name, Type, SubType, Offset, Size, Flags
17 nvs, data, nvs, 0x9000, 16K,
18 otadata, data, ota, 0xd000, 8K,
19 phy_init, data, phy, 0xf000, 4K,
20 ota_0, app, ota_0, 0x10000, 2M,
21 ota_1, app, ota_1, 0x210000, 2M,
22 storage, data, littlefs, 0x410000, 0x1E0000,
23 slave_fw, data, 0x40, 0x5F0000, 0x200000,
@@ -0,0 +1,7 @@
CONFIG_IDF_TARGET="esp32p4"
CONFIG_ESP_CONSOLE_UART_DEFAULT=y
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
CONFIG_SLAVE_IDF_TARGET_ESP32C6=y
CONFIG_ESP_HOSTED_SDIO_HOST_INTERFACE=y