diff --git a/apps/apps_container.cpp b/apps/apps_container.cpp index 981aaa813..1eee9ce07 100644 --- a/apps/apps_container.cpp +++ b/apps/apps_container.cpp @@ -138,7 +138,7 @@ bool AppsContainer::dispatchEvent(Ion::Events::Event event) { Ion::LED::updateColorWithPlugAndCharge(); } if (event == Ion::Events::USBEnumeration) { - if (Ion::USB::isPlugged() && GlobalPreferences::sharedGlobalPreferences()->getDfuLevel() != 3) { + if (Ion::USB::isPlugged()) { App::Snapshot * activeSnapshot = (s_activeApp == nullptr ? appSnapshotAtIndex(0) : s_activeApp->snapshot()); /* Just after a software update, the battery timer does not have time to * fire before the calculator enters DFU mode. As the DFU mode blocks the @@ -147,8 +147,7 @@ bool AppsContainer::dispatchEvent(Ion::Events::Event event) { * pictogram. */ updateBatteryState(); if (switchTo(usbConnectedAppSnapshot())) { - Ion::USB::DFU(true, GlobalPreferences::sharedGlobalPreferences()->dfuStatus(), GlobalPreferences::sharedGlobalPreferences()->getDfuLevel()); - GlobalPreferences::sharedGlobalPreferences()->setDfuStatus(false); + Ion::USB::DFU(true, GlobalPreferences::sharedGlobalPreferences()->dfuUnlocked(), GlobalPreferences::sharedGlobalPreferences()->dfuLevel()); // Update LED when exiting DFU mode Ion::LED::updateColorWithPlugAndCharge(); bool switched = switchTo(activeSnapshot); diff --git a/apps/global_preferences.h b/apps/global_preferences.h index 62a9dadd4..83ee56109 100644 --- a/apps/global_preferences.h +++ b/apps/global_preferences.h @@ -30,10 +30,10 @@ public: void setTempExamMode(ExamMode examMode); bool showPopUp() const { return m_showPopUp; } void setShowPopUp(bool showPopUp) { m_showPopUp = showPopUp; } - bool dfuStatus() const { return m_dfuUnlocked; } - void setDfuStatus(bool status) { m_dfuUnlocked = status; } - int getDfuLevel() const { return m_dfuProtectLevel; } - void setDfuLevel(int level) { m_dfuProtectLevel = level; } + bool dfuUnlocked() const { return m_dfuUnlocked; } + void setDfuUnlocked(bool unlocked) { m_dfuUnlocked = unlocked; } + int dfuLevel() const { return m_dfuLevel; } + void setDfuLevel(int level) { m_dfuLevel = level; } bool autocomplete() const { return m_autoComplete; } void setAutocomplete(bool autocomple) { m_autoComplete = autocomple; } int brightnessLevel() const { return m_brightnessLevel; } @@ -41,7 +41,6 @@ public: const KDFont * font() const { return m_font; } void setFont(const KDFont * font) { m_font = font; } constexpr static int NumberOfBrightnessStates = 15; - constexpr static int DfuUnlockStep = 3; private: static_assert(I18n::NumberOfLanguages > 0, "I18n::NumberOfLanguages is not superior to 0"); // There should already have been an error when processing an empty EPSILON_I18N flag static_assert(I18n::NumberOfCountries > 0, "I18n::NumberOfCountries is not superior to 0"); // There should already have been an error when processing an empty EPSILON_COUNTRIES flag @@ -52,7 +51,7 @@ private: m_tempExamMode(ExamMode::Standard), m_showPopUp(true), m_dfuUnlocked(false), - m_dfuProtectLevel(0), + m_dfuLevel(0), m_autoComplete(true), m_brightnessLevel(Ion::Backlight::MaxBrightness), m_font(KDFont::LargeFont) {} @@ -64,8 +63,10 @@ private: mutable ExamMode m_tempExamMode; bool m_showPopUp; bool m_dfuUnlocked; + uint8_t m_dfuLevel; bool m_autoComplete; int m_brightnessLevel; + const KDFont * m_font; }; #endif diff --git a/apps/home/base.de.i18n b/apps/home/base.de.i18n index 5b9d53782..a0fc91420 100644 --- a/apps/home/base.de.i18n +++ b/apps/home/base.de.i18n @@ -2,5 +2,3 @@ Apps = "Anwendungen" AppsCapital = "UPSILON" ForbidenAppInExamMode1 = "Diese Anwendung ist im" ForbidenAppInExamMode2 = "Prüfungsmodus nicht erlaubt." -DfuWarning1 = "DFU-Schutzwarnung" -DfuWarning2 = "Mehr Informationen: bit.ly/upsiDfu" diff --git a/apps/home/base.en.i18n b/apps/home/base.en.i18n index 81e3e0914..3468cca66 100644 --- a/apps/home/base.en.i18n +++ b/apps/home/base.en.i18n @@ -2,5 +2,3 @@ Apps = "Applications" AppsCapital = "UPSILON" ForbidenAppInExamMode1 = "This application is" ForbidenAppInExamMode2 = "forbidden in exam mode" -DfuWarning1 = "DFU Protection Warning" -DfuWarning2 = "More informations: bit.ly/upsiDfu" diff --git a/apps/home/base.es.i18n b/apps/home/base.es.i18n index 12bcd7288..3c262497c 100644 --- a/apps/home/base.es.i18n +++ b/apps/home/base.es.i18n @@ -2,5 +2,3 @@ Apps = "Aplicaciones" AppsCapital = "UPSILON" ForbidenAppInExamMode1 = "Esta aplicación está prohibida" ForbidenAppInExamMode2 = "en el modo de examen" -DfuWarning1 = "Advertencia de protección DFU" -DfuWarning2 = "Más información: bit.ly/upsiDfu" diff --git a/apps/home/base.fr.i18n b/apps/home/base.fr.i18n index aba1412ef..4b4ab02dd 100644 --- a/apps/home/base.fr.i18n +++ b/apps/home/base.fr.i18n @@ -2,5 +2,3 @@ Apps = "Applications" AppsCapital = "UPSILON" ForbidenAppInExamMode1 = "Cette application n'est" ForbidenAppInExamMode2 = "pas autorisée en mode examen." -DfuWarning1 = "Alerte protection DFU" -DfuWarning2 = "Plus d'infos: bit.ly/upsiDfu" diff --git a/apps/home/base.hu.i18n b/apps/home/base.hu.i18n index 2bcc9fd6e..d526193eb 100644 --- a/apps/home/base.hu.i18n +++ b/apps/home/base.hu.i18n @@ -2,5 +2,3 @@ Apps = "Alkalmazások" AppsCapital = "UPSILON" ForbidenAppInExamMode1 = "Ez az alkalmazás" ForbidenAppInExamMode2 = "tilos vizsga módban" -DfuWarning1 = "DFU védelmi figyelmeztetés" -DfuWarning2 = "További információk: bit.ly/upsiDfu" diff --git a/apps/home/base.it.i18n b/apps/home/base.it.i18n index 09ae09d43..4bd26ced3 100644 --- a/apps/home/base.it.i18n +++ b/apps/home/base.it.i18n @@ -2,5 +2,3 @@ Apps = "Applicazioni" AppsCapital = "UPSILON" ForbidenAppInExamMode1 = "Questa applicazione è" ForbidenAppInExamMode2 = "proibita nella modalità d'esame" -DfuWarning1 = "Avviso protezione DFU" -DfuWarning2 = "Più informazioni: bit.ly/upsiDfu" diff --git a/apps/home/base.nl.i18n b/apps/home/base.nl.i18n index 9037187aa..496e8d6a3 100644 --- a/apps/home/base.nl.i18n +++ b/apps/home/base.nl.i18n @@ -2,5 +2,3 @@ Apps = "Applicaties" AppsCapital = "UPSILON" ForbidenAppInExamMode1 = "Deze applicatie is" ForbidenAppInExamMode2 = "uitgesloten in examenstand" -DfuWarning1 = "DFU-beveiligingswaarschuwing" -DfuWarning2 = "Meer informatie: bit.ly/upsiDfu" diff --git a/apps/home/base.pt.i18n b/apps/home/base.pt.i18n index bf1e307e4..6c074aa86 100644 --- a/apps/home/base.pt.i18n +++ b/apps/home/base.pt.i18n @@ -2,5 +2,3 @@ Apps = "Aplicações" AppsCapital = "UPSILON" ForbidenAppInExamMode1 = "Esta aplicação é" ForbidenAppInExamMode2 = "proibida no Modo de Exame" -DfuWarning1 = "Aviso de proteção DFU" -DfuWarning2 = "Mais informações: bit.ly/upsiDfu" diff --git a/apps/home/controller.cpp b/apps/home/controller.cpp index 8f02cc5b8..df725f10f 100644 --- a/apps/home/controller.cpp +++ b/apps/home/controller.cpp @@ -87,33 +87,9 @@ Controller::Controller(Responder * parentResponder, SelectableTableViewDataSourc } bool Controller::handleEvent(Ion::Events::Event event) { - if (event == Ion::Events::Six) { - GlobalPreferences::sharedGlobalPreferences()->dfuIncreaseStep(); - if (GlobalPreferences::sharedGlobalPreferences()->dfuCurrentStep() >= GlobalPreferences::DfuUnlockStep && !GlobalPreferences::sharedGlobalPreferences()->dfuStatus()) { - if (!GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) { - Ion::LED::setColor(KDColorPurple); - Ion::LED::setBlinking(500, 0.5f); - } - GlobalPreferences::sharedGlobalPreferences()->setDfuStatus(true); - App::app()->displayWarning(I18n::Message::DfuWarning1, I18n::Message::DfuWarning2); - return true; - } else if (GlobalPreferences::sharedGlobalPreferences()->dfuStatus()) { - if (!GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) { - Ion::LED::setColor(KDColorBlack); - } - GlobalPreferences::sharedGlobalPreferences()->dfuResetStep(); - GlobalPreferences::sharedGlobalPreferences()->setDfuStatus(false); - } - } if (event == Ion::Events::OK || event == Ion::Events::EXE) { AppsContainer * container = AppsContainer::sharedAppsContainer(); - if (!GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) { - Ion::LED::setColor(KDColorBlack); - } - GlobalPreferences::sharedGlobalPreferences()->dfuResetStep(); - GlobalPreferences::sharedGlobalPreferences()->setDfuStatus(false); - int index = selectionDataSource()->selectedRow()*k_numberOfColumns+selectionDataSource()->selectedColumn()+1; #ifdef HOME_DISPLAY_EXTERNALS if (index >= container->numberOfApps()) { diff --git a/apps/settings/Makefile b/apps/settings/Makefile index ec6684d1a..9823f80dd 100644 --- a/apps/settings/Makefile +++ b/apps/settings/Makefile @@ -25,8 +25,7 @@ app_settings_src = $(addprefix apps/settings/,\ sub_menu/contributors_controller.cpp \ sub_menu/math_options_controller.cpp \ sub_menu/selectable_view_with_messages.cpp \ - sub_menu/usb_info_controller.cpp \ - sub_menu/usb_protection_level_controller.cpp \ + sub_menu/usb_protection_controller.cpp \ ) SFLAGS += -DOMEGA_STATE="$(OMEGA_STATE)" @@ -34,6 +33,6 @@ SFLAGS += -DOMEGA_STATE="$(OMEGA_STATE)" app_settings_src += $(app_settings_test_src) apps_src += $(app_settings_src) -i18n_files += $(call i18n_without_universal_for,settings/base) +i18n_files += $(call i18n_with_universal_for,settings/base) $(eval $(call depends_on_image,apps/settings/app.cpp,apps/settings/settings_icon.png)) diff --git a/apps/settings/base.de.i18n b/apps/settings/base.de.i18n index 2174ddf9c..6f2b7ef25 100644 --- a/apps/settings/base.de.i18n +++ b/apps/settings/base.de.i18n @@ -73,7 +73,7 @@ USBExplanation1= "USB-Schutz schützt Ihren" USBExplanation2= "Taschenrechner vor" USBExplanation3= "unbeabsichtigter Verriegelung" USBProtection= "USB-Schutz" -USBLevelProtect = "Akzeptierte Updates" +USBProtectionLevel = "Akzeptierte Updates" USBDefaultLevel = "Basierend auf Upsilon" USBLowLevel = "Basierend auf Omega" USBParanoidLevel = "Nichts" diff --git a/apps/settings/base.en.i18n b/apps/settings/base.en.i18n index a0c5ce5f8..97aedba4b 100644 --- a/apps/settings/base.en.i18n +++ b/apps/settings/base.en.i18n @@ -73,7 +73,7 @@ USBExplanation1= "The USB protection protects" USBExplanation2= "the calculator from" USBExplanation3= "unintentional locking" USBProtection= "USB Protection" -USBLevelProtect = "Updates accepted" +USBProtectionLevel = "Updates accepted" USBDefaultLevel = "Based on Upsilon" USBLowLevel = "Based on Omega" USBParanoidLevel = "None" diff --git a/apps/settings/base.es.i18n b/apps/settings/base.es.i18n index adaf7704d..44465debd 100644 --- a/apps/settings/base.es.i18n +++ b/apps/settings/base.es.i18n @@ -73,7 +73,7 @@ USBExplanation1= "La protección USB protege" USBExplanation2= "su calculadora del" USBExplanation3= "bloqueo involuntario" USBProtection= "Protección USB" -USBLevelProtect = "Actualizaciones aceptadas" +USBProtectionLevel = "Actualizaciones aceptadas" USBDefaultLevel = "Basado en Upsilon" USBLowLevel = "Basado en Omega" USBParanoidLevel = "Ninguno" diff --git a/apps/settings/base.fr.i18n b/apps/settings/base.fr.i18n index f2103455b..f2affaec3 100644 --- a/apps/settings/base.fr.i18n +++ b/apps/settings/base.fr.i18n @@ -73,7 +73,7 @@ USBExplanation1= "La protection USB protège votre" USBExplanation2= "calculatrice contre un verrouillage" USBExplanation3= "non-intentionnel" USBProtection= "Protection USB" -USBLevelProtect = "Mise à jour acceptées" +USBProtectionLevel = "Mise à jour acceptées" USBDefaultLevel = "Basées sur Upsilon" USBLowLevel = "Basées sur Omega" USBParanoidLevel = "Aucune" diff --git a/apps/settings/base.hu.i18n b/apps/settings/base.hu.i18n index ae7e6cc7d..f0bc9ad26 100644 --- a/apps/settings/base.hu.i18n +++ b/apps/settings/base.hu.i18n @@ -73,8 +73,7 @@ USBExplanation1= "Az USB-védelem megvédi" USBExplanation2= "a számológépet a nem" USBExplanation3= "szándékos reteszeléstől" USBProtection= "USB védelem" -USBLevelProtect = "Elfogadott frissítések" +USBProtectionLevel = "Elfogadott frissítések" USBDefaultLevel = "Upsilon alapján" USBLowLevel = "Omega alapján" USBParanoidLevel = "Egyik sem" - diff --git a/apps/settings/base.it.i18n b/apps/settings/base.it.i18n index 5eb0d8930..861b8a073 100644 --- a/apps/settings/base.it.i18n +++ b/apps/settings/base.it.i18n @@ -73,7 +73,7 @@ USBExplanation1= "La protezione USB protegge" USBExplanation2= "la calcolatrice dal" USBExplanation3= "blocco involontario" USBProtection= "Protezione USB" -USBLevelProtect = "Aggiornamenti accettati" +USBProtectionLevel = "Aggiornamenti accettati" USBDefaultLevel = "Basato su Upsilon" USBLowLevel = "A base di Omega" USBParanoidLevel = "Nessuno" diff --git a/apps/settings/base.nl.i18n b/apps/settings/base.nl.i18n index 4423887fe..6bba2ae22 100644 --- a/apps/settings/base.nl.i18n +++ b/apps/settings/base.nl.i18n @@ -73,7 +73,7 @@ USBExplanation1= "USB-beveiliging beschermt uw" USBExplanation2= "rekenmachine tegen" USBExplanation3= "onbedoelde vergrendeling" USBProtection= "USB-beveiliging" -USBLevelProtect = "Updates geaccepteerd" +USBProtectionLevel = "Updates geaccepteerd" USBDefaultLevel = "Gebaseerd op Upsilon" USBLowLevel = "Op basis van Omega" USBParanoidLevel = "Geen" diff --git a/apps/settings/base.pt.i18n b/apps/settings/base.pt.i18n index 927cac527..c10264ae4 100644 --- a/apps/settings/base.pt.i18n +++ b/apps/settings/base.pt.i18n @@ -73,7 +73,7 @@ USBExplanation1= "A proteção USB protege" USBExplanation2= "sua calculadora contra" USBExplanation3= "bloqueios não intencionais" USBProtection= "Proteção USB" -USBLevelProtect = "Atualizações aceitas" +USBProtectionLevel = "Atualizações aceitas" USBDefaultLevel = "Baseado em Upsilon" USBLowLevel = "Baseado em Ômega" USBParanoidLevel = "Nenhum" diff --git a/apps/settings/main_controller.cpp b/apps/settings/main_controller.cpp index 7277f85fc..9bbde50fc 100644 --- a/apps/settings/main_controller.cpp +++ b/apps/settings/main_controller.cpp @@ -15,8 +15,8 @@ constexpr SettingsMessageTree s_modelFloatDisplayModeChildren[4] = {SettingsMess constexpr SettingsMessageTree s_modelComplexFormatChildren[3] = {SettingsMessageTree(I18n::Message::Real), SettingsMessageTree(I18n::Message::Cartesian), SettingsMessageTree(I18n::Message::Polar)}; constexpr SettingsMessageTree s_modelDateTimeChildren[3] = {SettingsMessageTree(I18n::Message::ActivateClock), SettingsMessageTree(I18n::Message::Date), SettingsMessageTree(I18n::Message::Time)}; constexpr SettingsMessageTree s_symbolChildren[4] = {SettingsMessageTree(I18n::Message::SymbolMultiplicationCross),SettingsMessageTree(I18n::Message::SymbolMultiplicationMiddleDot),SettingsMessageTree(I18n::Message::SymbolMultiplicationStar),SettingsMessageTree(I18n::Message::SymbolMultiplicationAutoSymbol)}; -constexpr SettingsMessageTree s_usbLevelSelector[3] = {SettingsMessageTree(I18n::Message::USBDefaultLevel), SettingsMessageTree(I18n::Message::USBLowLevel), SettingsMessageTree(I18n::Message::USBParanoidLevel)}; -constexpr SettingsMessageTree s_usbSteps[2] = {SettingsMessageTree(I18n::Message::USBProtection), SettingsMessageTree(I18n::Message::USBLevelProtect, s_usbLevelSelector)}; +constexpr SettingsMessageTree s_usbProtectionChildren[2] = {SettingsMessageTree(I18n::Message::USBProtection), SettingsMessageTree(I18n::Message::USBProtectionLevel, s_usbProtectionLevelChildren)}; +constexpr SettingsMessageTree s_usbProtectionLevelChildren[3] = {SettingsMessageTree(I18n::Message::USBDefaultLevel), SettingsMessageTree(I18n::Message::USBLowLevel), SettingsMessageTree(I18n::Message::USBParanoidLevel)}; constexpr SettingsMessageTree s_symbolFunctionChildren[3] = {SettingsMessageTree(I18n::Message::SymbolDefaultFunction), SettingsMessageTree(I18n::Message::SymbolArgDefaultFunction), SettingsMessageTree(I18n::Message::SymbolArgFunction)}; constexpr SettingsMessageTree s_modelMathOptionsChildren[6] = {SettingsMessageTree(I18n::Message::AngleUnit, s_modelAngleChildren), SettingsMessageTree(I18n::Message::DisplayMode, s_modelFloatDisplayModeChildren), SettingsMessageTree(I18n::Message::EditionMode, s_modelEditionModeChildren), SettingsMessageTree(I18n::Message::SymbolFunction, s_symbolFunctionChildren), SettingsMessageTree(I18n::Message::ComplexFormat, s_modelComplexFormatChildren), SettingsMessageTree(I18n::Message::SymbolMultiplication, s_symbolChildren)}; constexpr SettingsMessageTree s_accessibilityChildren[6] = {SettingsMessageTree(I18n::Message::AccessibilityInvertColors), SettingsMessageTree(I18n::Message::AccessibilityMagnify),SettingsMessageTree(I18n::Message::AccessibilityGamma),SettingsMessageTree(I18n::Message::AccessibilityGammaRed),SettingsMessageTree(I18n::Message::AccessibilityGammaGreen),SettingsMessageTree(I18n::Message::AccessibilityGammaBlue)}; diff --git a/apps/settings/main_controller.h b/apps/settings/main_controller.h index 2d7cec4b1..b20e47e0d 100644 --- a/apps/settings/main_controller.h +++ b/apps/settings/main_controller.h @@ -12,7 +12,7 @@ #include "sub_menu/localization_controller.h" #include "sub_menu/math_options_controller.h" #include "sub_menu/preferences_controller.h" -#include "sub_menu/usb_info_controller.h" +#include "sub_menu/usb_protection_controller.h" namespace Settings { @@ -29,8 +29,8 @@ extern const Shared::SettingsMessageTree s_modelDateTimeChildren[3]; extern const Shared::SettingsMessageTree s_accessibilityChildren[6]; extern const Shared::SettingsMessageTree s_contributorsChildren[23]; extern const Shared::SettingsMessageTree s_modelAboutChildren[9]; -extern const Shared::SettingsMessageTree s_usbLevelSelector[3]; -extern const Shared::SettingsMessageTree s_usbSteps[2]; +extern const Shared::SettingsMessageTree s_usbProtectionChildren[2]; +extern const Shared::SettingsMessageTree s_usbProtectionLevelChildren[3]; extern const Shared::SettingsMessageTree s_model; class MainController : public ViewController, public ListViewDataSource, public SelectableTableViewDataSource { diff --git a/apps/settings/main_controller_prompt_beta.cpp b/apps/settings/main_controller_prompt_beta.cpp index 7c4f4acf3..80b3e1459 100644 --- a/apps/settings/main_controller_prompt_beta.cpp +++ b/apps/settings/main_controller_prompt_beta.cpp @@ -18,7 +18,7 @@ constexpr SettingsMessageTree s_modelMenu[] = #endif SettingsMessageTree(I18n::Message::BetaPopUp), SettingsMessageTree(I18n::Message::About, s_modelAboutChildren), - SettingsMessageTree(I18n::Message::UsbSetting, s_usbSteps), + SettingsMessageTree(I18n::Message::UsbSetting, s_usbProtectionChildren), SettingsMessageTree(I18n::Message::Accessibility, s_accessibilityChildren)}; constexpr SettingsMessageTree s_model = SettingsMessageTree(I18n::Message::SettingsApp, s_modelMenu); diff --git a/apps/settings/main_controller_prompt_none.cpp b/apps/settings/main_controller_prompt_none.cpp index cb25548a3..d0b2727c5 100644 --- a/apps/settings/main_controller_prompt_none.cpp +++ b/apps/settings/main_controller_prompt_none.cpp @@ -17,14 +17,14 @@ constexpr SettingsMessageTree s_modelMenu[] = #ifdef HAS_CODE SettingsMessageTree(I18n::Message::CodeApp, s_codeChildren), #endif - SettingsMessageTree(I18n::Message::UsbSetting, s_usbSteps), + SettingsMessageTree(I18n::Message::UsbSetting, s_usbProtectionChildren), SettingsMessageTree(I18n::Message::Accessibility, s_accessibilityChildren), SettingsMessageTree(I18n::Message::About, s_modelAboutChildren)}; constexpr SettingsMessageTree s_model = SettingsMessageTree(I18n::Message::SettingsApp, s_modelMenu); I18n::Message MainController::promptMessage() const { - return I18n::Message::Default; + return I18n::Message::Default; } -} // namespace Settings +} diff --git a/apps/settings/main_controller_prompt_update.cpp b/apps/settings/main_controller_prompt_update.cpp index 148f5c16d..e028803ef 100644 --- a/apps/settings/main_controller_prompt_update.cpp +++ b/apps/settings/main_controller_prompt_update.cpp @@ -18,7 +18,7 @@ constexpr SettingsMessageTree s_modelMenu[] = #endif SettingsMessageTree(I18n::Message::UpdatePopUp), SettingsMessageTree(I18n::Message::Accessibility, s_accessibilityChildren), - SettingsMessageTree(I18n::Message::UsbSetting, s_usbSteps), + SettingsMessageTree(I18n::Message::UsbSetting, s_usbProtectionChildren), SettingsMessageTree(I18n::Message::About, s_modelAboutChildren)}; constexpr SettingsMessageTree s_model = SettingsMessageTree(I18n::Message::SettingsApp, s_modelMenu); diff --git a/apps/settings/sub_menu/preferences_controller.cpp b/apps/settings/sub_menu/preferences_controller.cpp index dbf254966..bba0ae46b 100644 --- a/apps/settings/sub_menu/preferences_controller.cpp +++ b/apps/settings/sub_menu/preferences_controller.cpp @@ -170,6 +170,15 @@ Layout PreferencesController::layoutForPreferences(I18n::Message message) { return LayoutHelper::String(text, strlen(text), font); } + // DFU Protection level + case I18n::Message::USBDefaultLevel: + case I18n::Message::USBLowLevel: + case I18n::Message::USBParanoidLevel: + { + const char * text = " "; + return LayoutHelper::String(text, strlen(text), k_layoutFont); + } + default: assert(false); return Layout(); @@ -213,6 +222,8 @@ void PreferencesController::setPreferenceWithValueIndex(I18n::Message message, i preferences->setSymbolOfFunction((Preferences::SymbolFunction)valueIndex); } else if (message == I18n::Message::FontSizes) { GlobalPreferences::sharedGlobalPreferences()->setFont(valueIndex == 0 ? KDFont::LargeFont : KDFont::SmallFont); + } else if (message == I18n::Message::USBProtectionLevel) { + GlobalPreferences::sharedGlobalPreferences()->setDfuLevel(valueIndex); } } @@ -239,6 +250,9 @@ int PreferencesController::valueIndexForPreference(I18n::Message message) const if (message == I18n::Message::FontSizes) { return GlobalPreferences::sharedGlobalPreferences()->font() == KDFont::LargeFont ? 0 : 1; } + if (message == I18n::Message::USBProtectionLevel) { + return GlobalPreferences::sharedGlobalPreferences()->dfuLevel(); + } return 0; } diff --git a/apps/settings/sub_menu/usb_info_controller.h b/apps/settings/sub_menu/usb_info_controller.h deleted file mode 100644 index d80356985..000000000 --- a/apps/settings/sub_menu/usb_info_controller.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef SETTINGS_USB_INFO_CONTROLLER_H -#define SETTINGS_USB_INFO_CONTROLLER_H - -#include "generic_sub_controller.h" -#include "preferences_controller.h" -#include "selectable_view_with_messages.h" -#include "usb_protection_level_controller.h" - -namespace Settings { - -class UsbInfoController : public GenericSubController { - public: - UsbInfoController(Responder* parentResponder); - View* view() override { return &m_contentView; } - bool handleEvent(Ion::Events::Event event) override; - TELEMETRY_ID("UsbInfo"); - void didEnterResponderChain(Responder* previousFirstResponder) override; - - HighlightCell* reusableCell(int index, int type) override; - int reusableCellCount(int type) override; - void willDisplayCellForIndex(HighlightCell* cell, int index) override; - - private: - static constexpr int k_numberOfExplanationMessages = 3; - MessageTableCellWithSwitch m_switchCell; - UsbProtectionLevelController m_usbProtectionLevelController; - MessageTableCellWithChevronAndMessage m_dfuLevelCell; -}; - -} - -#endif diff --git a/apps/settings/sub_menu/usb_info_controller.cpp b/apps/settings/sub_menu/usb_protection_controller.cpp similarity index 70% rename from apps/settings/sub_menu/usb_info_controller.cpp rename to apps/settings/sub_menu/usb_protection_controller.cpp index 3b518b042..f551f6121 100644 --- a/apps/settings/sub_menu/usb_info_controller.cpp +++ b/apps/settings/sub_menu/usb_protection_controller.cpp @@ -1,13 +1,10 @@ -#include "usb_info_controller.h" +#include "usb_protection_controller.h" #include #include #include #include #include - -#include - #include "../../apps_container.h" #include "../../global_preferences.h" @@ -19,37 +16,36 @@ namespace Settings { UsbInfoController::UsbInfoController(Responder *parentResponder): GenericSubController(parentResponder), m_usbProtectionLevelController(this), - m_dfuLevel(KDFont::LargeFont, KDFont::SmallFont) + m_contentView(&m_selectableTableView) { - for (int i = 0; i < k_maxSwitchCells; i++) { - m_switchCells[i].setMessageFont(KDFont::LargeFont); - } + m_switchCell.setMessageFont(KDFont::LargeFont); + m_dfuLevelCell.setMessageFont(KDFont::LargeFont); } bool UsbInfoController::handleEvent(Ion::Events::Event event) { if ((Ion::Events::OK == event || Ion::Events::EXE == event) && selectedRow() == 0) { - if (!GlobalPreferences::sharedGlobalPreferences()->dfuStatus()) { + if (!GlobalPreferences::sharedGlobalPreferences()->dfuUnlocked()) { if (!GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) { Ion::LED::setColor(KDColorPurple); Ion::LED::setBlinking(500, 0.5f); } - GlobalPreferences::sharedGlobalPreferences()->setDfuStatus(true); - Container::activeApp()->displayWarning(I18n::Message::DfuWarning1, I18n::Message::DfuWarning2); + GlobalPreferences::sharedGlobalPreferences()->setDfuUnlocked(true); } else { if (!GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) { Ion::LED::setColor(KDColorBlack); } - GlobalPreferences::sharedGlobalPreferences()->setDfuStatus(false); + GlobalPreferences::sharedGlobalPreferences()->setDfuUnlocked(false); } - m_selectableTableView.reloadCellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow()); - AppsContainer::sharedAppsContainer()->redrawWindow(true); + m_selectableTableView.reloadCellAtLocation(0, 0); return true; } // We cannot use things like willExitResponderChain because this view can disappear due to an USB connection, // and in this case we must keep the DFU status. - if ((Ion::Events::Left == event || Ion::Events::Home == event) && GlobalPreferences::sharedGlobalPreferences()->dfuStatus()) { - Container::activeApp()->displayWarning(I18n::Message::USBProtectionReanabled); - GlobalPreferences::sharedGlobalPreferences()->setDfuStatus(false); + if ((Ion::Events::Left == event || Ion::Events::Home == event || Ion::Events::Back == event) && GlobalPreferences::sharedGlobalPreferences()->dfuUnlocked()) { + GlobalPreferences::sharedGlobalPreferences()->setDfuUnlocked(false); + m_selectableTableView.reloadCellAtLocation(0, 0); + Container::activeApp()->displayWarning(I18n::Message::USBProtectionReactivated); + return true; } if ((Ion::Events::OK == event || Ion::Events::EXE == event) && selectedRow() == 1) { GenericSubController *subController = &m_usbProtectionLevelController; @@ -63,13 +59,16 @@ bool UsbInfoController::handleEvent(Ion::Events::Event event) { } HighlightCell *UsbInfoController::reusableCell(int index, int type) { - assert(index == 0 || index == 1); - return index == 0 ? &m_switchCell : &m_dfuLevelCell; + if (index == 0) { + return &m_switchCell; + } + assert(index == 1); + return &m_dfuLevelCell; } int UsbInfoController::reusableCellCount(int type) { assert(type == 0); - return 1; + return 2; } void UsbInfoController::willDisplayCellForIndex(HighlightCell *cell, int index) { @@ -78,10 +77,10 @@ void UsbInfoController::willDisplayCellForIndex(HighlightCell *cell, int index) if (index == 0) { MessageTableCellWithSwitch *myCell = (MessageTableCellWithSwitch *)cell; SwitchView *mySwitch = (SwitchView *)myCell->accessoryView(); - mySwitch->setState(!GlobalPreferences::sharedGlobalPreferences()->dfuStatus()); + mySwitch->setState(!GlobalPreferences::sharedGlobalPreferences()->dfuUnlocked()); } else if (index == 1) { MessageTableCellWithChevronAndMessage *mcell = (MessageTableCellWithChevronAndMessage *)cell; - int currentLevel = GlobalPreferences::sharedGlobalPreferences()->getDfuLevel(); + int currentLevel = GlobalPreferences::sharedGlobalPreferences()->dfuLevel(); if (currentLevel == 0) { mcell->setSubtitle(I18n::Message::USBDefaultLevelDesc); } else if (currentLevel == 1) {; @@ -94,8 +93,8 @@ void UsbInfoController::willDisplayCellForIndex(HighlightCell *cell, int index) } void UsbInfoController::didEnterResponderChain(Responder *previousFirstResponder) { - m_selectableTableView.reload(); + m_contentView.reload(); I18n::Message infoMessages[] = {I18n::Message::USBExplanation1, I18n::Message::USBExplanation2, I18n::Message::USBExplanation3}; - m_selectableTableView.setMessages(infoMessages, k_numberOfExplanationMessages); + m_contentView.setMessages(infoMessages, k_numberOfExplanationMessages); } } diff --git a/apps/settings/sub_menu/usb_protection_controller.h b/apps/settings/sub_menu/usb_protection_controller.h new file mode 100644 index 000000000..ec7b097fd --- /dev/null +++ b/apps/settings/sub_menu/usb_protection_controller.h @@ -0,0 +1,30 @@ +#ifndef SETTINGS_usb_protection_controller_H +#define SETTINGS_usb_protection_controller_H + +#include "generic_sub_controller.h" +#include "preferences_controller.h" +#include "selectable_view_with_messages.h" + +namespace Settings { + +class UsbInfoController : public GenericSubController { +public: + UsbInfoController(Responder* parentResponder); + View* view() override { return &m_contentView; } + bool handleEvent(Ion::Events::Event event) override; + TELEMETRY_ID("UsbInfo"); + void didEnterResponderChain(Responder* previousFirstResponder) override; + HighlightCell* reusableCell(int index, int type) override; + int reusableCellCount(int type) override; + void willDisplayCellForIndex(HighlightCell* cell, int index) override; +private: + static constexpr int k_numberOfExplanationMessages = 3; + PreferencesController m_usbProtectionLevelController; + SelectableViewWithMessages m_contentView; + MessageTableCellWithSwitch m_switchCell; + MessageTableCellWithChevronAndMessage m_dfuLevelCell; +}; + +} + +#endif diff --git a/apps/settings/sub_menu/usb_protection_level_controller.cpp b/apps/settings/sub_menu/usb_protection_level_controller.cpp deleted file mode 100644 index 6959b742a..000000000 --- a/apps/settings/sub_menu/usb_protection_level_controller.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "usb_protection_level_controller.h" - -#include -#include - -#include "../../apps_container.h" -#include "../../global_preferences.h" - -using namespace Poincare; -using namespace Shared; - -namespace Settings { -UsbProtectionLevelController::UsbProtectionLevelController(Responder *parentResponder) : GenericSubController(parentResponder) { - for (int i = 0; i < k_maxNumberOfCells; i++) { - m_cell[i].setMessageFont(KDFont::LargeFont); - m_cell[i].setAccessoryFont(KDFont::SmallFont); - } -} - -bool UsbProtectionLevelController::handleEvent(Ion::Events::Event event) { - if (event == Ion::Events::OK || event == Ion::Events::EXE) { - for (int i = 0; i < k_maxNumberOfCells; i++) { - m_cell[i].setAccessoryText(""); - } - if (m_messageTreeModel->childAtIndex(selectedRow())->label() == I18n::Message::USBLowLevel) { - GlobalPreferences::sharedGlobalPreferences()->setDfuLevel(1); - } else if (m_messageTreeModel->childAtIndex(selectedRow())->label() == I18n::Message::USBDefaultLevel) { - GlobalPreferences::sharedGlobalPreferences()->setDfuLevel(0); - } else if (m_messageTreeModel->childAtIndex(selectedRow())->label() == I18n::Message::USBParanoidLevel) { - GlobalPreferences::sharedGlobalPreferences()->setDfuLevel(2); - } else if (m_messageTreeModel->childAtIndex(selectedRow())->label() == I18n::Message::USBMegaParanoidLevel) { - GlobalPreferences::sharedGlobalPreferences()->setDfuLevel(3); - } - - StackViewController * stack = stackController(); - stack->pop(); - return true; - } else { - return GenericSubController::handleEvent(event); - } -} - -HighlightCell *UsbProtectionLevelController::reusableCell(int index, int type) { - assert(index >= 0 && index < k_maxNumberOfCells); - return &m_cell[index]; -} - -int UsbProtectionLevelController::reusableCellCount(int type) { - return k_maxNumberOfCells; -} - -void UsbProtectionLevelController::willDisplayCellForIndex(HighlightCell *cell, int index) { - GenericSubController::willDisplayCellForIndex(cell, index); - I18n::Message childLabel = m_messageTreeModel->childAtIndex(index)->label(); - MessageTableCellWithBuffer *messageComp = (MessageTableCellWithBuffer *)cell; - - int currentLevel = GlobalPreferences::sharedGlobalPreferences()->getDfuLevel(); - - if (childLabel == I18n::Message::USBLowLevel && currentLevel == 1) { - // messageComp->setTextColor(Palette::Green); - messageComp->setAccessoryText("√"); - } else if (childLabel == I18n::Message::USBDefaultLevel && currentLevel == 0) { - // messageComp->setTextColor(Palette::Green); - messageComp->setAccessoryText("√"); - } else if (childLabel == I18n::Message::USBParanoidLevel && currentLevel == 2) { - // messageComp->setTextColor(Palette::Green); - messageComp->setAccessoryText("√"); - } else if (childLabel == I18n::Message::USBMegaParanoidLevel && currentLevel == 3) { - // messageComp->setTextColor(Palette::Green); - messageComp->setAccessoryText("√"); - } -} - -int UsbProtectionLevelController::typeAtLocation(int i, int j) { - return 0; -} -} // namespace Settings \ No newline at end of file diff --git a/apps/settings/sub_menu/usb_protection_level_controller.h b/apps/settings/sub_menu/usb_protection_level_controller.h deleted file mode 100644 index bf7d23754..000000000 --- a/apps/settings/sub_menu/usb_protection_level_controller.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef SETTINGS_USB_PROTECTION_LEVEL_CONTROLLER_H -#define SETTINGS_USB_PROTECTION_LEVEL_CONTROLLER_H - -#include "generic_sub_controller.h" -#include - -namespace Settings { - -class UsbProtectionLevelController : public GenericSubController { -public: - UsbProtectionLevelController(Responder * parentResponder); - bool handleEvent(Ion::Events::Event event) override; - HighlightCell * reusableCell(int index, int type) override; - int reusableCellCount(int type) override; - void willDisplayCellForIndex(HighlightCell * cell, int index) override; - int typeAtLocation(int i, int j) override; -private: - static constexpr int k_maxNumberOfCells = 3; - MessageTableCellWithBuffer m_cell[k_maxNumberOfCells]; -}; - -} - -#endif diff --git a/apps/shared.de.i18n b/apps/shared.de.i18n index ec7a063b4..721941691 100644 --- a/apps/shared.de.i18n +++ b/apps/shared.de.i18n @@ -99,15 +99,3 @@ ExamModeModeStandard = "Standard " ExamModeModeNoSym = "Kein Symbol " ExamModeModeNoSymNoText = "Kein Symbol kein Text " ExamModeModeDutch = "Niederländisch " -USBE16_expl1= "USB-Schutz schützt Ihren" -USBE16_expl2= "Taschenrechner vor" -USBE16_expl3= "unbeabsichtigter Verriegelung" -USBProtection= "USB-Schutz" -USBSettingDeact = "Bitte schalte den Schutz ein" -USBLevelProtect = "Akzeptierte Updates" -USBDefaultLevel = "Basierend auf Upsilon" -USBLowLevel = "Basierend auf Omega" -USBParanoidLevel = "Nur Python" -USBMegaParanoidLevel = "Nichts" -USBDeacAlert1 = "Ändern Sie diesen Parameter nur," -USBDeacAlert2 = "wenn Sie wissen, was Sie tun!" diff --git a/apps/shared.en.i18n b/apps/shared.en.i18n index cdf85677e..d61df44e1 100644 --- a/apps/shared.en.i18n +++ b/apps/shared.en.i18n @@ -99,15 +99,3 @@ ExamModeModeStandard = "Standard " ExamModeModeNoSym = "No sym " ExamModeModeNoSymNoText = "No sym no text " ExamModeModeDutch = "Dutch " -USBE16_expl1= "The USB protection protects" -USBE16_expl2= "the calculator from" -USBE16_expl3= "unintentional locking" -USBProtection= "USB Protection" -USBSettingDeact = "Please turn on the protection" -USBLevelProtect = "Updates accepted" -USBDefaultLevel = "Based on Upsilon" -USBLowLevel = "Based on Omega" -USBParanoidLevel = "Python Only" -USBMegaParanoidLevel = "None" -USBDeacAlert1 = "Change this parameter only if" -USBDeacAlert2 = "you know what you are doing !" diff --git a/apps/shared.es.i18n b/apps/shared.es.i18n index eb21e5516..e542571ed 100644 --- a/apps/shared.es.i18n +++ b/apps/shared.es.i18n @@ -99,15 +99,3 @@ ExamModeModeStandard = "Estándar " ExamModeModeNoSym = "Sin simbólico " ExamModeModeNoSymNoText = "Sin simbólico sin texto " ExamModeModeDutch = "Holandés " -USBE16_expl1= "La protección USB protege" -USBE16_expl2= "su calculadora del" -USBE16_expl3= "bloqueo involuntario" -USBProtection= "Protección USB" -USBSettingDeact = "Enciende la protección" -USBLevelProtect = "Actualizaciones aceptadas" -USBDefaultLevel = "Basado en Upsilon" -USBLowLevel = "Basado en Omega" -USBParanoidLevel = "Solo Python" -USBMegaParanoidLevel = "Ninguno" -USBDeacAlert1 = "¡Cambie este parámetro solo" -USBDeacAlert2 = "si sabe lo que está haciendo!" diff --git a/apps/shared.fr.i18n b/apps/shared.fr.i18n index bd01041b5..46b76202d 100644 --- a/apps/shared.fr.i18n +++ b/apps/shared.fr.i18n @@ -99,15 +99,3 @@ ExamModeModeStandard = "Standard " ExamModeModeNoSym = "Sans symbolique " ExamModeModeNoSymNoText = "Sans symbolique ni texte " ExamModeModeDutch = "Dutch " -USBE16_expl1= "La protection USB protège votre" -USBE16_expl2= "calculatrice contre un verrouillage" -USBE16_expl3= "non-intentionnel" -USBProtection= "Protection USB" -USBSettingDeact = "Veuillez activer la protection" -USBLevelProtect = "Mise à jour acceptées" -USBDefaultLevel = "Basées sur Upsilon" -USBLowLevel = "Basées sur Omega" -USBParanoidLevel = "Aucune" -USBMegaParanoidLevel = "Aucune" -USBDeacAlert1 = "Ne modifiez ce paramètre que" -USBDeacAlert2 = "si vous savez ce que vous faites !" diff --git a/apps/shared.hu.i18n b/apps/shared.hu.i18n index 84b3c1451..60ba0754b 100644 --- a/apps/shared.hu.i18n +++ b/apps/shared.hu.i18n @@ -99,15 +99,3 @@ ExamModeModeStandard = "Normál " ExamModeModeNoSym = "Szimbólikus nélkül " ExamModeModeNoSymNoText = "Szimbólikus és szöveg nélkül " ExamModeModeDutch = "Holland " -USBE16_expl1= "Az USB-védelem megvédi" -USBE16_expl2= "a számológépet a nem" -USBE16_expl3= "szándékos reteszeléstől" -USBProtection= "USB védelem" -USBSettingDeact = "Kérjük, kapcsolja be a védelmet" -USBLevelProtect = "Elfogadott frissítések" -USBDefaultLevel = "Upsilon alapján" -USBLowLevel = "Omega alapján" -USBParanoidLevel = "Csak Python" -USBMegaParanoidLevel = "Egyik sem" -USBDeacAlert1 = "Csak akkor módosítsa ezt a" -USBDeacAlert2 = "paramétert, ha tudja, mit csinál!" diff --git a/apps/shared.it.i18n b/apps/shared.it.i18n index 60cd96bce..3322800c8 100644 --- a/apps/shared.it.i18n +++ b/apps/shared.it.i18n @@ -99,15 +99,3 @@ ExamModeModeStandard = "Standard " ExamModeModeNoSym = "Nessun simbolo " ExamModeModeNoSymNoText = "Nessun simbolo nessun testo " ExamModeModeDutch = "Olandese " -USBE16_expl1= "La protezione USB protegge" -USBE16_expl2= "la calcolatrice dal" -USBE16_expl3= "blocco involontario" -USBProtection= "Protezione USB" -USBSettingDeact = "Si prega di attivare la protezione" -USBLevelProtect = "Aggiornamenti accettati" -USBDefaultLevel = "Basato su Upsilon" -USBLowLevel = "A base di Omega" -USBParanoidLevel = "Solo Python" -USBMegaParanoidLevel = "Nessuno" -USBDeacAlert1 = "Cambia questo parametro solo" -USBDeacAlert2 = "se sai cosa stai facendo !" diff --git a/apps/shared.nl.i18n b/apps/shared.nl.i18n index 6fbde69a4..b3971aa6c 100644 --- a/apps/shared.nl.i18n +++ b/apps/shared.nl.i18n @@ -99,15 +99,3 @@ ExamModeModeStandard = "Standaard " ExamModeModeNoSym = "Geen sym " ExamModeModeNoSymNoText = "Geen sym geen tekst " ExamModeModeDutch = "Nederlands " -USBE16_expl1= "USB-beveiliging beschermt uw" -USBE16_expl2= "rekenmachine tegen" -USBE16_expl3= "onbedoelde vergrendeling" -USBProtection= "USB-beveiliging" -USBSettingDeact = "Schakel a.u.b. de bescherming in" -USBLevelProtect = "Updates geaccepteerd" -USBDefaultLevel = "Gebaseerd op Upsilon" -USBLowLevel = "Op basis van Omega" -USBParanoidLevel = "Alleen Python" -USBMegaParanoidLevel = "Geen" -USBDeacAlert1 = "Wijzig deze parameter alleen" -USBDeacAlert2 = "als u weet wat u doet!" diff --git a/apps/shared.pt.i18n b/apps/shared.pt.i18n index 11f9a8b96..39fa24c12 100644 --- a/apps/shared.pt.i18n +++ b/apps/shared.pt.i18n @@ -99,15 +99,3 @@ ExamModeModeStandard = "Padrão " ExamModeModeNoSym = "Sem sym " ExamModeModeNoSymNoText = "Sem sym sem texto " ExamModeModeDutch = "holandês " -USBE16_expl1= "A proteção USB protege" -USBE16_expl2= "sua calculadora contra" -USBE16_expl3= "bloqueios não intencionais" -USBProtection= "Proteção USB" -USBSettingDeact = "Por favor, ligue a proteção" -USBLevelProtect = "Atualizações aceitas" -USBDefaultLevel = "Baseado em Upsilon" -USBLowLevel = "Baseado em Ômega" -USBParanoidLevel = "Apenas Python" -USBMegaParanoidLevel = "Nenhum" -USBDeacAlert1 = "Mude este parâmetro somente" -USBDeacAlert2 = "se você souber o que está fazendo!" diff --git a/apps/shared.universal.i18n b/apps/shared.universal.i18n index dd7181a99..c93abe957 100644 --- a/apps/shared.universal.i18n +++ b/apps/shared.universal.i18n @@ -458,11 +458,6 @@ HartreeConstant = "4.3597447222071·10^-18_J" MagneticFluxQuantum = "2.067833848·10^-15_Wb" ConductanceQuantum = "7.748091729·10^-5_S" CirculationQuantum = "3.6369475516·10^-4_m^2_s^-1" -UsbSetting = "USB" -USBDefaultLevelDesc = "L0" -USBLowLevelDesc = "L1" -USBParanoidLevelDesc = "L2" -USBMegaParanoidLevelDesc = "L3" Cndcvt_Silver = "6.30·10^7_S_m^-1" Cndcvt_Copper = "5.96·10^7_S_m^-1" Cndcvt_Gold = "4.11·10^7_S_m^-1" diff --git a/apps/usb/Makefile b/apps/usb/Makefile index fb8cfd2b7..79692e351 100644 --- a/apps/usb/Makefile +++ b/apps/usb/Makefile @@ -1,7 +1,6 @@ app_usb_src = $(addprefix apps/usb/,\ app.cpp \ usb_connected_controller.cpp \ - usb_view.cpp \ ) apps_src += $(app_usb_src) diff --git a/apps/usb/app.cpp b/apps/usb/app.cpp index ad0256be1..99cdd7a6c 100644 --- a/apps/usb/app.cpp +++ b/apps/usb/app.cpp @@ -27,7 +27,6 @@ App::App(Snapshot * snapshot) : } bool App::processEvent(Ion::Events::Event e) { - // Impossible de gérer mes events ici lorsqu'on active le DFU return false; } diff --git a/apps/usb/base.de.i18n b/apps/usb/base.de.i18n index a79b6c49a..20e6a097a 100644 --- a/apps/usb/base.de.i18n +++ b/apps/usb/base.de.i18n @@ -11,3 +11,4 @@ DfuStatusUnprotected = "UNGESCHÜTZT" USBProtectionLevel0 = "Standardschutz" USBProtectionLevel1 = "Omega Schutz" USBProtectionLevel2 = "Systemschutz" +USBProtectionReactivated = "USB-Schutz wurde wieder aktiviert" diff --git a/apps/usb/base.en.i18n b/apps/usb/base.en.i18n index b660f9da4..d4a394c6c 100644 --- a/apps/usb/base.en.i18n +++ b/apps/usb/base.en.i18n @@ -11,3 +11,4 @@ DfuStatusUnprotected = "UNPROTECTED" USBProtectionLevel0 = "Default Protection" USBProtectionLevel1 = "Omega Protection" USBProtectionLevel2 = "System Protection" +USBProtectionReactivated = "USB Protection reactivated" diff --git a/apps/usb/base.es.i18n b/apps/usb/base.es.i18n index e6e396e94..ad89f1ee3 100644 --- a/apps/usb/base.es.i18n +++ b/apps/usb/base.es.i18n @@ -11,3 +11,4 @@ DfuStatusUnprotected = "DESABRIGADO" USBProtectionLevel0 = "Protección predeterminada" USBProtectionLevel1 = "Protección Omega" USBProtectionLevel2 = "Protección del sistema" +USBProtectionReactivated = "La protección de la calculadora ha sido reactivada" \ No newline at end of file diff --git a/apps/usb/base.fr.i18n b/apps/usb/base.fr.i18n index f81365671..a19e798ac 100644 --- a/apps/usb/base.fr.i18n +++ b/apps/usb/base.fr.i18n @@ -11,3 +11,4 @@ DfuStatusUnprotected = "NON PROTÉGÉE" USBProtectionLevel0 = "Default Protection" USBProtectionLevel1 = "Omega Protection" USBProtectionLevel2 = "System Protection" +USBProtectionReactivated = "La protection USB a été réactivée" \ No newline at end of file diff --git a/apps/usb/base.hu.i18n b/apps/usb/base.hu.i18n index 141101767..7413410dc 100644 --- a/apps/usb/base.hu.i18n +++ b/apps/usb/base.hu.i18n @@ -11,3 +11,4 @@ DfuStatusUnprotected = "VÉDTELEN" USBProtectionLevel0 = "Alapértelmezett védelem" USBProtectionLevel1 = "Omega védelem" USBProtectionLevel2 = "Rendszervédelem" +USBProtectionReactivated = "A védelem újra aktiválva" diff --git a/apps/usb/base.it.i18n b/apps/usb/base.it.i18n index 54b29beae..f2c6f8677 100644 --- a/apps/usb/base.it.i18n +++ b/apps/usb/base.it.i18n @@ -11,3 +11,4 @@ DfuStatusUnprotected = "INDIFESO" USBProtectionLevel0 = "Protezione predefinita" USBProtectionLevel1 = "Protezione Omega" USBProtectionLevel2 = "Protezione del sistema" +USBProtectionReactivated = "Protezione riattivata" diff --git a/apps/usb/base.nl.i18n b/apps/usb/base.nl.i18n index 2f5684169..fe427fb69 100644 --- a/apps/usb/base.nl.i18n +++ b/apps/usb/base.nl.i18n @@ -11,3 +11,4 @@ DfuStatusUnprotected = "NIET BESCHERMD" USBProtectionLevel0 = "Standaardbeveiliging" USBProtectionLevel1 = "Omega Bescherming" USBProtectionLevel2 = "Systeembeveiliging" +USBProtectionReactivated = "USB-bescherming is geactiveerd" diff --git a/apps/usb/base.pt.i18n b/apps/usb/base.pt.i18n index a87f034ea..49d50845d 100644 --- a/apps/usb/base.pt.i18n +++ b/apps/usb/base.pt.i18n @@ -11,3 +11,4 @@ DfuStatusUnprotected = "DESPROTEGIDO" USBProtectionLevel0 = "Proteção padrão" USBProtectionLevel1 = "Proteção Ômega" USBProtectionLevel2 = "Proteção do sistema" +USBProtectionReactivated = "Proteção reativada" diff --git a/apps/usb/usb_connected_controller.cpp b/apps/usb/usb_connected_controller.cpp index e63cf699b..3592d498e 100644 --- a/apps/usb/usb_connected_controller.cpp +++ b/apps/usb/usb_connected_controller.cpp @@ -2,9 +2,9 @@ #include #include "../global_preferences.h" -namespace USB -{ -static constexpr I18n::Message sUSBConnectedMessages[k_numberOfUSBMessages] = { +namespace USB { + +static constexpr I18n::Message sUSBConnectedMessages[] = { I18n::Message::USBConnected, I18n::Message::ConnectedMessage1, I18n::Message::ConnectedMessage2, @@ -33,35 +33,35 @@ USBConnectedController::USBConnectedController() : } -USBConnectedController::ContentView::ContentView(KDColor * fgcolors, KDColor * bgcolors, uint8_t numberOfMessages) { +USBConnectedController::ContentView::ContentView() { // We set the styles of the messages for (uint8_t i = 0; i < k_numberOfMessages; i++) { m_messageTextViews[i].setFont(i == 0 ? KDFont::LargeFont : KDFont::SmallFont); m_messageTextViews[i].setAlignment(0.5f, 0.5f); - m_messageTextViews[i].setTextColor(fgcolors[i]); + m_messageTextViews[i].setTextColor(sUSBConnectedFGColors[i]); m_messageTextViews[i].setBackgroundColor(Palette::BackgroundHard); } // We set the texts of the firsts defaults messages for (uint8_t i = 0; i < k_numberOfUSBMessages; i++) { - m_messageTextViews[i].setText(sUSBConnectedMessages[i]); + m_messageTextViews[i].setText(I18n::translate(sUSBConnectedMessages[i])); } // Last message, depending of the USB protection level - if (GlobalPreferences::sharedGlobalPreferences()->dfuStatus()) { - m_messageTextViews[i].setText(DfuStatusUnprotected); + if (GlobalPreferences::sharedGlobalPreferences()->dfuUnlocked()) { + m_messageTextViews[k_numberOfUSBMessages].setText(I18n::translate(I18n::Message::DfuStatusUnprotected)); } else { - int protectionLevel = GlobalPreferences::sharedGlobalPreferences()->getDfuLevel(); + int protectionLevel = GlobalPreferences::sharedGlobalPreferences()->dfuLevel(); switch (protectionLevel) { case 0: - m_messageTextViews[9].setText(USBProtectionLevel0); + m_messageTextViews[9].setText(I18n::translate(I18n::Message::USBProtectionLevel0)); break; case 1: - m_messageTextViews[9].setText(USBProtectionLevel1); + m_messageTextViews[9].setText(I18n::translate(I18n::Message::USBProtectionLevel1)); break; default: assert(protectionLevel == 2); - m_messageTextViews[9].setText(USBProtectionLevel2); + m_messageTextViews[9].setText(I18n::translate(I18n::Message::USBProtectionLevel2)); break; } } diff --git a/apps/usb/usb_connected_controller.h b/apps/usb/usb_connected_controller.h index 5fd0675fd..c0b991521 100644 --- a/apps/usb/usb_connected_controller.h +++ b/apps/usb/usb_connected_controller.h @@ -8,11 +8,12 @@ namespace USB { class USBConnectedController : public ViewController { public: USBConnectedController(); - View * view() override { return &m_messageView; } - USBView * getMessageView() {return &m_messageView; } + View * view() override { return &m_contentView; } bool handleEvent(Ion::Events::Event event) override { return false; }; +private: + class ContentView : public View { public: - ContentView(KDColor * fgcolors, KDColor * bgcolors); + ContentView(); void drawRect(KDContext * ctx, KDRect rect) const override; protected: int numberOfSubviews() const override { return k_numberOfMessages; } diff --git a/build/device/secure_ext.py b/build/device/secure_ext.py index 68d2a6a65..e1939a542 100644 --- a/build/device/secure_ext.py +++ b/build/device/secure_ext.py @@ -1,8 +1,8 @@ import sys import os -MAGIK_CODE = [0x64, 0x6c, 0x31, 0x31, 0x23, 0x39, 0x38, 0x33, 0x35] -MAGIK_POS = [0x03, 0xb, 0x44f] +MAGIK_CODE = [0x32, 0x30, 0x30, 0x36] +MAGIK_POS = 0x44F if len(sys.argv) > 1: print("Patching external bin...") @@ -18,11 +18,7 @@ if len(sys.argv) > 1: sys.exit(-1) for i in range(4): - first_packet[MAGIK_POS[0] + i] = MAGIK_CODE[i] - for i in range(4): - first_packet[MAGIK_POS[1] + i] = MAGIK_CODE[i + 5] - for i in range(len(MAGIK_CODE)): - first_packet[MAGIK_POS[2] + i] = MAGIK_CODE[i] + first_packet[MAGIK_POS + i] = MAGIK_CODE[i] file.seek(0) file.write(first_packet) diff --git a/build/targets.device.mak b/build/targets.device.mak index 27b8d1a97..eb3ad0a8f 100644 --- a/build/targets.device.mak +++ b/build/targets.device.mak @@ -27,11 +27,11 @@ $(BUILD_DIR)/%.map: $(BUILD_DIR)/%.elf @echo "LDMAP $@" $(Q) $(LD) $^ $(LDFLAGS) -Wl,-M -Wl,-Map=$@ -o /dev/null -.PHONY: mapfile -mapfile: - $(BUILD_DIR)/%.map: $(BUILD_DIR)/%.elf - @echo "LDMAP $@" - $(Q) $(LD) $^ $(LDFLAGS) -Wl,-M -Wl,-Map=$@ -o /dev/null +.PHONY: %_memory_map +%_memory_map: $(BUILD_DIR)/%.map + @echo "========== MEMORY MAP =========" + $(Q) awk -f build/device/memory_map.awk < $< + @echo "===============================" .PHONY: openocd openocd: diff --git a/ion/src/device/n0110/drivers/board.cpp b/ion/src/device/n0110/drivers/board.cpp index caca26ea3..98403abb6 100644 --- a/ion/src/device/n0110/drivers/board.cpp +++ b/ion/src/device/n0110/drivers/board.cpp @@ -123,7 +123,7 @@ void init() { initClocks(); // The bootloader leaves its own after flashing - // SYSCFG.MEMRMP()->setMEM_MODE(SYSCFG::MEMRMP::MemMode::MainFlashmemory); + //SYSCFG.MEMRMP()->setMEM_MODE(SYSCFG::MEMRMP::MemMode::MainFlashmemory); // Ensure right location of interrupt vectors CORTEX.VTOR()->setVTOR((void*)&InitialisationVector); diff --git a/ion/src/device/shared/boot/isr.h b/ion/src/device/shared/boot/isr.h index e0f8da160..cec396388 100644 --- a/ion/src/device/shared/boot/isr.h +++ b/ion/src/device/shared/boot/isr.h @@ -8,7 +8,7 @@ extern "C" { void bf_abort(); void uf_abort(); void nmi_abort(); -// Here and below, we mean init the abort handler, not the opposite +// Here and below, we are doing operations on the abort handler, not the opposite void abort_init(); void abort_core(const char *); void abort_screen(const char *); diff --git a/ion/src/device/shared/boot/rt0.cpp b/ion/src/device/shared/boot/rt0.cpp index 24b9cb807..a2949b3c0 100644 --- a/ion/src/device/shared/boot/rt0.cpp +++ b/ion/src/device/shared/boot/rt0.cpp @@ -1,4 +1,3 @@ -#include "isr.h" #include #include #include @@ -28,20 +27,20 @@ typedef void (*cxx_constructor)(); extern "C" { - extern char _data_section_start_flash; - extern char _data_section_start_ram; - extern char _data_section_end_ram; - extern char _bss_section_start_ram; - extern char _bss_section_end_ram; - extern cxx_constructor _init_array_start; - extern cxx_constructor _init_array_end; +extern char _data_section_start_flash; +extern char _data_section_start_ram; +extern char _data_section_end_ram; +extern char _bss_section_start_ram; +extern char _bss_section_end_ram; +extern cxx_constructor _init_array_start; +extern cxx_constructor _init_array_end; } /* In order to ensure that this method is execute from the external flash, we * forbid inlining it.*/ static void __attribute__((noinline)) external_flash_start() { - /* Init the peripherals. We do not initialize the backlight in case there is + /* Init the peripherals. We do not initialize the backlight in case there is * an on boarding app: indeed, we don't want the user to see the LCD tests * happening during the on boarding app. The backlight will be initialized * after the Power-On Self-Test if there is one or before switching to the @@ -69,155 +68,7 @@ static void __attribute__((noinline)) external_flash_start() { * internal flash to the external flash. */ static void __attribute__((noinline)) jump_to_external_flash() { - external_flash_start(); -} - -void __attribute__((noinline)) abort_init() { - Ion::Device::Board::shutdownPeripherals(true); - Ion::Device::Board::initPeripherals(false); - Ion::Timing::msleep(100); - Ion::Backlight::init(); - Ion::LED::setColor(KDColorRed); - Ion::Backlight::setBrightness(180); -} - -void __attribute__((noinline)) abort_economy() { - int brightness = Ion::Backlight::brightness(); - bool plugged = Ion::USB::isPlugged(); - while (brightness > 0) { - brightness--; - Ion::Backlight::setBrightness(brightness); - Ion::Timing::msleep(50); - if(plugged || (!plugged && Ion::USB::isPlugged())){ - Ion::Backlight::setBrightness(180); - return; - } - } - Ion::Backlight::shutdown(); - while (1) { - Ion::Device::Power::sleepConfiguration(); - Ion::Device::WakeUp::onUSBPlugging(); - Ion::Device::WakeUp::onChargingEvent(); - Ion::Device::Power::internalFlashSuspend(true); - if (!plugged && Ion::USB::isPlugged()) { - break; - } - plugged = Ion::USB::isPlugged(); - }; - Ion::Device::Board::setStandardFrequency(Ion::Device::Board::Frequency::High); - Ion::Backlight::init(); - Ion::Backlight::setBrightness(180); -} - -void __attribute__((noinline)) abort_sleeping() { - if (Ion::Battery::level() != Ion::Battery::Charge::EMPTY) { - return; - } - // we don't use Ion::Power::suspend because we don't want to move the exam buffer into the internal - Ion::Device::Board::shutdownPeripherals(true); - bool plugged = Ion::USB::isPlugged(); - while (1) { - Ion::Device::Battery::initGPIO(); - Ion::Device::USB::initGPIO(); - Ion::Device::LED::init(); - Ion::Device::Power::sleepConfiguration(); - Ion::Device::Board::shutdownPeripherals(true); - Ion::Device::WakeUp::onUSBPlugging(); - Ion::Device::WakeUp::onChargingEvent(); - Ion::Device::Power::internalFlashSuspend(true); - Ion::Device::USB::initGPIO(); - if (!plugged && Ion::USB::isPlugged()) { - break; - } - plugged = Ion::USB::isPlugged(); - } - Ion::Device::Board::setStandardFrequency(Ion::Device::Board::Frequency::High); - abort_init(); -} - -void __attribute__((noinline)) abort_core(const char * text) { - Ion::Timing::msleep(100); - int counting; - while (true) { - counting = 0; - if (Ion::Battery::level() == Ion::Battery::Charge::EMPTY) { - abort_sleeping(); - abort_screen(text); - } - - Ion::USB::enable(); - Ion::Battery::Charge previous_state = Ion::Battery::level(); - while (!Ion::USB::isEnumerated()) { - if (Ion::Battery::level() == Ion::Battery::Charge::LOW) { - if (previous_state != Ion::Battery::Charge::LOW) { - previous_state = Ion::Battery::Charge::LOW; - counting = 0; - } - Ion::Timing::msleep(500); - if (counting >= 20) { - abort_sleeping(); - abort_screen(text); - counting = -1; - } - counting++; - - } else { - if (previous_state == Ion::Battery::Charge::LOW) { - previous_state = Ion::Battery::level(); - counting = 0; - } - Ion::Timing::msleep(100); - if (counting >= 300) { - abort_economy(); - counting = -1; - } - counting++; - } - } - Ion::USB::DFU(false, false, 0); - } -} - -void __attribute__((noinline)) abort_screen(const char * text){ - KDRect screen = KDRect(0, 0, Ion::Display::Width, Ion::Display::Height); - Ion::Display::pushRectUniform(KDRect(0, 0, Ion::Display::Width, Ion::Display::Height), KDColor::RGB24(0xffffff)); - KDContext* ctx = KDIonContext::sharedContext(); - ctx->setOrigin(KDPointZero); - ctx->setClippingRect(screen); - ctx->drawString("UPSILON CRASH", KDPoint(90, 10), KDFont::LargeFont, KDColorRed, KDColor::RGB24(0xffffff)); - ctx->drawString("An error occurred", KDPoint(10, 30), KDFont::SmallFont, KDColorBlack, KDColor::RGB24(0xffffff)); - ctx->drawString("If you have some important data, please", KDPoint(10, 45), KDFont::SmallFont, KDColorBlack, KDColor::RGB24(0xffffff)); - ctx->drawString("use bit.ly/upsiBackup to backup them.", KDPoint(10, 60), KDFont::SmallFont, KDColorBlack, KDColor::RGB24(0xffffff)); - ctx->drawString("YOU WILL LOSE ALL YOUR DATA", KDPoint(10, 85), KDFont::SmallFont, KDColorBlack, KDColor::RGB24(0xffffff)); - ctx->drawString("→ You can try to reboot by presssing the", KDPoint(10, 110), KDFont::SmallFont, KDColorBlack, KDColor::RGB24(0xffffff)); - ctx->drawString("reset button at the back of the calculator", KDPoint(10, 125), KDFont::SmallFont, KDColorBlack, KDColor::RGB24(0xffffff)); - ctx->drawString("→ If Upsilon keeps crashing, you can connect", KDPoint(10, 140), KDFont::SmallFont, KDColorBlack, KDColor::RGB24(0xffffff)); - ctx->drawString("the calculator to a computer or a phone", KDPoint(10, 160), KDFont::SmallFont, KDColorBlack, KDColor::RGB24(0xffffff)); - ctx->drawString("and try to reinstall Upsilon", KDPoint(10, 175), KDFont::SmallFont, KDColorBlack, KDColor::RGB24(0xffffff)); - ctx->drawString(text, KDPoint(220, 200), KDFont::SmallFont, KDColorRed, KDColor::RGB24(0xffffff)); -} - -void __attribute__((noinline)) abort() { - abort_init(); - abort_screen("HARDFAULT"); - abort_core("HARDFAULT"); -} - -void __attribute__((noinline)) nmi_abort() { - abort_init(); - abort_screen("NMIFAULT"); - abort_core("NMIFAULT"); -} - -void __attribute__((noinline)) bf_abort() { - abort_init(); - abort_screen("BUSFAULT"); - abort_core("BUSFAULT"); -} -void __attribute__((noinline)) uf_abort() { - abort_init(); - abort_screen("USAGEFAULT"); - abort_core("USAGEFAULT"); + external_flash_start(); } void __attribute__((noinline)) abort_init() { @@ -261,10 +112,10 @@ void __attribute__((noinline)) abort_sleeping() { if (Ion::Battery::level() != Ion::Battery::Charge::EMPTY) { return; } - // We don't use Ion::Power::suspend because we don't want to move the exam buffer into the internal + // we don't use Ion::Power::suspend because we don't want to move the exam buffer into the internal Ion::Device::Board::shutdownPeripherals(true); bool plugged = Ion::USB::isPlugged(); - while (true) { + while (1) { Ion::Device::Battery::initGPIO(); Ion::Device::USB::initGPIO(); Ion::Device::LED::init(); @@ -373,27 +224,27 @@ void __attribute__((noinline)) uf_abort() { * (just in case 'start' was to be called from the external flash). */ void __attribute__((noinline)) start() { - /* This is where execution starts after reset. + /* This is where execution starts after reset. * Many things are not initialized yet so the code here has to pay attention. */ - /* Copy data section to RAM + /* Copy data section to RAM * The data section is R/W but its initialization value matters. It's stored * in Flash, but linked as if it were in RAM. Now's our opportunity to copy * it. Note that until then the data section (e.g. global variables) contains * garbage values and should not be used. */ - size_t dataSectionLength = (&_data_section_end_ram - &_data_section_start_ram); - memcpy(&_data_section_start_ram, &_data_section_start_flash, dataSectionLength); + size_t dataSectionLength = (&_data_section_end_ram - &_data_section_start_ram); + memcpy(&_data_section_start_ram, &_data_section_start_flash, dataSectionLength); - /* Zero-out the bss section in RAM + /* Zero-out the bss section in RAM * Until we do, any uninitialized global variable will be unusable. */ - size_t bssSectionLength = (&_bss_section_end_ram - &_bss_section_start_ram); - memset(&_bss_section_start_ram, 0, bssSectionLength); + size_t bssSectionLength = (&_bss_section_end_ram - &_bss_section_start_ram); + memset(&_bss_section_start_ram, 0, bssSectionLength); - /* Initialize the FPU as early as possible. + /* Initialize the FPU as early as possible. * For example, static C++ objects are very likely to manipulate float values */ - Ion::Device::Board::initFPU(); + Ion::Device::Board::initFPU(); - /* Call static C++ object constructors + /* Call static C++ object constructors * The C++ compiler creates an initialization function for each static object. * The linker then stores the address of each of those functions consecutively * between _init_array_start and _init_array_end. So to initialize all C++ @@ -405,26 +256,26 @@ void __attribute__((noinline)) start() { (*c)(); } #else - /* In practice, static initialized objects are a terrible idea. Since the init + /* In practice, static initialized objects are a terrible idea. Since the init * order is not specified, most often than not this yields the dreaded static * init order fiasco. How about bypassing the issue altogether? */ - if (&_init_array_start != &_init_array_end) { - abort(); - } + if (&_init_array_start != &_init_array_end) { + abort(); + } #endif - Ion::Device::Board::init(); + Ion::Device::Board::init(); - /* At this point, we initialized clocks and the external flash but no other + /* At this point, we initialized clocks and the external flash but no other * peripherals. */ - jump_to_external_flash(); + jump_to_external_flash(); - abort(); + abort(); } void __attribute__((interrupt, noinline)) isr_systick() { - auto t = Ion::Device::Timing::MillisElapsed; - t++; - Ion::Device::Timing::MillisElapsed = t; + auto t = Ion::Device::Timing::MillisElapsed; + t++; + Ion::Device::Timing::MillisElapsed = t; } diff --git a/ion/src/device/shared/usb/dfu_interface.cpp b/ion/src/device/shared/usb/dfu_interface.cpp index 2fdc9b5e1..6a7a02441 100644 --- a/ion/src/device/shared/usb/dfu_interface.cpp +++ b/ion/src/device/shared/usb/dfu_interface.cpp @@ -10,10 +10,13 @@ #include #include #include + namespace Ion { namespace Device { namespace USB { +constexpr static uint8_t k_externalMagik[9] = {0x64, 0x6c, 0x31, 0x31, 0x23, 0x39, 0x38, 0x33, 0x35}; + static inline uint32_t minUint32T(uint32_t x, uint32_t y) { return x < y ? x : y; } void DFUInterface::StatusData::push(Channel *c) const { @@ -54,7 +57,6 @@ void DFUInterface::wholeDataReceivedCallback(SetupPacket *request, uint8_t *tran if (request->wLength() > 0) { // The request is a "real" download. Compute the writing address. m_writeAddress = (request->wValue() - 2) * Endpoint0::MaxTransferSize + m_addressPointer; - // Store the received data until we copy it on the flash. memcpy(m_largeBuffer, transferBuffer, *transferBufferLength); m_largeBufferLength = *transferBufferLength; @@ -67,9 +69,6 @@ void DFUInterface::wholeDataSentCallback(SetupPacket *request, uint8_t *transfer if (request->bRequest() == (uint8_t)DFURequest::GetStatus) { // Do any needed action after the GetStatus request. if (m_state == State::dfuMANIFEST) { - if (m_dfuLevel == 1 && m_isFirstExternalFlash && !m_isInternalLocked) { - return; - } /* If we leave the DFU and reset immediately, dfu-util outputs an error: * "File downloaded successfully * dfu-util: Error during download get_status" @@ -81,7 +80,6 @@ void DFUInterface::wholeDataSentCallback(SetupPacket *request, uint8_t *transfer // Leave DFU routine: Leave DFU, reset device, jump to application code leaveDFUAndReset(); } else if (m_state == State::dfuDNBUSY) { - m_state = State::dfuDNBUSY; if (m_largeBufferLength != 0) { // Here, copy the data from the transfer buffer to the flash memory writeOnMemory(); @@ -168,7 +166,10 @@ bool DFUInterface::processUploadRequest(SetupPacket *request, uint8_t *transferB void DFUInterface::setAddressPointerCommand(SetupPacket *request, uint8_t *transferBuffer, uint16_t transferBufferLength) { assert(transferBufferLength == 5); // Compute the new address but change it after the next getStatus request. - m_potentialNewAddressPointer = transferBuffer[1] + (transferBuffer[2] << 8) + (transferBuffer[3] << 16) + (transferBuffer[4] << 24); + m_potentialNewAddressPointer = transferBuffer[1] + + (transferBuffer[2] << 8) + + (transferBuffer[3] << 16) + + (transferBuffer[4] << 24); m_state = State::dfuDNLOADSYNC; } @@ -198,7 +199,10 @@ void DFUInterface::eraseCommand(uint8_t *transferBuffer, uint16_t transferBuffer // Sector erase assert(transferBufferLength == 5); - m_eraseAddress = transferBuffer[1] + (transferBuffer[2] << 8) + (transferBuffer[3] << 16) + (transferBuffer[4] << 24); + uint32_t m_eraseAddress = transferBuffer[1] + + (transferBuffer[2] << 8) + + (transferBuffer[3] << 16) + + (transferBuffer[4] << 24); m_erasePage = Flash::SectorAtAddress(m_eraseAddress); if (m_erasePage < 0) { @@ -210,13 +214,24 @@ void DFUInterface::eraseCommand(uint8_t *transferBuffer, uint16_t transferBuffer void DFUInterface::eraseMemoryIfNeeded() { if (m_erasePage < 0) { + // There was no erase waiting. return; } + willErase(); - if ((m_eraseAddress >= k_ExternalBorderAddress && m_eraseAddress < ExternalFlash::Config::EndAddress) || m_dfuUnlocked) { - int32_t order = Flash::SectorAtAddress(m_eraseAddress); - Flash::EraseSector(order); + +#if 0 // We don't erase now the flash memory to avoid crash if writing is refused + if (m_erasePage == Flash::TotalNumberOfSectors()) { + Flash::MassErase(); } +#endif + + if ((m_eraseAddress >= k_externalAppsBorderAddress && m_eraseAddress < ExternalFlash::Config::EndAddress) || m_dfuUnlocked) { + Flash::EraseSector(m_erasePage); + } + /* Put an out of range value in m_erasePage to indicate that no erase is + * waiting. */ + m_erasePage = -1; m_state = State::dfuDNLOADIDLE; m_status = Status::OK; m_erasePage = -1; @@ -227,238 +242,67 @@ void DFUInterface::writeOnMemory() { // Write on SRAM // FIXME We should check that we are not overriding the current instructions. memcpy((void *)m_writeAddress, m_largeBuffer, m_largeBufferLength); - reset_custom_vars(); // On reset les vars car la ram n'a pas de secteur à effacer + resetProtectionVariables(); // We can reset the protection variables because update process is finsihed. } else if (Flash::SectorAtAddress(m_writeAddress) >= 0) { - if (m_dfuLevel == 2) { + if (m_dfuLevel == 2) { // If no-update mode, we throw an error m_largeBufferLength = 0; m_state = State::dfuERROR; m_status = Status::errWRITE; + leaveDFUAndReset(false); return; } - - int current_memory_flashed; - if (m_writeAddress >= InternalFlash::Config::StartAddress && m_writeAddress <= InternalFlash::Config::EndAddress) { - if (m_isInternalLocked && !m_dfuUnlocked) // On vérifie si l'external a été flash - { - m_largeBufferLength = 0; - m_state = State::dfuERROR; - m_status = Status::errTARGET; - leaveDFUAndReset(false); // Numworks flash l'internal avant donc on exit pour afficher le message - return; - } - current_memory_flashed = 0; - - //on écrit dans la mémoire interne - if (m_isFirstInternalFlash && !m_dfuUnlocked) { - m_temp_is_valid = true; - for (int i = 0; i < 4; i++) { - if (magik[i] != m_largeBuffer[magik_adrs + i]) { - m_temp_is_valid = false; - break; + + if (!(m_isTemporaryUnlocked || m_dfuUnlocked)) { + if (m_writeAddress >= InternalFlash::Config::StartAddress && m_writeAddress <= InternalFlash::Config::EndAddress) { + // We check if the user is autorized to write on the internal flash + if (m_haveAlreadyFlashedExternal) { + for (size_t i = 0; i < 4; i++) { + if (k_internalMagik[i] != m_largeBuffer[k_internalMagikPointer + i]) { + m_largeBufferLength = 0; + m_state = State::dfuERROR; + m_status = Status::errWRITE; + // We don't leave DFU to avoid having only external flashed + return; + } + m_largeBuffer[k_internalMagikPointer + i] = 0; // We reset the buffer to its initial value } } - if (!m_temp_is_valid) { + else { // All people trying to write on the internal flash before external are considered as not authorized m_largeBufferLength = 0; m_state = State::dfuERROR; - m_status = Status::errVERIFY; - //leaveDFUAndReset(); On ne leave plus sinon on fait crash la calc si il n'y a que la partie ext. + m_status = Status::errTARGET; + leaveDFUAndReset(false); return; - } else { - m_isFirstInternalFlash = false; } } - } else { - current_memory_flashed = 1; - // Nous écrivons la partie external os - if (m_writeAddress < k_ExternalBorderAddress && m_isFirstExternalFlash && !m_dfuUnlocked) // On vérifie si on installe des apps ext - { - // if (m_dfuLevel == 1 && m_isInternalLocked) { - // m_largeBufferLength = 0; - // m_state = State::dfuERROR; - // m_status = Status::errTARGET; - // return; - // } + else if (m_writeAddress < k_externalAppsBorderAddress) { // If we are not installing external apps if (m_dfuLevel == 0) { - // Partie moche du code parce que je n'arrivais pas à compil avec 3 boucles for sous msys - int adress_magik = magik_ext_adrs[0]; - m_temp_is_valid = external_magik[0] == m_largeBuffer[adress_magik]; - m_largeBuffer[adress_magik] = 0xff; - - if (!m_temp_is_valid) { - m_largeBufferLength = 0; - leaveDFUAndReset(false); - return; + for (size_t i = 0; i < 9; i++) { + if (k_externalMagik[i] != m_largeBuffer[k_externalMagikPointer + i]) { + m_largeBufferLength = 0; + m_state = State::dfuERROR; + m_status = Status::errWRITE; + leaveDFUAndReset(false); + return; + } + m_largeBuffer[k_externalMagikPointer + i] = 0; // We reset the buffer to its initial value } - - m_temp_is_valid = external_magik[1] == m_largeBuffer[adress_magik + 1]; - m_largeBuffer[adress_magik + 1] = 0xff; - - if (!m_temp_is_valid) { - m_largeBufferLength = 0; - leaveDFUAndReset(false); - return; - } - - m_temp_is_valid = external_magik[2] == m_largeBuffer[adress_magik + 2]; - m_largeBuffer[adress_magik + 2] = 0xff; - - if (!m_temp_is_valid) { - m_largeBufferLength = 0; - leaveDFUAndReset(false); - return; - } - - m_temp_is_valid = external_magik[3] == m_largeBuffer[adress_magik + 3]; - m_largeBuffer[adress_magik + 3] = 0xff; - - if (!m_temp_is_valid) { - m_largeBufferLength = 0; - leaveDFUAndReset(false); - return; - } - - adress_magik = magik_ext_adrs[1]; - - m_temp_is_valid = external_magik[5] == m_largeBuffer[adress_magik]; - m_largeBuffer[adress_magik] = 0xff; - - if (!m_temp_is_valid) { - m_largeBufferLength = 0; - leaveDFUAndReset(false); - return; - } - - m_temp_is_valid = external_magik[6] == m_largeBuffer[adress_magik + 1]; - m_largeBuffer[adress_magik + 1] = 0xff; - - if (!m_temp_is_valid) { - m_largeBufferLength = 0; - leaveDFUAndReset(false); - return; - } - - m_temp_is_valid = external_magik[7] == m_largeBuffer[adress_magik + 2]; - m_largeBuffer[adress_magik + 2] = 0xff; - - if (!m_temp_is_valid) { - m_largeBufferLength = 0; - leaveDFUAndReset(false); - return; - } - - m_temp_is_valid = external_magik[8] == m_largeBuffer[adress_magik + 3]; - m_largeBuffer[adress_magik + 3] = 0xff; - - if (!m_temp_is_valid) { - m_largeBufferLength = 0; - leaveDFUAndReset(false); - return; - } - - adress_magik = magik_ext_adrs[2]; - m_temp_is_valid = true; - - m_temp_is_valid = external_magik[0] == m_largeBuffer[adress_magik]; - m_largeBuffer[adress_magik] = 0xff; - - if (!m_temp_is_valid) { - m_largeBufferLength = 0; - leaveDFUAndReset(false); - return; - } - - m_temp_is_valid = external_magik[1] == m_largeBuffer[adress_magik + 1]; - m_largeBuffer[adress_magik + 1] = 0xff; - - if (!m_temp_is_valid) { - m_largeBufferLength = 0; - leaveDFUAndReset(false); - return; - } - - m_temp_is_valid = external_magik[2] == m_largeBuffer[adress_magik + 2]; - m_largeBuffer[adress_magik + 2] = 0xff; - - if (!m_temp_is_valid) { - m_largeBufferLength = 0; - leaveDFUAndReset(false); - return; - } - - m_temp_is_valid = external_magik[3] == m_largeBuffer[adress_magik + 3]; - m_largeBuffer[adress_magik + 3] = 0xff; - - if (!m_temp_is_valid) { - m_largeBufferLength = 0; - leaveDFUAndReset(false); - return; - } - - m_temp_is_valid = external_magik[4] == m_largeBuffer[adress_magik + 4]; - m_largeBuffer[adress_magik + 4] = 0xff; - - if (!m_temp_is_valid) { - m_largeBufferLength = 0; - leaveDFUAndReset(false); - return; - } - m_temp_is_valid = external_magik[5] == m_largeBuffer[adress_magik + 5]; - m_largeBuffer[adress_magik + 5] = 0xff; - - if (!m_temp_is_valid) { - m_largeBufferLength = 0; - leaveDFUAndReset(false); - return; - } - m_temp_is_valid = external_magik[6] == m_largeBuffer[adress_magik + 6]; - m_largeBuffer[adress_magik + 6] = 0xff; - - if (!m_temp_is_valid) { - m_largeBufferLength = 0; - leaveDFUAndReset(false); - return; - } - m_temp_is_valid = external_magik[7] == m_largeBuffer[adress_magik + 7]; - m_largeBuffer[adress_magik + 7] = 0xff; - - if (!m_temp_is_valid) { - m_largeBufferLength = 0; - leaveDFUAndReset(false); - return; - } - m_temp_is_valid = external_magik[8] == m_largeBuffer[adress_magik + 8]; - m_largeBuffer[adress_magik + 8] = 0xff; - - if (!m_temp_is_valid) { - m_largeBufferLength = 0; - leaveDFUAndReset(false); - return; - } else { - m_isFirstExternalFlash = false; - m_isInternalLocked = false; - } - } else { - m_isFirstExternalFlash = false; - m_isInternalLocked = false; + m_isTemporaryUnlocked = true; // We can unlock the flash because signature is good + } + else { + m_haveAlreadyFlashedExternal = true; } } } - if (m_last_memoryFlashed >= 0 && current_memory_flashed != m_last_memoryFlashed) { - m_last_memoryFlashed = -1; - } - m_erasePage = Flash::SectorAtAddress(m_writeAddress); + int pageToErase = Flash::SectorAtAddress(m_writeAddress); //On vérifie qu'on a pas déjà effacé le secteur et si ce n'est pas un secteur external déjà effacé - if ((m_last_memoryFlashed < 0 || m_erasePage != m_lastPageErased) && m_writeAddress < k_ExternalBorderAddress && !m_dfuUnlocked) { - Flash::EraseSector(m_erasePage); - m_last_memoryFlashed = current_memory_flashed; + if ((m_lastErasedPage == -1 || pageToErase != m_lastErasedPage) && m_writeAddress < k_externalAppsBorderAddress && !m_dfuUnlocked) { + Flash::EraseSector(pageToErase); + m_lastErasedPage = pageToErase; } - m_lastPageErased = m_erasePage; - m_erasePage = -1; - - Ion::Timing::msleep(1); Flash::WriteMemory(reinterpret_cast(m_writeAddress), m_largeBuffer, m_largeBufferLength); } else { // Invalid write address @@ -467,6 +311,7 @@ void DFUInterface::writeOnMemory() { m_status = Status::errTARGET; return; } + // Reset the buffer length m_largeBufferLength = 0; // Change the interface state and status @@ -505,14 +350,11 @@ bool DFUInterface::dfuAbort(uint16_t *transferBufferLength) { } void DFUInterface::leaveDFUAndReset(bool do_reset) { - reset_custom_vars(); - m_isInternalLocked = true; - m_isFirstInternalFlash = true; - m_isFirstExternalFlash = true; + resetProtectionVariables(); m_device->setResetOnDisconnect(do_reset); m_device->detach(); } -} // namespace USB -} // namespace Device -} // namespace Ion +} +} +} diff --git a/ion/src/device/shared/usb/dfu_interface.h b/ion/src/device/shared/usb/dfu_interface.h index 621c38a4c..dd87c6cdd 100644 --- a/ion/src/device/shared/usb/dfu_interface.h +++ b/ion/src/device/shared/usb/dfu_interface.h @@ -148,10 +148,10 @@ private: constexpr static uint32_t k_sramEndAddress = 0x20040000; constexpr static uint32_t k_externalAppsBorderAddress = 0x90200000; - const static int k_internalMagikPointer = 0x1C4; + constexpr static int k_internalMagikPointer = 0x1C4; constexpr static int k_externalMagikPointer = 0x44F; constexpr static uint8_t k_internalMagik[4] = {0xF0, 0x0D, 0xC0, 0xDE}; - constexpr static uint8_t k_externalMagik[9] = {0x64, 0x6c, 0x31, 0x31, 0x23, 0x39, 0x38, 0x33, 0x35}; + constexpr static uint8_t k_externalMagik[4] = {0x32, 0x30, 0x30, 0x36}; // Download and upload bool processDownloadRequest(uint16_t wLength, uint16_t *transferBufferLength);