From 0e9147a6082952d1593147cd9d71bd5791303bbf Mon Sep 17 00:00:00 2001 From: Frank Preel Date: Thu, 11 Aug 2022 20:33:00 +0200 Subject: [PATCH 1/8] Emerald lock bootloader. --- README.md | 6 ++++- .../linux/emerald-install-from-bootloader.sh | 19 +++++++------ .../ecorp/easy/installer/AppConstants.java | 2 +- .../resources/lang/translation.properties | 2 ++ .../lang/translation_fr_FR.properties | 5 +++- src/main/resources/yaml/emerald_flash.yml | 27 ++++++++++++++++--- 6 files changed, 46 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 4bab30d7..4b3b905a 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,11 @@ developer: ## Changelogs -### v0.15.0 (candidate) +### v0.16.0 (candidate) +- Lock emarald bootloader + + +### v0.15.0 - No shortcut created when installing from a non-admin account on Windows - e-recovery assets - Update German translation - by F. Wildermuth diff --git a/flash-scripts/linux/emerald-install-from-bootloader.sh b/flash-scripts/linux/emerald-install-from-bootloader.sh index 6fd529b5..5bd376a4 100755 --- a/flash-scripts/linux/emerald-install-from-bootloader.sh +++ b/flash-scripts/linux/emerald-install-from-bootloader.sh @@ -27,15 +27,16 @@ # - 1 : generic error # - 10: can't unpack system.img # - 11: can't wipe userdata -# - 11: can't wipe metadata +# - 12: can't wipe metadata +# - 13: can't active partition # - 20-30 : see partition_name index below # - 101 : DEVICE_ID missing # - 102 : ARCHIVE_PATH missing # - 103 : fastboot folder path missing -partition_name=(gz_a lk_a md1img_a scp_a spmfw_a sspm_a tee_a boot_a dtbo_a vbmeta_a super) -partition_image=(gz.img lk.img md1img.img scp.img spmfw.img sspm.img tee.img boot.img dtbo.img vbmeta.img super.img) -partition_error=(20 21 22 23 24 25 26 27 28 29 30) +partition_name=(boot_a dtbo_a vbmeta_a vbmeta_system_a vbmeta_vendor_a super lk_a logo preloader_a) +partition_image=(boot.img dtbo.img vbmeta.img vbmeta_system.img vbmeta_vendor.img super.img lk.img logo-verified.bin preloader_yk673v6_lwg62_64.bin) +partition_error=(20 21 22 23 24 25 26 27) DEVICE_ID=$1 ARCHIVE_PATH=$2 @@ -87,7 +88,6 @@ echo "unpacked archive" sleep 1 - # Wipe user data if ! "$FASTBOOT_PATH" erase userdata ; then @@ -97,12 +97,12 @@ fi echo "user data wiped" sleep 5 -if ! "$FASTBOOT_PATH" erase metadata ; +if ! "$FASTBOOT_PATH" format md_udc ; then exit 12 fi -echo "meta data wiped" +echo "format md_udc" sleep 5 #Flash partition @@ -116,5 +116,8 @@ for i in ${!partition_name[@]}; do done -"$FASTBOOT_PATH" --set-active=a +if ! "$FASTBOOT_PATH" --set-active=a ; +then + exit 13 +fi diff --git a/src/main/java/ecorp/easy/installer/AppConstants.java b/src/main/java/ecorp/easy/installer/AppConstants.java index 62497b77..fe120b3f 100644 --- a/src/main/java/ecorp/easy/installer/AppConstants.java +++ b/src/main/java/ecorp/easy/installer/AppConstants.java @@ -27,7 +27,7 @@ import java.nio.file.Paths; */ public abstract class AppConstants { - public final static String APP_VERSION = "v0.15.0"; + public final static String APP_VERSION = "v0.16.0-dev"; public final static String Separator = FileSystems.getDefault().getSeparator(); public final static String OsName = System.getProperty("os.name"); public final static String JavaHome = System.getProperty("java.home"); diff --git a/src/main/resources/lang/translation.properties b/src/main/resources/lang/translation.properties index e17910e3..cb374d8c 100644 --- a/src/main/resources/lang/translation.properties +++ b/src/main/resources/lang/translation.properties @@ -139,6 +139,7 @@ install_instr_startDownload=Keep pressing simultaneously "Power" & "Home" & "Vol install_instr_startFastboot=Keep pressing simultaneously "Power" & "Volume Down" until a screen with green "START" appears to access Fastboot Mode install_instr_startFastbootFromOptions=From options menu use "Volume Up/Down" to select "Fastboot" and "Power" to confirm install_instr_acceptWarning=Accept warning by pressing on "Volume Up" +emerald_install_instr_accept_lock=Accept lock by pressing on "Volume Up" install_instr_verifyHeimdall=Verify Heimdall install_instr_oemUnlock=OEM Unlocking install_instr_recoveryInstall=Recovery installation @@ -252,6 +253,7 @@ script_error_unknown= The installation encounter an error script_error_cantRebootBootloader= Failed to reboot into bootloader script_error_cantUnpackSources=Failed to unpack /e/ sources script_error_cantWipeData=Failed to wipe data +script_error_cantActivePartition=Failed to active partition script_error_cantFlashBoot=Failed to flash Boot partition script_error_cantFlashDtbo=Failed to flash dtbo partition script_error_cantFlashRecovery=Failed to flash Recovery diff --git a/src/main/resources/lang/translation_fr_FR.properties b/src/main/resources/lang/translation_fr_FR.properties index 0b672a30..3f7cc569 100644 --- a/src/main/resources/lang/translation_fr_FR.properties +++ b/src/main/resources/lang/translation_fr_FR.properties @@ -71,7 +71,9 @@ download_lbl_complete=Le téléchargement est terminé, vous êtes maintenant pr install_instr_turnOff=Éteignez le téléphone install_instr_turnOffAgain=Éteignez à nouveau le téléphone install_instr_startDownload=Continuez d'appuyer simultanément sur les boutons « Marche/Arrêt » & « Home » & « Volume moins » jusqu'à ce qu'un écran bleu apparaisse pour accéder au Mode de Téléchargement -install_instr_acceptWarning=Acceptez l'avertissement en appuyant sur « Volume plus » +install_instr_acceptWarning=Acceptez l'avertissement en appuyant sur "Volume plus" +emerald_install_instr_accept_lock=Acceptez le vérouillage en appuyant sur "Volume plus" +install_title_lockBootloader=Vérouillez le bootloader install_instr_oemUnlock=Dévérouillage OEM install_instr_recoveryInstall=Installation du mode de récupération install_instr_leaveDownload=Continuez à appuyer simultanément sur les boutons « Power » & « Home » & « Volume moins » jusqu'à ce que l'appareil s'éteigne @@ -344,3 +346,4 @@ script_error_cantFlashBoot_a =Erreur de flash boot_a partition script_error_cantFlashDtbo_a =Erreur de flash dtbo_a partition script_error_cantFlashVbmeta_a =Erreur de flash vbmeta_a partition script_error_cantFlashSuper =Erreur de flash super partition + diff --git a/src/main/resources/yaml/emerald_flash.yml b/src/main/resources/yaml/emerald_flash.yml index 48161c36..d4449b33 100644 --- a/src/main/resources/yaml/emerald_flash.yml +++ b/src/main/resources/yaml/emerald_flash.yml @@ -14,7 +14,7 @@ ## along with this program. If not, see . ## Author: Frank Preel --- -stepsCount: 6 +stepsCount: 7 steps: f0: type: custom @@ -89,7 +89,8 @@ steps: 1: script_error_unknown 10: script_error_cantUnpackSources 11: script_error_cantWipeData - 12: script_error_cantWipeData + 12: script_error_cantWipeData + 13: script_error_cantActivePartition 20: script_error_cantFlashGz_a 21: script_error_cantFlashLk_a 22: script_error_cantFlashMd1img_a @@ -105,12 +106,30 @@ steps: 102: script_error_installFromFastboot_102 103: script_error_fastboot_path_missing f4: - type: askAccount + type: custom-executable stepNumber: 5 nextStepKey: f5 + titleKey: install_title_lockBootloader + instructions: + - emerald_install_instr_accept_lock + script: emerald-flashingLock + parameters: + device_id: ${DEVICE_ID} + fastboot_folder_path: ${ADB_FOLDER_PATH} + okCodes: + 0: ~ + koCodes: + 1: script_error_unknown + 2: script_error_fastboot_flashingUnlock_failed + 101: script_error_serialNumber_missing + 102: script_error_fastboot_path_missing f5: - type: custom-executable + type: askAccount stepNumber: 6 + nextStepKey: f6 + f6: + type: custom-executable + stepNumber: 7 nextStepKey: end titleKey: stepTitle_rebootDevice titleIconName: icon-download.png -- GitLab From 51be5ab3458f900d027347ce2fd73f4dfbc1af92 Mon Sep 17 00:00:00 2001 From: Frank Preel Date: Thu, 11 Aug 2022 20:35:23 +0200 Subject: [PATCH 2/8] Add Lock process --- flash-scripts/linux/emerald-flashingLock.sh | 53 +++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 flash-scripts/linux/emerald-flashingLock.sh diff --git a/flash-scripts/linux/emerald-flashingLock.sh b/flash-scripts/linux/emerald-flashingLock.sh new file mode 100755 index 00000000..4973c8c0 --- /dev/null +++ b/flash-scripts/linux/emerald-flashingLock.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +# Copyright (C) 2022 ECORP SAS - Author: Frank Preel +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Parameter +# $1: device id +# $2: fastboot folder path + +# Exit status +# - 0 : bootloader locked +# - 1 : unknown error +# - 2 : Flashing locked failed +# - 101 : $DEVICE_ID missing +# - 102 : $FASTBOOT_FOLDER_PATH is missing + +DEVICE_ID=$1 +FASTBOOT_FOLDER_PATH=$2 + +# check serial number has been provided +if [ -z "$DEVICE_ID" ] +then + exit 101 +fi + +# Check fastboot parent folder path has been provided +if [ -z "$FASTBOOT_FOLDER_PATH" ] +then + exit 102 +fi + +# Build fastboot path +FASTBOOT_PATH=${FASTBOOT_FOLDER_PATH}"fastboot" + +# Lock bootloader +if ! ${FASTBOOT_PATH} flashing lock ; +then + exit 2 +fi + +sleep 1 -- GitLab From eb267db40040ab6c3989b74953238ecd3d0edc83 Mon Sep 17 00:00:00 2001 From: Frank Preel Date: Thu, 11 Aug 2022 20:35:38 +0200 Subject: [PATCH 3/8] Exclude bin folder --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fe1d19fe..a8480176 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ sources/ .waiting.lock .cables/ .devices/ +bin/ -- GitLab From 7dc3a929cfa9e5473cbae4a4f7966879835190b2 Mon Sep 17 00:00:00 2001 From: Frank Preel Date: Thu, 11 Aug 2022 20:51:34 +0200 Subject: [PATCH 4/8] Add missing info --- flash-scripts/linux/emerald-install-from-bootloader.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flash-scripts/linux/emerald-install-from-bootloader.sh b/flash-scripts/linux/emerald-install-from-bootloader.sh index 5bd376a4..6d4ea2df 100755 --- a/flash-scripts/linux/emerald-install-from-bootloader.sh +++ b/flash-scripts/linux/emerald-install-from-bootloader.sh @@ -36,7 +36,7 @@ partition_name=(boot_a dtbo_a vbmeta_a vbmeta_system_a vbmeta_vendor_a super lk_a logo preloader_a) partition_image=(boot.img dtbo.img vbmeta.img vbmeta_system.img vbmeta_vendor.img super.img lk.img logo-verified.bin preloader_yk673v6_lwg62_64.bin) -partition_error=(20 21 22 23 24 25 26 27) +partition_error=(20 21 22 23 24 25 26 27 28) DEVICE_ID=$1 ARCHIVE_PATH=$2 -- GitLab From fbae29ff81986a7783f5822b708fc80f999e58cc Mon Sep 17 00:00:00 2001 From: Frank Preel Date: Thu, 11 Aug 2022 20:53:56 +0200 Subject: [PATCH 5/8] Emerald MSWindows install --- .../emerald-install-from-bootloader.bat | 54 +++++++++---------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/flash-scripts/windows/emerald-install-from-bootloader.bat b/flash-scripts/windows/emerald-install-from-bootloader.bat index be287ed0..bcda45dc 100755 --- a/flash-scripts/windows/emerald-install-from-bootloader.bat +++ b/flash-scripts/windows/emerald-install-from-bootloader.bat @@ -27,35 +27,32 @@ :: - 1 : generic error :: - 10: can't unpack system.img :: - 11: can't wipe userdata -:: - 11: can't wipe metadata +:: - 12: can't wipe metadata +:: - 13: can't active partition :: - 20-30 : see partition_name index below :: - 101 : DEVICE_ID missing :: - 102 : ARCHIVE_PATH missing :: - 103 : fastboot folder path missing -SET partition_name[0]=gz_a -SET partition_name[1]=lk_a -SET partition_name[2]=md1img_a -SET partition_name[3]=scp_a -SET partition_name[4]=spmfw_a -SET partition_name[5]=sspm_a -SET partition_name[6]=tee_a -SET partition_name[7]=boot_a -SET partition_name[8]=dtbo_a -SET partition_name[9]=vbmeta_a -SET partition_name[10]=super - -SET partition_image[0]=gz.img -SET partition_image[1]=lk.img -SET partition_image[2]=md1img.img -SET partition_image[3]=scp.img -SET partition_image[4]=spmfw.img -SET partition_image[5]=sspm.img -SET partition_image[6]=tee.img -SET partition_image[7]=boot.img -SET partition_image[8]=dtbo.img -SET partition_image[9]=vbmeta.img -SET partition_image[10]=super.img +SET partition_name[0]=boot_a +SET partition_name[1]=dtbo_a +SET partition_name[2]=vbmeta_a +SET partition_name[3]=vbmeta_system_a +SET partition_name[4]=vbmeta_vendor_a +SET partition_name[5]=super +SET partition_name[6]=lk_a +SET partition_name[7]=logo +SET partition_name[8]=preloader_a + +SET partition_image[0]=boot.img +SET partition_image[1]=dtbo.img +SET partition_image[2]=vbmeta.img +SET partition_image[3]=vbmeta_system.img +SET partition_image[4]=vbmeta_vendor.img +SET partition_image[5]=super.img +SET partition_image[6]=lk.img +SET partition_image[7]=logo-verified.img +SET partition_image[8]=preloader_yk673v6_lwg62_64.img SET partition_error[0]=20 SET partition_error[1]=21 @@ -66,8 +63,6 @@ SET partition_error[5]=25 SET partition_error[6]=26 SET partition_error[7]=27 SET partition_error[8]=28 -SET partition_error[9]=29 -SET partition_error[10]=30 SET DEVICE_ID=%~1 SET ARCHIVE_PATH=%~2 @@ -114,7 +109,7 @@ echo "user data wiped" timeout 5 >nul 2>&1 :: Wipe meta data -%FASTBOOT_PATH% erase userdata +%FASTBOOT_PATH% format md_udc if errorLevel 1 ( exit /b 12 ) echo "meta data wiped" timeout 5 >nul 2>&1 @@ -127,5 +122,8 @@ timeout 5 >nul 2>&1 call echo "Flashed %%partition_name[%%i]%% " )) +:: Activate %FASTBOOT_PATH% --set-active=a - +if errorLevel 1 ( exit /b 13 ) +echo "set acivated" +timeout 5 >nul 2>&1 \ No newline at end of file -- GitLab From e9d50fa793d8aef750f33ea932d1ea1cd1197fa7 Mon Sep 17 00:00:00 2001 From: Frank Preel Date: Thu, 11 Aug 2022 20:55:47 +0200 Subject: [PATCH 6/8] Lock process for emerald --- .../windows/emerald-flashingLock.bat | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 flash-scripts/windows/emerald-flashingLock.bat diff --git a/flash-scripts/windows/emerald-flashingLock.bat b/flash-scripts/windows/emerald-flashingLock.bat new file mode 100755 index 00000000..a2631220 --- /dev/null +++ b/flash-scripts/windows/emerald-flashingLock.bat @@ -0,0 +1,47 @@ +@echo off + +:: Coyright (C) 2022 ECORP SAS - Author: Frank Preel + +:: This program is free software: you can redistribute it and/or modify +:: it under the terms of the GNU General Public License as published by +:: the Free Software Foundation, either version 3 of the License, or +:: (at your option) any later version. + +:: This program is distributed in the hope that it will be useful, +:: but WITHOUT ANY WARRANTY; without even the implied warranty of +:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +:: GNU General Public License for more details. + +:: You should have received a copy of the GNU General Public License +:: along with this program. If not, see . + +:: Parameter +:: $1: device id +:: $2: fastboot folder path + +:: Exit status +:: - 0 : bootloader locked +:: - 1 : unknown error +:: - 2 : Flashing unlocked failed +:: - 101 : $DEVICE_ID missing +:: - 102 : $FASTBOOT_FOLDER_PATH is missing + + +SET DEVICE_ID=%~1 +SET FASTBOOT_FOLDER_PATH=%~2 + +IF not defined %DEVICE_ID ( + exit /b 101 +) +IF not defined %FASTBOOT_FOLDER_PATH ( + exit /b 102 +) + +SET FASTBOOT_PATH="%FASTBOOT_FOLDER_PATH%fastboot" +%FASTBOOT_PATH% -s %DEVICE_ID% flashing lock +if errorlevel 1 ( + exit /b 2 +) + +timeout 1 >nul 2>&1 +exit /b 0 -- GitLab From c59a7394bcad298d2d0bd280ceb9046342afa7a8 Mon Sep 17 00:00:00 2001 From: Frank Preel Date: Thu, 22 Sep 2022 13:47:41 +0200 Subject: [PATCH 7/8] Fix wording --- src/main/resources/lang/translation.properties | 1 + src/main/resources/lang/translation_fr_FR.properties | 3 ++- src/main/resources/yaml/emerald_flash.yml | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/resources/lang/translation.properties b/src/main/resources/lang/translation.properties index cb374d8c..6b0a3c4e 100644 --- a/src/main/resources/lang/translation.properties +++ b/src/main/resources/lang/translation.properties @@ -249,6 +249,7 @@ script_error_waitRebootFromFastboot_101 = Can't run instruction on the device script_error_serialNumber_missing=No device's serial number provided script_error_fastboot_path_missing= No fastboot tool path provided script_error_fastboot_flashingUnlock_failed=Could not unlock flashing +script_error_fastboot_flashingLock_failed=Could not lock flashing script_error_unknown= The installation encounter an error script_error_cantRebootBootloader= Failed to reboot into bootloader script_error_cantUnpackSources=Failed to unpack /e/ sources diff --git a/src/main/resources/lang/translation_fr_FR.properties b/src/main/resources/lang/translation_fr_FR.properties index 3f7cc569..9a6ac9bc 100644 --- a/src/main/resources/lang/translation_fr_FR.properties +++ b/src/main/resources/lang/translation_fr_FR.properties @@ -289,7 +289,8 @@ stepTitle_beforeInstallation=Avant l'installation stepTitle_enableOemUnlock=Autorisez le déverouillage OEM stepTitle_checkDeviceUptodate=Verifiez les mises à jour feedback_lbl_sendPrecision=Aucune information qui vous identifie ne sera envoyée -script_error_fastboot_flashingUnlock_failed=Impossible de déverouiller le flashage +script_error_fastboot_flashingUnlock_failed=Impossible de déverrouiller le flashage +script_error_fastboot_flashingLock_failed=Impossible de vérrouiller le flashage script_error_fastboot_path_missing=Aucun chemin vers l'outil fastboot n'a été fourni script_error_serialNumber_missing=Aucun numéro de série fourni install_instr_pressVolUpToAcceptOEMUnlocking=Appuyez sur "volume +" pour accepter le dévérouillage OEM diff --git a/src/main/resources/yaml/emerald_flash.yml b/src/main/resources/yaml/emerald_flash.yml index d4449b33..63d05551 100644 --- a/src/main/resources/yaml/emerald_flash.yml +++ b/src/main/resources/yaml/emerald_flash.yml @@ -120,7 +120,7 @@ steps: 0: ~ koCodes: 1: script_error_unknown - 2: script_error_fastboot_flashingUnlock_failed + 2: script_error_fastboot_flashingLock_failed 101: script_error_serialNumber_missing 102: script_error_fastboot_path_missing f5: -- GitLab From 0cc9a6a0ca5ae80ba0b47f07b5c2e80088e150a3 Mon Sep 17 00:00:00 2001 From: frankpreel Date: Thu, 29 Sep 2022 11:48:03 +0200 Subject: [PATCH 8/8] Fix MSWindows variable interpretation --- flash-scripts/windows/emerald-install-from-bootloader.bat | 2 +- src/main/java/ecorp/easy/installer/AppConstants.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/flash-scripts/windows/emerald-install-from-bootloader.bat b/flash-scripts/windows/emerald-install-from-bootloader.bat index bcda45dc..232c4881 100755 --- a/flash-scripts/windows/emerald-install-from-bootloader.bat +++ b/flash-scripts/windows/emerald-install-from-bootloader.bat @@ -116,7 +116,7 @@ timeout 5 >nul 2>&1 :: Flash partition (for /L %%i in (0,1,10) do ( - %FASTBOOT_PATH% -s %DEVICE_ID% flash %%partition_name[%%i]%% %%partition_image[%%i]%% + call %FASTBOOT_PATH% -s %DEVICE_ID% flash %%partition_name[%%i]%% %%partition_image[%%i]%% if errorLevel 1 ( exit /b %%partition_error[%%i]%% ) timeout 1 >nul 2>&1 call echo "Flashed %%partition_name[%%i]%% " diff --git a/src/main/java/ecorp/easy/installer/AppConstants.java b/src/main/java/ecorp/easy/installer/AppConstants.java index fe120b3f..14cb30ca 100644 --- a/src/main/java/ecorp/easy/installer/AppConstants.java +++ b/src/main/java/ecorp/easy/installer/AppConstants.java @@ -27,7 +27,7 @@ import java.nio.file.Paths; */ public abstract class AppConstants { - public final static String APP_VERSION = "v0.16.0-dev"; + public final static String APP_VERSION = "v0.16.0"; public final static String Separator = FileSystems.getDefault().getSeparator(); public final static String OsName = System.getProperty("os.name"); public final static String JavaHome = System.getProperty("java.home"); -- GitLab