~aleteoryx/muditaos

afd7e7bc2c5d80383207e58f447dc21a5a187e02 — Lefucjusz 3 years ago 01857dd
[MOS-783] Working Pure simulator after partition changes

Fixed iosyscalls so that Pure simulator
works after directory structure changes.
M board/linux/libiosyscalls/src/iosyscalls.cpp => board/linux/libiosyscalls/src/iosyscalls.cpp +20 -30
@@ 23,13 23,14 @@ namespace
    constexpr auto ENV_NAME       = "IOSYSCALLS_REDIRECT_TO_IMAGE";
    constexpr auto FIRST_FILEDESC = 64'566'756;
    constexpr auto SYSROOT        = "sysroot";
    constexpr auto SYSTEM_PARTITION = "system_a";
    constexpr auto SYSTEM_DATA_DIR  = "data";
    bool g_evaluated              = false;
    bool g_redirect               = false;

    constexpr const char *LINUX_PATHS[]{
        "/dev/", "/etc/", "/lib", "/usr/share", "/run/user", "/home", "/proc", "/tmp", "MuditaOS.log", nullptr};

    constexpr const char *IMAGE_PATHS[]{"/sys", "/mfgconf", "sys", "assets", "country-codes.db", "Luts.bin", nullptr};
    constexpr auto LINUX_PATHS = {
        "/dev/", "/etc/", "/lib", "/usr/share", "/run/user", "/home", "/proc", "/tmp", "MuditaOS.log"};
    constexpr auto IMAGE_PATHS = {"/system", "/mfgconf", "/user"};

    pthread_mutex_t g_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
    phmap::flat_hash_set<vfsn::linux::internal::FILEX *> g_fdlist;


