Skip to content

Commit

Permalink
Merge branch 'dev' into release-candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
skotopes committed Dec 24, 2021
2 parents 208ea6f + 7cea359 commit bb650c4
Show file tree
Hide file tree
Showing 17 changed files with 123 additions and 99 deletions.
5 changes: 2 additions & 3 deletions applications/desktop/desktop.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "portmacro.h"
#include "storage/filesystem-api-defines.h"
#include "storage/storage.h"
#include <furi-hal-lock.h>
#include <stdint.h>
#include <power/power_service/power.h>
#include "helpers/desktop_animation.h"
Expand Down Expand Up @@ -155,14 +154,14 @@ int32_t desktop_srv(void* p) {

bool loaded = LOAD_DESKTOP_SETTINGS(&desktop->settings);
if(!loaded) {
furi_hal_lock_set(false);
furi_hal_rtc_reset_flag(FuriHalRtcFlagLock);
memset(&desktop->settings, 0, sizeof(desktop->settings));
SAVE_DESKTOP_SETTINGS(&desktop->settings);
}

scene_manager_next_scene(desktop->scene_manager, DesktopSceneMain);

if(furi_hal_lock_get()) {
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagLock)) {
furi_hal_usb_disable();
scene_manager_set_scene_state(
desktop->scene_manager, DesktopSceneLocked, DesktopLockedWithPin);
Expand Down
2 changes: 1 addition & 1 deletion applications/desktop/helpers/desktop_animation.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void desktop_start_new_idle_animation(DesktopAnimation* animation) {
DolphinStats stats = dolphin_stats(dolphin);
furi_record_close("dolphin");

furi_assert((stats.level >= 1) && (stats.level <= 3));
furi_check((stats.level >= 1) && (stats.level <= 3));

AnimationList_t animation_list;
AnimationList_init(animation_list);
Expand Down
3 changes: 1 addition & 2 deletions applications/desktop/scenes/desktop_scene_lock_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "../views/desktop_lock_menu.h"
#include <toolbox/saved_struct.h>
#include <stdbool.h>
#include <furi-hal-lock.h>

void desktop_scene_lock_menu_callback(DesktopLockMenuEvent event, void* context) {
Desktop* desktop = (Desktop*)context;
Expand Down Expand Up @@ -33,7 +32,7 @@ bool desktop_scene_lock_menu_on_event(void* context, SceneManagerEvent event) {
break;
case DesktopLockMenuEventPinLock:
if(desktop->settings.pincode.length > 0) {
furi_hal_lock_set(true);
furi_hal_rtc_set_flag(FuriHalRtcFlagLock);
furi_hal_usb_disable();
scene_manager_set_scene_state(
desktop->scene_manager, DesktopSceneLocked, DesktopLockedWithPin);
Expand Down
3 changes: 1 addition & 2 deletions applications/desktop/scenes/desktop_scene_locked.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "../views/desktop_locked.h"
#include "desktop/helpers/desktop_animation.h"
#include "desktop/views/desktop_main.h"
#include <furi-hal-lock.h>

void desktop_scene_locked_callback(DesktopLockedEvent event, void* context) {
Desktop* desktop = (Desktop*)context;
Expand Down Expand Up @@ -56,7 +55,7 @@ static bool desktop_scene_locked_check_pin(Desktop* desktop, DesktopMainEvent ev
if(match) {
desktop->pincode_buffer.length = 0;
furi_hal_usb_enable();
furi_hal_lock_set(false);
furi_hal_rtc_reset_flag(FuriHalRtcFlagLock);
desktop_main_unlocked(desktop->main_view);
}

Expand Down
3 changes: 1 addition & 2 deletions applications/dolphin/passport/passport.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ int32_t passport_app(void* p) {
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
view_port_update(view_port);

osStatus_t status = osSemaphoreAcquire(semaphore, osWaitForever);
furi_assert(status == osOK);
furi_check(osSemaphoreAcquire(semaphore, osWaitForever) == osOK);

gui_remove_view_port(gui, view_port);
view_port_free(view_port);
Expand Down
28 changes: 26 additions & 2 deletions applications/storage/storages/storage-int.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,36 @@ static LFSData* storage_int_lfs_data_alloc() {
return lfs_data;
};

static bool storage_int_is_fingerprint_valid(LFSData* lfs_data) {
bool value = true;

uint32_t os_fingerprint = 0;
os_fingerprint |= ((lfs_data->start_page & 0xFF) << 0);
os_fingerprint |= ((lfs_data->config.block_count & 0xFF) << 8);
os_fingerprint |= ((LFS_DISK_VERSION_MAJOR & 0xFFFF) << 16);

uint32_t rtc_fingerprint = furi_hal_rtc_get_register(FuriHalRtcRegisterLfsFingerprint);
if(rtc_fingerprint == 0) {
FURI_LOG_I(TAG, "Storing LFS fingerprint in RTC");
furi_hal_rtc_set_register(FuriHalRtcRegisterLfsFingerprint, os_fingerprint);
} else if(rtc_fingerprint != os_fingerprint) {
FURI_LOG_E(TAG, "LFS fingerprint mismatch");
furi_hal_rtc_set_register(FuriHalRtcRegisterLfsFingerprint, os_fingerprint);
value = false;
}

return value;
}

static void storage_int_lfs_mount(LFSData* lfs_data, StorageData* storage) {
int err;
lfs_t* lfs = &lfs_data->lfs;

if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagFactoryReset)) {
// Factory reset
bool need_format = furi_hal_rtc_is_flag_set(FuriHalRtcFlagFactoryReset) ||
!storage_int_is_fingerprint_valid(lfs_data);

if(need_format) {
// Format storage
err = lfs_format(lfs, &lfs_data->config);
if(err == 0) {
FURI_LOG_I(TAG, "Factory reset: Format successful, trying to mount");
Expand Down
8 changes: 4 additions & 4 deletions firmware/targets/f6/furi-hal/furi-hal-bootloader.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <furi-hal-bootloader.h>
#include <stm32wbxx_ll_rtc.h>
#include <furi-hal-rtc.h>
#include <furi.h>

#define TAG "FuriHalBoot"
Expand All @@ -11,15 +11,15 @@

void furi_hal_bootloader_init() {
#ifndef DEBUG
LL_RTC_BAK_SetRegister(RTC, LL_RTC_BKP_DR0, BOOT_REQUEST_TAINTED);
furi_hal_rtc_set_register(FuriHalRtcRegisterBoot, BOOT_REQUEST_TAINTED);
#endif
FURI_LOG_I(TAG, "Init OK");
}

void furi_hal_bootloader_set_mode(FuriHalBootloaderMode mode) {
if (mode == FuriHalBootloaderModeNormal) {
LL_RTC_BAK_SetRegister(RTC, LL_RTC_BKP_DR0, BOOT_REQUEST_CLEAN);
furi_hal_rtc_set_register(FuriHalRtcRegisterBoot, BOOT_REQUEST_CLEAN);
} else if (mode == FuriHalBootloaderModeDFU) {
LL_RTC_BAK_SetRegister(RTC, LL_RTC_BKP_DR0, BOOT_REQUEST_DFU);
furi_hal_rtc_set_register(FuriHalRtcRegisterBoot, BOOT_REQUEST_DFU);
}
}
17 changes: 0 additions & 17 deletions firmware/targets/f6/furi-hal/furi-hal-lock.c

This file was deleted.

45 changes: 28 additions & 17 deletions firmware/targets/f6/furi-hal/furi-hal-rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@

#define TAG "FuriHalRtc"

#define FURI_HAL_RTC_BOOT_FLAGS_REG LL_RTC_BKP_DR0
#define FURI_HAL_RTC_BOOT_VERSION_REG LL_RTC_BKP_DR1
#define FURI_HAL_RTC_SYSTEM_REG LL_RTC_BKP_DR2

typedef struct {
uint8_t log_level:4;
uint8_t log_reserved:4;
uint8_t flags;
uint16_t reserved;
} DeveloperReg;

_Static_assert(sizeof(DeveloperReg) == 4, "DeveloperReg size mismatch");

void furi_hal_rtc_init() {
if(LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_LSE) {
LL_RCC_ForceBackupDomainReset();
Expand All @@ -38,33 +36,46 @@ void furi_hal_rtc_init() {
FURI_LOG_I(TAG, "Init OK");
}

uint32_t furi_hal_rtc_get_register(FuriHalRtcRegister reg) {
return LL_RTC_BAK_GetRegister(RTC, reg);
}

void furi_hal_rtc_set_register(FuriHalRtcRegister reg, uint32_t value) {
LL_RTC_BAK_SetRegister(RTC, reg, value);
}

void furi_hal_rtc_set_log_level(uint8_t level) {
uint32_t data = LL_RTC_BAK_GetRegister(RTC, FURI_HAL_RTC_SYSTEM_REG);
((DeveloperReg*)&data)->log_level = level;
LL_RTC_BAK_SetRegister(RTC, FURI_HAL_RTC_SYSTEM_REG, data);
uint32_t data_reg = furi_hal_rtc_get_register(FuriHalRtcRegisterSystem);
DeveloperReg* data = (DeveloperReg*)&data_reg;
data->log_level = level;
furi_hal_rtc_set_register(FuriHalRtcRegisterSystem, data_reg);
furi_log_set_level(level);
}

uint8_t furi_hal_rtc_get_log_level() {
uint32_t data = LL_RTC_BAK_GetRegister(RTC, FURI_HAL_RTC_SYSTEM_REG);
return ((DeveloperReg*)&data)->log_level;
uint32_t data_reg = furi_hal_rtc_get_register(FuriHalRtcRegisterSystem);
DeveloperReg* data = (DeveloperReg*)&data_reg;
return data->log_level;
}

void furi_hal_rtc_set_flag(FuriHalRtcFlag flag) {
uint32_t data = LL_RTC_BAK_GetRegister(RTC, FURI_HAL_RTC_SYSTEM_REG);
((DeveloperReg*)&data)->flags |= flag;
LL_RTC_BAK_SetRegister(RTC, FURI_HAL_RTC_SYSTEM_REG, data);
uint32_t data_reg = furi_hal_rtc_get_register(FuriHalRtcRegisterSystem);
DeveloperReg* data = (DeveloperReg*)&data_reg;
data->flags |= flag;
furi_hal_rtc_set_register(FuriHalRtcRegisterSystem, data_reg);
}

void furi_hal_rtc_reset_flag(FuriHalRtcFlag flag) {
uint32_t data = LL_RTC_BAK_GetRegister(RTC, FURI_HAL_RTC_SYSTEM_REG);
((DeveloperReg*)&data)->flags &= ~flag;
LL_RTC_BAK_SetRegister(RTC, FURI_HAL_RTC_SYSTEM_REG, data);
uint32_t data_reg = furi_hal_rtc_get_register(FuriHalRtcRegisterSystem);
DeveloperReg* data = (DeveloperReg*)&data_reg;
data->flags &= ~flag;
furi_hal_rtc_set_register(FuriHalRtcRegisterSystem, data_reg);
}

bool furi_hal_rtc_is_flag_set(FuriHalRtcFlag flag) {
uint32_t data = LL_RTC_BAK_GetRegister(RTC, FURI_HAL_RTC_SYSTEM_REG);
return ((DeveloperReg*)&data)->flags & flag;
uint32_t data_reg = furi_hal_rtc_get_register(FuriHalRtcRegisterSystem);
DeveloperReg* data = (DeveloperReg*)&data_reg;
return data->flags & flag;
}

void furi_hal_rtc_set_datetime(FuriHalRtcDateTime* datetime) {
Expand Down
6 changes: 5 additions & 1 deletion firmware/targets/f6/furi-hal/furi-hal-version.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <furi-hal-version.h>
#include <furi-hal-rtc.h>

#include <furi.h>
#include <stm32wbxx.h>
Expand Down Expand Up @@ -193,6 +194,9 @@ void furi_hal_version_init() {
break;
default: furi_crash(NULL);
}

furi_hal_rtc_set_register(FuriHalRtcRegisterSystemVersion, (uint32_t)version_get());

FURI_LOG_I(TAG, "Init OK");
}

Expand Down Expand Up @@ -283,7 +287,7 @@ const struct Version* furi_hal_version_get_bootloader_version(void) {
return 0;
#else
/* Backup register which points to structure in flash memory */
return (const struct Version*)LL_RTC_BAK_GetRegister(RTC, LL_RTC_BKP_DR1);
return (const struct Version*)furi_hal_rtc_get_register(FuriHalRtcRegisterBootVersion);
#endif
}

Expand Down
8 changes: 4 additions & 4 deletions firmware/targets/f7/furi-hal/furi-hal-bootloader.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <furi-hal-bootloader.h>
#include <stm32wbxx_ll_rtc.h>
#include <furi-hal-rtc.h>
#include <furi.h>

#define TAG "FuriHalBoot"
Expand All @@ -11,15 +11,15 @@

void furi_hal_bootloader_init() {
#ifndef DEBUG
LL_RTC_BAK_SetRegister(RTC, LL_RTC_BKP_DR0, BOOT_REQUEST_TAINTED);
furi_hal_rtc_set_register(FuriHalRtcRegisterBoot, BOOT_REQUEST_TAINTED);
#endif
FURI_LOG_I(TAG, "Init OK");
}

void furi_hal_bootloader_set_mode(FuriHalBootloaderMode mode) {
if (mode == FuriHalBootloaderModeNormal) {
LL_RTC_BAK_SetRegister(RTC, LL_RTC_BKP_DR0, BOOT_REQUEST_CLEAN);
furi_hal_rtc_set_register(FuriHalRtcRegisterBoot, BOOT_REQUEST_CLEAN);
} else if (mode == FuriHalBootloaderModeDFU) {
LL_RTC_BAK_SetRegister(RTC, LL_RTC_BKP_DR0, BOOT_REQUEST_DFU);
furi_hal_rtc_set_register(FuriHalRtcRegisterBoot, BOOT_REQUEST_DFU);
}
}
17 changes: 0 additions & 17 deletions firmware/targets/f7/furi-hal/furi-hal-lock.c

This file was deleted.

45 changes: 28 additions & 17 deletions firmware/targets/f7/furi-hal/furi-hal-rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@

#define TAG "FuriHalRtc"

#define FURI_HAL_RTC_BOOT_FLAGS_REG LL_RTC_BKP_DR0
#define FURI_HAL_RTC_BOOT_VERSION_REG LL_RTC_BKP_DR1
#define FURI_HAL_RTC_SYSTEM_REG LL_RTC_BKP_DR2

typedef struct {
uint8_t log_level:4;
uint8_t log_reserved:4;
uint8_t flags;
uint16_t reserved;
} DeveloperReg;

_Static_assert(sizeof(DeveloperReg) == 4, "DeveloperReg size mismatch");

void furi_hal_rtc_init() {
if(LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_LSE) {
LL_RCC_ForceBackupDomainReset();
Expand All @@ -38,33 +36,46 @@ void furi_hal_rtc_init() {
FURI_LOG_I(TAG, "Init OK");
}

uint32_t furi_hal_rtc_get_register(FuriHalRtcRegister reg) {
return LL_RTC_BAK_GetRegister(RTC, reg);
}

void furi_hal_rtc_set_register(FuriHalRtcRegister reg, uint32_t value) {
LL_RTC_BAK_SetRegister(RTC, reg, value);
}

void furi_hal_rtc_set_log_level(uint8_t level) {
uint32_t data = LL_RTC_BAK_GetRegister(RTC, FURI_HAL_RTC_SYSTEM_REG);
((DeveloperReg*)&data)->log_level = level;
LL_RTC_BAK_SetRegister(RTC, FURI_HAL_RTC_SYSTEM_REG, data);
uint32_t data_reg = furi_hal_rtc_get_register(FuriHalRtcRegisterSystem);
DeveloperReg* data = (DeveloperReg*)&data_reg;
data->log_level = level;
furi_hal_rtc_set_register(FuriHalRtcRegisterSystem, data_reg);
furi_log_set_level(level);
}

uint8_t furi_hal_rtc_get_log_level() {
uint32_t data = LL_RTC_BAK_GetRegister(RTC, FURI_HAL_RTC_SYSTEM_REG);
return ((DeveloperReg*)&data)->log_level;
uint32_t data_reg = furi_hal_rtc_get_register(FuriHalRtcRegisterSystem);
DeveloperReg* data = (DeveloperReg*)&data_reg;
return data->log_level;
}

void furi_hal_rtc_set_flag(FuriHalRtcFlag flag) {
uint32_t data = LL_RTC_BAK_GetRegister(RTC, FURI_HAL_RTC_SYSTEM_REG);
((DeveloperReg*)&data)->flags |= flag;
LL_RTC_BAK_SetRegister(RTC, FURI_HAL_RTC_SYSTEM_REG, data);
uint32_t data_reg = furi_hal_rtc_get_register(FuriHalRtcRegisterSystem);
DeveloperReg* data = (DeveloperReg*)&data_reg;
data->flags |= flag;
furi_hal_rtc_set_register(FuriHalRtcRegisterSystem, data_reg);
}

void furi_hal_rtc_reset_flag(FuriHalRtcFlag flag) {
uint32_t data = LL_RTC_BAK_GetRegister(RTC, FURI_HAL_RTC_SYSTEM_REG);
((DeveloperReg*)&data)->flags &= ~flag;
LL_RTC_BAK_SetRegister(RTC, FURI_HAL_RTC_SYSTEM_REG, data);
uint32_t data_reg = furi_hal_rtc_get_register(FuriHalRtcRegisterSystem);
DeveloperReg* data = (DeveloperReg*)&data_reg;
data->flags &= ~flag;
furi_hal_rtc_set_register(FuriHalRtcRegisterSystem, data_reg);
}

bool furi_hal_rtc_is_flag_set(FuriHalRtcFlag flag) {
uint32_t data = LL_RTC_BAK_GetRegister(RTC, FURI_HAL_RTC_SYSTEM_REG);
return ((DeveloperReg*)&data)->flags & flag;
uint32_t data_reg = furi_hal_rtc_get_register(FuriHalRtcRegisterSystem);
DeveloperReg* data = (DeveloperReg*)&data_reg;
return data->flags & flag;
}

void furi_hal_rtc_set_datetime(FuriHalRtcDateTime* datetime) {
Expand Down
Loading

0 comments on commit bb650c4

Please sign in to comment.