2018-09-07 16:00:13 +01:00
|
|
|
/*
|
2019-04-07 19:00:49 -07:00
|
|
|
* Copyright (c) 2018-2019 Atmosphère-NX
|
2018-09-07 16:00:13 +01:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2018-02-21 10:57:51 -08:00
|
|
|
#ifndef EXOSPHERE_BOOTCONFIG_H
|
|
|
|
#define EXOSPHERE_BOOTCONFIG_H
|
|
|
|
|
2018-02-24 15:46:57 -05:00
|
|
|
#include <stdbool.h>
|
2018-02-21 10:57:51 -08:00
|
|
|
#include <stdint.h>
|
2018-03-01 11:06:55 +01:00
|
|
|
#include "memory_map.h"
|
2018-02-21 10:57:51 -08:00
|
|
|
|
|
|
|
/* This provides management for Switch BootConfig. */
|
|
|
|
|
2018-03-01 11:06:55 +01:00
|
|
|
#define LOADED_BOOTCONFIG (get_loaded_bootconfig())
|
|
|
|
|
2018-02-21 10:57:51 -08:00
|
|
|
typedef struct {
|
2018-02-27 20:28:34 -08:00
|
|
|
uint8_t data[0x200];
|
|
|
|
} bootconfig_unsigned_config_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint8_t _0x0[8];
|
|
|
|
uint8_t package2_config;
|
|
|
|
uint8_t _0x9[7];
|
|
|
|
uint8_t hardware_info[0x10];
|
|
|
|
uint8_t disable_program_verification;
|
|
|
|
uint8_t _0x21[0xDF];
|
|
|
|
} bootconfig_signed_config_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
bootconfig_unsigned_config_t unsigned_config;
|
2018-02-21 10:57:51 -08:00
|
|
|
uint8_t signature[0x100];
|
2018-02-27 20:28:34 -08:00
|
|
|
bootconfig_signed_config_t signed_config;
|
2018-02-21 10:57:51 -08:00
|
|
|
} bootconfig_t;
|
|
|
|
|
2018-03-01 11:06:55 +01:00
|
|
|
static inline bootconfig_t *get_loaded_bootconfig(void) {
|
|
|
|
/* this is also get_exception_entry_stack_address(2) */
|
|
|
|
return (bootconfig_t *)(TZRAM_GET_SEGMENT_ADDRESS(TZRAM_SEGEMENT_ID_SECMON_EVT) + 0x180);
|
|
|
|
}
|
|
|
|
|
2018-03-08 01:48:57 -08:00
|
|
|
typedef struct {
|
2018-08-29 18:28:21 +01:00
|
|
|
uint32_t bootloader_version;
|
|
|
|
uint32_t bootloader_start_block;
|
|
|
|
uint32_t bootloader_start_page;
|
|
|
|
uint32_t bootloader_attribute;
|
|
|
|
uint32_t boot_reason_value;
|
|
|
|
uint32_t boot_reason_state;
|
2018-03-08 01:48:57 -08:00
|
|
|
} boot_reason_t;
|
|
|
|
|
2018-02-21 11:52:39 -08:00
|
|
|
void bootconfig_load_and_verify(const bootconfig_t *bootconfig);
|
2018-02-21 10:57:51 -08:00
|
|
|
void bootconfig_clear(void);
|
|
|
|
|
2018-03-08 01:48:57 -08:00
|
|
|
void bootconfig_load_boot_reason(volatile boot_reason_t *boot_reason);
|
|
|
|
|
2018-03-25 15:05:08 -06:00
|
|
|
void bootconfig_set_package2_hash_for_recovery(const void *package2, size_t package2_size);
|
|
|
|
void bootconfig_get_package2_hash_for_recovery(uint64_t *out_hash);
|
|
|
|
|
2018-02-21 11:52:39 -08:00
|
|
|
/* Actual configuration getters. */
|
2018-02-22 22:58:39 -05:00
|
|
|
bool bootconfig_is_package2_plaintext(void);
|
|
|
|
bool bootconfig_is_package2_unsigned(void);
|
2018-04-11 21:56:30 -06:00
|
|
|
void bootconfig_set_package2_plaintext_and_unsigned(void);
|
2018-02-24 07:25:38 -08:00
|
|
|
bool bootconfig_disable_program_verification(void);
|
2018-02-25 01:21:52 -08:00
|
|
|
bool bootconfig_is_debug_mode(void);
|
|
|
|
|
2018-03-03 19:31:22 +01:00
|
|
|
bool bootconfig_take_extabt_serror_to_el3(void);
|
2018-03-02 15:04:16 -08:00
|
|
|
|
2018-06-01 22:20:04 -06:00
|
|
|
uint64_t bootconfig_get_value_for_sysctr0(void);
|
|
|
|
|
2018-02-25 01:21:52 -08:00
|
|
|
uint64_t bootconfig_get_memory_arrangement(void);
|
|
|
|
uint64_t bootconfig_get_kernel_memory_configuration(void);
|
2018-02-21 11:52:39 -08:00
|
|
|
|
2018-03-08 01:48:57 -08:00
|
|
|
bool bootconfig_is_recovery_boot(void);
|
|
|
|
uint64_t bootconfig_get_boot_reason(void);
|
|
|
|
|
2018-03-01 11:06:55 +01:00
|
|
|
#endif
|