mirror of
https://github.com/ruppert/fmini-1.git
synced 2026-12-06 21:04:26 +01:00
The SMK-37 target from github.com/genkigenki/Felucca branch smk37 (commit b67312c on Felucca 1.6.1, = hugelton/Felucca#237; the fm1-to-smk37 kit's Felucca layer), applied to FMini-1, whose firmware/hal and firmware/loader are Felucca 1.6.1's: - BOARD=smk37 / MODEL=pro|elite|mke (tools/build.py, build.sh), the SMK flash map with its protected ranges (fm1_flash_map.h), the update path and its size checks (ota.c, ldr_core.c), the SMK input HAL, LCD and pad LEDs, the owner tag of the store, installers and tests. - Conflicts resolved for FMini-1: packages fmini-1-fm1-<version>.fwsc and fmini-1-smk37[-elite|-mke]-<version>.fwsc; FL_JEDEC_OK keeps the UC25HQ80 (0xB36014) on the FM-1 and accepts it on the SMK too; the official V16 length stays FM-1 only; the sample slots stay gone (FMini-1 has no SAMPLE engine: the layer's eng_sample.c and editor sample hunks are not taken); main.c keeps FMini-1's UI_* hooks with the SMK calls around them. - The FM-1 build is byte-identical to 2.5.0 (app, package and loader hashes). The SMK build does not link yet: FMini-1's preset objects need places in the SMK store, and fmini_app.c's LED code is FM-1 sized. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QUF6pQ1NkTwmBC8SR8AK94
116 lines
8.4 KiB
C
116 lines
8.4 KiB
C
/* SPDX-License-Identifier: GPL-3.0-only
|
|
* Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */
|
|
/* The flash map: which ranges the RAM flash driver (fm1_flash.h) may erase / program, per board
|
|
* (BOARD_SMK37, fm1_cc.h). Macros and compile-time checks only, so host tests can include it. */
|
|
#pragma once
|
|
#include <stdint.h>
|
|
#include "fm1_cc.h"
|
|
|
|
/* [off, off + n) inside [lo, hi), without wrapping: off + n can overflow, and
|
|
* the 1 MiB part ignores the high address bits, so a wrapped range lands low. */
|
|
#define FL_IN(off, n, lo, hi) ((uint32_t)(off) >= (lo) && (uint32_t)(off) <= (hi) && \
|
|
(uint32_t)(n) <= (hi) - (uint32_t)(off))
|
|
/* The flash chip Felucca's storage accepts (JEDEC id from 0x9F, project.c); extend it here for another part. */
|
|
#if BOARD_SMK37
|
|
/* SMK-37 Pro: 0xEB6014, 1 MiB, read from a unit over mask-ROM UBOOT (2026-10-09; jl-uboot-tool "Online device:
|
|
* ID: 0xeb6014"). The driver uses only generic SPI NOR commands (9F, 05/35, 06, 20, 02, 0B). */
|
|
#define FL_JEDEC_OK(id) ((id) == 0xEB6014u || (id) == 0x856014u || (id) == 0xB36014u)
|
|
#else
|
|
/* FM-1: the Puya P25Q80 (0x856014); newer units (mostly AliExpress) carry a UC25HQ80 (0xB36014): same size, the same
|
|
* plain SPI NOR commands (FMini-1 2.5.0) */
|
|
#define FL_JEDEC_OK(id) ((id) == 0x856014u || (id) == 0xB36014u)
|
|
#endif
|
|
|
|
#if BOARD_SMK37
|
|
/* ---- SMK-37 Pro flash map (hardware notes: https://github.com/genkigenki/fm1-to-smk37) ----
|
|
* 0x00000-0x03FFF head (SPL, isd_config) NEVER
|
|
* 0x04000-0x9CFFF app area (stock PRCT end) update loader only (FL_APP)
|
|
* 0x9D000-0xBAFFF VM: Felucca store (projects, user presets, autosave, FM6 patches, settings,
|
|
* owner tag 0xAF000, FM6 voice bank 0xB0000; storage.c) FL_DATA
|
|
* 0xBB000-0xBFFFF VM: M-UPGRADE loader staging + update record (ota.c) FL_OTA
|
|
* 0xC0000-0xC0FFF BTIF (BT pairing) NEVER
|
|
* 0xC1000-0xC1FFF USRTRIM (key/pad/wheel calibration, "trimdat") NEVER
|
|
* 0xC2000-0xE9FFF USRFLASH: user sample slots USR1, USR2 (2 x 80 KiB) FL_SMP
|
|
* (the stock mapping until a sample is first loaded there)
|
|
* 0xEA000-0xEAFFF USRFLASH tail: the stock end marker "usrdata" at 0xEAFF8; erased once before the first
|
|
* write into FL_SMP (FL_STOCKTAG)
|
|
* 0xEB000-0xF3FFF free (unlisted), unused
|
|
* 0xF4000-0xFDFFF USR (stock resources; kept for a rollback) NEVER
|
|
* 0xFE000-0xFEFFF free, unused
|
|
* 0xFF000-0xFFFFF key_mac NEVER
|
|
* Everything below is an explicit allow-list; the asserts keep each allowed window out of the
|
|
* protected ranges at compile time. */
|
|
#define FL_HEAD_HI 0x00004000u /* protected: [0, FL_HEAD_HI) */
|
|
#define FL_CAL_LO 0x000C0000u /* protected: BTIF + USRTRIM */
|
|
#define FL_CAL_HI 0x000C2000u
|
|
#define FL_USRRES_LO 0x000F4000u /* protected: stock USR resources */
|
|
#define FL_USRRES_HI 0x000FE000u
|
|
#define FL_KEYMAC_LO 0x000FF000u /* protected: key_mac and above */
|
|
#define FL_APP_LO 0x00004000u /* the update loader: app area */
|
|
#define FL_APP_HI 0x0009D000u
|
|
#define FL_REC_LO 0x0009D000u /* the update loader: where it may drop records (VM only) */
|
|
#define FL_REC_HI 0x000C0000u
|
|
#define FL_PLAIN_LO 0x0009D000u /* plain XIP window from the VM start */
|
|
#define FL_DATA_LO 0x0009D000u /* Felucca store */
|
|
#define FL_DATA_HI 0x000BB000u
|
|
#define FL_OTA_LO 0x000BB000u /* M-UPGRADE loader staging, ota.c */
|
|
#define FL_OTA_HI 0x000C0000u
|
|
#define FL_SMP_LO 0x000C2000u /* user sample slots (eng_sample.c) */
|
|
#define FL_SMP_HI 0x000EA000u
|
|
/* USRFLASH is the stock firmware's mapping (global settings 0xC2000, 8 presets from 0xC3000) with its end marker
|
|
* "usrdata\0" at 0xEAFF8: while the marker is there the stock firmware trusts the area and never rebuilds it.
|
|
* Before the first write into USRFLASH the marker sector is erased (storage.c st_stock_release), so a return to
|
|
* stock rebuilds the factory mapping. Exactly that one sector, nothing else above FL_SMP_HI. */
|
|
#define FL_STOCKTAG_LO 0x000EA000u
|
|
#define FL_STOCKTAG_HI 0x000EB000u
|
|
#define FL_STOCKTAG_OFF 0x000EAFF8u
|
|
#define FL_STOCKTAG_OK(off, n) ((uint32_t)(off) == FL_STOCKTAG_LO && (uint32_t)(n) == FL_STOCKTAG_HI - FL_STOCKTAG_LO)
|
|
/* a window [lo, hi) is allowed: sector aligned, non-empty, and clear of every protected range */
|
|
#define FL_WIN_SAFE(lo, hi) ((lo) % 0x1000u == 0u && (hi) % 0x1000u == 0u && (lo) < (hi) && \
|
|
(lo) >= FL_HEAD_HI && (hi) <= FL_KEYMAC_LO && \
|
|
((hi) <= FL_CAL_LO || (lo) >= FL_CAL_HI) && \
|
|
((hi) <= FL_USRRES_LO || (lo) >= FL_USRRES_HI))
|
|
_Static_assert(FL_WIN_SAFE(FL_DATA_LO, FL_DATA_HI), "SMK: FL_DATA overlaps a protected range");
|
|
_Static_assert(FL_WIN_SAFE(FL_OTA_LO, FL_OTA_HI), "SMK: FL_OTA overlaps a protected range");
|
|
_Static_assert(FL_WIN_SAFE(FL_SMP_LO, FL_SMP_HI), "SMK: FL_SMP overlaps a protected range");
|
|
_Static_assert(FL_WIN_SAFE(FL_STOCKTAG_LO, FL_STOCKTAG_HI) && FL_STOCKTAG_LO == FL_SMP_HI &&
|
|
FL_STOCKTAG_OFF + 8u == FL_STOCKTAG_HI, "SMK: the stock marker sector");
|
|
_Static_assert(FL_WIN_SAFE(FL_APP_LO, FL_APP_HI), "SMK: FL_APP overlaps a protected range");
|
|
_Static_assert(FL_WIN_SAFE(FL_REC_LO, FL_REC_HI), "SMK: FL_REC overlaps a protected range");
|
|
_Static_assert(FL_REC_HI == FL_CAL_LO && FL_OTA_HI <= FL_REC_HI && FL_OTA_LO >= FL_REC_LO,
|
|
"SMK: the update record (OTA area) must lie in the loader's record window, below BTIF");
|
|
_Static_assert(FL_DATA_HI <= FL_OTA_LO && FL_APP_HI <= FL_DATA_LO, "SMK: windows overlap");
|
|
/* the update loader (loader.c): the app area, and records only in the VM below BTIF */
|
|
#define FL_LDR_RANGE_OK(off, n) (FL_IN(off, n, FL_APP_LO, FL_APP_HI) || FL_IN(off, n, FL_REC_LO, FL_REC_HI))
|
|
/* Felucca's own store: FL_DATA and the sample slots */
|
|
#define FL_STORE_OK(off, n) (FL_IN(off, n, FL_DATA_LO, FL_DATA_HI) || FL_IN(off, n, FL_SMP_LO, FL_SMP_HI))
|
|
#ifndef FL_RANGE_OK
|
|
#define FL_RANGE_OK(off, n) (FL_STORE_OK(off, n) || FL_IN(off, n, FL_OTA_LO, FL_OTA_HI) || FL_STOCKTAG_OK(off, n))
|
|
#endif
|
|
/* second, independent net in the RAM driver: [off, off + n) touches a protected range (also when a
|
|
* caller supplies its own FL_RANGE_OK, as the update loader does) */
|
|
#define FL_HITS(off, n, lo, hi) ((uint32_t)(off) < (hi) && ((uint32_t)(off) >= (lo) || (uint32_t)(n) > (lo) - (uint32_t)(off)))
|
|
#define FL_PROTECTED(off, n) (FL_HITS(off, n, 0u, FL_HEAD_HI) || FL_HITS(off, n, FL_CAL_LO, FL_CAL_HI) || FL_HITS(off, n, FL_USRRES_LO, FL_USRRES_HI) || (uint32_t)(off) >= FL_KEYMAC_LO || (uint32_t)(n) > FL_KEYMAC_LO - (uint32_t)(off))
|
|
#define FL_GUARD(off, n) (FL_RANGE_OK(off, n) && !FL_PROTECTED(off, n))
|
|
#else /* FM-1 */
|
|
#define FL_PLAIN_LO 0x00093000u /* plain XIP window from the FM-1 VM start */
|
|
#define FL_DATA_LO 0x00097000u /* Felucca main store */
|
|
#define FL_DATA_HI 0x000E0000u
|
|
#define FL_GLOB_LO 0x000FC000u /* Felucca superblock / globals */
|
|
#define FL_GLOB_HI 0x000FF000u
|
|
#define FL_OTA_LO 0x000E0000u /* M-UPGRADE loader staging, ota.c */
|
|
#define FL_OTA_HI 0x000E5000u
|
|
#define FL_AUTO_LO 0x000E5000u /* 1.2: the autosave (storage.c OBJ_AUTOSAVE), A/B, just above */
|
|
#define FL_AUTO_HI 0x000E7000u /* the OTA staging */
|
|
#define FL_VBANK_LO 0x000E7000u /* 1.4.1: the FM6 voice bank (fm6_vbank.c), the sector above */
|
|
#define FL_VBANK_HI 0x000E8000u /* (below the stock OTA's VM backup, 0xE8000: never written) */
|
|
/* Felucca's own store (projects, user samples; settings; the autosave and the FM6 voice bank: one range) */
|
|
#define FL_STORE_OK(off, n) (FL_IN(off, n, FL_DATA_LO, FL_DATA_HI) || FL_IN(off, n, FL_GLOB_LO, FL_GLOB_HI) || FL_IN(off, n, FL_AUTO_LO, FL_VBANK_HI))
|
|
/* Where the RAM driver may erase / program. The app build allows only its own
|
|
* data regions; the update loader (firmware/loader) defines its own window. */
|
|
#ifndef FL_RANGE_OK
|
|
#define FL_RANGE_OK(off, n) (FL_STORE_OK(off, n) || FL_IN(off, n, FL_OTA_LO, FL_OTA_HI))
|
|
#endif
|
|
#define FL_GUARD(off, n) FL_RANGE_OK(off, n)
|
|
#endif /* BOARD_SMK37 */
|