| 1 | /*
|
|---|
| 2 | * SPDX-FileCopyrightText: 2007 Michal Kebrt
|
|---|
| 3 | *
|
|---|
| 4 | * SPDX-License-Identifier: BSD-3-Clause
|
|---|
| 5 | */
|
|---|
| 6 |
|
|---|
| 7 | /** @addtogroup boot_arm32
|
|---|
| 8 | * @{
|
|---|
| 9 | */
|
|---|
| 10 | /** @file
|
|---|
| 11 | * @brief Bootstrap.
|
|---|
| 12 | */
|
|---|
| 13 |
|
|---|
| 14 | #include <arch/main.h>
|
|---|
| 15 | #include <arch/types.h>
|
|---|
| 16 | #include <arch/asm.h>
|
|---|
| 17 | #include <arch/mm.h>
|
|---|
| 18 | #include <halt.h>
|
|---|
| 19 | #include <printf.h>
|
|---|
| 20 | #include <memstr.h>
|
|---|
| 21 | #include <version.h>
|
|---|
| 22 | #include <macros.h>
|
|---|
| 23 | #include <align.h>
|
|---|
| 24 | #include <stdbool.h>
|
|---|
| 25 | #include <str.h>
|
|---|
| 26 | #include <errno.h>
|
|---|
| 27 | #include <inflate.h>
|
|---|
| 28 | #include <arch/cp15.h>
|
|---|
| 29 | #include <payload.h>
|
|---|
| 30 | #include <kernel.h>
|
|---|
| 31 |
|
|---|
| 32 | static void clean_dcache_poc(void *address, size_t size)
|
|---|
| 33 | {
|
|---|
| 34 | const uintptr_t addr = (uintptr_t) address;
|
|---|
| 35 |
|
|---|
| 36 | #if !defined(PROCESSOR_ARCH_armv7_a)
|
|---|
| 37 | bool sep;
|
|---|
| 38 | if (MIDR_read() != CTR_read()) {
|
|---|
| 39 | sep = (CTR_read() & CTR_SEP_FLAG) == CTR_SEP_FLAG;
|
|---|
| 40 | } else {
|
|---|
| 41 | printf("Unknown cache type.\n");
|
|---|
| 42 | halt();
|
|---|
| 43 | }
|
|---|
| 44 | #endif
|
|---|
| 45 |
|
|---|
| 46 | for (uintptr_t a = ALIGN_DOWN(addr, CP15_C7_MVA_ALIGN); a < addr + size;
|
|---|
| 47 | a += CP15_C7_MVA_ALIGN) {
|
|---|
| 48 | #if defined(PROCESSOR_ARCH_armv7_a)
|
|---|
| 49 | DCCMVAC_write(a);
|
|---|
| 50 | #else
|
|---|
| 51 | if (sep)
|
|---|
| 52 | DCCMVA_write(a);
|
|---|
| 53 | else
|
|---|
| 54 | CCMVA_write(a);
|
|---|
| 55 | #endif
|
|---|
| 56 | }
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | static bootinfo_t bootinfo;
|
|---|
| 60 |
|
|---|
| 61 | void bootstrap(void)
|
|---|
| 62 | {
|
|---|
| 63 | /* Enable MMU and caches */
|
|---|
| 64 | mmu_start();
|
|---|
| 65 | version_print();
|
|---|
| 66 |
|
|---|
| 67 | printf("Boot loader: %p -> %p\n", loader_start, loader_end);
|
|---|
| 68 | printf("\nMemory statistics\n");
|
|---|
| 69 | printf(" %p|%p: bootstrap stack\n", &boot_stack, &boot_stack);
|
|---|
| 70 | printf(" %p|%p: bootstrap page table\n", &boot_pt, &boot_pt);
|
|---|
| 71 | printf(" %p|%p: boot info structure\n", &bootinfo, &bootinfo);
|
|---|
| 72 | printf(" %p|%p: kernel entry point\n",
|
|---|
| 73 | (void *) PA2KA(BOOT_OFFSET), (void *) BOOT_OFFSET);
|
|---|
| 74 |
|
|---|
| 75 | // FIXME: Use the correct value.
|
|---|
| 76 | uint8_t *kernel_dest = (uint8_t *) BOOT_OFFSET;
|
|---|
| 77 | uint8_t *ram_end = kernel_dest + (1 << 24);
|
|---|
| 78 |
|
|---|
| 79 | extract_payload(&bootinfo.taskmap, kernel_dest, ram_end,
|
|---|
| 80 | PA2KA(kernel_dest), clean_dcache_poc);
|
|---|
| 81 |
|
|---|
| 82 | /* Flush PT too. We need this if we disable caches later */
|
|---|
| 83 | clean_dcache_poc(boot_pt, PTL0_ENTRIES * PTL0_ENTRY_SIZE);
|
|---|
| 84 |
|
|---|
| 85 | uintptr_t entry = check_kernel((void *) PA2KA(BOOT_OFFSET));
|
|---|
| 86 |
|
|---|
| 87 | printf("Booting the kernel...\n");
|
|---|
| 88 | jump_to_kernel((void *) entry, &bootinfo);
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | /** @}
|
|---|
| 92 | */
|
|---|