blob: 699595699beb7974c349a95e6db3e3d3b0b3c7d8 [file] [log] [blame]
David Brazdil0dbb41f2019-09-09 18:03:35 +01001/*
2 * Copyright 2019 The Hafnium Authors.
3 *
Andrew Walbrane959ec12020-06-17 15:01:09 +01004 * Use of this source code is governed by a BSD-style
5 * license that can be found in the LICENSE file or at
6 * https://opensource.org/licenses/BSD-3-Clause.
David Brazdil0dbb41f2019-09-09 18:03:35 +01007 */
8
David Brazdil136f2942019-09-23 14:11:03 +01009#include "hf/check.h"
Andrew Scull9c251d32019-09-19 13:30:42 +010010#include "hf/cpio.h"
11#include "hf/dlog.h"
David Brazdil0dbb41f2019-09-09 18:03:35 +010012#include "hf/fdt_handler.h"
David Brazdilb856be62020-03-25 10:14:55 +000013#include "hf/fdt_patch.h"
David Brazdil0dbb41f2019-09-09 18:03:35 +010014#include "hf/plat/boot_flow.h"
Andrew Scull9c251d32019-09-19 13:30:42 +010015#include "hf/std.h"
16
David Brazdil0dbb41f2019-09-09 18:03:35 +010017/* Set by arch-specific boot-time hook. */
Andrew Scullc3771072019-09-19 13:30:42 +010018uintreg_t plat_boot_flow_fdt_addr;
David Brazdil0dbb41f2019-09-09 18:03:35 +010019
20/**
21 * Returns the physical address of board FDT. This was passed to Hafnium in the
22 * first kernel arg by the boot loader.
23 */
Andrew Scullc3771072019-09-19 13:30:42 +010024paddr_t plat_boot_flow_get_fdt_addr(void)
David Brazdil0dbb41f2019-09-09 18:03:35 +010025{
Andrew Scullc3771072019-09-19 13:30:42 +010026 return pa_init((uintpaddr_t)plat_boot_flow_fdt_addr);
David Brazdil0dbb41f2019-09-09 18:03:35 +010027}
28
29/**
30 * When handing over to the primary, give it the same FDT address that was given
31 * to Hafnium. The FDT may have been modified during Hafnium init.
32 */
Andrew Scullc3771072019-09-19 13:30:42 +010033uintreg_t plat_boot_flow_get_kernel_arg(void)
David Brazdil0dbb41f2019-09-09 18:03:35 +010034{
Andrew Scullc3771072019-09-19 13:30:42 +010035 return plat_boot_flow_fdt_addr;
David Brazdil0dbb41f2019-09-09 18:03:35 +010036}
37
38/**
39 * Load initrd range from the board FDT.
40 */
David Brazdilb856be62020-03-25 10:14:55 +000041bool plat_boot_flow_get_initrd_range(const struct fdt *fdt, paddr_t *begin,
42 paddr_t *end)
David Brazdil0dbb41f2019-09-09 18:03:35 +010043{
David Brazdilb856be62020-03-25 10:14:55 +000044 return fdt_find_initrd(fdt, begin, end);
David Brazdil0dbb41f2019-09-09 18:03:35 +010045}
Andrew Scullc3771072019-09-19 13:30:42 +010046
47bool plat_boot_flow_update(struct mm_stage1_locked stage1_locked,
David Brazdile6f83222019-09-23 14:47:37 +010048 const struct manifest *manifest,
Andrew Scull9c251d32019-09-19 13:30:42 +010049 struct boot_params_update *update,
50 struct memiter *cpio, struct mpool *ppool)
Andrew Scullc3771072019-09-19 13:30:42 +010051{
Andrew Scull9c251d32019-09-19 13:30:42 +010052 struct memiter primary_initrd;
David Brazdile6f83222019-09-23 14:47:37 +010053 const struct string *filename =
54 &manifest->vm[HF_PRIMARY_VM_INDEX].primary.ramdisk_filename;
Andrew Scull9c251d32019-09-19 13:30:42 +010055
David Brazdile6f83222019-09-23 14:47:37 +010056 if (string_is_empty(filename)) {
57 memiter_init(&primary_initrd, NULL, 0);
58 } else if (!cpio_get_file(cpio, filename, &primary_initrd)) {
Andrew Walbran17eebf92020-02-05 16:35:49 +000059 dlog_error("Unable to find primary initrd \"%s\".\n",
60 string_data(filename));
Andrew Scull9c251d32019-09-19 13:30:42 +010061 return false;
62 }
63
64 update->initrd_begin = pa_from_va(va_from_ptr(primary_initrd.next));
65 update->initrd_end = pa_from_va(va_from_ptr(primary_initrd.limit));
66
67 return fdt_patch(stage1_locked, plat_boot_flow_get_fdt_addr(), update,
Andrew Scullc3771072019-09-19 13:30:42 +010068 ppool);
69}