2021-08-21 18:10:13 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
#include <exosphere.hpp>
|
2021-08-23 18:57:39 +00:00
|
|
|
#include "fusee_display.hpp"
|
2021-08-23 21:18:59 +00:00
|
|
|
#include "sein/fusee_secure_initialize.hpp"
|
|
|
|
#include "sdram/fusee_sdram.hpp"
|
|
|
|
#include "fs/fusee_fs_api.hpp"
|
2021-08-23 14:11:28 +00:00
|
|
|
#include "fusee_sd_card.hpp"
|
2021-08-23 21:18:59 +00:00
|
|
|
#include "fusee_fatal.hpp"
|
|
|
|
#include "fusee_secondary_archive.hpp"
|
2021-08-21 18:10:13 +00:00
|
|
|
|
|
|
|
namespace ams::nxboot {
|
|
|
|
|
2021-08-23 21:18:59 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
/* TODO: Change to fusee-secondary.bin when development is done. */
|
|
|
|
constexpr const char FuseeSecondaryFilePath[] = "sdmc:/atmosphere/fusee-boogaloo.bin";
|
|
|
|
|
|
|
|
void ReadFuseeSecondary() {
|
|
|
|
Result result;
|
|
|
|
|
|
|
|
/* Open fusee-secondary. */
|
|
|
|
fs::FileHandle file;
|
|
|
|
if (R_FAILED((result = fs::OpenFile(std::addressof(file), FuseeSecondaryFilePath, fs::OpenMode_Read)))) {
|
|
|
|
ShowFatalError("Failed to open %s!\n", FuseeSecondaryFilePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
ON_SCOPE_EXIT { fs::CloseFile(file); };
|
|
|
|
|
|
|
|
/* Get file size. */
|
|
|
|
s64 file_size;
|
|
|
|
if (R_FAILED((result = fs::GetFileSize(std::addressof(file_size), file)))) {
|
|
|
|
ShowFatalError("Failed to get fusee-secondary size: 0x%08" PRIx32 "\n", result.GetValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check file size. */
|
|
|
|
if (static_cast<size_t>(file_size) != SecondaryArchiveSize) {
|
|
|
|
ShowFatalError("fusee-secondary seems corrupted (size 0x%zx != 0x%zx)", static_cast<size_t>(file_size), SecondaryArchiveSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read to fixed address. */
|
|
|
|
if (R_FAILED((result = fs::ReadFile(file, 0, const_cast<SecondaryArchive *>(std::addressof(GetSecondaryArchive())), SecondaryArchiveSize)))) {
|
|
|
|
ShowFatalError("Failed to read fusee-secondary: 0x%08" PRIx32 "\n", result.GetValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-08-21 18:10:13 +00:00
|
|
|
void Main() {
|
2021-08-21 22:49:36 +00:00
|
|
|
/* Perform secure hardware initialization. */
|
2021-08-21 23:32:05 +00:00
|
|
|
SecureInitialize(true);
|
2021-08-21 22:49:36 +00:00
|
|
|
|
2021-08-23 22:10:24 +00:00
|
|
|
/* Overclock the bpmp. */
|
|
|
|
clkrst::SetBpmpClockRate(fuse::GetSocType() == fuse::SocType_Mariko ? clkrst::BpmpClockRate_589MHz : clkrst::BpmpClockRate_576MHz);
|
|
|
|
|
2021-08-22 09:32:05 +00:00
|
|
|
/* Initialize Sdram. */
|
|
|
|
InitializeSdram();
|
|
|
|
|
2021-08-23 16:13:26 +00:00
|
|
|
/* Initialize cache. */
|
|
|
|
hw::InitializeDataCache();
|
|
|
|
|
2021-08-23 14:11:28 +00:00
|
|
|
/* Initialize SD card. */
|
|
|
|
{
|
2021-08-23 21:18:59 +00:00
|
|
|
Result result = InitializeSdCard();
|
|
|
|
if (R_FAILED(result)) {
|
|
|
|
ShowFatalError("Failed to initialize the SD card: 0x%08" PRIx32 "\n", result.GetValue());
|
2021-08-23 14:11:28 +00:00
|
|
|
}
|
2021-08-23 21:18:59 +00:00
|
|
|
}
|
2021-08-23 17:13:46 +00:00
|
|
|
|
2021-08-23 21:18:59 +00:00
|
|
|
/* Mount SD card. */
|
|
|
|
if (!fs::MountSdCard()) {
|
|
|
|
ShowFatalError("Failed to mount the SD card.");
|
2021-08-23 14:11:28 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 21:18:59 +00:00
|
|
|
/* If we have a fatal error, save and display it. */
|
|
|
|
SaveAndShowFatalError();
|
|
|
|
|
|
|
|
/* Read our overlay file. */
|
|
|
|
ReadFuseeSecondary();
|
|
|
|
|
2021-08-23 22:10:24 +00:00
|
|
|
/* Initialize display (splash screen will be visible from this point onwards). */
|
|
|
|
InitializeDisplay();
|
|
|
|
ShowDisplay();
|
|
|
|
|
2021-08-23 21:18:59 +00:00
|
|
|
/* TODO */
|
2021-08-23 22:10:24 +00:00
|
|
|
WaitForReboot();
|
2021-08-23 21:18:59 +00:00
|
|
|
|
2021-08-21 18:10:13 +00:00
|
|
|
/* TODO */
|
|
|
|
AMS_INFINITE_LOOP();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|