From ba7d0c2cb6b363f2a1d576440d79a71017a0841d Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Wed, 9 May 2018 06:29:56 -0600 Subject: [PATCH] Exosphere: Add API for retrieving versioning info. --- exosphere/src/configitem.c | 5 +++++ exosphere/src/configitem.h | 5 ++++- exosphere/src/version.h | 7 +++++++ stratosphere/loader/source/ldr_main.cpp | 12 ++++++++++++ stratosphere/pm/source/pm_main.cpp | 12 +++++++++--- stratosphere/sm/source/sm_main.cpp | 2 +- 6 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 exosphere/src/version.h diff --git a/exosphere/src/configitem.c b/exosphere/src/configitem.c index 79c351338..7244fa692 100644 --- a/exosphere/src/configitem.c +++ b/exosphere/src/configitem.c @@ -9,6 +9,7 @@ #include "utils.h" #include "masterkey.h" #include "exocfg.h" +#include "version.h" static bool g_battery_profile = false; @@ -132,6 +133,10 @@ uint32_t configitem_get(ConfigItem item, uint64_t *p_outvalue) { result = 2; } break; + case CONFIGITEM_EXOSPHERE_VERSION: + /* UNOFFICIAL: Gets information about the current exosphere version. */ + *p_outvalue = (EXOSPHERE_RELEASE_VERSION_MAJOR << 24) | (EXOSPHERE_RELEASE_VERSION_MINOR << 16) | (exosphere_get_target_firmware() << 8) | (mkey_get_revision() << 0); + break; default: result = 2; break; diff --git a/exosphere/src/configitem.h b/exosphere/src/configitem.h index c9cd1d699..8ff65af8a 100644 --- a/exosphere/src/configitem.h +++ b/exosphere/src/configitem.h @@ -21,7 +21,10 @@ typedef enum { CONFIGITEM_ODM4BIT10_4X = 14, CONFIGITEM_NEWHARDWARETYPE_5X = 15, CONFIGITEM_NEWKEYGENERATION_5X = 16, - CONFIGITEM_PACKAGE2HASH_5X = 17 + CONFIGITEM_PACKAGE2HASH_5X = 17, + + /* These are unofficial, for usage by Exosphere. */ + CONFIGITEM_EXOSPHERE_VERSION = 65000 } ConfigItem; uint32_t configitem_set(ConfigItem item, uint64_t value); diff --git a/exosphere/src/version.h b/exosphere/src/version.h new file mode 100644 index 000000000..a22c9027f --- /dev/null +++ b/exosphere/src/version.h @@ -0,0 +1,7 @@ +#ifndef EXOSPHERE_VERSION_H +#define EXOSPHERE_VERSION_H + +#define EXOSPHERE_RELEASE_VERSION_MAJOR 0 +#define EXOSPHERE_RELEASE_VERSION_MINOR 1 + +#endif \ No newline at end of file diff --git a/stratosphere/loader/source/ldr_main.cpp b/stratosphere/loader/source/ldr_main.cpp index 379a7f9cc..f2075abe8 100644 --- a/stratosphere/loader/source/ldr_main.cpp +++ b/stratosphere/loader/source/ldr_main.cpp @@ -63,6 +63,18 @@ void __appInit(void) { if (R_FAILED(rc)) { fatalSimple(0xCAFE << 4 | 2); } + + rc = splInitialize(); + if (R_FAILED(rc)) { + fatalSimple(0xCAFE << 4 | 3); + } + + /* Check for exosphere API compatibility. */ + u64 exosphere_cfg; + if (R_FAILED(splGetConfig((SplConfigItem)65000, &exosphere_cfg))) { + fatalSimple(0xCAFE << 4 | 0xFF); + /* TODO: Does Loader need to know about target firmware/master key revision? If so, extract from exosphere_cfg. */ + } } void __appExit(void) { diff --git a/stratosphere/pm/source/pm_main.cpp b/stratosphere/pm/source/pm_main.cpp index 909923cf1..5a65793fd 100644 --- a/stratosphere/pm/source/pm_main.cpp +++ b/stratosphere/pm/source/pm_main.cpp @@ -70,13 +70,19 @@ void __appInit(void) { rc = smManagerInitialize(); if (R_FAILED(rc)) { - fatalSimple(0xCAFE << 4 | 4); + fatalSimple(0xCAFE << 4 | 5); } - rc = splInitialize(); if (R_FAILED(rc)) { - fatalSimple(0xCAFE << 4 | 5); + fatalSimple(0xCAFE << 4 | 6); + } + + /* Check for exosphere API compatibility. */ + u64 exosphere_cfg; + if (R_FAILED(splGetConfig((SplConfigItem)65000, &exosphere_cfg))) { + fatalSimple(0xCAFE << 4 | 0xFF); + /* TODO: Does PM need to know about target firmware/master key revision? If so, extract from exosphere_cfg. */ } } diff --git a/stratosphere/sm/source/sm_main.cpp b/stratosphere/sm/source/sm_main.cpp index aa1fe0f8d..e68b6674d 100644 --- a/stratosphere/sm/source/sm_main.cpp +++ b/stratosphere/sm/source/sm_main.cpp @@ -38,7 +38,7 @@ void __libnx_initheap(void) { } void __appInit(void) { - /* We must do nothing here, because we are sm. */ + /* We must do no setup here, because we are sm. */ } void __appExit(void) {