David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Hafnium Authors. |
| 3 | * |
Andrew Walbran | e959ec1 | 2020-06-17 15:01:09 +0100 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style |
| 5 | * license that can be found in the LICENSE file or at |
| 6 | * https://opensource.org/licenses/BSD-3-Clause. |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
David Brazdil | 136f294 | 2019-09-23 14:11:03 +0100 | [diff] [blame] | 9 | #include "hf/check.h" |
Andrew Scull | 9c251d3 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 10 | #include "hf/cpio.h" |
| 11 | #include "hf/dlog.h" |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 12 | #include "hf/fdt_handler.h" |
David Brazdil | b856be6 | 2020-03-25 10:14:55 +0000 | [diff] [blame] | 13 | #include "hf/fdt_patch.h" |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 14 | #include "hf/plat/boot_flow.h" |
Andrew Scull | 9c251d3 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 15 | #include "hf/std.h" |
| 16 | |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 17 | /* Set by arch-specific boot-time hook. */ |
Andrew Scull | c377107 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 18 | uintreg_t plat_boot_flow_fdt_addr; |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 19 | |
| 20 | /** |
| 21 | * Returns the physical address of board FDT. This was passed to Hafnium in the |
| 22 | * first kernel arg by the boot loader. |
| 23 | */ |
Andrew Scull | c377107 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 24 | paddr_t plat_boot_flow_get_fdt_addr(void) |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 25 | { |
Andrew Scull | c377107 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 26 | return pa_init((uintpaddr_t)plat_boot_flow_fdt_addr); |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | /** |
| 30 | * When handing over to the primary, give it the same FDT address that was given |
| 31 | * to Hafnium. The FDT may have been modified during Hafnium init. |
| 32 | */ |
Andrew Scull | c377107 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 33 | uintreg_t plat_boot_flow_get_kernel_arg(void) |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 34 | { |
Andrew Scull | c377107 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 35 | return plat_boot_flow_fdt_addr; |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Load initrd range from the board FDT. |
| 40 | */ |
David Brazdil | b856be6 | 2020-03-25 10:14:55 +0000 | [diff] [blame] | 41 | bool plat_boot_flow_get_initrd_range(const struct fdt *fdt, paddr_t *begin, |
| 42 | paddr_t *end) |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 43 | { |
David Brazdil | b856be6 | 2020-03-25 10:14:55 +0000 | [diff] [blame] | 44 | return fdt_find_initrd(fdt, begin, end); |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 45 | } |
Andrew Scull | c377107 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 46 | |
| 47 | bool plat_boot_flow_update(struct mm_stage1_locked stage1_locked, |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 48 | const struct manifest *manifest, |
Andrew Scull | 9c251d3 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 49 | struct boot_params_update *update, |
| 50 | struct memiter *cpio, struct mpool *ppool) |
Andrew Scull | c377107 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 51 | { |
Andrew Scull | 9c251d3 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 52 | struct memiter primary_initrd; |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 53 | const struct string *filename = |
| 54 | &manifest->vm[HF_PRIMARY_VM_INDEX].primary.ramdisk_filename; |
Andrew Scull | 9c251d3 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 55 | |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 56 | if (string_is_empty(filename)) { |
| 57 | memiter_init(&primary_initrd, NULL, 0); |
| 58 | } else if (!cpio_get_file(cpio, filename, &primary_initrd)) { |
Andrew Walbran | 17eebf9 | 2020-02-05 16:35:49 +0000 | [diff] [blame] | 59 | dlog_error("Unable to find primary initrd \"%s\".\n", |
| 60 | string_data(filename)); |
Andrew Scull | 9c251d3 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 61 | return false; |
| 62 | } |
| 63 | |
| 64 | update->initrd_begin = pa_from_va(va_from_ptr(primary_initrd.next)); |
| 65 | update->initrd_end = pa_from_va(va_from_ptr(primary_initrd.limit)); |
| 66 | |
| 67 | return fdt_patch(stage1_locked, plat_boot_flow_get_fdt_addr(), update, |
Andrew Scull | c377107 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 68 | ppool); |
| 69 | } |