From 074b9c4c9d164208e7dc006dd31672df862d9d69 Mon Sep 17 00:00:00 2001 From: jhChun Date: Fri, 27 Mar 2026 10:29:10 +0900 Subject: [PATCH] =?UTF-8?q?cpd=5FeraseALL.bat=20=EC=B6=94=EA=B0=80:=20?= =?UTF-8?q?=EC=A0=84=EC=B2=B4=20erase=20=EA=B0=9C=EB=B0=9C=EC=9A=A9=20?= =?UTF-8?q?=ED=94=8C=EB=9E=98=EC=8B=B1=20=EC=8A=A4=ED=81=AC=EB=A6=BD?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hex/cpd_eraseALL.bat | 176 ++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 project/ble_peripheral/ble_app_bladder_patch/hex/cpd_eraseALL.bat diff --git a/project/ble_peripheral/ble_app_bladder_patch/hex/cpd_eraseALL.bat b/project/ble_peripheral/ble_app_bladder_patch/hex/cpd_eraseALL.bat new file mode 100644 index 0000000..1b90228 --- /dev/null +++ b/project/ble_peripheral/ble_app_bladder_patch/hex/cpd_eraseALL.bat @@ -0,0 +1,176 @@ +@echo off +setlocal enabledelayedexpansion + +echo ========================================== +echo MEDiThings Bladder Patch Programming +echo (DEBUG MODE - ERASE ALL, FDS Reset) +echo ========================================== + +REM ----------------------------------------------------- +REM Set script directory as base path +REM ----------------------------------------------------- +cd /d "%~dp0" +echo Working directory: %CD% + +REM ----------------------------------------------------- +REM Create hex output folder +REM ----------------------------------------------------- +if not exist hex mkdir hex + +REM ----------------------------------------------------- +REM 1. Copy HEX files (with verification) +REM ----------------------------------------------------- +echo [1/6] Copying HEX files... + +set "APP_SRC=..\pca10056\s140\arm5_no_packs\_build\nrf52840_xxaa.hex" +set "BOOT_SRC=..\..\..\dfu\secure_bootloader\pca10056_s140_ble\arm5_no_packs\_build\nrf52840_xxaa_s140.hex" + +REM Check source files exist +if not exist "%APP_SRC%" ( + echo ERROR: Application HEX not found: %APP_SRC% + pause + exit /b 1 +) + +if not exist "%BOOT_SRC%" ( + echo ERROR: Bootloader HEX not found: %BOOT_SRC% + pause + exit /b 1 +) + +REM Copy with /Y to overwrite without prompt +copy /Y "%APP_SRC%" hex\app.hex +if %errorlevel% neq 0 ( + echo ERROR: Failed to copy app.hex + pause + exit /b 1 +) +echo - app.hex copied OK + +copy /Y "%BOOT_SRC%" hex\boot.hex +if %errorlevel% neq 0 ( + echo ERROR: Failed to copy boot.hex + pause + exit /b 1 +) +echo - boot.hex copied OK + +REM ----------------------------------------------------- +REM 2. Generate Bootloader DFU Settings +REM ----------------------------------------------------- +echo [2/6] Generating Bootloader DFU settings... +nrfutil settings generate ^ + --family NRF52840 ^ + --application hex\app.hex ^ + --application-version 1 ^ + --bootloader-version 1 ^ + --bl-settings-version 2 ^ + hex\settings.hex + +if %errorlevel% neq 0 ( + echo ERROR: nrfutil settings failed. + pause + exit /b 1 +) + +REM ----------------------------------------------------- +REM 3. Merge HEX (SoftDevice + Application) +REM ----------------------------------------------------- +echo [3/6] Merging SoftDevice + Application... +mergehex.exe --merge s140_nrf52_7.2.0_softdevice.hex hex\app.hex --output hex\part1.hex + +if %errorlevel% neq 0 ( + echo ERROR: mergehex part1 failed. + pause + exit /b 1 +) + +REM ----------------------------------------------------- +REM 4. Merge HEX (Bootloader + Settings) +REM ----------------------------------------------------- +echo [4/6] Merging Bootloader + Settings... +mergehex.exe --merge hex\boot.hex hex\settings.hex --output hex\part2.hex + +if %errorlevel% neq 0 ( + echo ERROR: mergehex part2 failed. + pause + exit /b 1 +) + +REM ----------------------------------------------------- +REM 5. Final HEX merge (Combine everything) +REM ----------------------------------------------------- +echo [5/6] Creating final combined HEX... +mergehex.exe --merge hex\part1.hex hex\part2.hex --output hex\firmware_all.hex + +if %errorlevel% neq 0 ( + echo ERROR: mergehex final merge failed. + pause + exit /b 1 +) + +echo Final merged HEX: hex\firmware_all.hex + +REM ----------------------------------------------------- +REM 6. Detect device SERIAL NUMBER and Flash +REM ----------------------------------------------------- +echo [6/6] Detecting device serial number... + +for /f %%A in (' + powershell -Command "(nrfutil device list --json | Select-String '\"type\":\"info\"' | ConvertFrom-Json).data.devices[0].serialNumber" +') do set SERIALNUMBER=%%A + +if "%SERIALNUMBER%"=="" ( + echo ERROR: No serial number found. + pause + exit /b 1 +) + +echo Using Serial Number: %SERIALNUMBER% +echo Flashing: ERASE ALL + program + reset (FDS will be reset!) + +REM program (ERASE_ALL: chip erase -> FDS/bond data all cleared) +nrfutil device program --firmware hex\firmware_all.hex --serial-number %SERIALNUMBER% +if %errorlevel% neq 0 ( + echo. + echo [WARNING] Program failed - device may have Readback Protection enabled. + echo Recover will ERASE ALL flash including FDS data. + echo. + set /p RECOVER_YN="Recover and retry? (Y/N): " + if /i "!RECOVER_YN!"=="Y" ( + echo Recovering device... + nrfutil device recover --serial-number %SERIALNUMBER% + if %errorlevel% neq 0 goto flash_fail + echo Re-programming... + nrfutil device program --firmware hex\firmware_all.hex --serial-number %SERIALNUMBER% + if %errorlevel% neq 0 goto flash_fail + ) else ( + goto flash_fail + ) +) + +REM reset +nrfutil device reset --serial-number %SERIALNUMBER% +if %errorlevel% neq 0 goto flash_fail + +goto flash_success + +:flash_fail +echo ERROR: Flashing failed. +pause +exit /b 1 + +:flash_success + +REM ----------------------------------------------------- +REM NOTE: Readback Protection SKIPPED for debugging +REM ----------------------------------------------------- +echo ========================================== +echo Programming Complete! (ERASE ALL) +echo No Readback Protection Applied +echo FDS/Bond data cleared (factory default) +echo %date% %time% +echo ========================================== +pause + +endlocal