blob: f4f34e0357dd21664a9141b94801d0f341970bd4 [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
Andrew Scull9c251d32019-09-19 13:30:42 +010017#include "hf/cpio.h"
18#include "hf/dlog.h"
David Brazdil0dbb41f2019-09-09 18:03:35 +010019#include "hf/fdt_handler.h"
20#include "hf/plat/boot_flow.h"
Andrew Scull9c251d32019-09-19 13:30:42 +010021#include "hf/std.h"
22
23/**
24 * Looks for a file in the given cpio archive. The file, if found, is returned
25 * in the "it" argument.
26 */
27static bool find_file(const struct memiter *cpio, const char *name,
28 struct memiter *it)
29{
30 const char *fname;
31 const void *fcontents;
32 size_t fsize;
33 struct memiter iter = *cpio;
34
35 while (cpio_next(&iter, &fname, &fcontents, &fsize)) {
36 if (!strcmp(fname, name)) {
37 memiter_init(it, fcontents, fsize);
38 return true;
39 }
40 }
41
42 return false;
43}
David Brazdil0dbb41f2019-09-09 18:03:35 +010044
45/* Set by arch-specific boot-time hook. */
Andrew Scullc3771072019-09-19 13:30:42 +010046uintreg_t plat_boot_flow_fdt_addr;
David Brazdil0dbb41f2019-09-09 18:03:35 +010047
48/**
49 * Returns the physical address of board FDT. This was passed to Hafnium in the
50 * first kernel arg by the boot loader.
51 */
Andrew Scullc3771072019-09-19 13:30:42 +010052paddr_t plat_boot_flow_get_fdt_addr(void)
David Brazdil0dbb41f2019-09-09 18:03:35 +010053{
Andrew Scullc3771072019-09-19 13:30:42 +010054 return pa_init((uintpaddr_t)plat_boot_flow_fdt_addr);
David Brazdil0dbb41f2019-09-09 18:03:35 +010055}
56
57/**
58 * When handing over to the primary, give it the same FDT address that was given
59 * to Hafnium. The FDT may have been modified during Hafnium init.
60 */
Andrew Scullc3771072019-09-19 13:30:42 +010061uintreg_t plat_boot_flow_get_kernel_arg(void)
David Brazdil0dbb41f2019-09-09 18:03:35 +010062{
Andrew Scullc3771072019-09-19 13:30:42 +010063 return plat_boot_flow_fdt_addr;
David Brazdil0dbb41f2019-09-09 18:03:35 +010064}
65
66/**
67 * Load initrd range from the board FDT.
68 */
Andrew Scullc3771072019-09-19 13:30:42 +010069bool plat_boot_flow_get_initrd_range(const struct fdt_node *fdt_root,
70 paddr_t *begin, paddr_t *end)
David Brazdil0dbb41f2019-09-09 18:03:35 +010071{
72 return fdt_find_initrd(fdt_root, begin, end);
73}
Andrew Scullc3771072019-09-19 13:30:42 +010074
75bool plat_boot_flow_update(struct mm_stage1_locked stage1_locked,
Andrew Scull9c251d32019-09-19 13:30:42 +010076 struct boot_params_update *update,
77 struct memiter *cpio, struct mpool *ppool)
Andrew Scullc3771072019-09-19 13:30:42 +010078{
Andrew Scull9c251d32019-09-19 13:30:42 +010079 struct memiter primary_initrd;
80
81 if (!find_file(cpio, "initrd.img", &primary_initrd)) {
82 dlog("Unable to find initrd.img\n");
83 return false;
84 }
85
86 update->initrd_begin = pa_from_va(va_from_ptr(primary_initrd.next));
87 update->initrd_end = pa_from_va(va_from_ptr(primary_initrd.limit));
88
89 return fdt_patch(stage1_locked, plat_boot_flow_get_fdt_addr(), update,
Andrew Scullc3771072019-09-19 13:30:42 +010090 ppool);
91}