exo: add stub warmboot.bin
This commit is contained in:
41
exosphere/lp0fw/src/lp0.c
Normal file
41
exosphere/lp0fw/src/lp0.c
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Atmosphère-NX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include "utils.h"
|
||||
#include "lp0.h"
|
||||
#include "pmc.h"
|
||||
#include "timer.h"
|
||||
|
||||
void reboot(void) {
|
||||
/* Write MAIN_RST */
|
||||
APBDEV_PMC_CNTRL_0 = 0x10;
|
||||
while (true) {
|
||||
/* Wait for reboot. */
|
||||
}
|
||||
}
|
||||
|
||||
void lp0_entry_main(warmboot_metadata_t *meta) {
|
||||
/* Before doing anything else, ensure some sanity. */
|
||||
if (meta->magic != WARMBOOT_MAGIC || meta->tz_relative_offset > 0x2000) {
|
||||
reboot();
|
||||
}
|
||||
|
||||
/* TODO: stuff */
|
||||
|
||||
while (true) { /* TODO: Halt BPMP */ }
|
||||
}
|
||||
|
||||
|
||||
35
exosphere/lp0fw/src/lp0.h
Normal file
35
exosphere/lp0fw/src/lp0.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Atmosphère-NX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef EXOSPHERE_WARMBOOT_BIN_LP0_H
|
||||
#define EXOSPHERE_WARMBOOT_BIN_LP0_H
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
/* WBT0 */
|
||||
#define WARMBOOT_MAGIC 0x30544257
|
||||
|
||||
typedef struct {
|
||||
uint32_t magic;
|
||||
uint32_t tz_relative_offset;
|
||||
uint32_t padding[2];
|
||||
} warmboot_metadata_t;
|
||||
|
||||
void lp0_entry_main(warmboot_metadata_t *meta);
|
||||
|
||||
void reboot(void);
|
||||
|
||||
#endif
|
||||
53
exosphere/lp0fw/src/pmc.h
Normal file
53
exosphere/lp0fw/src/pmc.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Atmosphère-NX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef EXOSPHERE_WARMBOOT_BIN_PMC_H
|
||||
#define EXOSPHERE_WARMBOOT_BIN_PMC_H
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define PMC_BASE (0x7000E400)
|
||||
|
||||
#define MAKE_PMC_REG(ofs) (MAKE_REG32(PMC_BASE + ofs))
|
||||
|
||||
#define APBDEV_PMC_CNTRL_0 MAKE_PMC_REG(0x000)
|
||||
|
||||
#define APBDEV_PMC_DPD_SAMPLE_0 MAKE_PMC_REG(0x020)
|
||||
|
||||
#define APBDEV_PMC_DPD_ENABLE_0 MAKE_PMC_REG(0x024)
|
||||
|
||||
#define APBDEV_PMC_CLAMP_STATUS_0 MAKE_PMC_REG(0x02C)
|
||||
|
||||
#define APBDEV_PMC_PWRGATE_STATUS_0 MAKE_PMC_REG(0x038)
|
||||
|
||||
#define APBDEV_PMC_SCRATCH12_0 MAKE_PMC_REG(0x080)
|
||||
#define APBDEV_PMC_SCRATCH13_0 MAKE_PMC_REG(0x084)
|
||||
#define APBDEV_PMC_SCRATCH18_0 MAKE_PMC_REG(0x098)
|
||||
|
||||
|
||||
#define APBDEV_PMC_WEAK_BIAS_0 MAKE_PMC_REG(0x2C8)
|
||||
|
||||
#define APBDEV_PMC_IO_DPD3_REQ_0 MAKE_PMC_REG(0x45C)
|
||||
#define APBDEV_PMC_IO_DPD3_STATUS_0 MAKE_PMC_REG(0x460)
|
||||
|
||||
#define APBDEV_PMC_IO_DPD4_REQ_0 MAKE_PMC_REG(0x464)
|
||||
#define APBDEV_PMC_IO_DPD4_STATUS_0 MAKE_PMC_REG(0x468)
|
||||
|
||||
#define APBDEV_PMC_SET_SW_CLAMP_0 MAKE_PMC_REG(0x47C)
|
||||
|
||||
#define APBDEV_PMC_DDR_CNTRL_0 MAKE_PMC_REG(0x4E4)
|
||||
|
||||
#endif
|
||||
68
exosphere/lp0fw/src/start.s
Normal file
68
exosphere/lp0fw/src/start.s
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Atmosphère-NX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
.section .text.start
|
||||
|
||||
/* Warmboot header. */
|
||||
/* Binary size */
|
||||
.word __total_size__
|
||||
.rept 3
|
||||
.word 0x00000000
|
||||
.endr
|
||||
/* RSA modulus */
|
||||
.rept 0x40
|
||||
.word 0xFFFFFFFF
|
||||
.endr
|
||||
/* Padding */
|
||||
.rept 4
|
||||
.word 0x00000000
|
||||
.endr
|
||||
/* RSA signature */
|
||||
.rept 0x40
|
||||
.word 0xFFFFFFFF
|
||||
.endr
|
||||
/* Padding */
|
||||
.rept 4
|
||||
.word 0x00000000
|
||||
.endr
|
||||
/* Relocation meta */
|
||||
.word __total_size__
|
||||
.word _start
|
||||
.word _start
|
||||
.word __executable_size__
|
||||
|
||||
.global _start
|
||||
_start:
|
||||
b crt0
|
||||
.rept 0x7C
|
||||
.word 0x00000000 /* Padding */
|
||||
.endr
|
||||
|
||||
.global _metadata
|
||||
_metadata:
|
||||
.ascii "WBT0" /* Magic number */
|
||||
.word 0x00000000 /* TrustZone relative base. */
|
||||
.word 0x00000000 /* Reserved */
|
||||
.word 0x00000000 /* Reserved */
|
||||
|
||||
.global crt0
|
||||
.type crt0, %function
|
||||
crt0:
|
||||
@ setup to call lp0_entry_main
|
||||
ldr sp, =__stack_top__
|
||||
ldr lr, =reboot
|
||||
ldr r0, =_metadata
|
||||
b lp0_entry_main
|
||||
33
exosphere/lp0fw/src/timer.h
Normal file
33
exosphere/lp0fw/src/timer.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Atmosphère-NX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef EXOSPHERE_WARMBOOT_BIN_TIMER_H
|
||||
#define EXOSPHERE_WARMBOOT_BIN_TIMER_H
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define TIMERUS_CNTR_1US_0 MAKE_REG32(0x60005010)
|
||||
|
||||
static inline void timer_wait(uint32_t microseconds) {
|
||||
uint32_t old_time = TIMERUS_CNTR_1US_0;
|
||||
while (TIMERUS_CNTR_1US_0 - old_time <= microseconds) {
|
||||
/* Spin-lock. */
|
||||
}
|
||||
}
|
||||
|
||||
void spinlock_wait(uint32_t count);
|
||||
|
||||
#endif
|
||||
38
exosphere/lp0fw/src/utils.h
Normal file
38
exosphere/lp0fw/src/utils.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Atmosphère-NX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef EXOSPHERE_WARMBOOT_BIN_UTILS_H
|
||||
#define EXOSPHERE_WARMBOOT_BIN_UTILS_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define BIT(n) (1u << (n))
|
||||
#define BITL(n) (1ull << (n))
|
||||
#define MASK(n) (BIT(n) - 1)
|
||||
#define MASKL(n) (BITL(n) - 1)
|
||||
#define MASK2(a,b) (MASK(a) & ~MASK(b))
|
||||
#define MASK2L(a,b) (MASKL(a) & ~MASKL(b))
|
||||
|
||||
#define MAKE_REG32(a) (*(volatile uint32_t *)(a))
|
||||
|
||||
#define ALIGN(m) __attribute__((aligned(m)))
|
||||
#define PACKED __attribute__((packed))
|
||||
|
||||
#define ALINLINE __attribute__((always_inline))
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user