diff --git a/exosphere2/program/source/boot/secmon_boot_setup.cpp b/exosphere2/program/source/boot/secmon_boot_setup.cpp index eacfd9940..1f56214b6 100644 --- a/exosphere2/program/source/boot/secmon_boot_setup.cpp +++ b/exosphere2/program/source/boot/secmon_boot_setup.cpp @@ -245,7 +245,7 @@ namespace ams::secmon::boot { void DeriveAllKeys() { /* Determine whether we're prod. */ - const bool is_prod = fuse::GetHardwareState() != fuse::HardwareState_Development; + const bool is_prod = IsProduction(); /* Get the ephemeral work block. */ u8 * const work_block = se::GetEphemeralWorkBlock(); diff --git a/exosphere2/program/source/secmon_setup.cpp b/exosphere2/program/source/secmon_setup.cpp index 6748022bf..f2ae08b69 100644 --- a/exosphere2/program/source/secmon_setup.cpp +++ b/exosphere2/program/source/secmon_setup.cpp @@ -94,6 +94,9 @@ namespace ams::secmon { /* If we don't have a valid storage context, we can just use the default one. */ ctx.secmon_cfg = DefaultSecureMonitorConfiguration; } + + /* Cache the fuse info for quick access. */ + ctx.secmon_cfg.SetFuseInfo(); } void GenerateSecurityEngineAesKeySlotTestVector(void *dst, size_t size) { @@ -387,7 +390,7 @@ namespace ams::secmon { SLAVE_SECURITY_REG_BITS_ENUM(2, DDS, ENABLE), SLAVE_SECURITY_REG_BITS_ENUM(2, DP2, ENABLE)); - const auto hw_type = fuse::GetHardwareType(); + const auto hw_type = GetHardwareType(); /* Switch Lite can't use HDMI, so set CEC to secure on hoag. */ if (hw_type == fuse::HardwareType_Hoag) { diff --git a/libraries/libexosphere/include/exosphere/secmon/secmon_configuration_context.arch.arm64.hpp b/libraries/libexosphere/include/exosphere/secmon/secmon_configuration_context.arch.arm64.hpp index 5b2c5bdcb..fff53236b 100644 --- a/libraries/libexosphere/include/exosphere/secmon/secmon_configuration_context.arch.arm64.hpp +++ b/libraries/libexosphere/include/exosphere/secmon/secmon_configuration_context.arch.arm64.hpp @@ -100,4 +100,20 @@ namespace ams::secmon { return GetSecmonConfiguration().GetKeyGeneration(); } + ALWAYS_INLINE fuse::HardwareType GetHardwareType() { + return GetSecmonConfiguration().GetHardwareType(); + } + + ALWAYS_INLINE fuse::SocType GetSocType() { + return GetSecmonConfiguration().GetSocType(); + } + + ALWAYS_INLINE fuse::HardwareState GetHardwareState() { + return GetSecmonConfiguration().GetHardwareState(); + } + + ALWAYS_INLINE bool IsProduction() { + return GetSecmonConfiguration().IsProduction(); + } + } diff --git a/libraries/libexosphere/include/exosphere/secmon/secmon_monitor_context.hpp b/libraries/libexosphere/include/exosphere/secmon/secmon_monitor_context.hpp index 2b3822b00..263ab28f8 100644 --- a/libraries/libexosphere/include/exosphere/secmon/secmon_monitor_context.hpp +++ b/libraries/libexosphere/include/exosphere/secmon/secmon_monitor_context.hpp @@ -15,6 +15,7 @@ */ #pragma once #include +#include #include namespace ams::secmon { @@ -48,16 +49,31 @@ namespace ams::secmon { struct SecureMonitorConfiguration { ams::TargetFirmware target_firmware; s32 key_generation; + u8 hardware_type; + u8 soc_type; + u8 hardware_state; + u8 pad_0B[1]; u32 flags; - u32 reserved[(0x80 - 0x0C) / sizeof(u32)]; + u32 reserved[(0x80 - 0x10) / sizeof(u32)]; constexpr void CopyFrom(const SecureMonitorStorageConfiguration &storage) { this->target_firmware = storage.target_firmware; this->flags = storage.flags; } + void SetFuseInfo() { + this->hardware_type = fuse::GetHardwareType(); + this->soc_type = fuse::GetSocType(); + this->hardware_state = fuse::GetHardwareState(); + } + constexpr ams::TargetFirmware GetTargetFirmware() const { return this->target_firmware; } constexpr int GetKeyGeneration() const { return this->key_generation; } + constexpr fuse::HardwareType GetHardwareType() const { return static_cast(this->hardware_type); } + constexpr fuse::SocType GetSocType() const { return static_cast(this->soc_type); } + constexpr fuse::HardwareState GetHardwareState() const { return static_cast(this->hardware_state); } + + constexpr bool IsProduction() const { return this->GetHardwareState() != fuse::HardwareState_Development; } constexpr bool IsDevelopmentFunctionEnabledForKernel() const { return (this->flags & SecureMonitorConfigurationFlag_IsDevelopmentFunctionEnabledForKernel) != 0; } constexpr bool IsDevelopmentFunctionEnabledForUser() const { return (this->flags & SecureMonitorConfigurationFlag_IsDevelopmentFunctionEnabledForUser) != 0; }