2019-01-21 07:13:16 +00:00
|
|
|
/*
|
2019-04-08 02:00:49 +00:00
|
|
|
* Copyright (c) 2018-2019 Atmosphère-NX
|
2019-01-21 07:13:16 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <mutex>
|
|
|
|
#include <switch.h>
|
|
|
|
|
|
|
|
#include "setsys_firmware_version.hpp"
|
|
|
|
|
|
|
|
static HosMutex g_version_mutex;
|
|
|
|
static bool g_got_version = false;
|
2019-03-24 21:41:49 +00:00
|
|
|
static SetSysFirmwareVersion g_ams_fw_version = {0};
|
2019-01-21 07:13:16 +00:00
|
|
|
static SetSysFirmwareVersion g_fw_version = {0};
|
|
|
|
|
2019-03-24 21:41:49 +00:00
|
|
|
void VersionManager::Initialize() {
|
2019-01-21 07:13:16 +00:00
|
|
|
std::scoped_lock<HosMutex> lock(g_version_mutex);
|
2019-03-24 21:41:49 +00:00
|
|
|
|
|
|
|
if (g_got_version) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Mount firmware version data archive. */
|
2019-06-20 11:04:33 +00:00
|
|
|
R_ASSERT(romfsMountFromDataArchive(TitleId_ArchiveSystemVersion, FsStorageId_NandSystem, "sysver"));
|
|
|
|
{
|
2019-03-29 04:36:08 +00:00
|
|
|
ON_SCOPE_EXIT { romfsUnmount("sysver"); };
|
2019-03-24 21:41:49 +00:00
|
|
|
|
|
|
|
SetSysFirmwareVersion fw_ver;
|
|
|
|
|
|
|
|
/* Firmware version file must exist. */
|
2019-03-29 04:36:08 +00:00
|
|
|
FILE *f = fopen("sysver:/file", "rb");
|
2019-03-24 21:41:49 +00:00
|
|
|
if (f == NULL) {
|
|
|
|
std::abort();
|
2019-01-21 07:13:16 +00:00
|
|
|
}
|
2019-03-24 21:41:49 +00:00
|
|
|
|
|
|
|
/* Must be possible to read firmware version from file. */
|
|
|
|
if (fread(&fw_ver, sizeof(fw_ver), 1, f) != 1) {
|
|
|
|
std::abort();
|
2019-01-21 07:13:16 +00:00
|
|
|
}
|
2019-03-24 21:41:49 +00:00
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
g_fw_version = fw_ver;
|
|
|
|
g_ams_fw_version = fw_ver;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Modify the output firmware version. */
|
|
|
|
{
|
|
|
|
u32 major, minor, micro;
|
|
|
|
char display_version[sizeof(g_ams_fw_version.display_version)] = {0};
|
2019-06-20 11:04:33 +00:00
|
|
|
|
2019-03-24 21:41:49 +00:00
|
|
|
GetAtmosphereApiVersion(&major, &minor, µ, nullptr, nullptr);
|
|
|
|
snprintf(display_version, sizeof(display_version), "%s (AMS %u.%u.%u)", g_ams_fw_version.display_version, major, minor, micro);
|
|
|
|
|
|
|
|
memcpy(g_ams_fw_version.display_version, display_version, sizeof(g_ams_fw_version.display_version));
|
2019-01-21 07:13:16 +00:00
|
|
|
}
|
2019-03-24 21:41:49 +00:00
|
|
|
|
|
|
|
g_got_version = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Result VersionManager::GetFirmwareVersion(u64 title_id, SetSysFirmwareVersion *out) {
|
|
|
|
VersionManager::Initialize();
|
2019-06-20 11:04:33 +00:00
|
|
|
|
2019-01-21 07:13:16 +00:00
|
|
|
/* Report atmosphere string to qlaunch, maintenance and nothing else. */
|
2019-03-29 04:36:08 +00:00
|
|
|
if (title_id == TitleId_AppletQlaunch || title_id == TitleId_AppletMaintenanceMenu) {
|
2019-03-24 21:41:49 +00:00
|
|
|
*out = g_ams_fw_version;
|
2019-01-21 07:13:16 +00:00
|
|
|
} else {
|
2019-03-24 21:41:49 +00:00
|
|
|
*out = g_fw_version;
|
2019-01-21 07:13:16 +00:00
|
|
|
}
|
2019-03-24 21:41:49 +00:00
|
|
|
|
2019-03-29 05:39:39 +00:00
|
|
|
return ResultSuccess;
|
2019-01-21 07:13:16 +00:00
|
|
|
}
|