From 07207a2fb6117ca99d9445b75c0d2513256b3122 Mon Sep 17 00:00:00 2001 From: MechanicalDragon Date: Wed, 6 May 2020 08:52:23 -0700 Subject: [PATCH] Clear a9lh stage2 section & fix compile (#39) Fixes #40 and #41 --- Makefile | 6 +++--- source/installer.c | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 77ef477..271874e 100644 --- a/Makefile +++ b/Makefile @@ -25,11 +25,11 @@ INCLUDES := source source/common source/font source/fs source/crypto source/fatf #--------------------------------------------------------------------------------- # options for code generation #--------------------------------------------------------------------------------- -ARCH := -mthumb -mthumb-interwork -flto +ARCH := -mthumb -mthumb-interwork CFLAGS := -g -Wall -Wextra -Wpedantic -Wcast-align -Wno-main -O2\ -march=armv5te -mtune=arm946e-s -fomit-frame-pointer -ffast-math -std=gnu11\ - $(ARCH) + -fno-builtin-memcpy $(ARCH) -fdata-sections -ffunction-sections CFLAGS += $(INCLUDE) -DARM9 @@ -53,7 +53,7 @@ endif CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -ASFLAGS := -g $(ARCH) +ASFLAGS := -g -mcpu=arm946e-s $(ARCH) LDFLAGS = -T../link.ld -nostartfiles -g $(ARCH) -Wl,-Map,$(TARGET).map LIBS := diff --git a/source/installer.c b/source/installer.c index 2465ab2..c15ec7b 100644 --- a/source/installer.c +++ b/source/installer.c @@ -3,6 +3,7 @@ #include "validator.h" #include "unittype.h" #include "nand.h" +#include "sdmmc.h" #include "ui.h" #include "qff.h" #include "hid.h" @@ -17,6 +18,8 @@ #define NAME_FIRMBACKUP INPUT_PATH "/firm%lu_enc.bak" #define NAME_SECTORBACKUP INPUT_PATH "/sector0x96_enc.bak" +#define MAX_STAGE2_SIZE 0x89A00 + #define STATUS_GREY -1 #define STATUS_GREEN 0 #define STATUS_YELLOW 1 @@ -279,6 +282,11 @@ u32 SafeB9SInstaller(void) { ShowInstallerStatus(); } if (ret != 0) break; + uint8_t emptyStage2[MAX_STAGE2_SIZE]={0}; + // Uninstall a9lh stage 2 always if firm flashed ok + // This prevents false positives in the event of cfw uninstall + ret = sdmmc_nand_writesectors(0x5C000, MAX_STAGE2_SIZE / 0x200, emptyStage2); + if (ret != 0) break; if ((IS_A9LH && !IS_SIGHAX)) { snprintf(msgInstall, 64, "0x96 revert..."); ShowInstallerStatus();