Merge pull request #1 from NicholeMattera/master

Support latest version of libnx and improve the reboot to payload code.
This commit is contained in:
FennecTECH 2020-05-17 11:44:12 -05:00 committed by GitHub
commit e75830c3a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 70 additions and 5 deletions

View File

@ -78,9 +78,8 @@ LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) \
-Wl,-Map,$(notdir $*.map)
LIBS := -lSDL2_ttf -lSDL2_image -lSDL2_gfx -lfreetype -lwebp -lpng -ljpeg \
-ljansson -lSwurl -lcurl -lz -lmbedtls -lmbedcrypto -lmbedx509 \
-lSimpleIniParser -lminizip -lconfig -lnx `sdl2-config --libs` \
`freetype-config --libs`
-ljansson -lSwurl -lcurl -lz -lSimpleIniParser -lminizip -lconfig \
-lnx `sdl2-config --libs` `freetype-config --libs`
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing

View File

@ -17,6 +17,7 @@
#include <algorithm>
#include <dirent.h>
#include <fstream>
#include <SimpleIniParser.hpp>
#include <string.h>
#include <switch.h>
@ -31,6 +32,20 @@ using namespace simpleIniParser;
using namespace std;
namespace ku {
std::vector<char> FileManager::readFile(std::string path) {
std::ifstream file;
file.open(path, std::ios::in | std::ios::binary | std::ios::ate);
auto size = file.tellg();
file.seekg(0, std::ios::beg);
std::vector<char> buffer(size);
file.read(buffer.data(), size);
file.close();
return buffer;
}
bool FileManager::writeFile(string filename, string data) {
deleteFile(filename);

View File

@ -24,6 +24,7 @@
namespace ku {
class FileManager {
public:
static std::vector<char> readFile(std::string path);
static bool writeFile(std::string filename, std::string data);
static bool deleteFile(std::string filename);
static bool fileExists(std::string filename);

View File

@ -29,7 +29,7 @@ namespace ku {
romfsInit();
setsysInitialize();
plInitialize();
plInitialize(PlServiceType_User);
SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_AUDIO);

View File

@ -15,6 +15,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <cstring>
#include <jansson.h>
#include <SimpleIniParser.hpp>
@ -24,6 +25,12 @@
#include "../FileManager.hpp"
#include "../SceneDirector.hpp"
#define IRAM_PAYLOAD_MAX_SIZE 0x2F000
#define IRAM_PAYLOAD_BASE 0x40010000
static __attribute__((aligned(0x1000))) u8 g_ff_page[0x1000];
static __attribute__((aligned(0x1000))) u8 g_work_page[0x1000];
using namespace ku;
using namespace ku::models;
using namespace ku::views;
@ -109,6 +116,27 @@ namespace ku::scenes {
Scene::render(rect, dTime);
}
void PackageDownloadScene::_copyToIram(uintptr_t iram_addr, void *buf, size_t size) {
memcpy(g_work_page, buf, size);
SecmonArgs args = {0};
args.X[0] = 0xF0000201; /* smcAmsIramCopy */
args.X[1] = (uintptr_t)g_work_page; /* DRAM Address */
args.X[2] = iram_addr; /* IRAM Address */
args.X[3] = size; /* Copy size */
args.X[4] = 1;
svcCallSecureMonitor(&args);
memcpy(buf, g_work_page, size);
}
void PackageDownloadScene::_clearIram() {
memset(g_ff_page, 0xFF, sizeof(g_ff_page));
for(size_t i = 0; i < IRAM_PAYLOAD_MAX_SIZE; i += sizeof(g_ff_page)) {
this->_copyToIram(IRAM_PAYLOAD_BASE + i, g_ff_page, sizeof(g_ff_page));
}
}
void PackageDownloadScene::_showStatus(string text, string subtext, bool wasSuccessful) {
_statusView->setText(text);
_statusView->setSubtext(subtext);
@ -125,7 +153,26 @@ namespace ku::scenes {
void PackageDownloadScene::_onAlertViewDismiss(ModalView * view, bool success) {
if (success) {
if (_restartAlertView->getSelectedOption() == 0) {
bpcRebootSystem();
auto payload = FileManager::readFile("sdmc:/bootloader/update.bin");
if (payload.size() == 0) {
SceneDirector::exitApp = true;
return;
}
Result rc = splInitialize();
if (R_FAILED(rc)) {
SceneDirector::exitApp = true;
return;
}
this->_clearIram();
for (size_t i = 0; i < IRAM_PAYLOAD_MAX_SIZE; i += 0x1000) {
this->_copyToIram(IRAM_PAYLOAD_BASE + i, &payload[i], 0x1000);
}
splSetConfig((SplConfigItem) 65001, 2);
splExit();
}
else {
SceneDirector::exitApp = true;

View File

@ -49,6 +49,9 @@ namespace ku::scenes {
swurl::WebRequest * _DeepSeaUrlRequest = NULL;
swurl::WebRequest * _DeepSeaRequest = NULL;
void _copyToIram(uintptr_t iram_addr, void *buf, size_t size);
void _clearIram();
void _showStatus(std::string text, std::string subtext, bool wasSuccessful);
void _onAlertViewDismiss(ku::ModalView * view, bool success);
std::string _getVersionNumber(std::string version);