exo2: implement main through sync-for-pk21-load
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
namespace ams::secmon::boot {
|
||||
|
||||
void MakePageTable();
|
||||
void UnmapPhysicalIdentityMapping();
|
||||
|
||||
void InitializeColdBoot();
|
||||
|
||||
|
||||
@@ -14,9 +14,10 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <exosphere.hpp>
|
||||
#include "secmon_boot_cache.hpp"
|
||||
|
||||
namespace ams::secmon::boot {
|
||||
|
||||
/* TODO */
|
||||
#include "../secmon_cache_impl.inc"
|
||||
|
||||
}
|
||||
23
exosphere2/program/source/boot/secmon_boot_cache.hpp
Normal file
23
exosphere2/program/source/boot/secmon_boot_cache.hpp
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <exosphere.hpp>
|
||||
|
||||
namespace ams::secmon::boot {
|
||||
|
||||
#include "../secmon_cache.inc"
|
||||
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
#include <exosphere.hpp>
|
||||
#include "secmon_boot.hpp"
|
||||
#include "secmon_boot_cache.hpp"
|
||||
#include "secmon_boot_functions.hpp"
|
||||
|
||||
namespace ams::secmon::boot {
|
||||
@@ -104,4 +105,30 @@ namespace ams::secmon::boot {
|
||||
SYSCTR0_REG_BITS_ENUM(CNTCR_EN, ENABLE));
|
||||
}
|
||||
|
||||
void WriteGpuCarveoutMagicNumbers() {
|
||||
/* Define the magic numbers. */
|
||||
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<u32>() - (0x004 / sizeof(*gpu_magic));
|
||||
u32 *tsec_magic = MemoryRegionDramGpuCarveout.GetEndPointer<u32>() - (0x100 / sizeof(*tsec_magic));
|
||||
|
||||
/* Write the gpu magic number. */
|
||||
gpu_magic[0] = GpuMagicNumber;
|
||||
|
||||
/* Write the tsec magic numbers. */
|
||||
tsec_magic[0] = SkuInfo;
|
||||
tsec_magic[1] = HdcpMicroCodeVersion;
|
||||
tsec_magic[2] = (false /* TODO: IsMariko */) ? ChipIdMariko : ChipIdErista;
|
||||
|
||||
/* Flush the magic numbers. */
|
||||
hw::FlushDataCache(gpu_magic, 1 * sizeof(u32));
|
||||
hw::FlushDataCache(tsec_magic, 3 * sizeof(u32));
|
||||
hw::DataSynchronizationBarrierInnerShareable();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,4 +27,6 @@ namespace ams::secmon::boot {
|
||||
|
||||
void EnableTsc(u64 initial_tsc_value);
|
||||
|
||||
void WriteGpuCarveoutMagicNumbers();
|
||||
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
#include <exosphere.hpp>
|
||||
#include "secmon_boot.hpp"
|
||||
#include "secmon_boot_cache.hpp"
|
||||
#include "../secmon_setup.hpp"
|
||||
#include "../secmon_key_storage.hpp"
|
||||
|
||||
@@ -308,6 +309,25 @@ namespace ams::secmon::boot {
|
||||
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace ams::mmu;
|
||||
|
||||
constexpr void UnmapPhysicalIdentityMappingImpl(u64 *l1, u64 *l2, u64 *l3) {
|
||||
/* Invalidate the L3 entries for the tzram and iram boot code regions. */
|
||||
InvalidateL3Entries(l3, MemoryRegionPhysicalTzram.GetAddress(), MemoryRegionPhysicalTzram.GetSize());
|
||||
InvalidateL3Entries(l3, MemoryRegionPhysicalIramBootCode.GetAddress(), MemoryRegionPhysicalIramBootCode.GetSize());
|
||||
|
||||
/* Unmap the L2 entries corresponding to those L3 entries. */
|
||||
InvalidateL2Entries(l2, MemoryRegionPhysicalIramL2.GetAddress(), MemoryRegionPhysicalIramL2.GetSize());
|
||||
InvalidateL2Entries(l2, MemoryRegionPhysicalTzramL2.GetAddress(), MemoryRegionPhysicalTzramL2.GetSize());
|
||||
|
||||
/* Unmap the L1 entry corresponding to to those L2 entries. */
|
||||
InvalidateL1Entries(l1, MemoryRegionPhysical.GetAddress(), MemoryRegionPhysical.GetSize());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void InitializeColdBoot() {
|
||||
/* Ensure that the system counters are valid. */
|
||||
ValidateSystemCounters();
|
||||
@@ -334,4 +354,16 @@ namespace ams::secmon::boot {
|
||||
SaveSecurityEngineAesKeySlotTestVector();
|
||||
}
|
||||
|
||||
}
|
||||
void UnmapPhysicalIdentityMapping() {
|
||||
/* Get the tables. */
|
||||
u64 * const l1 = MemoryRegionPhysicalTzramL1PageTable.GetPointer<u64>();
|
||||
u64 * const l2_l3 = MemoryRegionPhysicalTzramL2L3PageTable.GetPointer<u64>();
|
||||
|
||||
/* Unmap. */
|
||||
UnmapPhysicalIdentityMappingImpl(l1, l2_l3, l2_l3);
|
||||
|
||||
/* Ensure the mappings are consistent. */
|
||||
secmon::boot::EnsureMappingConsistency();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -89,6 +89,36 @@ namespace ams::secmon {
|
||||
|
||||
secmon::boot::EnableTsc(bc.data.GetInitialTscValue() & TscMask);
|
||||
}
|
||||
|
||||
/* Wait for NX Bootloader to initialize DRAM. */
|
||||
secmon::boot::WaitForNxBootloader(secmon_params, pkg1::BootloaderState_InitializedDram);
|
||||
|
||||
/* Secure the PMC and MC. */
|
||||
secmon::SetupPmcAndMcSecure();
|
||||
|
||||
/* Copy warmboot to dram. */
|
||||
{
|
||||
/* Define warmboot extents. */
|
||||
const void * const src = MemoryRegionPhysicalIramWarmbootBin.GetPointer();
|
||||
void * const dst = MemoryRegionVirtualDramSecureDataStoreWarmbootFirmware.GetPointer();
|
||||
const size_t size = MemoryRegionPhysicalIramWarmbootBin.GetSize();
|
||||
|
||||
/* Ensure we copy the correct data. */
|
||||
hw::FlushDataCache(src, size);
|
||||
hw::DataSynchronizationBarrierInnerShareable();
|
||||
|
||||
/* Copy warmboot.bin to its secure dram location. */
|
||||
std::memcpy(dst, src, size);
|
||||
}
|
||||
|
||||
/* Unmap the identity mapping. */
|
||||
secmon::boot::UnmapPhysicalIdentityMapping();
|
||||
|
||||
/* Setup the GPU carveout's magic numbers. */
|
||||
secmon::boot::WriteGpuCarveoutMagicNumbers();
|
||||
|
||||
/* Wait for NX bootloader to load Package2. */
|
||||
secmon::boot::WaitForNxBootloader(secmon_params, pkg1::BootloaderState_LoadedPackage2);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -144,4 +144,4 @@ namespace ams::secmon::boot {
|
||||
MakePageTablesImpl(l1, l2_l3, l2_l3);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user