David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Hafnium Authors. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
David Brazdil | 136f294 | 2019-09-23 14:11:03 +0100 | [diff] [blame] | 17 | #include "hf/check.h" |
Andrew Scull | 9c251d3 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 18 | #include "hf/cpio.h" |
| 19 | #include "hf/dlog.h" |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 20 | #include "hf/fdt_handler.h" |
| 21 | #include "hf/plat/boot_flow.h" |
Andrew Scull | 9c251d3 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 22 | #include "hf/std.h" |
| 23 | |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 24 | /* Set by arch-specific boot-time hook. */ |
Andrew Scull | c377107 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 25 | uintreg_t plat_boot_flow_fdt_addr; |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * Returns the physical address of board FDT. This was passed to Hafnium in the |
| 29 | * first kernel arg by the boot loader. |
| 30 | */ |
Andrew Scull | c377107 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 31 | paddr_t plat_boot_flow_get_fdt_addr(void) |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 32 | { |
Andrew Scull | c377107 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 33 | return pa_init((uintpaddr_t)plat_boot_flow_fdt_addr); |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | /** |
| 37 | * When handing over to the primary, give it the same FDT address that was given |
| 38 | * to Hafnium. The FDT may have been modified during Hafnium init. |
| 39 | */ |
Andrew Scull | c377107 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 40 | uintreg_t plat_boot_flow_get_kernel_arg(void) |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 41 | { |
Andrew Scull | c377107 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 42 | return plat_boot_flow_fdt_addr; |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Load initrd range from the board FDT. |
| 47 | */ |
Andrew Scull | c377107 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 48 | bool plat_boot_flow_get_initrd_range(const struct fdt_node *fdt_root, |
| 49 | paddr_t *begin, paddr_t *end) |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 50 | { |
| 51 | return fdt_find_initrd(fdt_root, begin, end); |
| 52 | } |
Andrew Scull | c377107 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 53 | |
| 54 | bool plat_boot_flow_update(struct mm_stage1_locked stage1_locked, |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 55 | const struct manifest *manifest, |
Andrew Scull | 9c251d3 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 56 | struct boot_params_update *update, |
| 57 | struct memiter *cpio, struct mpool *ppool) |
Andrew Scull | c377107 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 58 | { |
Andrew Scull | 9c251d3 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 59 | struct memiter primary_initrd; |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 60 | const struct string *filename = |
| 61 | &manifest->vm[HF_PRIMARY_VM_INDEX].primary.ramdisk_filename; |
Andrew Scull | 9c251d3 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 62 | |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 63 | if (string_is_empty(filename)) { |
| 64 | memiter_init(&primary_initrd, NULL, 0); |
| 65 | } else if (!cpio_get_file(cpio, filename, &primary_initrd)) { |
Andrew Walbran | 17eebf9 | 2020-02-05 16:35:49 +0000 | [diff] [blame] | 66 | dlog_error("Unable to find primary initrd \"%s\".\n", |
| 67 | string_data(filename)); |
Andrew Scull | 9c251d3 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 68 | return false; |
| 69 | } |
| 70 | |
| 71 | update->initrd_begin = pa_from_va(va_from_ptr(primary_initrd.next)); |
| 72 | update->initrd_end = pa_from_va(va_from_ptr(primary_initrd.limit)); |
| 73 | |
| 74 | return fdt_patch(stage1_locked, plat_boot_flow_get_fdt_addr(), update, |
Andrew Scull | c377107 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 75 | ppool); |
| 76 | } |