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, |
Andrew Scull | 9c251d3 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 55 | struct boot_params_update *update, |
| 56 | struct memiter *cpio, struct mpool *ppool) |
Andrew Scull | c377107 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 57 | { |
David Brazdil | 136f294 | 2019-09-23 14:11:03 +0100 | [diff] [blame^] | 58 | static struct string filename = STRING_INIT("initrd.img"); |
Andrew Scull | 9c251d3 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 59 | struct memiter primary_initrd; |
| 60 | |
David Brazdil | 136f294 | 2019-09-23 14:11:03 +0100 | [diff] [blame^] | 61 | if (!cpio_get_file(cpio, &filename, &primary_initrd)) { |
Andrew Scull | 9c251d3 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 62 | dlog("Unable to find initrd.img\n"); |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | update->initrd_begin = pa_from_va(va_from_ptr(primary_initrd.next)); |
| 67 | update->initrd_end = pa_from_va(va_from_ptr(primary_initrd.limit)); |
| 68 | |
| 69 | return fdt_patch(stage1_locked, plat_boot_flow_get_fdt_addr(), update, |
Andrew Scull | c377107 | 2019-09-19 13:30:42 +0100 | [diff] [blame] | 70 | ppool); |
| 71 | } |