Browse Source

Update the way reboot to payload works.

main
Nichole Mattera 5 months ago
parent
commit
b675ddeb82
4 changed files with 67 additions and 1 deletions
  1. +15
    -0
      source/FileManager.cpp
  2. +1
    -0
      source/FileManager.hpp
  3. +48
    -1
      source/scenes/PackageDownloadScene.cpp
  4. +3
    -0
      source/scenes/PackageDownloadScene.hpp

+ 15
- 0
source/FileManager.cpp 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);



+ 1
- 0
source/FileManager.hpp 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);


+ 48
- 1
source/scenes/PackageDownloadScene.cpp 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;


+ 3
- 0
source/scenes/PackageDownloadScene.hpp View File

@@ -49,6 +49,9 @@ namespace ku::scenes {
swurl::WebRequest * _kosmosUrlRequest = NULL;
swurl::WebRequest * _kosmosRequest = 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);


Loading…
Cancel
Save