2018-09-07 16:00:13 +01:00
|
|
|
/*
|
2020-01-24 10:10:40 +00:00
|
|
|
* Copyright (c) 2018-2020 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/>.
|
|
|
|
*/
|
2019-06-19 07:54:53 +01:00
|
|
|
|
2018-02-21 18:57:51 +00:00
|
|
|
#ifndef EXOSPHERE_PACKAGE2_H
|
|
|
|
#define EXOSPHERE_PACKAGE2_H
|
|
|
|
|
|
|
|
/* This is code responsible for validating a package2. Actual file reading is done by bootloader. */
|
|
|
|
|
2018-03-02 01:19:35 +00:00
|
|
|
#include "utils.h"
|
2018-02-21 18:57:51 +00:00
|
|
|
#include "bootconfig.h"
|
2019-01-31 07:13:27 +00:00
|
|
|
#include "exocfg.h"
|
2018-02-24 16:13:42 +00:00
|
|
|
#include "memory_map.h"
|
2018-02-21 18:57:51 +00:00
|
|
|
|
|
|
|
/* Physaddr 0x40002EF8 */
|
2019-01-31 07:13:27 +00:00
|
|
|
static inline uintptr_t get_nx_bootloader_mailbox_base(unsigned int targetfw) {
|
|
|
|
return MMIO_GET_DEVICE_ADDRESS(MMIO_DEVID_NXBOOTLOADER_MAILBOX) + ((targetfw >= ATMOSPHERE_TARGET_FIRMWARE_700) ? (0x000ull) : (0xE00ull));
|
2018-02-26 21:09:35 +00:00
|
|
|
}
|
2018-02-23 01:08:54 +00:00
|
|
|
|
2019-01-31 07:13:27 +00:00
|
|
|
#define MAILBOX_NX_BOOTLOADER_BASE(targetfw) (get_nx_bootloader_mailbox_base(targetfw))
|
2018-02-26 21:09:35 +00:00
|
|
|
|
2019-01-31 07:13:27 +00:00
|
|
|
#define MAILBOX_NX_SECMON_BOOT_TIME(targetfw) MAKE_REG32(MAILBOX_NX_BOOTLOADER_BASE(targetfw) + 0x08ull)
|
2018-03-03 23:36:40 +00:00
|
|
|
|
2019-01-31 07:13:27 +00:00
|
|
|
#define MAILBOX_NX_BOOTLOADER_SETUP_STATE(targetfw) MAKE_REG32(MAILBOX_NX_BOOTLOADER_BASE(targetfw) + 0xF8ull)
|
2018-02-21 18:57:51 +00:00
|
|
|
|
|
|
|
#define NX_BOOTLOADER_STATE_INIT 0
|
|
|
|
#define NX_BOOTLOADER_STATE_MOVED_BOOTCONFIG 1
|
2018-03-02 19:28:05 +00:00
|
|
|
|
2018-02-21 18:57:51 +00:00
|
|
|
#define NX_BOOTLOADER_STATE_LOADED_PACKAGE2 2
|
2018-02-26 21:09:35 +00:00
|
|
|
#define NX_BOOTLOADER_STATE_FINISHED 3
|
2018-02-21 18:57:51 +00:00
|
|
|
|
2018-03-02 19:28:05 +00:00
|
|
|
#define NX_BOOTLOADER_STATE_DRAM_INITIALIZED_4X 2
|
|
|
|
#define NX_BOOTLOADER_STATE_LOADED_PACKAGE2_4X 3
|
|
|
|
#define NX_BOOTLOADER_STATE_FINISHED_4X 4
|
|
|
|
|
2018-02-21 18:57:51 +00:00
|
|
|
/* Physaddr 0x40002EFC */
|
2019-01-31 07:13:27 +00:00
|
|
|
#define MAILBOX_NX_BOOTLOADER_IS_SECMON_AWAKE(targetfw) MAKE_REG32(MAILBOX_NX_BOOTLOADER_BASE(targetfw) + 0xFCULL)
|
2018-02-21 18:57:51 +00:00
|
|
|
|
2019-01-31 07:13:27 +00:00
|
|
|
#define MAILBOX_NX_BOOTLOADER_BOOT_REASON(targetfw) (MAILBOX_NX_BOOTLOADER_BASE(targetfw) + 0x10ULL)
|
2018-03-08 09:48:57 +00:00
|
|
|
|
2018-02-26 21:09:35 +00:00
|
|
|
#define NX_BOOTLOADER_BOOTCONFIG_POINTER ((void *)(0x4003D000ull))
|
2018-09-09 07:51:52 +01:00
|
|
|
#define NX_BOOTLOADER_BOOTCONFIG_POINTER_6X ((void *)(0x4003F800ull))
|
2018-02-21 19:52:39 +00:00
|
|
|
|
2018-02-26 21:09:35 +00:00
|
|
|
#define NX_BOOTLOADER_PACKAGE2_LOAD_ADDRESS ((void *)(0xA9800000ull))
|
2018-02-21 19:52:39 +00:00
|
|
|
|
2018-02-26 21:09:35 +00:00
|
|
|
#define DRAM_BASE_PHYSICAL (0x80000000ull)
|
2018-02-21 19:52:39 +00:00
|
|
|
|
|
|
|
#define MAGIC_PK21 (0x31324B50)
|
2018-02-21 21:38:55 +00:00
|
|
|
#define PACKAGE2_SIZE_MAX 0x7FC000
|
|
|
|
#define PACKAGE2_SECTION_MAX 0x3
|
|
|
|
|
|
|
|
#define PACKAGE2_MINVER_THEORETICAL 0x0
|
|
|
|
#define PACKAGE2_MAXVER_100 0x2
|
|
|
|
#define PACKAGE2_MAXVER_200 0x3
|
|
|
|
#define PACKAGE2_MAXVER_300 0x4
|
|
|
|
#define PACKAGE2_MAXVER_302 0x5
|
2018-04-12 04:56:30 +01:00
|
|
|
#define PACKAGE2_MAXVER_400_410 0x6
|
2018-10-16 22:10:00 +01:00
|
|
|
#define PACKAGE2_MAXVER_500_510 0x7
|
2018-11-26 06:37:24 +00:00
|
|
|
#define PACKAGE2_MAXVER_600_610 0x8
|
2019-01-31 09:39:53 +00:00
|
|
|
#define PACKAGE2_MAXVER_620 0x9
|
2019-06-19 07:54:53 +01:00
|
|
|
#define PACKAGE2_MAXVER_700_800 0xA
|
2019-09-12 09:18:58 +01:00
|
|
|
#define PACKAGE2_MAXVER_810 0xB
|
2019-12-07 21:44:08 +00:00
|
|
|
#define PACKAGE2_MAXVER_900 0xC
|
2020-04-14 07:30:54 +01:00
|
|
|
#define PACKAGE2_MAXVER_910_920 0xD
|
|
|
|
#define PACKAGE2_MAXVER_1000_CURRENT 0xE
|
2018-02-21 21:38:55 +00:00
|
|
|
|
|
|
|
#define PACKAGE2_MINVER_100 0x3
|
|
|
|
#define PACKAGE2_MINVER_200 0x4
|
|
|
|
#define PACKAGE2_MINVER_300 0x5
|
|
|
|
#define PACKAGE2_MINVER_302 0x6
|
2018-04-12 04:56:30 +01:00
|
|
|
#define PACKAGE2_MINVER_400_410 0x7
|
2018-10-16 22:10:00 +01:00
|
|
|
#define PACKAGE2_MINVER_500_510 0x8
|
2018-11-26 06:37:24 +00:00
|
|
|
#define PACKAGE2_MINVER_600_610 0x9
|
2019-01-31 09:39:53 +00:00
|
|
|
#define PACKAGE2_MINVER_620 0xA
|
2019-06-19 07:54:53 +01:00
|
|
|
#define PACKAGE2_MINVER_700_800 0xB
|
2019-09-12 09:18:58 +01:00
|
|
|
#define PACKAGE2_MINVER_810 0xC
|
2019-12-07 21:44:08 +00:00
|
|
|
#define PACKAGE2_MINVER_900 0xD
|
2020-04-14 07:30:54 +01:00
|
|
|
#define PACKAGE2_MINVER_910_920 0xE
|
|
|
|
#define PACKAGE2_MINVER_1000_CURRENT 0xF
|
2018-02-21 21:38:55 +00:00
|
|
|
|
2018-02-21 19:52:39 +00:00
|
|
|
typedef struct {
|
|
|
|
union {
|
|
|
|
uint8_t ctr[0x10];
|
|
|
|
uint32_t ctr_dwords[0x4];
|
|
|
|
};
|
|
|
|
uint8_t section_ctrs[4][0x10];
|
|
|
|
uint32_t magic;
|
2018-02-21 21:38:55 +00:00
|
|
|
uint32_t entrypoint;
|
2018-02-21 19:52:39 +00:00
|
|
|
uint32_t _0x58;
|
|
|
|
uint8_t version_max; /* Must be > TZ value. */
|
|
|
|
uint8_t version_min; /* Must be < TZ value. */
|
|
|
|
uint16_t _0x5E;
|
|
|
|
uint32_t section_sizes[4];
|
|
|
|
uint32_t section_offsets[4];
|
|
|
|
uint8_t section_hashes[4][0x20];
|
|
|
|
} package2_meta_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint8_t signature[0x100];
|
|
|
|
union {
|
|
|
|
package2_meta_t metadata;
|
|
|
|
uint8_t encrypted_header[0x100];
|
|
|
|
};
|
2018-05-17 15:11:10 +01:00
|
|
|
uint8_t data[];
|
2018-02-21 19:52:39 +00:00
|
|
|
} package2_header_t;
|
2018-02-21 18:57:51 +00:00
|
|
|
|
2018-03-02 01:19:35 +00:00
|
|
|
void load_package2(coldboot_crt0_reloc_list_t *reloc_list);
|
2018-02-21 18:57:51 +00:00
|
|
|
|
2018-02-24 16:13:42 +00:00
|
|
|
#endif
|