Skip to content

Commit fab9068

Browse files
committed
[MOS-786] Added A/B booting support in OS
Added basic support for A/B booting
1 parent 178fba1 commit fab9068

File tree

14 files changed

+67
-65
lines changed

14 files changed

+67
-65
lines changed

.idea/runConfigurations/JLink_server.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ include(AddPackage)
2929
include(AutoModuleOption)
3030
include(AddDirectories)
3131
include(AddDatabases)
32+
include(FetchContent)
3233
include(AddScripts)
3334

3435
message("Selected product: ${PRODUCT}")
@@ -124,6 +125,12 @@ if (NOT ENABLE_SECURE_BOOT)
124125
)
125126
endif ()
126127

128+
FetchContent_Declare(
129+
pure-core
130+
GIT_REPOSITORY [email protected]:mudita/pure-core
131+
)
132+
FetchContent_MakeAvailable(pure-core)
133+
127134
add_subdirectory(board)
128135
add_subdirectory(source)
129136
add_subdirectory(module-platform)

module-apps/application-alarm-clock/widgets/AlarmMusicOptionsItem.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ namespace gui
9393

9494
std::vector<tags::fetcher::Tags> AlarmMusicOptionsItem::getMusicFilesList()
9595
{
96-
const auto musicFolder = (purefs::dir::getSystemDiskPath() / "assets/audio/alarm").string();
96+
const auto musicFolder = (purefs::dir::getAssetsPath() / "audio/alarm").string();
9797
std::vector<tags::fetcher::Tags> musicFiles;
9898
LOG_INFO("Scanning music folder: %s", musicFolder.c_str());
9999
for (const auto &ent : std::filesystem::directory_iterator(musicFolder)) {

module-apps/application-meditation/widgets/MeditationTimer.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ namespace gui
8686
}
8787
void MeditationTimer::playSound()
8888
{
89-
AudioServiceAPI::PlaybackStart(application,
90-
audio::PlaybackType::Meditation,
91-
purefs::dir::getSystemDiskPath() / "assets/audio/meditation/gong.mp3");
89+
AudioServiceAPI::PlaybackStart(
90+
application, audio::PlaybackType::Meditation, purefs::dir::getAssetsPath() / "audio/meditation/gong.mp3");
9291
}
9392
} // namespace gui

module-apps/application-settings/models/apps/SoundsModel.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,16 @@ std::filesystem::path SoundsModel::getSoundPath(audio_settings::AbstractAudioSet
7777
assert(model);
7878
switch (model->getPlaybackType()) {
7979
case audio::PlaybackType::CallRingtone:
80-
return purefs::dir::getSystemDiskPath() / "assets/audio/ringtone";
80+
return purefs::dir::getAssetsPath() / "audio/ringtone";
8181

8282
case audio::PlaybackType::TextMessageRingtone:
83-
return purefs::dir::getSystemDiskPath() / "assets/audio/sms";
83+
return purefs::dir::getAssetsPath() / "audio/sms";
8484

8585
case audio::PlaybackType::Notifications:
86-
return purefs::dir::getSystemDiskPath() / "assets/audio/alarm";
86+
return purefs::dir::getAssetsPath() / "audio/alarm";
8787

8888
default:
89-
return purefs::dir::getSystemDiskPath() / "assets/audio";
89+
return purefs::dir::getAssetsPath() / "audio";
9090
}
9191
}
9292

