blob: a3dff653405a8d6b786ba4ca2acdd0518904c93e [file] [log] [blame]
David Brazdil0dbb41f2019-09-09 18:03:35 +01001/*
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 Brazdil136f2942019-09-23 14:11:03 +010017#include "hf/check.h"
Andrew Scull9c251d32019-09-19 13:30:42 +010018#include "hf/cpio.h"
19#include "hf/dlog.h"
David Brazdil0dbb41f2019-09-09 18:03:35 +010020#include "hf/fdt_handler.h"
21#include "hf/plat/boot_flow.h"
Andrew Scull9c251d32019-09-19 13:30:42 +010022#include "hf/std.h"
23
David Brazdil0dbb41f2019-09-09 18:03:35 +010024/* Set by arch-specific boot-time hook. */
Andrew Scullc3771072019-09-19 13:30:42 +010025uintreg_t plat_boot_flow_fdt_addr;
David Brazdil0dbb41f2019-09-09 18:03:35 +010026
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 Scullc3771072019-09-19 13:30:42 +010031paddr_t plat_boot_flow_get_fdt_addr(void)
David Brazdil0dbb41f2019-09-09 18:03:35 +010032{
Andrew Scullc3771072019-09-19 13:30:42 +010033 return pa_init((uintpaddr_t)plat_boot_flow_fdt_addr);
David Brazdil0dbb41f2019-09-09 18:03:35 +010034}
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 Scullc3771072019-09-19 13:30:42 +010040uintreg_t plat_boot_flow_get_kernel_arg(void)
David Brazdil0dbb41f2019-09-09 18:03:35 +010041{
Andrew Scullc3771072019-09-19 13:30:42 +010042 return plat_boot_flow_fdt_addr;
David Brazdil0dbb41f2019-09-09 18:03:35 +010043}
44
45/**
46 * Load initrd range from the board FDT.
47 */
Andrew Scullc3771072019-09-19 13:30:42 +010048bool plat_boot_flow_get_initrd_range(const struct fdt_node *fdt_root,
49 paddr_t *begin, paddr_t *end)
David Brazdil0dbb41f2019-09-09 18:03:35 +010050{
51 return fdt_find_initrd(fdt_root, begin, end);
52}
Andrew Scullc3771072019-09-19 13:30:42 +010053
54bool plat_boot_flow_update(struct mm_stage1_locked stage1_locked,
David Brazdile6f83222019-09-23 14:47:37 +010055 const struct manifest *manifest,
Andrew Scull9c251d32019-09-19 13:30:42 +010056 struct boot_params_update *update,
57 struct memiter *cpio, struct mpool *ppool)
Andrew Scullc3771072019-09-19 13:30:42 +010058{
Andrew Scull9c251d32019-09-19 13:30:42 +010059 struct memiter primary_initrd;
David Brazdile6f83222019-09-23 14:47:37 +010060 const struct string *filename =
61 &manifest->vm[HF_PRIMARY_VM_INDEX].primary.ramdisk_filename;
Andrew Scull9c251d32019-09-19 13:30:42 +010062
David Brazdile6f83222019-09-23 14:47:37 +010063 if (string_is_empty(filename)) {
64 memiter_init(&primary_initrd, NULL, 0);
65 } else if (!cpio_get_file(cpio, filename, &primary_initrd)) {
Andrew Walbran17eebf92020-02-05 16:35:49 +000066 dlog_error("Unable to find primary initrd \"%s\".\n",
67 string_data(filename));
Andrew Scull9c251d32019-09-19 13:30:42 +010068 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 Scullc3771072019-09-19 13:30:42 +010075 ppool);
76}