blob: 9d4d886cf2afc7492591b436b3617a50bc9b1315 [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,
Andrew Scull9c251d32019-09-19 13:30:42 +010055 struct boot_params_update *update,
56 struct memiter *cpio, struct mpool *ppool)
Andrew Scullc3771072019-09-19 13:30:42 +010057{
David Brazdil136f2942019-09-23 14:11:03 +010058 static struct string filename = STRING_INIT("initrd.img");
Andrew Scull9c251d32019-09-19 13:30:42 +010059 struct memiter primary_initrd;
60
David Brazdil136f2942019-09-23 14:11:03 +010061 if (!cpio_get_file(cpio, &filename, &primary_initrd)) {
Andrew Scull9c251d32019-09-19 13:30:42 +010062 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 Scullc3771072019-09-19 13:30:42 +010070 ppool);
71}