From ecbd986529489315eb55d6e9b326aa44ea35a106 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sat, 27 Jun 2020 07:33:36 -0700 Subject: [PATCH] sysupdater: minor api fixes (now verified working on hardware) --- .../ncm/ncm_content_meta_extended_data.hpp | 6 ++--- stratosphere/ams_mitm/ams_mitm.json | 2 ++ .../source/sysupdater/sysupdater_fs_utils.cpp | 22 +++++++++++++++---- .../source/sysupdater/sysupdater_service.cpp | 4 ++-- .../source/sysupdater/sysupdater_service.hpp | 4 ++-- 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_meta_extended_data.hpp b/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_meta_extended_data.hpp index 2f997f174..ee9348418 100644 --- a/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_meta_extended_data.hpp +++ b/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_meta_extended_data.hpp @@ -318,12 +318,12 @@ namespace ams::ncm { return reinterpret_cast(this->data); } - uintptr_t GetFirmwarVariationIdStartAddress() const { + uintptr_t GetFirmwareVariationIdStartAddress() const { return this->GetHeaderAddress() + sizeof(SystemUpdateMetaExtendedDataHeader); } uintptr_t GetFirmwareVariationIdAddress(size_t i) const { - return this->GetFirmwarVariationIdStartAddress() + i * sizeof(FirmwareVariationId); + return this->GetFirmwareVariationIdStartAddress() + i * sizeof(FirmwareVariationId); } uintptr_t GetFirmwareVariationInfoStartAddress() const { @@ -331,7 +331,7 @@ namespace ams::ncm { } uintptr_t GetFirmwareVariationInfoAddress(size_t i) const { - return this->GetFirmwarVariationIdStartAddress() + i * sizeof(FirmwareVariationInfo); + return this->GetFirmwareVariationInfoStartAddress() + i * sizeof(FirmwareVariationInfo); } uintptr_t GetContentMetaInfoStartAddress() const { diff --git a/stratosphere/ams_mitm/ams_mitm.json b/stratosphere/ams_mitm/ams_mitm.json index 431a1f5f0..c78327d05 100644 --- a/stratosphere/ams_mitm/ams_mitm.json +++ b/stratosphere/ams_mitm/ams_mitm.json @@ -62,6 +62,8 @@ "svcReplyAndReceive": "0x43", "svcReplyAndReceiveWithUserBuffer": "0x44", "svcCreateEvent": "0x45", + "svcMapTransferMemory": "0x51", + "svcUnmapTransferMemory": "0x52", "svcCreateInterruptEvent": "0x53", "svcReadWriteRegister": "0x4E", "svcQueryIoMapping": "0x55", diff --git a/stratosphere/ams_mitm/source/sysupdater/sysupdater_fs_utils.cpp b/stratosphere/ams_mitm/source/sysupdater/sysupdater_fs_utils.cpp index 7ec57d497..b8a88fc13 100644 --- a/stratosphere/ams_mitm/source/sysupdater/sysupdater_fs_utils.cpp +++ b/stratosphere/ams_mitm/source/sysupdater/sysupdater_fs_utils.cpp @@ -55,10 +55,10 @@ namespace ams::mitm::sysupdater { } Result ParseMountName(const char **path, std::shared_ptr *out) { - /* The equivalent function here supports all the common mount names; we'll only support the SD card. */ - if (const auto sd_mount_len = strnlen(ams::fs::impl::SdCardFileSystemMountName, ams::fs::MountNameLengthMax); std::strncmp(*path, ams::fs::impl::SdCardFileSystemMountName, sd_mount_len) == 0) { - /* Open an sd card fs. */ - *path += sd_mount_len; + /* The equivalent function here supports all the common mount names; we'll only support the SD card, system content storage. */ + if (const auto mount_len = strnlen(ams::fs::impl::SdCardFileSystemMountName, ams::fs::MountNameLengthMax); std::strncmp(*path, ams::fs::impl::SdCardFileSystemMountName, mount_len) == 0) { + /* Advance the path. */ + *path += mount_len; /* Open the SD card. This uses libnx bindings. */ FsFileSystem fs; @@ -68,6 +68,20 @@ namespace ams::mitm::sysupdater { auto fsa = std::make_shared(fs); R_UNLESS(fsa != nullptr, fs::ResultAllocationFailureInSdCardA()); + /* Set the output fs. */ + *out = std::move(fsa); + } else if (const auto mount_len = strnlen(ams::fs::impl::ContentStorageSystemMountName, ams::fs::MountNameLengthMax); std::strncmp(*path, ams::fs::impl::ContentStorageSystemMountName, mount_len) == 0) { + /* Advance the path. */ + *path += mount_len; + + /* Open the system content storage. This uses libnx bindings. */ + FsFileSystem fs; + R_TRY(fsOpenContentStorageFileSystem(std::addressof(fs), FsContentStorageId_System)); + + /* Allocate a new filesystem wrapper. */ + auto fsa = std::make_shared(fs); + R_UNLESS(fsa != nullptr, fs::ResultAllocationFailureInContentStorageA()); + /* Set the output fs. */ *out = std::move(fsa); } else { diff --git a/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.cpp b/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.cpp index 493b49b56..9a04d4560 100644 --- a/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.cpp +++ b/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.cpp @@ -403,11 +403,11 @@ namespace ams::mitm::sysupdater { return ResultSuccess(); }; - Result SystemUpdateService::SetupUpdate(sf::MoveHandle transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat) { + Result SystemUpdateService::SetupUpdate(sf::CopyHandle transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat) { return this->SetupUpdateImpl(transfer_memory.GetValue(), transfer_memory_size, path, exfat, GetFirmwareVariationId()); } - Result SystemUpdateService::SetupUpdateWithVariation(sf::MoveHandle transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat, ncm::FirmwareVariationId firmware_variation_id) { + Result SystemUpdateService::SetupUpdateWithVariation(sf::CopyHandle transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat, ncm::FirmwareVariationId firmware_variation_id) { return this->SetupUpdateImpl(transfer_memory.GetValue(), transfer_memory_size, path, exfat, firmware_variation_id); } diff --git a/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.hpp b/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.hpp index d8a748202..82ac8332f 100644 --- a/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.hpp +++ b/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.hpp @@ -65,8 +65,8 @@ namespace ams::mitm::sysupdater { private: Result GetUpdateInformation(sf::Out out, const ncm::Path &path); Result ValidateUpdate(sf::Out out_validate_result, sf::Out out_validate_info, const ncm::Path &path); - Result SetupUpdate(sf::MoveHandle transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat); - Result SetupUpdateWithVariation(sf::MoveHandle transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat, ncm::FirmwareVariationId firmware_variation_id); + Result SetupUpdate(sf::CopyHandle transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat); + Result SetupUpdateWithVariation(sf::CopyHandle transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat, ncm::FirmwareVariationId firmware_variation_id); Result RequestPrepareUpdate(sf::OutCopyHandle out_event_handle, sf::Out> out_async); Result GetPrepareUpdateProgress(sf::Out out); Result HasPreparedUpdate(sf::Out out);