diff --git a/firmware/src/fmini_app.c b/firmware/src/fmini_app.c index 2acff73..fed17ae 100644 --- a/firmware/src/fmini_app.c +++ b/firmware/src/fmini_app.c @@ -2585,7 +2585,7 @@ static void fa_input(void) static void fa_leds(void) { - uint8_t nl[FM1_NCOL] = {0}, nd[FM1_NCOL] = {0}, nb[FM1_NCOL] = {0}, nm[FM1_NCOL] = {0}; + uint8_t nl[LED_BUF] = {0}, nd[LED_BUF] = {0}, nb[LED_BUF] = {0}, nm[LED_BUF] = {0}; /* (LED_BUF: FM1_NCOL on the FM-1) */ uint32_t k, c; static uint8_t ready; if (idle_leds() || fm1_led_anim_on()) @@ -2597,7 +2597,7 @@ static void fa_leds(void) for (k = 0; k < NB; k++) led_put(nd, panel.btn[k], 1); /* every button's glow */ for (k = 0; k < 27u; k++) - led_put(nd, 14u + k, 1); /* every key's glow too: the keys lit when held or sounding stand over it */ + led_put(nd, LED_KEY0 + k, 1); /* every key's glow too: the keys lit when held or sounding stand over it */ { static const uint8_t PG_LED[FA_NPAGE] = {B_LFO, B_SCL, B_SCL, B_EDIT, B_ENV, B_ENV, B_FX}; led_put(nl, panel.btn[PG_LED[fa_page]], 1); /* the page's button */ @@ -2615,13 +2615,20 @@ static void fa_leds(void) led_put(nl, panel.btn[B_OCTUP], song.octave > 0); c = fm1_in.notes | fa_sound_keys(); /* the keys held, and the notes sounding: arpeggio, sequence, MIDI */ for (k = 0; k < 27u; k++) - led_put(nl, 14u + k, (int)((c >> k) & 1u)); + led_put(nl, LED_KEY0 + k, (int)((c >> k) & 1u)); +#if BOARD_SMK37 + { + static const uint8_t Z[LED_BUF]; /* (no DRUM-grid lanes, no SCALE LEDS on FMini-1) */ + smk_leds(nl, nb, nm, Z, Z); /* the 19 button LEDs and the pads (ui_input.c) */ + } +#else for (k = 0; k < FM1_NCOL; k++) { fm1_led_dim[k] = nd[k]; fm1_led_breath[k] = nb[k]; fm1_led_mid[k] = nm[k]; fm1_led[k] = nl[k]; } +#endif } /* power-on: track 1 is the instrument (the first factory patch), the others are muted FMINI parts */ diff --git a/firmware/src/storage.c b/firmware/src/storage.c index a48ec24..f4c565d 100644 --- a/firmware/src/storage.c +++ b/firmware/src/storage.c @@ -75,22 +75,32 @@ static uint32_t st_crc32(const void *p, uint32_t n) { return ~st_crc32_add(0xFFF #define ST_SMK_PAIRS 9u #define ST_SMK_SECTORS (2u * ST_SMK_PAIRS) #define ST_SMK_VBANK 0xB0000u /* the FM6 voice bank (fm6_vbank.c), one sector */ -_Static_assert(OBJ_COUNT == 10u && OBJ_UPFM6 == OBJ_FM6BANK + 1u, "SMK store: a new object needs a place"); +/* FMini-1: the 200 preset slots (OBJ_PRESET0..OBJ_PRESET_LAST, 13 A/B pairs, 26 sectors) do not fit FL_DATA's spare + * room (0xB1000..0xBAFFF, 10 sectors). FMini-1 has no sample engine, so they take USRFLASH, from FL_SMP_LO: 0xC2000.. + * 0xDBFFF (st_erase releases the stock mapping's marker before the first erase there, storage_hw.c). */ +#define ST_SMK_PRESET 0xC2000u +_Static_assert(OBJ_COUNT == 10u + 13u && OBJ_PRESET0 == 10u && OBJ_UPFM6 == OBJ_FM6BANK + 1u, + "SMK store: a new object needs a place"); +_Static_assert(ST_SMK_PRESET == FL_SMP_LO && ST_SMK_PRESET + 26u * ST_SECTOR <= FL_SMP_HI, + "SMK store: the preset slots inside USRFLASH (FL_SMP)"); _Static_assert(ST_SMK_BASE + ST_SMK_SECTORS * ST_SECTOR == 0xAF000u, "SMK store: the objects end at the owner tag"); _Static_assert(ST_SMK_VBANK >= 0xAF000u + ST_SECTOR && ST_SMK_VBANK + ST_SECTOR <= 0xBB000u, "SMK store: past FL_DATA"); static uint32_t st_sector(uint32_t obj, uint32_t copy) /* flash offset of copy A (0) / B (1) */ { - static const uint8_t ORDER[OBJ_COUNT] = { + static const uint8_t ORDER[OBJ_PRESET0] = { [OBJ_PROJECT0] = 0, [OBJ_PROJECT0 + 1] = 1, [OBJ_PROJECT0 + 2] = 2, [OBJ_PROJECT0 + 3] = 3, [OBJ_UPRESET0] = 4, [OBJ_UPRESET0 + 1] = 5, [OBJ_AUTOSAVE] = 6, [OBJ_FM6BANK] = 7, [OBJ_UPFM6] = 7, [OBJ_SETTINGS] = 8}; - return ST_SMK_BASE + (ORDER[obj % OBJ_COUNT] * 2u + (copy & 1u)) * ST_SECTOR; + if (obj >= OBJ_PRESET0 && obj <= OBJ_PRESET_LAST) + return ST_SMK_PRESET + ((obj - OBJ_PRESET0) * 2u + (copy & 1u)) * ST_SECTOR; + return ST_SMK_BASE + (ORDER[obj % OBJ_PRESET0] * 2u + (copy & 1u)) * ST_SECTOR; } /* The owner of the store. The store area is the stock firmware's VM, so after an install it may hold the stock * firmware's (or any other firmware's) data, which Felucca must never parse as its own. The sector after the objects - * (0xAF000) holds the tag "SMK37DATAFELUCCA". Tagged: load as ever. Anything else (another tag, or none): clear the - * objects (0x9D000..0xAEFFF) and the FM6 voice bank (0xB0000), then write the tag. FELUCCA_DATA_UNTAGGED_OK 1 would + * (0xAF000) holds the tag "SMK37DATAFMINI" (FMini-1's own family). Tagged: load as ever. Anything else (another tag, + * or none): clear the objects (0x9D000..0xAEFFF), the FM6 voice bank (0xB0000) and those of the preset slots + * (0xC2000..0xDBFFF) that hold an FMini-1 commit record, then write the tag. FELUCCA_DATA_UNTAGGED_OK 1 would * keep a store with an erased tag (0: the SMK build never wrote untagged data). User samples (FL_SMP) validate * themselves. Calibration, BT pairing and key_mac are outside FL_DATA: never touched. Called first in persist_boot * (project.c), before any store read. */ @@ -142,10 +152,11 @@ static void st_stock_release(void) /* erase the marker's sector, on st_erase(FL_STOCKTAG_LO); } static inline int st_in_usrflash(uint32_t off) { return off >= FL_SMP_LO && off < FL_SMP_HI; } +static int st_head(uint32_t obj, uint32_t copy, st_hdr_t *h); /* (below) */ static uint8_t st_owner_cleared; /* (the UI may say so) */ static void st_owner_check(void) { - static const char FAM[] = "FELUCCA"; /* the tag: "SMK37DATA" + this, zero-padded to 16 B */ + static const char FAM[] = "FMINI"; /* the tag: "SMK37DATA" + this, zero-padded to 16 B (FMini-1's own family) */ uint8_t tag[16], want[16]; uint32_t i, erased = 1, ours = 1, s; for (i = 0; i < 16u; i++) @@ -164,6 +175,13 @@ static void st_owner_check(void) for (s = 0; s < ST_SMK_SECTORS; s++) st_erase(ST_SMK_BASE + s * ST_SECTOR); st_erase(ST_SMK_VBANK); + for (s = OBJ_PRESET0; s <= OBJ_PRESET_LAST; s++) { /* FMini-1's preset slots in USRFLASH: only a copy that */ + st_hdr_t h; /* is ours (a valid commit record): the stock mapping or */ + uint32_t c; /* another firmware's samples there are left alone */ + for (c = 0; c < 2u; c++) + if (!st_head(s, c, &h)) + st_erase(st_sector(s, c)); + } st_owner_cleared = 1; } st_erase(ST_OWNER_OFF); diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 92ac56f..a056a9e 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -251,8 +251,9 @@ done $CC -DT_CDC=0 -DT_UAC=1 -DT_LAYOUT=0 -DT_ON=0 -DT_48K=0 -DT_ASF=1 -DT_OUT=1 -o "$OUT/usb_desc_test" tests/usb_desc_test.c run "USB descriptors + playback (FELUCCA_UAC_OUT): 44.1 kHz only" "$OUT/usb_desc_test" -PKG=$(ls build/fmini-1-fm1-*.fwsc 2>/dev/null | head -1) -APP=$(ls build/fmini-1-fm1-*.bin 2>/dev/null | grep -v -- -app.bin | head -1) +FMV=$(sed -n 's/^#define FMINI_VERSION "v\(.*\)"/\1/p' firmware/src/core.h) # this version's files (build/ keeps older ones) +PKG=build/fmini-1-fm1-$FMV.fwsc +APP=build/fmini-1-fm1-$FMV.bin [ -f "$PKG" ] || { echo "run ./build.sh first"; exit 1; } $CC -DOWN_PKG=1 -o "$OUT/ota_test" tests/ota_test.c @@ -269,7 +270,7 @@ $CC -DBOARD_SMK37=1 -Ifirmware/hal -o "$OUT/smk_flash_test" tests/smk_flash_test run "SMK-37 Pro flash map: allow-lists never reach the head, BTIF/USRTRIM, USR, key_mac; store layout" "$OUT/smk_flash_test" $CC -DBOARD_SMK37=1 -Ifirmware/hal -o "$OUT/smk_owner_test" tests/smk_owner_test.c run "SMK-37 Pro store owner tag: another firmware's store cleared, ours kept, nothing else written" "$OUT/smk_owner_test" -python3 tools/fm1pkg_make.py --board smk37 build/felucca.bin build/loader/ota.bin "$OUT/smk_new.fwsc" >/dev/null +python3 tools/fm1pkg_make.py --board smk37 "$APP" build/loader/ota.bin "$OUT/smk_new.fwsc" >/dev/null python3 tools/fm1pkg_make.py --board smk37 "$OUT/old_app.bin" build/loader/ota.bin "$OUT/smk_old.fwsc" >/dev/null run "SMK-37 Pro package layout (fm1pkg_make --board smk37): PRCT 0x9D000, stock region table" python3 tests/smk_pkg_test.py "$OUT/smk_new.fwsc" $CC -DBOARD_SMK37=1 -DOWN_PKG=1 -o "$OUT/ota_test_smk" tests/ota_test.c @@ -279,9 +280,9 @@ for m in 1 2; do # the MODEL=elite / mke builds of ota.c run "M-UPGRADE entry, SMK model $m build (MODEL=elite / mke: its own parm identity)" "$OUT/ota_test_smk_m$m" "$OUT/smk_new.fwsc" done for m in pro elite mke; do # the packages build.sh made (BOARD=smk37 MODEL=...), when present - f=build/felucca-smk37.fwsc; id="SMK-37 Pro_900" - [ $m = elite ] && f=build/felucca-smk37-elite.fwsc && id="SMK-37 Elite_900" - [ $m = mke ] && f=build/felucca-smk37-mke.fwsc && id="MKE-P37_900" + f=build/fmini-1-smk37-$FMV.fwsc; id="SMK-37 Pro_900" + [ $m = elite ] && f=build/fmini-1-smk37-elite-$FMV.fwsc && id="SMK-37 Elite_900" + [ $m = mke ] && f=build/fmini-1-smk37-mke-$FMV.fwsc && id="MKE-P37_900" [ -f $f ] && run "SMK package $f: identity $id, stock region table" python3 tests/smk_pkg_test.py $f "$id" done $CC -DBOARD_SMK37=1 -o "$OUT/ldr_test_smk" tests/ldr_test.c diff --git a/tests/smk_flash_test.c b/tests/smk_flash_test.c index 7a8c938..d961b33 100644 --- a/tests/smk_flash_test.c +++ b/tests/smk_flash_test.c @@ -63,7 +63,10 @@ int main(void) !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) && st_sector(o, c) < FL_DATA_HI; + 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++) @@ -73,10 +76,12 @@ int main(void) 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, no two share a sector", in_store && distinct); + 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; + 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); } diff --git a/tests/smk_owner_test.c b/tests/smk_owner_test.c index 28daf3a..8651deb 100644 --- a/tests/smk_owner_test.c +++ b/tests/smk_owner_test.c @@ -14,11 +14,13 @@ static uint8_t nor[0x100000]; static int bad_write; +static int fmini_presets_ours; /* FMini-1: a preset slot with our commit record may be erased */ static int tag_erases; static int st_read(uint32_t off, void *dst, uint32_t n) { memcpy(dst, nor + off, n); return 0; } static int st_erase(uint32_t off) { - if ((off & 0xFFFu) || !(FL_IN(off, 0x1000u, 0x9D000u, 0xAF000u) || off == 0xAF000u || off == 0xB0000u || off == 0xEA000u)) + if ((off & 0xFFFu) || !(FL_IN(off, 0x1000u, 0x9D000u, 0xAF000u) || off == 0xAF000u || off == 0xB0000u || off == 0xEA000u || + (fmini_presets_ours && FL_IN(off, 0x1000u, 0xC2000u, 0xDC000u)))) bad_write++; if (off == 0xEA000u) tag_erases++; @@ -92,18 +94,18 @@ int main(void) fill(); memcpy(nor + 0xAF000, "SMK37DATAOTHER\0", 16); st_owner_check(); - check("another firmware's store (another tag): cleared, tagged FELUCCA", store_erased() && st_owner_cleared && - !memcmp(nor + 0xAF000, "SMK37DATAFELUCCA", 16)); + check("another firmware's store (another tag): cleared, tagged FMINI", store_erased() && st_owner_cleared && + !memcmp(nor + 0xAF000, "SMK37DATAFMINI\0\0", 16)); check("... calibration (USRTRIM) and samples untouched", others_kept()); fill(); - memcpy(nor + 0xAF000, "SMK37DATAFELUCCA", 16); + memcpy(nor + 0xAF000, "SMK37DATAFMINI\0\0", 16); st_owner_cleared = 0; st_owner_check(); check("our own store: kept as it is", nor[0x9D000] == 0x11 && nor[0xB0000] == 0x22 && !st_owner_cleared); fill(); st_owner_check(); check("an untagged store (FELUCCA_DATA_UNTAGGED_OK 0): cleared, tagged", store_erased() && - !memcmp(nor + 0xAF000, "SMK37DATAFELUCCA", 16) && others_kept()); + !memcmp(nor + 0xAF000, "SMK37DATAFMINI\0\0", 16) && others_kept()); /* the stock firmware's mapping in USRFLASH: kept while intact, its marker released over anything else */ fill(); stock(); @@ -143,6 +145,25 @@ int main(void) st_owner_check(); check("no marker: the marker sector never erased", tag_erases == 0); check("nothing written outside FL_DATA's objects, the voice bank and the tag", bad_write == 0); + /* FMini-1: the preset slots live in USRFLASH (0xC2000..0xDBFFF); under another firmware's tag only a copy with + * FMini-1's own commit record is erased, never the stock mapping or another firmware's samples */ + { + st_hdr_t h = {0}; + uint32_t sec = st_sector(OBJ_PRESET0 + 3u, 1u); + fill(); + memset(nor + 0xAF000, 0xFF, 0x1000); + memcpy(nor + 0xAF000, "SMK37DATAOTHER\0", 16); + h.magic = ST_MAGIC; h.type = (uint16_t)(OBJ_PRESET0 + 3u); h.slot = 1; h.len = 0; + h.hcrc = st_crc32(&h, sizeof h - 4u); + memset(nor + sec, 0x55, 0x1000); + memcpy(nor + sec, &h, sizeof h); + fmini_presets_ours = 1; + bad_write = 0; + st_owner_check(); + fmini_presets_ours = 0; + check("FMini-1 preset slot with our record under another tag: erased; a sample there kept", + erased(sec, sec + 0x1000u) && nor[0xC2000] == 0x44 && bad_write == 0); + } printf("%s\n", bad ? "SMK OWNER TEST FAILED" : "smk owner test passed"); return bad != 0; }