blob: d211df611d843ee78383b9f646359ea1f5a20445 [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
17#include "hf/boot_flow.h"
18#include "hf/dlog.h"
19#include "hf/fdt_handler.h"
20#include "hf/plat/boot_flow.h"
21
22/**
23 * Parses information from FDT needed to initialize Hafnium.
24 * FDT is mapped at the beginning and unmapped before exiting the function.
25 */
26bool boot_flow_init(struct mm_stage1_locked stage1_locked,
27 struct manifest *manifest, struct boot_params *boot_params,
28 struct mpool *ppool)
29{
30 bool ret = false;
31 struct fdt_header *fdt;
32 struct fdt_node fdt_root;
33 enum manifest_return_code manifest_ret;
34
35 /* Get the memory map from the FDT. */
36 fdt = fdt_map(stage1_locked, plat_get_fdt_addr(), &fdt_root, ppool);
37 if (fdt == NULL) {
38 dlog("Unable to map FDT.\n");
39 return false;
40 }
41
42 if (!fdt_find_child(&fdt_root, "")) {
43 dlog("Unable to find FDT root node.\n");
44 goto out_unmap_fdt;
45 }
46
47 manifest_ret = manifest_init(manifest, &fdt_root);
48 if (manifest_ret != MANIFEST_SUCCESS) {
49 dlog("Could not parse manifest: %s.\n",
50 manifest_strerror(manifest_ret));
51 goto out_unmap_fdt;
52 }
53
54 if (!boot_params_init(boot_params, &fdt_root)) {
55 dlog("Could not parse boot params.\n");
56 goto out_unmap_fdt;
57 }
58
59 ret = true;
60
61out_unmap_fdt:
62 if (!fdt_unmap(stage1_locked, fdt, ppool)) {
63 dlog("Unable to unmap FDT.\n");
64 ret = false;
65 }
66
67 return ret;
68}