~aleteoryx/muditaos

ref: f56609aa3b5fad0701ed91adc4c375a7737bdc7e muditaos/module-utils/bootconfig/include/boot/bootconfig.hpp -rw-r--r-- 1.8 KiB
f56609aa — Lucjan Bryndza [EGD-4502] Fix and remove old vfs boot 5 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once
#include <module-utils/json/json11.hpp>
#include <string>
#include <filesystem>

namespace boot
{
    class BootConfig
    {
      public:
        BootConfig();
        static int version_compare(const std::string &v1, const std::string &v2);
        [[nodiscard]] json11::Json to_json() const;
        int load();
        int save();
        auto os_image() -> const std::string &
        {
            return m_os_image;
        }
        auto os_type() -> const std::string &
        {
            return m_os_type;
        }
        auto os_version() -> const std::string &
        {
            return m_os_version;
        }
        auto bootloader_version() -> const std::string &
        {
            return m_bootloader_version;
        }
        auto timestamp() -> const std::string &
        {
            return m_timestamp;
        }
        auto os_root_path() -> const std::filesystem::path &
        {
            return m_os_root_path;
        }
        void updateTimestamp();

      private:
        bool loadBootConfig(const std::filesystem::path &bootJsonPath);
        const std::filesystem::path getCurrentBootJSON();
        bool verifyCRC(const std::filesystem::path filePath);
        bool verifyCRC(const std::string filePath, const unsigned long crc32);

      private:
        std::string m_os_image{"boot.bin"};
        std::string m_os_type{"current"};
        std::string m_os_version;
        std::string m_bootloader_version;
        std::string m_timestamp;
        json11::Json m_boot_json_parsed;
        std::filesystem::path m_os_root_path;
        std::filesystem::path m_boot_json;
    };
} // namespace boot