From 124b6cb6c1ffed03f06b5054ba0910f09d1a1329 Mon Sep 17 00:00:00 2001 From: Lucjan Bryndza Date: Fri, 16 Apr 2021 15:20:39 +0200 Subject: [PATCH] [EGD-6558] Add automount mechanism of the mfgconf Add optional mounting nfgconf partition on the EEPROM with the LFS filesystem for the manufacturing data. Signed-off-by: Lucjan Bryndza --- CMakeLists.txt | 8 ++++++ image/CMakeLists.txt | 1 + image/personalization.json | 9 +++++++ .../src/purefs/fs/filesystem_littlefs.cpp | 2 +- .../include/user/purefs/filesystem_paths.hpp | 3 ++- module-vfs/src/purefs/filesystem_paths.cpp | 9 ++++++- module-vfs/src/purefs/vfs_subsystem.cpp | 25 ++++++++++++++++++- 7 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 image/personalization.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 57f17881a448a05f00d9f2acec888b2234002ed9..1658232fc1ba7744eb89cc3ef5a47e3ccf0b55c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -379,6 +379,14 @@ if (${PROJECT_TARGET} STREQUAL "TARGET_Linux") -C ${PACKAGE_STAGING_DIRECTORY}/Standalone "." DEPENDS package-standalone-staged ) + add_custom_target( + eeprom_image ALL + DEPENDS genlittlefs + DEPENDS assets + COMMAND ${CMAKE_BINARY_DIR}/genlittlefs -b 128 -s 32768 --overwrite --image ${CMAKE_BINARY_DIR}/eeprom.img ${CMAKE_BINARY_DIR}/sys/personalization.json + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMENT "Generate eeprom image" + ) endif() if (${PROJECT_TARGET} STREQUAL "TARGET_RT1051") diff --git a/image/CMakeLists.txt b/image/CMakeLists.txt index cf7d28739208205f974ef4f4e0ccdcba5a039c33..3e58b891c10f943a9e4e5536de8bb811d6614300 100644 --- a/image/CMakeLists.txt +++ b/image/CMakeLists.txt @@ -7,6 +7,7 @@ add_custom_target( assets COMMAND rsync -ravu --delete ${ASSETS_SOURCE_DIR}/.boot.json* + ${ASSETS_SOURCE_DIR}/personalization.json ${ASSETS_DEST_DIR} COMMAND rsync -ravu --delete ${ASSETS_SOURCE_DIR}/assets diff --git a/image/personalization.json b/image/personalization.json new file mode 100644 index 0000000000000000000000000000000000000000..7808e29b027ca8fcc357e2f8f456f6bfa6a58483 --- /dev/null +++ b/image/personalization.json @@ -0,0 +1,9 @@ +{ + "serial" : "00000000000000", + "case_colour" : "nocase", + "pcb_mb_version" : "0v0", + "pcb_um_version" : "0v0", + "pcb_lm_version" : "0v0", + "pcb_am_version" : "0v0", + "battery_revision" : "0v0" +} diff --git a/module-vfs/drivers/src/purefs/fs/filesystem_littlefs.cpp b/module-vfs/drivers/src/purefs/fs/filesystem_littlefs.cpp index 46694d3874cc2d769b1fca738c0c9fb2935531fd..e3b4507ccc54889ed837672e314cc60947c682b6 100644 --- a/module-vfs/drivers/src/purefs/fs/filesystem_littlefs.cpp +++ b/module-vfs/drivers/src/purefs/fs/filesystem_littlefs.cpp @@ -134,7 +134,7 @@ namespace return -ERANGE; } cfg->block_count = total_siz / cfg->block_size - 1; - cfg->lookahead_size = std::min(131072, cfg->block_count); + cfg->lookahead_size = std::min(131072U, ((cfg->block_count >> 3U) + 1U) << 3U); cfg->read_size = cfg->block_size; cfg->prog_size = cfg->block_size; cfg->cache_size = cfg->block_size; diff --git a/module-vfs/include/user/purefs/filesystem_paths.hpp b/module-vfs/include/user/purefs/filesystem_paths.hpp index 4e3847e65cc9661c9bec9dcdeb882470041d9517..fdd4097771bbbbc00da1deef1dc609bc030861d3 100644 --- a/module-vfs/include/user/purefs/filesystem_paths.hpp +++ b/module-vfs/include/user/purefs/filesystem_paths.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -12,6 +12,7 @@ namespace purefs namespace dir { std::filesystem::path getRootDiskPath() noexcept; + std::filesystem::path getMfgConfPath() noexcept; std::filesystem::path getUserDiskPath() noexcept; std::filesystem::path getCurrentOSPath() noexcept; std::filesystem::path getPreviousOSPath() noexcept; diff --git a/module-vfs/src/purefs/filesystem_paths.cpp b/module-vfs/src/purefs/filesystem_paths.cpp index 4b04e3d57db8efe5e64f86310347c1dcb2541e67..ba502b304c5379afbc4985a41fd123550f015958 100644 --- a/module-vfs/src/purefs/filesystem_paths.cpp +++ b/module-vfs/src/purefs/filesystem_paths.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include @@ -6,6 +6,7 @@ namespace { constexpr inline auto PATH_SYS = "/sys"; + constexpr inline auto PATH_CONF = "/mfgconf"; constexpr inline auto PATH_USER = "user"; constexpr inline auto PATH_CURRENT = "current"; constexpr inline auto PATH_PREVIOUS = "previous"; @@ -29,6 +30,12 @@ namespace purefs { return std::filesystem::path{eMMC_disk}; } + + std::filesystem::path getMfgConfPath() noexcept + { + return std::filesystem::path{PATH_CONF}; + } + std::filesystem::path getUserDiskPath() noexcept { return std::filesystem::path{eMMC_disk} / PATH_USER; diff --git a/module-vfs/src/purefs/vfs_subsystem.cpp b/module-vfs/src/purefs/vfs_subsystem.cpp index 3c3ee90678bf44026af7b389ca2b19d33122968c..3c2263c06254c1f9109db04a587a67744d2f6eee 100644 --- a/module-vfs/src/purefs/vfs_subsystem.cpp +++ b/module-vfs/src/purefs/vfs_subsystem.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include @@ -19,6 +19,7 @@ namespace purefs::subsystem namespace { constexpr auto default_blkdev_name = "emmc0"; + constexpr auto default_nvrom_name = "nvrom0"; constexpr auto fat_part_code = 0x0b; constexpr auto lfs_part_code = 0x9e; constexpr auto old_layout_part_count = 2; @@ -26,6 +27,7 @@ namespace purefs::subsystem constexpr auto boot_size_limit = 16384L; constexpr auto block_size_max_shift = 21; constexpr auto block_size_min_shift = 8; + constexpr uint32_t nvrom_lfs_block_size = 128U; namespace json { constexpr auto os_type = "ostype"; @@ -123,6 +125,16 @@ namespace purefs::subsystem LOG_FATAL("Unable to register block device with error %i", err); return {}; } + const auto nvrom_bdev = internal::create_default_nvm_device(); + if (nvrom_bdev) { + err = disk_mgr->register_device(nvrom_bdev, default_nvrom_name, blkdev::flags::no_parts_scan); + if (err) { + LOG_WARN("Unable to register NVROM device err %i. Maybe running on rev>T7", err); + } + } + else { + LOG_WARN("No NVROM driver available for this platform"); + } auto fs_core = std::make_shared(disk_mgr); err = fs_core->register_filesystem("vfat", std::make_shared()); if (err) { @@ -207,6 +219,17 @@ namespace purefs::subsystem const auto boot_dir_name = parse_boot_json_directory(json_file); const auto user_dir = (dir::getRootDiskPath() / boot_dir_name).string(); fs::internal::set_default_thread_cwd(user_dir); + + // Mount NVRAM memory + err = vfs->mount(default_nvrom_name, + purefs::dir::getMfgConfPath().c_str(), + "littlefs", + fs::mount_flags::read_only, + &nvrom_lfs_block_size); + if (err) { + LOG_WARN("Unable to mount NVROM partition err %i. Maybe running on rev>T7", err); + err = 0; + } return err; }