blob: c1a4842e43c6d8c719b5e8fa36db7715361be9ee [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
Andrew Scull9c251d32019-09-19 13:30:42 +01009#include "hf/cpio.h"
10#include "hf/dlog.h"
David Brazdil0dbb41f2019-09-09 18:03:35 +010011#include "hf/fdt_handler.h"
David Brazdilb856be62020-03-25 10:14:55 +000012#include "hf/fdt_patch.h"
David Brazdil0dbb41f2019-09-09 18:03:35 +010013#include "hf/plat/boot_flow.h"
Andrew Scull9c251d32019-09-19 13:30:42 +010014#include "hf/std.h"
15
David Brazdil0dbb41f2019-09-09 18:03:35 +010016/* Set by arch-specific boot-time hook. */
Andrew Scullc3771072019-09-19 13:30:42 +010017uintreg_t plat_boot_flow_fdt_addr;
David Brazdil0dbb41f2019-09-09 18:03:35 +010018
19/**
20 * Returns the physical address of board FDT. This was passed to Hafnium in the
21 * first kernel arg by the boot loader.
22 */
Andrew Scullc3771072019-09-19 13:30:42 +010023paddr_t plat_boot_flow_get_fdt_addr(void)
David Brazdil0dbb41f2019-09-09 18:03:35 +010024{
Andrew Scullc3771072019-09-19 13:30:42 +010025 return pa_init((uintpaddr_t)plat_boot_flow_fdt_addr);
David Brazdil0dbb41f2019-09-09 18:03:35 +010026}
27
28/**
29 * When handing over to the primary, give it the same FDT address that was given
30 * to Hafnium. The FDT may have been modified during Hafnium init.
31 */
Andrew Scullc3771072019-09-19 13:30:42 +010032uintreg_t plat_boot_flow_get_kernel_arg(void)
David Brazdil0dbb41f2019-09-09 18:03:35 +010033{
Andrew Scullc3771072019-09-19 13:30:42 +010034 return plat_boot_flow_fdt_addr;
David Brazdil0dbb41f2019-09-09 18:03:35 +010035}
36
37/**
38 * Load initrd range from the board FDT.
39 */
David Brazdilb856be62020-03-25 10:14:55 +000040bool plat_boot_flow_get_initrd_range(const struct fdt *fdt, paddr_t *begin,
41 paddr_t *end)
David Brazdil0dbb41f2019-09-09 18:03:35 +010042{
David Brazdilb856be62020-03-25 10:14:55 +000043 return fdt_find_initrd(fdt, begin, end);
David Brazdil0dbb41f2019-09-09 18:03:35 +010044}
Andrew Scullc3771072019-09-19 13:30:42 +010045
46bool plat_boot_flow_update(struct mm_stage1_locked stage1_locked,
David Brazdile6f83222019-09-23 14:47:37 +010047 const struct manifest *manifest,
Andrew Scull9c251d32019-09-19 13:30:42 +010048 struct boot_params_update *update,
49 struct memiter *cpio, struct mpool *ppool)
Andrew Scullc3771072019-09-19 13:30:42 +010050{
Andrew Scull9c251d32019-09-19 13:30:42 +010051 struct memiter primary_initrd;
David Brazdile6f83222019-09-23 14:47:37 +010052 const struct string *filename =
53 &manifest->vm[HF_PRIMARY_VM_INDEX].primary.ramdisk_filename;
Andrew Scull9c251d32019-09-19 13:30:42 +010054
David Brazdile6f83222019-09-23 14:47:37 +010055 if (string_is_empty(filename)) {
56 memiter_init(&primary_initrd, NULL, 0);
57 } else if (!cpio_get_file(cpio, filename, &primary_initrd)) {
Andrew Walbran17eebf92020-02-05 16:35:49 +000058 dlog_error("Unable to find primary initrd \"%s\".\n",
59 string_data(filename));
Andrew Scull9c251d32019-09-19 13:30:42 +010060 return false;
61 }
62
63 update->initrd_begin = pa_from_va(va_from_ptr(primary_initrd.next));
64 update->initrd_end = pa_from_va(va_from_ptr(primary_initrd.limit));
65
66 return fdt_patch(stage1_locked, plat_boot_flow_get_fdt_addr(), update,
Andrew Scullc3771072019-09-19 13:30:42 +010067 ppool);
68}