@@ -97,7 +97,7 @@ void SoundsModel::applyItems(const std::vector<std::filesystem::path> &sounds,
9797
auto currentItemIndex = 0;
9898
auto selectedItemIndex = 0;
9999

100-
std::string selectedSound = purefs::dir::getSystemDiskPath() / model->getSound();
100+
std::string selectedSound = purefs::dir::getAssetsPath() / model->getSound();
101101
for (const auto &sound : sounds) {
102102

103103
bool isSelected = false;

module-services/service-evtmgr/service-evtmgr/EventManagerCommon.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class EventManagerCommon : public sys::Service
5252
static bool messageSetApplication(sys::Service *sender, const std::string &applicationName);
5353

5454
private:
55-
static constexpr auto stackDepth = 1024 * 4;
55+
static constexpr auto stackDepth = 1024 * 5;
5656
void handleMinuteUpdate(time_t timestamp);
5757

5858
void processRTCFromTmRequest(struct tm &newTime);

module-services/service-fileindexer/StartupIndexer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace service::detail
2020
using namespace std::literals;
2121
using namespace std::chrono_literals;
2222

23-
const auto lock_file_name = purefs::dir::getUserDiskPath() / "data" / ".directory_is_indexed";
23+
const auto lock_file_name = purefs::dir::getSystemDiskPath() / "data" / ".directory_is_indexed";
2424
constexpr auto indexing_interval = 50ms;
2525
constexpr auto start_delay = 10000ms;
2626

module-services/service-gui/ServiceGUI.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ namespace service::gui
5353

5454
void ServiceGUI::initAssetManagers()
5555
{
56-
const auto assetsPath = purefs::dir::getSystemDiskPath() / "assets";
57-
::gui::FontManager::getInstance().init(assetsPath);
58-
::gui::ImageManager::getInstance().init(assetsPath);
56+
::gui::FontManager::getInstance().init(purefs::dir::getAssetsPath());
57+
::gui::ImageManager::getInstance().init(purefs::dir::getAssetsPath());
5958
}
6059

6160
void ServiceGUI::registerMessageHandlers()

module-vfs/CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,12 @@ target_link_libraries(module-vfs
123123
module-bsp
124124
module-os
125125
module-utils
126-
PUBLIC
126+
pure-core
127+
128+
PUBLIC
127129
purefs-paths
128130
module-sys
129-
)
131+
)
130132

131133
if (${ENABLE_TESTS})
132134
add_subdirectory(tests)

module-vfs/paths/CMakeLists.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ target_sources(purefs-paths
55
filesystem_paths.cpp
66
include/purefs/filesystem_paths.hpp
77
)
8-
8+
target_link_libraries(purefs-paths
9+
PRIVATE
10+
pure-core
11+
)
912
target_include_directories(purefs-paths
1013
PUBLIC
1114
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>

module-vfs/paths/filesystem_paths.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

44
#include <purefs/filesystem_paths.hpp>
5+
#include <hal/boot_control.h>
56

67
namespace
78
{
@@ -18,6 +19,8 @@ namespace
1819
"media"; // TODO this won't work with our current non-hierarchical MTP implementation
1920
constexpr inline auto PATH_TMP = "tmp";
2021
constexpr inline auto PATH_BACKUP = "backup";
22+
constexpr inline auto PATH_ASSETS = "assets";
23+
2124
} // namespace
2225

2326
namespace purefs
@@ -88,5 +91,13 @@ namespace purefs
8891
{
8992
return getUserDiskPath() / PATH_BACKUP; // TODO is it still needed?
9093
}
94+
std::filesystem::path getBootJSONPath() noexcept
95+
{
96+
return getUserDiskPath() / file::boot_json;
97+
}
98+
std::filesystem::path getAssetsPath() noexcept
99+
{
100+
return getSystemDiskPath() / PATH_ASSETS;
101+
}
91102
} // namespace dir
92103
} // namespace purefs

module-vfs/paths/include/purefs/filesystem_paths.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ namespace purefs
2020
std::filesystem::path getFactoryDBsPath() noexcept;
2121
std::filesystem::path getLogsPath() noexcept;
2222
std::filesystem::path getCrashDumpsPath() noexcept;
23+
std::filesystem::path getBootJSONPath() noexcept;
24+
std::filesystem::path getAssetsPath() noexcept;
25+
2326
std::filesystem::path getUserMediaPath() noexcept;
2427
std::filesystem::path getTemporaryPath() noexcept;
2528
std::filesystem::path getBackupOSPath() noexcept;

module-vfs/src/purefs/vfs_subsystem.cpp

+24-47
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <purefs/blkdev/disk_manager.hpp>
99
#include <purefs/vfs_subsystem.hpp>
1010
#include <purefs/vfs_subsystem_internal.hpp>
11+
#include <hal/boot_reason.h>
12+
#include <hal/boot_control.h>
1113
#include <purefs/fs/thread_local_cwd.hpp>
1214
#include <log/log.hpp>
1315
#include <purefs/filesystem_paths.hpp>
@@ -40,30 +42,6 @@ namespace purefs::subsystem
4042
std::weak_ptr<fs::filesystem> g_fs_core;
4143
} // namespace
4244

