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