diff --git a/common/include/atmosphere/version.h b/common/include/atmosphere/version.h new file mode 100644 index 0000000..58dd3a5 --- /dev/null +++ b/common/include/atmosphere/version.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2018 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 . + */ + +#ifndef ATMOSPHERE_VERSION_H +#define ATMOSPHERE_VERSION_H + +#define ATMOSPHERE_RELEASE_VERSION_MAJOR 0 +#define ATMOSPHERE_RELEASE_VERSION_MINOR 7 +#define ATMOSPHERE_RELEASE_VERSION_MICRO 0 + +#endif \ No newline at end of file diff --git a/exosphere/Makefile b/exosphere/Makefile index 77e3e02..efadefc 100644 --- a/exosphere/Makefile +++ b/exosphere/Makefile @@ -20,7 +20,7 @@ BUILD := build SOURCES := src src/dbg DATA := data -INCLUDES := include +INCLUDES := include ../common/include #--------------------------------------------------------------------------------- # options for code generation diff --git a/exosphere/src/configitem.c b/exosphere/src/configitem.c index d228b01..389bbca 100644 --- a/exosphere/src/configitem.c +++ b/exosphere/src/configitem.c @@ -15,6 +15,7 @@ */ #include +#include #include "bootconfig.h" #include "configitem.h" @@ -25,7 +26,6 @@ #include "utils.h" #include "masterkey.h" #include "exocfg.h" -#include "version.h" static bool g_battery_profile = false; @@ -151,11 +151,11 @@ break; case CONFIGITEM_EXOSPHERE_VERSION: /* UNOFFICIAL: Gets information about the current exosphere version. */ - *p_outvalue = ((ATMOSPHERE_RELEASE_VERSION_MAJOR & 0xFF) << 24) | - ((ATMOSPHERE_RELEASE_VERSION_MINOR & 0xFF) << 16) | - ((ATMOSPHERE_RELEASE_VERSION_MICRO & 0x3F) << 10) | - ((exosphere_get_target_firmware() & 0x1F) << 6) | - ((mkey_get_revision() & 0x1F) << 0); + *p_outvalue = ((uint64_t)(ATMOSPHERE_RELEASE_VERSION_MAJOR & 0xFF) << 32ull) | + ((uint64_t)(ATMOSPHERE_RELEASE_VERSION_MINOR & 0xFF) << 24ull) | + ((uint64_t)(ATMOSPHERE_RELEASE_VERSION_MICRO & 0xFF) << 16ull) | + ((uint64_t)(exosphere_get_target_firmware() & 0xFF) << 8ull) | + ((uint64_t)(mkey_get_revision() & 0xFF) << 0ull); break; default: result = 2; diff --git a/exosphere/src/version.h b/exosphere/src/version.h deleted file mode 100644 index 8a1a4d3..0000000 --- a/exosphere/src/version.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2018 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 . - */ - -#ifndef EXOSPHERE_VERSION_H -#define EXOSPHERE_VERSION_H - -#define ATMOSPHERE_RELEASE_VERSION_MAJOR 0 -#define ATMOSPHERE_RELEASE_VERSION_MINOR 7 -#define ATMOSPHERE_RELEASE_VERSION_MICRO 0 - -#endif \ No newline at end of file diff --git a/fusee/fusee-primary/Makefile b/fusee/fusee-primary/Makefile index 34307fc..8dce2ef 100644 --- a/fusee/fusee-primary/Makefile +++ b/fusee/fusee-primary/Makefile @@ -20,7 +20,7 @@ BUILD := build SOURCES := src src/sdmmc src/lib src/lib/fatfs src/display DATA := data -INCLUDES := include +INCLUDES := include ../../common/include #--------------------------------------------------------------------------------- # options for code generation diff --git a/fusee/fusee-secondary/Makefile b/fusee/fusee-secondary/Makefile index d902d58..9055bbf 100644 --- a/fusee/fusee-secondary/Makefile +++ b/fusee/fusee-secondary/Makefile @@ -23,7 +23,7 @@ BUILD := build SOURCES := src src/sdmmc src/lib src/lib/fatfs src/display DATA := data -INCLUDES := include +INCLUDES := include ../../common/include #--------------------------------------------------------------------------------- # options for code generation diff --git a/stratosphere/boot/Makefile b/stratosphere/boot/Makefile index b4ff11d..57b69f6 100644 --- a/stratosphere/boot/Makefile +++ b/stratosphere/boot/Makefile @@ -21,7 +21,7 @@ BUILD := build SOURCES := source DATA := data -INCLUDES := include +INCLUDES := include ../../common/include EXEFS_SRC := exefs_src DEFINES := -DDISABLE_IPC diff --git a/stratosphere/boot/source/boot_main.cpp b/stratosphere/boot/source/boot_main.cpp index e636ff6..9eb94f1 100644 --- a/stratosphere/boot/source/boot_main.cpp +++ b/stratosphere/boot/source/boot_main.cpp @@ -83,6 +83,8 @@ fatalSimple(0xCAFE << 4 | 2); fsdevMountSdmc(); + + CheckAtmosphereVersion(); } void __appExit(void) { diff --git a/stratosphere/creport/Makefile b/stratosphere/creport/Makefile index 67fd1e2..c042e96 100644 --- a/stratosphere/creport/Makefile +++ b/stratosphere/creport/Makefile @@ -21,7 +21,7 @@ BUILD := build SOURCES := source DATA := data -INCLUDES := include +INCLUDES := include ../../common/include EXEFS_SRC := exefs_src DEFINES := -DDISABLE_IPC diff --git a/stratosphere/fs_mitm/Makefile b/stratosphere/fs_mitm/Makefile index 41a6cf7..e8b1f04 100644 --- a/stratosphere/fs_mitm/Makefile +++ b/stratosphere/fs_mitm/Makefile @@ -21,7 +21,7 @@ BUILD := build SOURCES := source DATA := data -INCLUDES := include +INCLUDES := include ../../common/include EXEFS_SRC := exefs_src DEFINES := -DDISABLE_IPC diff --git a/stratosphere/fs_mitm/source/fsmitm_main.cpp b/stratosphere/fs_mitm/source/fsmitm_main.cpp index e6271b1..9caf7f3 100644 --- a/stratosphere/fs_mitm/source/fsmitm_main.cpp +++ b/stratosphere/fs_mitm/source/fsmitm_main.cpp @@ -76,25 +76,7 @@ if (R_FAILED(rc)) { fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_FS)); } - - rc = splInitialize(); - if (R_FAILED(rc)) { - fatalSimple(0xCAFE << 4 | 3); - } - - /* Check for exosphere API compatibility. */ - u64 exosphere_cfg; - if (R_SUCCEEDED(splGetConfig((SplConfigItem)65000, &exosphere_cfg))) { - /* MitM requires Atmosphere API 0.1. */ - u16 api_version = (exosphere_cfg >> 16) & 0xFFFF; - if (api_version < 0x0001) { - fatalSimple(0xCAFE << 4 | 0xFE); - } - } else { - fatalSimple(0xCAFE << 4 | 0xFF); - } - - //splExit(); + CheckAtmosphereVersion(); } void __appExit(void) { diff --git a/stratosphere/libstratosphere/Makefile b/stratosphere/libstratosphere/Makefile index ff0e010..70ba194 100644 --- a/stratosphere/libstratosphere/Makefile +++ b/stratosphere/libstratosphere/Makefile @@ -18,7 +18,7 @@ TARGET := $(notdir $(CURDIR)) SOURCES := source DATA := data -INCLUDES := include +INCLUDES := include ../../common/include #--------------------------------------------------------------------------------- # options for code generation diff --git a/stratosphere/libstratosphere/include/stratosphere.hpp b/stratosphere/libstratosphere/include/stratosphere.hpp index fdd8b9d..041d727 100644 --- a/stratosphere/libstratosphere/include/stratosphere.hpp +++ b/stratosphere/libstratosphere/include/stratosphere.hpp @@ -33,3 +33,5 @@ #include "stratosphere/waitablemanager.hpp" #include "stratosphere/multithreadedwaitablemanager.hpp" + +#include "stratosphere/version_check.hpp" \ No newline at end of file diff --git a/stratosphere/libstratosphere/include/stratosphere/version_check.hpp b/stratosphere/libstratosphere/include/stratosphere/version_check.hpp new file mode 100644 index 0000000..336ea83 --- /dev/null +++ b/stratosphere/libstratosphere/include/stratosphere/version_check.hpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2018 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 . + */ + +#pragma once +#include +#include + +static inline void GetAtmosphereApiVersion(u32 *major, u32 *minor, u32 *micro, u32 *target_fw, u32 *mkey_rev) { + if (R_FAILED(splInitialize())) { + fatalSimple(0xCAFE << 4 | 0xD); + } + + /* Check for exosphere API compatibility. */ + u64 exosphere_cfg; + if (R_FAILED(splGetConfig((SplConfigItem)65000, &exosphere_cfg))) { + fatalSimple(0xCAFE << 4 | 0xE); + } + + if (mkey_rev) { + *mkey_rev = (u32)((exosphere_cfg >> 0x00) & 0xFF); + } + + if (target_fw) { + *target_fw = (u32)((exosphere_cfg >> 0x08) & 0xFF); + } + + if (micro) { + *micro = (u32)((exosphere_cfg >> 0x10) & 0xFF); + } + + if (minor) { + *minor = (u32)((exosphere_cfg >> 0x18) & 0xFF); + } + + if (major) { + *major = (u32)((exosphere_cfg >> 0x20) & 0xFF); + } + + splExit(); +} + +static inline u32 MakeAtmosphereVersion(u32 major, u32 minor, u32 micro) { + return (major << 16) | (minor << 8) | micro; +} + +static inline void CheckAtmosphereVersion() { + u32 major, minor, micro; + GetAtmosphereApiVersion(&major, &minor, µ, nullptr, nullptr); + + if (MakeAtmosphereVersion(major, minor, micro) < MakeAtmosphereVersion(ATMOSPHERE_RELEASE_VERSION_MAJOR, ATMOSPHERE_RELEASE_VERSION_MINOR, ATMOSPHERE_RELEASE_VERSION_MICRO)) { + fatalSimple(0xCAFE << 4 | 0xF); + } +} \ No newline at end of file diff --git a/stratosphere/loader/Makefile b/stratosphere/loader/Makefile index 41a6cf7..e8b1f04 100644 --- a/stratosphere/loader/Makefile +++ b/stratosphere/loader/Makefile @@ -21,7 +21,7 @@ BUILD := build SOURCES := source DATA := data -INCLUDES := include +INCLUDES := include ../../common/include EXEFS_SRC := exefs_src DEFINES := -DDISABLE_IPC diff --git a/stratosphere/loader/source/ldr_main.cpp b/stratosphere/loader/source/ldr_main.cpp index a8d69bf..a074977 100644 --- a/stratosphere/loader/source/ldr_main.cpp +++ b/stratosphere/loader/source/ldr_main.cpp @@ -80,19 +80,7 @@ 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. */ - } - - //splExit(); + CheckAtmosphereVersion(); } void __appExit(void) { diff --git a/stratosphere/pm/Makefile b/stratosphere/pm/Makefile index c819c77..c3b31a8 100644 --- a/stratosphere/pm/Makefile +++ b/stratosphere/pm/Makefile @@ -21,7 +21,7 @@ BUILD := build SOURCES := source DATA := data -INCLUDES := include +INCLUDES := include ../../common/include EXEFS_SRC := exefs_src DEFINES := -DDISABLE_IPC diff --git a/stratosphere/pm/source/pm_main.cpp b/stratosphere/pm/source/pm_main.cpp index 04200ba..2c33145 100644 --- a/stratosphere/pm/source/pm_main.cpp +++ b/stratosphere/pm/source/pm_main.cpp @@ -94,12 +94,7 @@ 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. */ - } + CheckAtmosphereVersion(); } void __appExit(void) { diff --git a/stratosphere/sm/Makefile b/stratosphere/sm/Makefile index a0da4da..3f6b058 100644 --- a/stratosphere/sm/Makefile +++ b/stratosphere/sm/Makefile @@ -21,7 +21,7 @@ BUILD := build SOURCES := source DATA := data -INCLUDES := include +INCLUDES := include ../../common/include EXEFS_SRC := exefs_src DEFINES := -DDISABLE_IPC diff --git a/thermosphere/Makefile b/thermosphere/Makefile index f62bcf1..76f6a10 100644 --- a/thermosphere/Makefile +++ b/thermosphere/Makefile @@ -20,7 +20,7 @@ BUILD := build SOURCES := src src/lib DATA := data -INCLUDES := include +INCLUDES := include ../common/include #--------------------------------------------------------------------------------- # options for code generation