43-
namespace
44-
{
45-
int read_mbr_lfs_erase_size(std::shared_ptr<blkdev::disk_manager> disk_mngr,
46-
std::string_view dev_name,
47-
int part_no)
48-
{
49-
static constexpr auto MBR_ERASE_BLK_OFFSET = 0x00E0;
50-
if (part_no <= 0) {
51-
return -EINVAL;
52-
}
53-
const auto sect_size = disk_mngr->get_info(dev_name, blkdev::info_type::sector_size);
54-
if (sect_size <= MBR_ERASE_BLK_OFFSET + part_no) {
55-
return (sect_size > 0) ? (-ERANGE) : (sect_size);
56-
}
57-
auto mbr_buf = std::make_unique<char[]>(sect_size);
58-
int err = disk_mngr->read(dev_name, mbr_buf.get(), 0, 1);
59-
if (err < 0) {
60-
return err;
61-
}
62-
return mbr_buf[MBR_ERASE_BLK_OFFSET + part_no];
63-
}
64-
65-
} // namespace
66-
6745
auto initialize(std::unique_ptr<DeviceFactory> deviceFactory)
6846
-> std::tuple<std::shared_ptr<blkdev::disk_manager>, std::shared_ptr<fs::filesystem>>
6947
{
@@ -128,8 +106,24 @@ namespace purefs::subsystem
128106
LOG_FATAL("Unknown partitions layout part size is %u", (unsigned)(parts.size()));
129107
return -EIO;
130108
}
131-
const auto &boot_part = parts[boot_part_index];
109+
110+
auto vfs = g_fs_core.lock();
111+
if (!vfs) {
112+
LOG_FATAL("Unable to lock vfs core");
113+
return -EIO;
114+
}
115+
132116
const auto &user_part = parts[user_part_index];
117+
118+
vfs->mount(user_part.name, purefs::dir::getUserDiskPath().string(), "auto");
119+
120+
auto ret = boot_control_init(purefs::dir::getBootJSONPath().string().c_str());
121+
if (ret != 0) {
122+
LOG_FATAL("Unable to init boot.json handling");
123+
return -ENOENT;
124+
}
125+
126+
const auto &boot_part = parts[(get_current_slot() == Slot_A) ? 0 : 1];
133127
if ((boot_part.type != fat_part_code) && (boot_part.type != linux_part_code)) {
134128
LOG_FATAL("Invalid boot partition type expected code: %02X or %02X current code: %02X",
135129
fat_part_code,
@@ -142,38 +136,21 @@ namespace purefs::subsystem
142136
"Invalid user partition type expected code: %02X current code: %02X", linux_part_code, user_part.type);
143137
return -EIO;
144138
}
145-
auto vfs = g_fs_core.lock();
146-
if (!vfs) {
147-
LOG_FATAL("Unable to lock vfs core");
148-
return -EIO;
149-
}
139+
150140
auto err = vfs->mount(boot_part.name, purefs::dir::getSystemDiskPath().string(), "auto");
151-
if (err) {
141+
if (err != 0) {
152142
return err;
153143
}
154-
if (user_part.type == lfs_part_code) {
155-
const int lfs_block_log2 = read_mbr_lfs_erase_size(disk, default_blkdev_name, user_part.physical_number);
156-
uint32_t lfs_block_size = 0;
157-
uint32_t *lfs_block_size_ptr = nullptr;
158-
if (lfs_block_log2 >= block_size_min_shift && lfs_block_log2 <= block_size_max_shift) {
159-
lfs_block_size = 1U << lfs_block_log2;
160-
lfs_block_size_ptr = &lfs_block_size;
161-
}
162-
err =
163-
vfs->mount(user_part.name, purefs::dir::getUserDiskPath().string(), "littlefs", 0, lfs_block_size_ptr);
164-
}
165-
else {
166-
err = vfs->mount(user_part.name, purefs::dir::getUserDiskPath().string(), "ext4");
167-
}
168-
fs::internal::set_default_thread_cwd(dir::getSystemDiskPath().string());
144+
145+
fs::internal::set_default_thread_cwd(purefs::dir::getSystemDiskPath().string());
169146

170147
// Mount NVRAM memory
171148
err = vfs->mount(default_nvrom_name,
172149
purefs::dir::getMfgConfPath().c_str(),
173150
"littlefs",
174151
fs::mount_flags::read_only,
175152
&nvrom_lfs_block_size);
176-
if (err) {
153+
if (err != 0) {
177154
LOG_WARN("Unable to mount NVROM partition err %i. Possible: NVROM unavailable", err);
178155
err = 0;
179156
}

products/BellHybrid/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ target_link_libraries(BellHybrid
6565
bell::time
6666
platform
6767
version-header
68+
pure-core
6869
"$<$<STREQUAL:${PROJECT_TARGET},TARGET_Linux>:iosyscalls>"
6970
"$<$<STREQUAL:${PROJECT_TARGET},TARGET_RT1051>:CrashCatcher::CrashCatcher>"
7071
)

0 commit comments

Comments
 (0)