@@ 70,8 71,8 @@ namespace vfsn::linux::internal
            return false;
        }

        for (auto path = LINUX_PATHS; *path; ++path) {
            if (std::strstr(inpath, *path) == inpath) {
        for (const auto &path : LINUX_PATHS) {
            if (std::strstr(inpath, path) == inpath) {
                return false;
            }
        }


@@ 83,35 84,24 @@ namespace vfsn::linux::internal
    {
        const auto inputPath = std::string(inpath);

        for (auto path = IMAGE_PATHS; *path != 0; ++path) {
            if (std::strstr(inpath, *path) == inpath) {
                std::string outpath;
        for (const auto &path : IMAGE_PATHS) {
            if (std::strstr(inpath, path) == inpath) {
                std::string outpath   = sysroot;
                const auto pathLength = std::strlen(path);

                if (std::strcmp(*path, "/mfgconf") == 0) {
                    outpath = sysroot;
                    outpath += "/sys/";
                    outpath += inputPath;
                if (std::strcmp(path, "/mfgconf") == 0) {
                    outpath += "/";
                    outpath += SYSTEM_PARTITION;
                    outpath += "/";
                    outpath += SYSTEM_DATA_DIR;
                    outpath += inputPath.substr(pathLength);
                }
                else if (std::strcmp(*path, "sys") == 0) {
                    outpath = sysroot;
                else if (std::strcmp(path, "/system") == 0) {
                    outpath += "/";
                    outpath += inputPath;
                    outpath += SYSTEM_PARTITION;
                    outpath += inputPath.substr(pathLength);
                }
                else if (*inpath == '/') {
                    constexpr auto os_path    = "/sys/os";
                    const auto os_path_length = strlen(os_path);
                    if (std::strncmp(inpath, os_path, os_path_length) == 0) {
                        outpath = sysroot;
                        outpath += "/sys";
                        outpath += inputPath.substr(os_path_length);
                    }
                    else {
                        outpath = sysroot + inputPath;
                    }
                }
                else {
                    outpath = sysroot;
                    outpath += "/sys/current/";
                    outpath += inputPath;
                }


M cmake/modules/AddVersionJson.cmake => cmake/modules/AddVersionJson.cmake +2 -0
@@ 25,6 25,7 @@ function(add_version_rt1051_json SOURCE_TARGET)
    )

    add_custom_command(OUTPUT add-${SOURCE_TARGET}-version.json
        COMMAND mkdir -p ${CMAKE_BINARY_DIR}/sysroot/system_a
        COMMAND rsync -qravu
            ${CMAKE_BINARY_DIR}/${SOURCE_TARGET}-version.json
            ${CMAKE_BINARY_DIR}/sysroot/system_a/version.json


@@ 52,6 53,7 @@ function(add_version_linux_json SOURCE_TARGET)
    )

    add_custom_command(OUTPUT add-${SOURCE_TARGET}-version.json
        COMMAND mkdir -p ${CMAKE_BINARY_DIR}/sysroot/system_a
        COMMAND rsync -qravu
            ${CMAKE_BINARY_DIR}/${SOURCE_TARGET}-version.json
            ${CMAKE_BINARY_DIR}/sysroot/system_a/version.json

M module-apps/application-alarm-clock/widgets/AlarmMusicOptionsItem.cpp => module-apps/application-alarm-clock/widgets/AlarmMusicOptionsItem.cpp +1 -1
@@ 93,7 93,7 @@ namespace gui

    std::vector<tags::fetcher::Tags> AlarmMusicOptionsItem::getMusicFilesList()
    {
        const auto musicFolder = (purefs::dir::getAssetsPath() / "audio/alarm").string();
        const auto musicFolder = (purefs::dir::getAssetsDirPath() / "audio/alarm").string();
        std::vector<tags::fetcher::Tags> musicFiles;
        LOG_INFO("Scanning music folder: %s", musicFolder.c_str());
        for (const auto &ent : std::filesystem::directory_iterator(musicFolder)) {

M module-apps/application-meditation/widgets/MeditationTimer.cpp => module-apps/application-meditation/widgets/MeditationTimer.cpp +3 -2
@@ 86,7 86,8 @@ namespace gui
    }
    void MeditationTimer::playSound()
    {
        AudioServiceAPI::PlaybackStart(
            application, audio::PlaybackType::Meditation, purefs::dir::getAssetsPath() / "audio/meditation/gong.mp3");
        AudioServiceAPI::PlaybackStart(application,
                                       audio::PlaybackType::Meditation,
                                       purefs::dir::getAssetsDirPath() / "audio/meditation/gong.mp3");
    }
} // namespace gui

M module-apps/application-onboarding/ApplicationOnBoarding.cpp => module-apps/application-onboarding/ApplicationOnBoarding.cpp +3 -1
@@ 143,7 143,9 @@ namespace app
                                  return std::make_unique<app::onBoarding::StartConfigurationWindow>(app);
                              });
        windowsFactory.attach(gui::window::name::onBoarding_eula, [&](ApplicationCommon *app, const std::string &name) {
            auto eulaRepository = std::make_unique<app::onBoarding::EULARepository>("data/licenses", "eula.txt");
            const auto eulaDirPath  = purefs::dir::getDataDirPath() / "licenses";
            const auto eulaFilename = "eula.txt";
            auto eulaRepository     = std::make_unique<app::onBoarding::EULARepository>(eulaDirPath, eulaFilename);
            auto presenter      = std::make_unique<app::onBoarding::EULALicenseWindowPresenter>([&]() { acceptEULA(); },
                                                                                           std::move(eulaRepository));
            return std::make_unique<app::onBoarding::EULALicenseWindow>(app, std::move(presenter));

M module-apps/application-settings/models/apps/SoundsModel.cpp => module-apps/application-settings/models/apps/SoundsModel.cpp +5 -5
@@ 77,16 77,16 @@ std::filesystem::path SoundsModel::getSoundPath(audio_settings::AbstractAudioSet
    assert(model);
    switch (model->getPlaybackType()) {
    case audio::PlaybackType::CallRingtone:
        return purefs::dir::getAssetsPath() / "audio/ringtone";
        return purefs::dir::getAssetsDirPath() / "audio/ringtone";

    case audio::PlaybackType::TextMessageRingtone:
        return purefs::dir::getAssetsPath() / "audio/sms";
        return purefs::dir::getAssetsDirPath() / "audio/sms";

    case audio::PlaybackType::Notifications:
        return purefs::dir::getAssetsPath() / "audio/alarm";
        return purefs::dir::getAssetsDirPath() / "audio/alarm";

    default:
        return purefs::dir::getAssetsPath() / "audio";
        return purefs::dir::getAssetsDirPath() / "audio";
    }
}



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

    std::string selectedSound = purefs::dir::getAssetsPath() / model->getSound();
    std::string selectedSound = purefs::dir::getAssetsDirPath() / model->getSound();
    for (const auto &sound : sounds) {

        bool isSelected = false;

M module-audio/Audio/Profiles/ProfilePlaybackHeadphones.hpp => module-audio/Audio/Profiles/ProfilePlaybackHeadphones.hpp +1 -1
@@ 14,7 14,7 @@ namespace audio
            : Profile(
                  "Playback Headphones",
                  Type::PlaybackHeadphones,
                  purefs::dir::getSystemDiskPath() / "data/equalizer/headphones_playback.json",
                  purefs::dir::getDataDirPath() / "equalizer/headphones_playback.json",
                  audio::codec::Configuration{
                      .sampleRate_Hz = 0,
                      .bitWidth      = 16,

M module-audio/Audio/Profiles/ProfilePlaybackLoudspeaker.hpp => module-audio/Audio/Profiles/ProfilePlaybackLoudspeaker.hpp +1 -1
@@ 15,7 15,7 @@ namespace audio
            : Profile(
                  "Playback Loudspeaker",
                  Type::PlaybackLoudspeaker,
                  purefs::dir::getSystemDiskPath() / "data/equalizer/loudspeaker_playback.json",
                  purefs::dir::getDataDirPath() / "equalizer/loudspeaker_playback.json",
                  audio::codec::Configuration{
                      .sampleRate_Hz     = 0,
                      .bitWidth          = 16,

M module-audio/Audio/Profiles/ProfileRoutingEarspeaker.hpp => module-audio/Audio/Profiles/ProfileRoutingEarspeaker.hpp +1 -1
@@ 14,7 14,7 @@ namespace audio
            : Profile(
                  "Routing Earspeaker",
                  Type::RoutingEarspeaker,
                  purefs::dir::getSystemDiskPath() / "data/equalizer/earspeaker_routing.json",
                  purefs::dir::getDataDirPath() / "equalizer/earspeaker_routing.json",
                  audio::codec::Configuration{
                      .sampleRate_Hz = 16000,
                      .bitWidth      = 16,

M module-audio/Audio/Profiles/ProfileRoutingHeadphones.hpp => module-audio/Audio/Profiles/ProfileRoutingHeadphones.hpp +1 -1
@@ 14,7 14,7 @@ namespace audio
            : Profile(
                  "Routing Headset",
                  Type::RoutingHeadphones,
                  purefs::dir::getSystemDiskPath() / "data/equalizer/headphones_routing.json",
                  purefs::dir::getDataDirPath() / "equalizer/headphones_routing.json",
                  audio::codec::Configuration{
                      .sampleRate_Hz = 16000,
                      .bitWidth      = 16,

M module-audio/Audio/Profiles/ProfileRoutingLoudspeaker.hpp => module-audio/Audio/Profiles/ProfileRoutingLoudspeaker.hpp +1 -1
@@ 15,7 15,7 @@ namespace audio
        ProfileRoutingLoudspeaker(Volume volume, Gain gain)
            : Profile("Routing Speakerphone",
                      Type::RoutingLoudspeaker,
                      purefs::dir::getSystemDiskPath() / "data/equalizer/loudspeaker_routing.json",
                      purefs::dir::getDataDirPath() / "equalizer/loudspeaker_routing.json",
                      audio::codec::Configuration{
                          .sampleRate_Hz = sampleRate,
                          .bitWidth      = 16,

M module-bsp/board/rt1051/bsp/eink/EinkDisplay.cpp => module-bsp/board/rt1051/bsp/eink/EinkDisplay.cpp +1 -1
@@ 31,7 31,7 @@ namespace hal::eink
        constexpr auto LUTTemperatureOffsetSubcritical = 12;
        constexpr auto LUTTemperatureOffsetCritical    = 13;

        const auto LutsFilePath = purefs::dir::getSystemDiskPath() / "assets" / "Luts.bin";
        const auto LutsFilePath = purefs::dir::getAssetsDirPath() / "luts.bin";

        EinkWaveformSettings_t createDefaultWaveFormSettings(EinkWaveforms_e waveformMode)
        {

M module-services/service-gui/ServiceGUI.cpp => module-services/service-gui/ServiceGUI.cpp +2 -2
@@ 53,8 53,8 @@ namespace service::gui

    void ServiceGUI::initAssetManagers()
    {
        ::gui::FontManager::getInstance().init(purefs::dir::getAssetsPath());
        ::gui::ImageManager::getInstance().init(purefs::dir::getAssetsPath());
        ::gui::FontManager::getInstance().init(purefs::dir::getAssetsDirPath());
        ::gui::ImageManager::getInstance().init(purefs::dir::getAssetsDirPath());
    }

    void ServiceGUI::registerMessageHandlers()

M module-utils/i18n/i18nImpl.hpp => module-utils/i18n/i18nImpl.hpp +4 -2
@@ 11,6 11,8 @@
#include <json11.hpp>
#include <i18n/i18n.hpp>

#include <purefs/filesystem_paths.hpp>

namespace utils
{
    class i18n


@@ 25,8 27,8 @@ namespace utils
        Language inputLanguage        = fallbackLanguageName;
        Language inputLanguageFilename;
        Language currentDisplayLanguage;
        std::filesystem::path InputLanguageDirPath   = "data/profiles";
        std::filesystem::path DisplayLanguageDirPath = "data/lang";
        std::filesystem::path InputLanguageDirPath   = purefs::dir::getDataDirPath() / "profiles";
        std::filesystem::path DisplayLanguageDirPath = purefs::dir::getDataDirPath() / "lang";
        cpp_freertos::MutexStandard mutex;
        std::vector<LanguageMetadata> metadata;


M module-vfs/paths/filesystem_paths.cpp => module-vfs/paths/filesystem_paths.cpp +10 -9
@@ 10,17 10,16 @@ namespace
    constexpr inline auto PATH_USER         = "/user";
    constexpr inline auto PATH_CONF         = "/mfgconf";
    constexpr inline auto PATH_DB           = "db";
    constexpr inline auto PATH_FACTORY      = "factory";
    constexpr inline auto PATH_UPDATE       = "update";
    constexpr inline auto PATH_SYNC         = "sync";
    constexpr inline auto PATH_LOGS         = "logs";
    constexpr inline auto PATH_LOGS         = "log";
    constexpr inline auto PATH_CRASH_DUMPS  = "crash_dumps";
    constexpr inline auto PATH_USER_MEDIA =
        "media"; // TODO this won't work with our current non-hierarchical MTP implementation
    constexpr inline auto PATH_TMP    = "tmp";
    constexpr inline auto PATH_BACKUP = "backup";
    constexpr inline auto PATH_ASSETS  = "assets";

    constexpr inline auto PATH_DATA    = "data";
} // namespace

namespace purefs


@@ 62,11 61,6 @@ namespace purefs
            return getUserDiskPath() / PATH_SYNC; // TODO what's this?
        }

        std::filesystem::path getFactoryDBsPath() noexcept
        {
            return getDatabasesPath() / PATH_FACTORY; // TODO this might not be required in OS
        }

        std::filesystem::path getLogsPath() noexcept
        {
            return getSystemDiskPath() / PATH_LOGS;


@@ 91,13 85,20 @@ namespace purefs
        {
            return getUserDiskPath() / PATH_BACKUP; // TODO is it still needed?
        }

        std::filesystem::path getBootJSONPath() noexcept
        {
            return getUserDiskPath() / file::boot_json;
        }
        std::filesystem::path getAssetsPath() noexcept

        std::filesystem::path getAssetsDirPath() noexcept
        {
            return getSystemDiskPath() / PATH_ASSETS;
        }

        std::filesystem::path getDataDirPath() noexcept
        {
            return getSystemDiskPath() / PATH_DATA;
        }
    } // namespace dir
} // namespace purefs

M module-vfs/paths/include/purefs/filesystem_paths.hpp => module-vfs/paths/include/purefs/filesystem_paths.hpp +3 -4
@@ 17,15 17,14 @@ namespace purefs
        std::filesystem::path getDatabasesPath() noexcept;
        std::filesystem::path getUpdateDirPath() noexcept;
        std::filesystem::path getSyncPackagePath() noexcept;
        std::filesystem::path getFactoryDBsPath() noexcept;
        std::filesystem::path getLogsPath() noexcept;
        std::filesystem::path getCrashDumpsPath() noexcept;
        std::filesystem::path getBootJSONPath() noexcept;
        std::filesystem::path getAssetsPath() noexcept;

        std::filesystem::path getUserMediaPath() noexcept;
        std::filesystem::path getTemporaryPath() noexcept;
        std::filesystem::path getBackupOSPath() noexcept;
        std::filesystem::path getBootJSONPath() noexcept;
        std::filesystem::path getAssetsDirPath() noexcept;
        std::filesystem::path getDataDirPath() noexcept;
    } // namespace dir

    namespace file

M module-vfs/src/purefs/vfs_subsystem.cpp => module-vfs/src/purefs/vfs_subsystem.cpp +7 -3
@@ 115,11 115,15 @@ namespace purefs::subsystem

        const auto &user_part = parts[user_part_index];

        vfs->mount(user_part.name, purefs::dir::getUserDiskPath().string(), "auto");
        auto ret = vfs->mount(user_part.name, purefs::dir::getUserDiskPath().string(), "auto");
        if (ret != 0) {
            LOG_FATAL("Failed to mount user partition on '%s'!", purefs::dir::getUserDiskPath().c_str());
            return -EIO;
        }

        auto ret = boot_control_init(purefs::dir::getBootJSONPath().string().c_str());
        ret = boot_control_init(purefs::dir::getBootJSONPath().string().c_str());
        if (ret != 0) {
            LOG_FATAL("Unable to init boot.json handling");
            LOG_FATAL("Unable to init boot.json handling!");
            return -ENOENT;
        }


M products/PurePhone/assets/assets_rt1051.json => products/PurePhone/assets/assets_rt1051.json +1 -1
@@ 4,7 4,7 @@
        {
            "name": "image/Luts.bin.tgz",
            "tarfile": "Luts.bin",
            "output": "Luts.bin",
            "output": "luts.bin",
            "unpack": true
        }
    ]