after finding out the rp2040 is as wide as a barn door and no flash dump protection i decided to upgrade to the 2350 as that has protection ie otp ect. i get the 2350 board enable protection and then i find out its useless some a2 version flaw. this left me with 2 ways to go find the new a4 versions or do a work around. the work around is by no means mission critical secure but it helps. below is the generator sketch and then a simple protected oled hello world. run the generator copy the key from serial moniter and paste in your main code...... this ony prevents some one using tools like picotool to dump your flash and clone your software....note anyone with time and tools and good with reverse code will break this but its way better than the std barn door wide open ..... hope this helps. SERIAL OUTPUT - ===== DT307 FLASH UNLOCK GENERATOR =====
FLASH ID = 0xE46488B28B3B0B38
#define UNLOCK_CODE 0x78C52393FDBE307ULL
=======================================
main code TESTED ON lots rp2040 and rp2350 boards can this be done better? yes but its a start
Code:
//DT307 FLASH ID TO PRIVATE KEY SCRAMBLE 2025 #include <Arduino.h>#include "hardware/flash.h"#include "hardware/sync.h"// ================= PRIVATE KEY =================#define MY_KEY 0xA9F3C7D2E4B8165FULL // enter yoor own unique private key // =================================================// Read UNIQUE FLASH ID (stable, per-board)// =================================================uint64_t read_flash_id() { uint8_t id[8]; uint32_t ints = save_and_disable_interrupts(); flash_get_unique_id(id); restore_interrupts(ints); uint64_t v = 0; for (int i = 0; i < 8; i++) { v = (v << 8) | id[i]; } return v;}// =================================================// UNLOCK GENERATOR — THIS IS THE ONLY LOGIC// =================================================uint64_t make_unlock_code(uint64_t chip) { uint64_t v = chip ^ MY_KEY; v ^= (v << 17); v ^= (v >> 31); v *= 0x9E3779B97F4A7C15ULL; return v;}// =================================================// SETUP// =================================================void setup() { Serial.begin(115200); while (!Serial) { delay(10); } uint64_t chip = read_flash_id(); uint64_t unlock = make_unlock_code(chip); Serial.println("\n===== DT307 FLASH UNLOCK GENERATOR ====="); Serial.print("FLASH ID = 0x"); Serial.println((unsigned long long)chip, HEX); Serial.print("#define UNLOCK_CODE 0x"); Serial.print((unsigned long long)unlock, HEX); Serial.println("ULL"); Serial.println("=======================================");}// =================================================// LOOP// =================================================void loop() {}FLASH ID = 0xE46488B28B3B0B38
#define UNLOCK_CODE 0x78C52393FDBE307ULL
=======================================
main code
Code:
// DR307 SIMPLE LOCK TEST #include <Arduino.h>#include <Wire.h>#include <Adafruit_GFX.h>#include <Adafruit_SSD1306.h>#include "hardware/flash.h"// ================= OLED CONFIG =================#define OLED_WIDTH 128#define OLED_HEIGHT 64#define OLED_ADDR 0x3C#define OLED_SDA 4#define OLED_SCL 5Adafruit_SSD1306 oled(OLED_WIDTH, OLED_HEIGHT, &Wire, -1);// ================= LOCK CONFIG =================#define MY_KEY 0xA9F3C7D2E4B8165FULL#define UNLOCK_CODE 0x78C52393FDBE307ULL// ================= FLASH LOCK =================uint64_t make_unlock_code() { uint8_t flash_id[8]; flash_get_unique_id(flash_id); uint64_t chip = 0; for (int i = 0; i < 8; i++) { chip = (chip << 8) | flash_id[i]; } uint64_t v = chip ^ MY_KEY; v ^= (v << 17); v ^= (v >> 31); v *= 0x9E3779B97F4A7C15ULL; return v;}bool unlock_ok() { uint64_t calc = make_unlock_code(); Serial.print("FLASH CALC = 0x"); Serial.println((unsigned long long)calc, HEX); return calc == UNLOCK_CODE;}// ================= SETUP =================void setup() { Serial.begin(115200); delay(500); // ---- UNLOCK CHECK ---- if (!unlock_ok()) { Serial.println("LOCKED"); while (1) { tight_loop_contents(); } } Serial.println("UNLOCK OK"); // ---- OLED INIT ---- Wire.setSDA(OLED_SDA); Wire.setSCL(OLED_SCL); Wire.begin(); if (!oled.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) { while (1); } oled.clearDisplay(); oled.setTextSize(2); oled.setTextColor(SSD1306_WHITE); oled.setCursor(0, 20); oled.println("HELLO"); oled.println("WORLD"); oled.display();}void loop() {}Statistics: Posted by dt307 — Thu Dec 18, 2025 5:54 am