From 4fe42eb99782695a9cd95199a0a0523474719c15 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sat, 16 May 2020 16:46:34 -0700 Subject: [PATCH] exo2: implement some mariko TODOs --- exosphere2/program/sc7fw/source/sc7fw_dram.cpp | 2 +- .../program/source/boot/secmon_boot_functions.cpp | 15 ++++++++++++--- libraries/libexosphere/source/se/se_aes.cpp | 9 ++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/exosphere2/program/sc7fw/source/sc7fw_dram.cpp b/exosphere2/program/sc7fw/source/sc7fw_dram.cpp index dcdf9c94b..b477a7d54 100644 --- a/exosphere2/program/sc7fw/source/sc7fw_dram.cpp +++ b/exosphere2/program/sc7fw/source/sc7fw_dram.cpp @@ -168,7 +168,7 @@ namespace ams::sc7fw { /* Request that DPD3 pads power down. */ constexpr u32 EristaDpd3Mask = 0x0FFFFFFF; constexpr u32 MarikoDpd3Mask = 0x0FFF9FFF; - if (true /* TODO: IsErista */) { + if (fuse::GetSocType() == fuse::SocType_Erista) { RequestAllPadsPowerDown(APBDEV_PMC_IO_DPD3_REQ, EristaDpd3Mask); } else { RequestAllPadsPowerDown(APBDEV_PMC_IO_DPD3_REQ, MarikoDpd3Mask); diff --git a/exosphere2/program/source/boot/secmon_boot_functions.cpp b/exosphere2/program/source/boot/secmon_boot_functions.cpp index 8773f4f4e..08e42c8cc 100644 --- a/exosphere2/program/source/boot/secmon_boot_functions.cpp +++ b/exosphere2/program/source/boot/secmon_boot_functions.cpp @@ -29,6 +29,17 @@ namespace ams::secmon::boot { secmon::boot::DecryptPackage2(reinterpret_cast(dst), size, reinterpret_cast(src), size, secmon::boot::GetPackage2AesKey(), crypto::AesEncryptor128::KeySize, iv, iv_size, key_generation); } + u32 GetChipId() { + constexpr u32 ChipIdErista = 0x210; + constexpr u32 ChipIdMariko = 0x214; + + switch (GetSocType()) { + case fuse::SocType_Erista: return ChipIdErista; + case fuse::SocType_Mariko: return ChipIdMariko; + AMS_UNREACHABLE_DEFAULT_CASE(); + } + } + } void CheckVerifyResult(bool verify_result, pkg1::ErrorInfo error_info, const char *message) { @@ -103,8 +114,6 @@ namespace ams::secmon::boot { constexpr u32 GpuMagicNumber = 0xC0EDBBCC; constexpr u32 SkuInfo = 0x83; constexpr u32 HdcpMicroCodeVersion = 0x2; - constexpr u32 ChipIdErista = 0x210; - constexpr u32 ChipIdMariko = 0x214; /* Get our pointers. */ u32 *gpu_magic = MemoryRegionDramGpuCarveout.GetEndPointer() - (0x004 / sizeof(*gpu_magic)); @@ -116,7 +125,7 @@ namespace ams::secmon::boot { /* Write the tsec magic numbers. */ tsec_magic[0] = SkuInfo; tsec_magic[1] = HdcpMicroCodeVersion; - tsec_magic[2] = (false /* TODO: IsMariko */) ? ChipIdMariko : ChipIdErista; + tsec_magic[2] = GetChipId(); /* Flush the magic numbers. */ hw::FlushDataCache(gpu_magic, 1 * sizeof(u32)); diff --git a/libraries/libexosphere/source/se/se_aes.cpp b/libraries/libexosphere/source/se/se_aes.cpp index 3ab0867b9..c46e02171 100644 --- a/libraries/libexosphere/source/se/se_aes.cpp +++ b/libraries/libexosphere/source/se/se_aes.cpp @@ -327,9 +327,12 @@ namespace ams::se { /* Set non per-key flags. */ if ((flags & ~KeySlotLockFlags_PerKey) != 0) { - /* TODO: KeySlotLockFlags_DstKeyTableOnly is Mariko-only. How should we handle this? */ - /* TODO: Mariko bit support. */ - reg::ReadWrite(SE->SE_CRYPTO_KEYTABLE_ACCESS[slot], REG_BITS_VALUE(0, 7, ~flags)); + /* KeySlotLockFlags_DstKeyTableOnly is Mariko-only. */ + if (fuse::GetSocType() == fuse::SocType_Mariko) { + reg::ReadWrite(SE->SE_CRYPTO_KEYTABLE_ACCESS[slot], REG_BITS_VALUE(0, 7, ~flags), REG_BITS_VALUE(7, 1, ((flags & KeySlotLockFlags_DstKeyTableOnly) != 0) ? 1 : 0)); + } else { + reg::ReadWrite(SE->SE_CRYPTO_KEYTABLE_ACCESS[slot], REG_BITS_VALUE(0, 7, ~flags)); + } } /* Set per-key flag. */