Files
fmini-1/tests/smk_flash_test.c
T
Claude f265ae9f69 SMK-37 port: FMini-1's preset slots in the SMK store, FMINI data family, LEDs sized for both
- storage.c (BOARD_SMK37): the 200 preset slots (13 A/B pairs, 26 sectors)
  do not fit FL_DATA's spare room; FMini-1 has no sample engine, so they take
  USRFLASH from 0xC2000 (0xC2000..0xDBFFF, inside FL_SMP; st_erase releases
  the stock mapping's marker before the first erase there). The store owner
  tag is "SMK37DATAFMINI" (FMini-1's own family). Under another tag, only the
  preset copies holding an FMini-1 commit record are erased: an intact stock
  mapping or another firmware's samples stay as they are.
- fmini_app.c: the LED picture is built in LED_BUF with LED_KEY0 (FM1_NCOL
  and 14 on the FM-1, unchanged) and goes to the SMK's button LEDs and pads
  through ui_input.c's smk_leds (the pads still as the white keys: the
  picker and the SEQ steps come with the mapping).
- Tests: smk_flash_test places the preset slots in FL_SMP; smk_owner_test
  takes the FMINI tag and checks the preset-slot rule; run_tests.sh uses this
  version's FM-1 files and FMini-1's SMK package names.
- BOARD=smk37 builds the Pro, Elite and MKE packages; the FM-1 build stays
  byte-identical to 2.5.0. The SMK flash map, owner, package, OTA (three
  models) and loader tests pass, as do the FM-1 OTA and loader tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QUF6pQ1NkTwmBC8SR8AK94
2026-11-09 12:51:16 -03:00

96 lines
6.0 KiB
C

/* SPDX-License-Identifier: GPL-3.0-only
* Felucca on the SMK-37 Pro (BOARD_SMK37) */
/* SMK-37 Pro flash map (build with -DBOARD_SMK37=1):
* every 4 KiB sector of the 1 MiB part through the app's allow-list (FL_RANGE_OK / FL_GUARD, fm1_flash.h),
* the update loader's (loader.c) and ldr_core.c's record window: none of them may ever reach
* the head 0x0-0x3FFF, BTIF / USRTRIM 0xC0000-0xC1FFF, USR 0xF4000-0xFDFFF or key_mac 0xFF000-;
* the store's objects (storage.c), the FM6 voice bank (fm6_vbank.c) and the OTA staging (ota.c) lie
* inside the allowed windows; ranges that wrap or straddle a boundary are refused. */
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "fm1_cc.h"
#if !BOARD_SMK37
#error "build with -DBOARD_SMK37=1"
#endif
#include "fm1_flash_map.h"
static int st_read(uint32_t off, void *dst, uint32_t n) { (void)off; (void)dst; (void)n; return -1; }
static int st_erase(uint32_t off) { (void)off; return -1; }
static int st_prog(uint32_t off, const void *src, uint32_t n) { (void)off; (void)src; (void)n; return -1; }
#include "../firmware/src/storage.c"
#define LDR_RANGE_OK(off, n) FL_LDR_RANGE_OK(off, n) /* what loader.c uses on the SMK */
static int bad;
static void check(const char *what, int ok) { printf("smk flash: %-78s %s\n", what, ok ? "ok" : "FAIL"); bad += !ok; }
static int protected_sector(uint32_t s)
{
return s < 0x4000u || (s >= 0xC0000u && s < 0xC2000u) || (s >= 0xF4000u && s < 0xFE000u) || s >= 0xFF000u;
}
int main(void)
{
uint32_t s, o, c, leak_app = 0, leak_ldr = 0, leak_guard = 0, allowed = 0, in_store = 1;
for (s = 0; s < 0x100000u; s += 0x1000u) {
if (!protected_sector(s))
continue;
leak_app += FL_RANGE_OK(s, 0x1000u) || FL_STORE_OK(s, 0x1000u) || FL_RANGE_OK(s, 256u) || FL_RANGE_OK(s + 0xF00u, 256u);
leak_ldr += LDR_RANGE_OK(s, 0x1000u) || LDR_RANGE_OK(s + 0xF00u, 256u);
leak_guard += !FL_PROTECTED(s, 0x1000u) || !FL_PROTECTED(s + 0xF00u, 256u);
}
for (s = 0; s < 0x100000u; s += 0x1000u)
allowed += FL_GUARD(s, 0x1000u);
check("no protected sector passes the app's allow-list (erase, page)", leak_app == 0);
check("no protected sector passes the loader's allow-list", leak_ldr == 0);
check("the RAM driver's own net (FL_PROTECTED) covers every protected sector", leak_guard == 0);
check("straddling ranges refused: 0xBF000+0x2000, 0xE9000+0x2000, 0x3000+0x2000",
!FL_GUARD(0xBF000u, 0x2000u) && !FL_GUARD(0xE9000u, 0x2000u) && !LDR_RANGE_OK(0xBF000u, 0x2000u) &&
!LDR_RANGE_OK(0x3000u, 0x2000u) && FL_PROTECTED(0xBF000u, 0x2000u) && FL_PROTECTED(0x3F00u, 0x200u));
check("wrapping ranges refused (off + n past 4 GiB)",
!FL_GUARD(0xBB000u, 0xFFFFF000u) && !LDR_RANGE_OK(0x9D000u, 0xFFFFFF00u) && FL_PROTECTED(0xBB000u, 0xFFFFF000u));
check("app windows: FL_DATA 0x9D000-0xBAFFF, FL_OTA 0xBB000-0xBFFFF, FL_SMP 0xC2000-0xE9FFF",
FL_GUARD(0x9D000u, 0x1000u) && FL_GUARD(0xBA000u, 0x1000u) && FL_GUARD(0xBF000u, 0x1000u) &&
FL_GUARD(0xC2000u, 0x1000u) && FL_GUARD(0xE9000u, 0x1000u) && FL_GUARD(0xEA000u, 0x1000u) &&
!FL_GUARD(0xEB000u, 0x1000u) && !FL_GUARD(0x9C000u, 0x1000u) &&
allowed == (0xC0000u - 0x9D000u + 0xEA000u - 0xC2000u) / 0x1000u + 1u);
check("the stock marker sector 0xEA000: the whole sector only (its erase), never a page or a range into it",
FL_STOCKTAG_OK(0xEA000u, 0x1000u) && !FL_GUARD(0xEA000u, 256u) && !FL_GUARD(0xEAF00u, 256u) &&
!FL_GUARD(0xE9000u, 0x2000u) && !FL_GUARD(0xEA000u, 0x2000u) && FL_STOCKTAG_OFF == 0xEAFF8u);
check("loader: app area 0x4000-0x9CFFF, records 0x9D000-0xBFFFF only",
LDR_RANGE_OK(0x4000u, 0x1000u) && LDR_RANGE_OK(0x9C000u, 0x1000u) && LDR_RANGE_OK(0xBF000u, 0x1000u) &&
!LDR_RANGE_OK(0xC0000u, 0x1000u) && FL_REC_HI == 0xC0000u);
for (o = 0; o < OBJ_COUNT; o++)
for (c = 0; c < 2u; c++)
in_store &= FL_STORE_OK(st_sector(o, c), 0x1000u) &&
((o >= OBJ_PRESET0 && o <= OBJ_PRESET_LAST) ? /* FMini-1: the preset slots in USRFLASH */
st_sector(o, c) >= FL_SMP_LO && st_sector(o, c) + 0x1000u <= FL_SMP_HI :
st_sector(o, c) < FL_DATA_HI);
{ /* every object's two copies distinct */
uint32_t o2, c2, distinct = 1;
for (o = 0; o < OBJ_COUNT; o++)
for (c = 0; c < 2u; c++)
for (o2 = 0; o2 < OBJ_COUNT; o2++)
for (c2 = 0; c2 < 2u; c2++)
if ((o != o2 || c != c2) && st_sector(o, c) == st_sector(o2, c2) &&
!(c == c2 && (o == OBJ_FM6BANK || o == OBJ_UPFM6) && (o2 == OBJ_FM6BANK || o2 == OBJ_UPFM6)))
distinct = 0; /* (the retired FM6 bank and OBJ_UPFM6 share a pair, as on the FM-1) */
check("storage.c: every object (A/B) in FL_DATA (FMini-1's preset slots in FL_SMP), no two share a sector",
in_store && distinct);
for (o = 0, distinct = 1; o < OBJ_COUNT; o++)
for (c = 0; c < 2u; c++)
distinct &= st_sector(o, c) != ST_SMK_VBANK &&
(st_sector(o, c) < 0xAF000u || (o >= OBJ_PRESET0 && o <= OBJ_PRESET_LAST));
check("FM6 voice bank 0xB0000: in FL_DATA, its own sector; objects below the owner tag 0xAF000",
distinct && FL_STORE_OK(ST_SMK_VBANK, 0x1000u) && ST_SMK_VBANK == 0xB0000u);
}
check("storage.c: settings 0xAD000/0xAE000, projects from 0x9D000",
st_sector(OBJ_SETTINGS, 0) == 0xAD000u && st_sector(OBJ_SETTINGS, 1) == 0xAE000u && st_sector(OBJ_PROJECT0, 0) == 0x9D000u);
check("FL_PLAIN_LO = the VM start 0x9D000", FL_PLAIN_LO == 0x9D000u);
check("FL_JEDEC_OK: the SMK part 0xEB6014 and 0x856014 only", FL_JEDEC_OK(0xEB6014u) && FL_JEDEC_OK(0x856014u) &&
!FL_JEDEC_OK(0u) && !FL_JEDEC_OK(0xFFFFFFu) && !FL_JEDEC_OK(0xEB6015u));
printf("%s\n", bad ? "SMK FLASH TEST FAILED" : "smk flash test passed");
return bad != 0;
}