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