support file based/sd partition emusd configs

This commit is contained in:
Christoph Baumann
2025-05-20 20:38:41 +02:00
parent b543194688
commit 7584ec3060
5 changed files with 19 additions and 12 deletions

View File

@@ -440,7 +440,6 @@ namespace ams::secmon::smc {
const uintptr_t user_offset = user_address % 4_KB; const uintptr_t user_offset = user_address % 4_KB;
/* Validate arguments. */ /* Validate arguments. */
/* NOTE: Only eMMC and SD redirection supported. GC redirection may be supported in the future */
SMC_R_UNLESS(mmc == EmummcMmc_Nand || mmc == EmummcMmc_Sd, NotSupported); SMC_R_UNLESS(mmc == EmummcMmc_Nand || mmc == EmummcMmc_Sd, NotSupported);
SMC_R_UNLESS(mmc != EmummcMmc_Nand || user_offset + 2 * sizeof(EmummcFilePath) <= 4_KB, InvalidArgument); SMC_R_UNLESS(mmc != EmummcMmc_Nand || user_offset + 2 * sizeof(EmummcFilePath) <= 4_KB, InvalidArgument);
@@ -489,14 +488,24 @@ namespace ams::secmon::smc {
static_assert(sizeof(cfg.base_cfg) <= InlineOutputSize); static_assert(sizeof(cfg.base_cfg) <= InlineOutputSize);
std::memcpy(inline_output, std::addressof(cfg.base_cfg), sizeof(cfg.base_cfg)); std::memcpy(inline_output, std::addressof(cfg.base_cfg), sizeof(cfg.base_cfg));
AtmosphereUserPageMapper mapper(user_address);
SMC_R_UNLESS(mapper.Map(), InvalidArgument);
switch(cfg.base_cfg.type) { switch(cfg.base_cfg.type) {
case EmummcSdType_None: case EmummcSdType_None:
/* Nothing to be copied if disabled */
break; break;
case EmummcSdType_Partition_Emmc: case EmummcSdType_Partition_Emmc:
case EmummcSdType_Partition_Sd:
/* Copy partition config */
static_assert(sizeof(cfg.base_cfg) + sizeof(cfg.partition_cfg) <= InlineOutputSize); static_assert(sizeof(cfg.base_cfg) + sizeof(cfg.partition_cfg) <= InlineOutputSize);
std::memcpy(inline_output + sizeof(cfg.base_cfg), std::addressof(cfg.partition_cfg), sizeof(cfg.partition_cfg)); std::memcpy(inline_output + sizeof(cfg.base_cfg), std::addressof(cfg.partition_cfg), sizeof(cfg.partition_cfg));
break; break;
/* File based and SD partition based (currently) not supported for SD redirection */ case EmummcSdType_File_Emmc:
case EmummcSdType_File_Sd:
/* Copy file config */
SMC_R_UNLESS(mapper.CopyToUser(user_address, std::addressof(cfg.file_cfg), sizeof(cfg.file_cfg)), InvalidArgument);
break;
AMS_UNREACHABLE_DEFAULT_CASE(); AMS_UNREACHABLE_DEFAULT_CASE();
} }
} }

View File

@@ -20,7 +20,6 @@
#include <exosphere/secmon/secmon_monitor_context.hpp> #include <exosphere/secmon/secmon_monitor_context.hpp>
namespace ams::secmon { namespace ams::secmon {
struct ConfigurationContext { struct ConfigurationContext {
union { union {
SecureMonitorConfiguration secmon_cfg; SecureMonitorConfiguration secmon_cfg;
@@ -28,7 +27,7 @@ namespace ams::secmon {
}; };
union { union {
EmummcConfiguration emummc_cfg; EmummcConfiguration emummc_cfg;
u8 _raw_emummc_config[0x128]; u8 _raw_emummc_config[0x1A0];
}; };
u8 sealed_device_keys[pkg1::KeyGeneration_Max][se::AesBlockSize]; u8 sealed_device_keys[pkg1::KeyGeneration_Max][se::AesBlockSize];
u8 sealed_master_keys[pkg1::KeyGeneration_Max][se::AesBlockSize]; u8 sealed_master_keys[pkg1::KeyGeneration_Max][se::AesBlockSize];

View File

@@ -29,10 +29,9 @@ namespace ams::secmon {
enum EmummcSdType : u32 { enum EmummcSdType : u32 {
EmummcSdType_None = 0, EmummcSdType_None = 0,
EmummcSdType_Partition_Emmc = 3, EmummcSdType_Partition_Emmc = 3,
// Not (currently) supported EmummcSdType_Partition_Sd = 1,
// EmummcSdType_Partition_Sd = 1, EmummcSdType_File_Sd = 2,
// EmummcSdType_File_Sd = 2, EmummcSdType_File_Emmc = 4,
// EmummcSdType_File_Emmc = 4,
}; };
enum EmummcMmc { enum EmummcMmc {
@@ -121,8 +120,7 @@ namespace ams::secmon {
EmummcSdBaseConfiguration base_cfg; EmummcSdBaseConfiguration base_cfg;
union { union {
EmummcPartitionConfiguration partition_cfg; EmummcPartitionConfiguration partition_cfg;
/* File based currently not supported */ EmummcFileConfiguration file_cfg;
/* EmummcFileConfiguration file_cfg */
}; };
constexpr bool IsValid() const { constexpr bool IsValid() const {
@@ -134,7 +132,7 @@ namespace ams::secmon {
} }
}; };
static_assert(util::is_pod<EmummcSdConfiguration>::value); static_assert(util::is_pod<EmummcSdConfiguration>::value);
static_assert(sizeof(EmummcSdConfiguration) == 0x18); static_assert(sizeof(EmummcSdConfiguration) == 0x90);
struct EmummcConfiguration { struct EmummcConfiguration {
EmummcEmmcConfiguration emmc_cfg; EmummcEmmcConfiguration emmc_cfg;

View File

@@ -50,7 +50,7 @@ namespace ams::secmon {
constexpr bool IsValid() const { return this->magic == Magic; } constexpr bool IsValid() const { return this->magic == Magic; }
}; };
static_assert(util::is_pod<SecureMonitorStorageConfiguration>::value); static_assert(util::is_pod<SecureMonitorStorageConfiguration>::value);
static_assert(sizeof(SecureMonitorStorageConfiguration) == 0x148); static_assert(sizeof(SecureMonitorStorageConfiguration) == 0x1C0);
struct SecureMonitorConfiguration { struct SecureMonitorConfiguration {
ams::TargetFirmware target_firmware; ams::TargetFirmware target_firmware;

View File

@@ -501,6 +501,7 @@ namespace ams::sdmmc::impl {
if (!is_read) { if (!is_read) {
#ifdef ATMOSPHERE_IS_EXOSPHERE #ifdef ATMOSPHERE_IS_EXOSPHERE
/* Allow unaligned writes */ /* Allow unaligned writes */
/* TODO: bad */
constexpr u32 MmcWriteSectorAlignment = 0; constexpr u32 MmcWriteSectorAlignment = 0;
#else #else
constexpr u32 MmcWriteSectorAlignment = 16_KB / SectorSize; constexpr u32 MmcWriteSectorAlignment = 16_KB / SectorSize;