exo2: Initial work on the exosphere rewrite.
exo2: Implement uncompressor stub and boot code up to Main(). exo2: implement some more init (uart/gic) exo2: implement more of init exo2: improve reg api, add keyslot flag setters exo2: implement se aes decryption/enc exo2: fix bugs in loader stub/mmu mappings exo2: start skeletoning bootconfig/global context types arch: fix makefile flags exo2: implement through master key derivation exo2: implement device master keygen exo2: more init through start of SetupSocSecurity exo2: implement pmc secure scratch management se: implement sticky bit validation libexosphere: fix building for arm32 libexo: fix makefile flags libexo: support building for arm64/arm sc7fw: skeleton binary sc7fw: skeleton a little more sc7fw: implement all non-dram functionality exo2: fix DivideUp error sc7fw: implement more dram code, fix reg library errors sc7fw: complete sc7fw impl. exo2: skeleton the rest of SetupSocSecurity exo2: implement fiq interrupt handler exo2: implement all exception handlers exo2: skeleton the entire smc api, implement the svc invoker exo2: implement rest of SetupSocSecurity exo2: correct slave security errors exo2: fix register definition exo2: minor fixes
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* 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 <vapours.hpp>
|
||||
|
||||
namespace ams::pkg1 {
|
||||
|
||||
enum MemorySize {
|
||||
MemorySize_4GB = 0,
|
||||
MemorySize_6GB = 1,
|
||||
MemorySize_8GB = 2,
|
||||
};
|
||||
|
||||
enum MemoryArrange {
|
||||
MemoryArrange_Normal = 1,
|
||||
MemoryArrange_AppletDev = 2,
|
||||
MemoryArrange_SystemDev = 2,
|
||||
};
|
||||
|
||||
enum MemoryMode {
|
||||
MemoryMode_SizeShift = 4,
|
||||
MemoryMode_SizeMask = 0x30,
|
||||
|
||||
MemoryMode_ArrangeMask = 0x0F,
|
||||
|
||||
MemoryMode_Auto = 0x00,
|
||||
|
||||
MemoryMode_4GB = ((MemorySize_4GB << MemoryMode_SizeShift) | (MemoryArrange_Normal)),
|
||||
MemoryMode_4GBAppletDev = ((MemorySize_4GB << MemoryMode_SizeShift) | (MemoryArrange_AppletDev)),
|
||||
MemoryMode_4GBSystemDev = ((MemorySize_4GB << MemoryMode_SizeShift) | (MemoryArrange_SystemDev)),
|
||||
|
||||
MemoryMode_6GB = ((MemorySize_6GB << MemoryMode_SizeShift) | (MemoryArrange_Normal)),
|
||||
MemoryMode_6GBAppletDev = ((MemorySize_6GB << MemoryMode_SizeShift) | (MemoryArrange_AppletDev)),
|
||||
|
||||
MemoryMode_8GB = ((MemorySize_8GB << MemoryMode_SizeShift) | (MemoryArrange_Normal)),
|
||||
};
|
||||
|
||||
constexpr ALWAYS_INLINE MemorySize GetMemorySize(MemoryMode mode) {
|
||||
return static_cast<MemorySize>(mode >> MemoryMode_SizeShift);
|
||||
}
|
||||
|
||||
constexpr ALWAYS_INLINE MemoryArrange GetMemoryArrange(MemoryMode mode) {
|
||||
return static_cast<MemoryArrange>(mode & MemoryMode_ArrangeMask);
|
||||
}
|
||||
|
||||
constexpr ALWAYS_INLINE MemoryMode MakeMemoryMode(MemorySize size, MemoryArrange arrange) {
|
||||
return static_cast<MemoryMode>((size << MemoryMode_SizeShift) | (arrange));
|
||||
}
|
||||
|
||||
struct BootConfigData {
|
||||
u32 version;
|
||||
u32 reserved_04;
|
||||
u32 reserved_08;
|
||||
u32 reserved_0C;
|
||||
u8 flags1[0x10];
|
||||
u8 flags0[0x10];
|
||||
u64 initial_tsc_value;
|
||||
u8 padding_38[0x200 - 0x38];
|
||||
|
||||
constexpr bool IsDevelopmentFunctionEnabled() const {
|
||||
return (this->flags1[0] & (1 << 1)) != 0;
|
||||
}
|
||||
|
||||
constexpr bool IsSErrorDebugEnabled() const {
|
||||
return (this->flags1[0] & (1 << 2)) != 0;
|
||||
}
|
||||
|
||||
constexpr u8 GetKernelFlags0() const {
|
||||
return this->flags0[1];
|
||||
}
|
||||
|
||||
constexpr u8 GetKernelFlags1() const {
|
||||
return this->flags1[0];
|
||||
}
|
||||
|
||||
constexpr MemoryMode GetMemoryMode() const {
|
||||
return static_cast<MemoryMode>(this->flags0[3]);
|
||||
}
|
||||
|
||||
bool IsTscInitialValueValid() const {
|
||||
return (this->flags0[4] & (1 << 0)) != 0;
|
||||
}
|
||||
};
|
||||
static_assert(util::is_pod<BootConfigData>::value);
|
||||
static_assert(sizeof(BootConfigData) == 0x200);
|
||||
|
||||
struct BootConfigSignedData {
|
||||
u32 version;
|
||||
u32 reserved_04;
|
||||
u8 flags;
|
||||
u8 reserved_09[0x10 - 9];
|
||||
u8 ecid[0x10];
|
||||
u8 flags1[0x10];
|
||||
u8 flags0[0x10];
|
||||
u8 padding_40[0x100 - 0x40];
|
||||
|
||||
constexpr bool IsPackage2EncryptionDisabled() const {
|
||||
return (this->flags & (1 << 0)) != 0;
|
||||
}
|
||||
|
||||
constexpr bool IsPackage2SignatureVerificationDisabled() const {
|
||||
return (this->flags & (1 << 1)) != 0;
|
||||
}
|
||||
|
||||
constexpr bool IsProgramVerificationDisabled() const {
|
||||
return (this->flags1[0] & (1 << 0)) != 0;
|
||||
}
|
||||
};
|
||||
static_assert(util::is_pod<BootConfigSignedData>::value);
|
||||
static_assert(sizeof(BootConfigSignedData) == 0x100);
|
||||
|
||||
struct BootConfig {
|
||||
BootConfigData data;
|
||||
u8 signature[0x100];
|
||||
BootConfigSignedData signed_data;
|
||||
};
|
||||
static_assert(util::is_pod<BootConfig>::value);
|
||||
static_assert(sizeof(BootConfig) == 0x400);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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 <vapours.hpp>
|
||||
|
||||
namespace ams::pkg1 {
|
||||
|
||||
enum BootloaderState {
|
||||
BootloaderState_Start = 0,
|
||||
BootloaderState_LoadedBootConfig = 1,
|
||||
BootloaderState_InitializedDram = 2,
|
||||
BootloaderState_LoadedPackage2 = 3,
|
||||
BootloaderState_Done = 4,
|
||||
};
|
||||
|
||||
enum SecureMonitorState {
|
||||
SecureMonitorState_Start = 0,
|
||||
SecureMonitorState_Initialized = 1,
|
||||
};
|
||||
|
||||
struct BctParameters {
|
||||
u32 bootloader_version;
|
||||
u32 bootloader_start_block;
|
||||
u32 bootloader_start_page;
|
||||
u32 bootloader_attributes;
|
||||
};
|
||||
static_assert(util::is_pod<BctParameters>::value && sizeof(BctParameters) == 0x10);
|
||||
|
||||
struct SecureMonitorParameters {
|
||||
u32 bootloader_start_time;
|
||||
u32 bootloader_end_time;
|
||||
u32 secmon_start_time;
|
||||
u32 secmon_end_time;
|
||||
BctParameters bct_params;
|
||||
u8 reserved[0xD8];
|
||||
u32 bootloader_state;
|
||||
u32 secmon_state;
|
||||
u8 reserved2[0x100];
|
||||
};
|
||||
static_assert(util::is_pod<SecureMonitorParameters>::value);
|
||||
static_assert(sizeof(SecureMonitorParameters) == 0x200);
|
||||
|
||||
static_assert(offsetof(SecureMonitorParameters, bct_params) == 0x10);
|
||||
static_assert(offsetof(SecureMonitorParameters, bootloader_state) == 0xF8);
|
||||
static_assert(offsetof(SecureMonitorParameters, secmon_state) == 0xFC);
|
||||
|
||||
enum BootloaderAttribute {
|
||||
BootloaderAttribute_None = (0u << 0),
|
||||
BootloaderAttribute_RecoveryBoot = (1u << 0),
|
||||
|
||||
BootloaderAttribute_RestrictedSmcShift = 1,
|
||||
BootloaderAttribute_RestrictedSmcMask = (0xFu << BootloaderAttribute_RestrictedSmcShift),
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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 <vapours.hpp>
|
||||
|
||||
namespace ams::pkg1 {
|
||||
|
||||
enum ErrorReason {
|
||||
ErrorReason_None = 0,
|
||||
ErrorReason_InvalidPackage2Signature = 1,
|
||||
ErrorReason_InvalidPackage2Meta = 2,
|
||||
ErrorReason_InvalidPackage2Version = 3,
|
||||
ErrorReason_InvalidPackage2Payload = 4,
|
||||
ErrorReason_UnknownSmc = 5,
|
||||
ErrorReason_UnknownAbort = 6,
|
||||
ErrorReason_InvalidCoreContext = 7,
|
||||
ErrorReason_InvalidSecurityEngineStickyBits = 8,
|
||||
ErrorReason_UnexpectedReset = 9,
|
||||
|
||||
ErrorReason_Exception = 0x10,
|
||||
|
||||
ErrorReason_TransitionToSafeMode = 0x20,
|
||||
ErrorReason_SecureInitializerReboot = 0x21,
|
||||
|
||||
ErrorReason_SdmmcError = 0x30,
|
||||
ErrorReason_InvalidDramId = 0x31,
|
||||
ErrorReason_InvalidPackage2 = 0x32,
|
||||
ErrorReason_InvalidBct = 0x33,
|
||||
ErrorReason_InvalidGpt = 0x34,
|
||||
ErrorReason_FailedToTransitionToSafeMode = 0x35,
|
||||
ErrorReason_ActivityMonitorInterrupt = 0x36,
|
||||
|
||||
ErrorReason_KernelPanic = 0x40,
|
||||
};
|
||||
|
||||
enum ErrorColor {
|
||||
ErrorColor_Black = 0x000,
|
||||
|
||||
ErrorColor_Red = 0x00F,
|
||||
ErrorColor_Yellow = 0x0FF,
|
||||
ErrorColor_Orange = 0x07F,
|
||||
ErrorColor_Blue = 0xF00,
|
||||
ErrorColor_LightBlue = 0xFF0,
|
||||
ErrorColor_Pink = 0xF7F,
|
||||
ErrorColor_Purple = 0xF0A,
|
||||
};
|
||||
|
||||
enum ErrorInfo {
|
||||
ErrorInfo_ReasonMask = 0xFF,
|
||||
ErrorInfo_ColorShift = 20,
|
||||
|
||||
#define MAKE_ERROR_INFO(_COLOR_, _DESC_) ((static_cast<u32>(ErrorColor_##_COLOR_) << ErrorInfo_ColorShift) | (ErrorReason_##_DESC_))
|
||||
|
||||
ErrorInfo_None = MAKE_ERROR_INFO(Black, None),
|
||||
|
||||
ErrorInfo_InvalidPackage2Signature = MAKE_ERROR_INFO(Blue, InvalidPackage2Signature),
|
||||
ErrorInfo_InvalidPackage2Meta = MAKE_ERROR_INFO(Blue, InvalidPackage2Meta),
|
||||
ErrorInfo_InvalidPackage2Version = MAKE_ERROR_INFO(Blue, InvalidPackage2Version),
|
||||
ErrorInfo_InvalidPackage2Payload = MAKE_ERROR_INFO(Blue, InvalidPackage2Payload),
|
||||
|
||||
ErrorInfo_UnknownSmc = MAKE_ERROR_INFO(LightBlue, UnknownSmc),
|
||||
|
||||
ErrorInfo_UnknownAbort = MAKE_ERROR_INFO(Yellow, UnknownAbort),
|
||||
|
||||
ErrorInfo_InvalidCoreContext = MAKE_ERROR_INFO(Pink, InvalidCoreContext),
|
||||
ErrorInfo_InvalidSecurityEngineStickyBits = MAKE_ERROR_INFO(Pink, InvalidSecurityEngineStickyBits),
|
||||
ErrorInfo_UnexpectedReset = MAKE_ERROR_INFO(Pink, UnexpectedReset),
|
||||
|
||||
ErrorInfo_Exception = MAKE_ERROR_INFO(Orange, Exception),
|
||||
|
||||
ErrorInfo_TransitionToSafeMode = MAKE_ERROR_INFO(Black, TransitionToSafeMode),
|
||||
ErrorInfo_SecureInitializerReboot = MAKE_ERROR_INFO(Black, SecureInitializerReboot),
|
||||
|
||||
ErrorInfo_SdmmcError = MAKE_ERROR_INFO(Purple, SdmmcError),
|
||||
ErrorInfo_InvalidDramId = MAKE_ERROR_INFO(Purple, InvalidDramId),
|
||||
ErrorInfo_InvalidPackage2 = MAKE_ERROR_INFO(Purple, InvalidPackage2),
|
||||
ErrorInfo_InvalidBct = MAKE_ERROR_INFO(Purple, InvalidBct),
|
||||
ErrorInfo_InvalidGpt = MAKE_ERROR_INFO(Purple, InvalidGpt),
|
||||
ErrorInfo_FailedToTransitionToSafeMode = MAKE_ERROR_INFO(Purple, FailedToTransitionToSafeMode),
|
||||
ErrorInfo_ActivityMonitorInterrupt = MAKE_ERROR_INFO(Purple, ActivityMonitorInterrupt),
|
||||
|
||||
#undef MAKE_ERROR_INFO
|
||||
};
|
||||
|
||||
constexpr inline ErrorReason GetErrorReason(u32 info) {
|
||||
return static_cast<ErrorReason>(info & ErrorInfo_ReasonMask);
|
||||
}
|
||||
|
||||
constexpr inline ErrorInfo MakeKernelPanicResetInfo(u32 color) {
|
||||
return static_cast<ErrorInfo>((color << ErrorInfo_ColorShift) | (ErrorReason_KernelPanic));
|
||||
}
|
||||
|
||||
#define PKG1_SECURE_MONITOR_PMC_ERROR_SCRATCH (0x840)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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 <vapours.hpp>
|
||||
|
||||
namespace ams::pkg1 {
|
||||
|
||||
enum KeyGeneration : int {
|
||||
|
||||
KeyGeneration_1_0_0 = 0x00,
|
||||
KeyGeneration_3_0_0 = 0x01,
|
||||
KeyGeneration_3_0_1 = 0x02,
|
||||
KeyGeneration_4_0_0 = 0x03,
|
||||
KeyGeneration_5_0_0 = 0x04,
|
||||
KeyGeneration_6_0_0 = 0x05,
|
||||
KeyGeneration_6_2_0 = 0x06,
|
||||
KeyGeneration_7_0_0 = 0x07,
|
||||
KeyGeneration_8_1_0 = 0x08,
|
||||
KeyGeneration_9_0_0 = 0x09,
|
||||
KeyGeneration_9_1_0 = 0x0A,
|
||||
|
||||
KeyGeneration_Count,
|
||||
|
||||
KeyGeneration_Current = KeyGeneration_Count - 1,
|
||||
|
||||
KeyGeneration_Min = 0x00,
|
||||
KeyGeneration_Max = 0x20,
|
||||
};
|
||||
static_assert(KeyGeneration_Count <= KeyGeneration_Max);
|
||||
|
||||
constexpr inline const int OldMasterKeyCount = KeyGeneration_Count - 1;
|
||||
constexpr inline const int OldDeviceMasterKeyCount = KeyGeneration_Count - KeyGeneration_4_0_0;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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 <vapours.hpp>
|
||||
|
||||
namespace ams::pkg1 {
|
||||
|
||||
enum AesKeySlot {
|
||||
AesKeySlot_UserStart = 0,
|
||||
|
||||
AesKeySlot_TzramSave = 2,
|
||||
|
||||
AesKeySlot_UserLast = 5,
|
||||
AesKeySlot_UserEnd = AesKeySlot_UserLast + 1,
|
||||
|
||||
AesKeySlot_SecmonStart = 8,
|
||||
|
||||
AesKeySlot_Temporary = 8,
|
||||
AesKeySlot_Smc = 9,
|
||||
AesKeySlot_RandomForUserWrap = 10,
|
||||
AesKeySlot_RandomForKeyStorageWrap = 11,
|
||||
AesKeySlot_DeviceMaster = 12,
|
||||
AesKeySlot_Master = 13,
|
||||
AesKeySlot_Device = 15,
|
||||
|
||||
AesKeySlot_SecmonEnd = 16,
|
||||
|
||||
/* Used only during boot. */
|
||||
AesKeySlot_Tsec = 12,
|
||||
AesKeySlot_TsecRoot = 13,
|
||||
AesKeySlot_SecureBoot = 14,
|
||||
AesKeySlot_SecureStorage = 15,
|
||||
|
||||
AesKeySlot_MasterKek = 13,
|
||||
AesKeySlot_DeviceMasterKeySourceKek = 14,
|
||||
};
|
||||
|
||||
enum RsaKeySlot {
|
||||
RsaKeySlot_Temporary = 0,
|
||||
RsaKeySlot_PrivateKey = 1,
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user