diff --git a/include/arm11/menu/bootslot.h b/include/arm11/menu/bootslot.h new file mode 100644 index 0000000..f7e0b9b --- /dev/null +++ b/include/arm11/menu/bootslot.h @@ -0,0 +1,27 @@ +#pragma once + +/* + * This file is part of fastboot 3DS + * Copyright (C) 2017 derrek, profi200, d0k3 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that 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 . + */ + +#include "types.h" + +#define N_BOOTSLOTS 3 +#define INVALID_BOOT_SLOT 0xFF + +u8 readStoredBootslot(void); +bool storeBootslot(u8 slot); diff --git a/include/arm11/menu/bootslot_store.h b/include/arm11/menu/bootslot_store.h deleted file mode 100644 index 02cc897..0000000 --- a/include/arm11/menu/bootslot_store.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -/* - * This file is part of fastboot 3DS - * Copyright (C) 2017 derrek, profi200, d0k3 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that 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 . - */ - -#include "types.h" - -#define INVALID_BOOT_SLOT 0xFF - -u8 readStoredBootslot(void); -bool storeBootslot(u8 slot); diff --git a/include/arm11/menu/menu.h b/include/arm11/menu/menu.h index c5ad16e..cc5c303 100644 --- a/include/arm11/menu/menu.h +++ b/include/arm11/menu/menu.h @@ -19,6 +19,7 @@ */ #include "types.h" +#include "arm11/menu/bootslot.h" #include "arm11/console.h" #define MENU_LEAVE_PARAM ((u32) -1) @@ -33,9 +34,10 @@ #define MENU_FLAG_SLOTS (1<<0) #define MENU_FLAG_SLOT(x) (1< 0) && !((flags >> x) & 0x1); x--) /** * @brief Menu entry description struct, used by MenuInfo. diff --git a/include/arm11/menu/menu_fb3ds.h b/include/arm11/menu/menu_fb3ds.h index 42c9d91..6c3faf5 100644 --- a/include/arm11/menu/menu_fb3ds.h +++ b/include/arm11/menu/menu_fb3ds.h @@ -19,9 +19,16 @@ */ #include "types.h" +#include "arm11/menu/bootslot.h" #include "arm11/menu/menu.h" #include "arm11/menu/menu_func.h" +#define SUBENTRY_SLOT_BOOT(x) \ + { "Boot [slot " #x "]", DESC_BOOT_SLOT(x), &menuLaunchFirm, (x-1) } + +#define SUBENTRY_SLOT_SETUP(x, m) \ + { "Setup [slot " #x "]...", DESC_SLOT_SETUP(x), NULL, (x+m-1) } + #define SUBMENU_SLOT_SETUP(x) \ { \ "Boot Slot #" #x " Setup", 4, &menuPresetSlotConfig##x, MENU_FLAG_SLOT(x) | MENU_FLAG_CONFIG, \ @@ -81,32 +88,29 @@ { "Boot menu...", DESC_BOOT_MENU, NULL, 1 }, { "Boot setup...", DESC_BOOT_SETUP, NULL, 2 }, { "Boot from file...", DESC_BOOT_FILE, &menuLaunchFirm, 0xFF }, - { "NAND tools...", DESC_NAND_TOOLS, NULL, 7 }, - { "Miscellaneous...", DESC_MISC, NULL, 8 }, - // { "Debug...", LOREM, NULL, 9 } + { "NAND tools...", DESC_NAND_TOOLS, NULL, 4 }, + { "Miscellaneous...", DESC_MISC, NULL, 5 }, + { "Debug...", LOREM, NULL, 9 } } }, { // 1 - "Boot Menu", 3, &menuPresetBootMenu, MENU_FLAG_SLOTS, + "Boot Menu", N_BOOTSLOTS, &menuPresetBootMenu, MENU_FLAG_SLOTS, { - { "Boot [slot 1]", DESC_BOOT_SLOT(1), &menuLaunchFirm, 0x00 }, - { "Boot [slot 2]", DESC_BOOT_SLOT(2), &menuLaunchFirm, 0x01 }, - { "Boot [slot 3]", DESC_BOOT_SLOT(3), &menuLaunchFirm, 0x02 } + SUBENTRY_SLOT_BOOT(1), + SUBENTRY_SLOT_BOOT(2), + SUBENTRY_SLOT_BOOT(3) } }, { // 2 - "Boot Setup", 4, &menuPresetBootConfig, MENU_FLAG_SLOTS | MENU_FLAG_BOOTMODE | MENU_FLAG_CONFIG, + "Boot Setup", N_BOOTSLOTS + 1, &menuPresetBootConfig, MENU_FLAG_SLOTS | MENU_FLAG_BOOTMODE | MENU_FLAG_CONFIG, { - { "Setup [slot 1]...", DESC_SLOT_SETUP(1), NULL, 3 }, - { "Setup [slot 2]...", DESC_SLOT_SETUP(2), NULL, 4 }, - { "Setup [slot 3]...", DESC_SLOT_SETUP(3), NULL, 5 }, - { "Change boot mode...", DESC_CHANGE_BOOT, NULL, 6 } + SUBENTRY_SLOT_SETUP(1,6), + SUBENTRY_SLOT_SETUP(2,6), + SUBENTRY_SLOT_SETUP(3,6), + { "Change boot mode...", DESC_CHANGE_BOOT, NULL, 3 } } }, - SUBMENU_SLOT_SETUP(1), // 3 - SUBMENU_SLOT_SETUP(2), // 4 - SUBMENU_SLOT_SETUP(3), // 5 - { // 6 + { // 3 "Boot Mode Setup", 3, &menuPresetBootMode, MENU_FLAG_CONFIG, { { "Set normal boot", DESC_BOOT_NORMAL, &menuSetBootMode, 0 }, @@ -114,7 +118,7 @@ { "Set quiet boot", DESC_BOOT_QUIET, &menuSetBootMode, 2 } } }, - { // 7 + { // 4 "NAND Tools", 4, &menuPresetNandTools, 0, { { "Backup NAND", DESC_NAND_BACKUP, &menuBackupNand, 0 }, @@ -123,14 +127,17 @@ { "Flash firmware to FIRM1", DESC_FIRM_FLASH, &menuInstallFirm, 1 } } }, - { // 8 + { // 5 "Miscellaneous", 2, NULL, 0, { { "Update fastboot3DS", DESC_UPDATE, &menuUpdateFastboot3ds, 0 }, { "Credits", DESC_CREDITS, &menuShowCredits, 0 } } - }/*, - { // 9 + }, + SUBMENU_SLOT_SETUP(1), // 6 + SUBMENU_SLOT_SETUP(2), // 7 + SUBMENU_SLOT_SETUP(3), // 8 + /*{ // 9 "Debug", 2, NULL, 0, // this will not show in the release version { { "View current settings", LOREM, &debugSettingsView, 0 }, diff --git a/source/arm11/main.c b/source/arm11/main.c index b413461..b5e060d 100644 --- a/source/arm11/main.c +++ b/source/arm11/main.c @@ -20,7 +20,7 @@ #include "types.h" #include "arm11/hardware/hardware.h" #include "arm11/hardware/hid.h" -#include "arm11/menu/bootslot_store.h" +#include "arm11/menu/bootslot.h" #include "arm11/menu/menu.h" #include "arm11/menu/menu_fb3ds.h" #include "arm11/menu/menu_util.h" @@ -71,7 +71,7 @@ keysToString(kHeld & 0xfff, combo_str); err_ptr += ee_sprintf(err_ptr, "Keys held on boot: %s\n", combo_str); - for(u32 i = 0; (i < 3) && !g_startFirmLaunch; i++) + for(u32 i = 0; (i < N_BOOTSLOTS) && !g_startFirmLaunch; i++) { if(!configDataExist(KBootOption1 + i) || !configDataExist(KBootOption1Buttons + i)) @@ -192,7 +192,7 @@ if (!nextBootSlot) { err_ptr += ee_sprintf(err_ptr, "Continuing bootloader...\n"); - for (u32 i = 0; (i < 3) && !g_startFirmLaunch; i++) + for (u32 i = 0; (i < N_BOOTSLOTS) && !g_startFirmLaunch; i++) { // FIRM not set for slot or slot not set to autoboot if (!configDataExist(KBootOption1 + i) || configDataExist(KBootOption1Buttons + i)) diff --git a/source/arm11/menu/bootslot.c b/source/arm11/menu/bootslot.c new file mode 100644 index 0000000..9ccfa4c --- /dev/null +++ b/source/arm11/menu/bootslot.c @@ -0,0 +1,59 @@ +/* + * This file is part of fastboot 3DS + * Copyright (C) 2017 derrek, profi200, d0k3 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that 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 . + */ + +#include "arm11/bootenv.h" +#include "arm11/hardware/i2c.h" +#include "arm11/menu/bootslot.h" + +#define BOOTSLOT_STORE_REG ((u8) 0x1E) + + +static u8 stored_slot = INVALID_BOOT_SLOT; + + +u8 readStoredBootslot(void) +{ + // stored slot is always zero on cold boots + if (getBootEnv() == BOOTENV_COLD_BOOT) + return 0; + + if (stored_slot == INVALID_BOOT_SLOT) + stored_slot = I2C_readReg(I2C_DEV_MCU, BOOTSLOT_STORE_REG); + + // slot must not exceed # of boot slots + if (stored_slot > N_BOOTSLOTS) + stored_slot = 0; + + return stored_slot; +} + +bool storeBootslot(u8 slot) +{ + if (slot == INVALID_BOOT_SLOT) // 0xFF is not allowed + slot = 0; + + if (slot != stored_slot) + { + stored_slot = slot; + return I2C_writeReg(I2C_DEV_MCU, BOOTSLOT_STORE_REG, (u8) slot); + } + else + { + return true; + } +} diff --git a/source/arm11/menu/bootslot_store.c b/source/arm11/menu/bootslot_store.c deleted file mode 100644 index bbd0b4b..0000000 --- a/source/arm11/menu/bootslot_store.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * This file is part of fastboot 3DS - * Copyright (C) 2017 derrek, profi200, d0k3 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that 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 . - */ - -#include "arm11/bootenv.h" -#include "arm11/hardware/i2c.h" -#include "arm11/menu/bootslot_store.h" - -#define BOOTSLOT_STORE_REG ((u8) 0x1E) - - -static u8 stored_slot = INVALID_BOOT_SLOT; - - -u8 readStoredBootslot(void) -{ - // stored slot is always zero on cold boots - if (getBootEnv() == BOOTENV_COLD_BOOT) - return 0; - - if (stored_slot == INVALID_BOOT_SLOT) - stored_slot = I2C_readReg(I2C_DEV_MCU, BOOTSLOT_STORE_REG); - - return stored_slot; -} - -bool storeBootslot(u8 slot) -{ - if (slot == INVALID_BOOT_SLOT) // 0xFF is not allowed - slot = 0; - - if (slot != stored_slot) - { - stored_slot = slot; - return I2C_writeReg(I2C_DEV_MCU, BOOTSLOT_STORE_REG, (u8) slot); - } - else - { - return true; - } -} diff --git a/source/arm11/menu/menu.c b/source/arm11/menu/menu.c index 663add9..ca09a4f 100644 --- a/source/arm11/menu/menu.c +++ b/source/arm11/menu/menu.c @@ -22,7 +22,7 @@ #include #include "types.h" #include "arm11/menu/bootinfo.h" -#include "arm11/menu/bootslot_store.h" +#include "arm11/menu/bootslot.h" #include "arm11/menu/menu.h" #include "arm11/menu/menu_util.h" #include "arm11/menu/menu_color.h" @@ -46,10 +46,16 @@ // handle flags - u32 slot = (flags & MENU_FLAG_SLOTS) ? index : - (flags & MENU_FLAG_SLOT(1)) ? 0 : - (flags & MENU_FLAG_SLOT(2)) ? 1 : - (flags & MENU_FLAG_SLOT(3)) ? 2 : (u32) -1; + u32 slot = -1; + if (flags & MENU_FLAG_SLOTS) + { + slot = index; + } + else + { + MENU_GET_FLAGSLOT(slot, flags); + slot--; + } // boot mode description if ((flags & MENU_FLAG_BOOTMODE) && (index == 3)) @@ -64,7 +70,7 @@ else desc_ptr += ee_sprintf(desc_ptr, "\n \ncurrent: - not set up -"); } // boot slot description - else if (slot < 3) + else if (slot < N_BOOTSLOTS) { // get strings for path and keycombo char slot_path_store[24+1]; @@ -159,7 +165,7 @@ // print slot config curY++; - for(u32 i = 0; i < 3; i++) + for(u32 i = 0; i < N_BOOTSLOTS; i++) { consoleSetCursor(desc_con, conw - 16 - 1, curY++); ee_printf(ESC_SCHEME_WEAK "slot %lu: " ESC_RESET, i + 1); diff --git a/source/arm11/menu/menu_func.c b/source/arm11/menu/menu_func.c index a007568..f32688e 100644 --- a/source/arm11/menu/menu_func.c +++ b/source/arm11/menu/menu_func.c @@ -25,7 +25,7 @@ #include "firmwriter.h" #include "fs.h" #include "fsutils.h" -#include "arm11/menu/bootslot_store.h" +#include "arm11/menu/bootslot.h" #include "arm11/menu/menu_color.h" #include "arm11/menu/menu_fsel.h" #include "arm11/menu/menu_func.h" @@ -52,7 +52,7 @@ u32 res = 0xFF; if (!configDataExist(KDevMode) || !(*(bool*) configGetData(KDevMode))) - res &= ~((1 << 2) | (1 << 3)); + res &= ~((1 << 2) | (1 << 3)); // disable forced restore and firmware flash return res; } @@ -61,7 +61,7 @@ { u32 res = 0xFF; - for (u32 i = 0; i < 3; i++) + for (u32 i = 0; i < N_BOOTSLOTS; i++) { if (!configDataExist(KBootOption1 + i)) { @@ -69,9 +69,6 @@ } } - if (!configDataExist(KDevMode) || !(*(bool*) configGetData(KDevMode))) - res &= ~(1 << 3); - return res; } @@ -79,7 +76,7 @@ { u32 res = 0; - for (u32 i = 0; i < 3; i++) + for (u32 i = 0; i < N_BOOTSLOTS; i++) { if (configDataExist(KBootOption1 + i)) { @@ -88,7 +85,7 @@ } if (configDataExist(KBootMode)) - res |= 1 << 3; + res |= 1 << N_BOOTSLOTS; return res; } @@ -266,7 +263,7 @@ consoleSelect(term_con); consoleClear(); - if (param < 3) // loading from bootslot + if (param < N_BOOTSLOTS) // loading from bootslot { // check if bootslot exists if (!configDataExist(KBootOption1 + param)) @@ -303,7 +300,7 @@ g_startFirmLaunch = true; // store the bootslot - u32 slot = (param < 3) ? (param + 1) : 0; + u32 slot = (param < N_BOOTSLOTS) ? (param + 1) : 0; storeBootslot(slot); return 0;