sysupdater: make GetUpdateInformation work on hardware.

This commit is contained in:
Michael Scire 2020-06-26 04:34:26 -07:00 committed by SciresM
parent a6218ed814
commit 3324dd52ef
5 changed files with 37 additions and 8 deletions

View file

@ -43,10 +43,9 @@ namespace ams::fs {
} }
Result MountSdCard(const char *name) { Result MountSdCard(const char *name) {
/* Validate the mount name. */ /* Validate the mount name. */
R_TRY(impl::CheckMountName(name)); R_TRY(impl::CheckMountNameAllowingReserved(name));
/* Open the SD card. This uses libnx bindings. */ /* Open the SD card. This uses libnx bindings. */
FsFileSystem fs; FsFileSystem fs;

View file

@ -139,6 +139,9 @@ namespace ams::mitm {
/* Open global SD card file system, so that other threads can begin using the SD. */ /* Open global SD card file system, so that other threads can begin using the SD. */
mitm::fs::OpenGlobalSdCardFileSystem(); mitm::fs::OpenGlobalSdCardFileSystem();
/* Mount the sd card at a convenient mountpoint. */
ams::fs::MountSdCard(ams::fs::impl::SdCardFileSystemMountName);
/* Initialize the reboot manager (load a payload off the SD). */ /* Initialize the reboot manager (load a payload off the SD). */
/* Discard result, since it doesn't need to succeed. */ /* Discard result, since it doesn't need to succeed. */
mitm::bpc::LoadRebootPayload(); mitm::bpc::LoadRebootPayload();

View file

@ -82,6 +82,7 @@ void __appInit(void) {
R_ABORT_UNLESS(fsInitialize()); R_ABORT_UNLESS(fsInitialize());
R_ABORT_UNLESS(pmdmntInitialize()); R_ABORT_UNLESS(pmdmntInitialize());
R_ABORT_UNLESS(pminfoInitialize()); R_ABORT_UNLESS(pminfoInitialize());
ncm::Initialize();
spl::InitializeForFs(); spl::InitializeForFs();
}); });
@ -97,6 +98,7 @@ void __appInit(void) {
void __appExit(void) { void __appExit(void) {
/* Cleanup services. */ /* Cleanup services. */
spl::Finalize(); spl::Finalize();
ncm::Finalize();
pminfoExit(); pminfoExit();
pmdmntExit(); pmdmntExit();
fsExit(); fsExit();

View file

@ -27,7 +27,13 @@ namespace ams::mitm::sysupdater {
constexpr size_t MaxServers = 1; constexpr size_t MaxServers = 1;
constexpr size_t MaxSessions = SystemUpdateMaxSessions; constexpr size_t MaxSessions = SystemUpdateMaxSessions;
using ServerOptions = sf::hipc::DefaultServerManagerOptions;
struct ServerOptions {
static constexpr size_t PointerBufferSize = 1_KB;
static constexpr size_t MaxDomains = 0;
static constexpr size_t MaxDomainObjects = 0;
};
sf::hipc::ServerManager<MaxServers, ServerOptions, MaxSessions> g_server_manager; sf::hipc::ServerManager<MaxServers, ServerOptions, MaxSessions> g_server_manager;
} }

View file

@ -78,9 +78,29 @@ namespace ams::mitm::sysupdater {
return info.version >= MinimumVersionForExFatDriver && ((info.attributes & ncm::ContentMetaAttribute_IncludesExFatDriver) != 0); return info.version >= MinimumVersionForExFatDriver && ((info.attributes & ncm::ContentMetaAttribute_IncludesExFatDriver) != 0);
} }
Result FormatUserPackagePath(ncm::Path *out, const ncm::Path &user_path) {
/* Ensure that the user path is valid. */
R_UNLESS(user_path.str[0] == '/', fs::ResultInvalidPath());
/* Print as @Sdcard:<user_path>/ */
std::snprintf(out->str, sizeof(out->str), "%s:%s/", ams::fs::impl::SdCardFileSystemMountName, user_path.str);
/* Normalize, if the user provided an ending / */
const size_t len = std::strlen(out->str);
if (out->str[len - 1] == '/' && out->str[len - 2] == '/') {
out->str[len - 1] = '\x00';
} }
Result SystemUpdateService::GetUpdateInformation(sf::Out<UpdateInformation> out, const ncm::Path &package_root) { return ResultSuccess();
}
}
Result SystemUpdateService::GetUpdateInformation(sf::Out<UpdateInformation> out, const ncm::Path &path) {
/* Adjust the path. */
ncm::Path package_root;
R_TRY(FormatUserPackagePath(std::addressof(package_root), path));
/* Create a new update information. */ /* Create a new update information. */
UpdateInformation update_info = {}; UpdateInformation update_info = {};
@ -115,15 +135,14 @@ namespace ams::mitm::sysupdater {
/* Create a reader. */ /* Create a reader. */
const auto reader = ncm::PackagedContentMetaReader(content_meta_buffer.Get(), content_meta_buffer.GetSize()); const auto reader = ncm::PackagedContentMetaReader(content_meta_buffer.Get(), content_meta_buffer.GetSize());
/* Get the version from the header. */
update_info.version = reader.GetHeader()->version;
/* Iterate over infos to find the system update info. */ /* Iterate over infos to find the system update info. */
for (size_t i = 0; i < reader.GetContentMetaCount(); ++i) { for (size_t i = 0; i < reader.GetContentMetaCount(); ++i) {
const auto &meta_info = *reader.GetContentMetaInfo(i); const auto &meta_info = *reader.GetContentMetaInfo(i);
switch (meta_info.type) { switch (meta_info.type) {
case ncm::ContentMetaType::SystemUpdate:
/* Set the version. */
update_info.version = meta_info.version;
break;
case ncm::ContentMetaType::BootImagePackage: case ncm::ContentMetaType::BootImagePackage:
/* Detect exFAT support. */ /* Detect exFAT support. */
update_info.exfat_supported |= IsExFatDriverSupported(meta_info); update_info.exfat_supported |= IsExFatDriverSupported(meta_info);