blob: 1c90aca1fff204d2d8d72f4b0db5c71dea9d0780 [file] [log] [blame]
Patrick Rudolpha45e9f82018-04-19 14:39:07 +02001/*
2 * Copyright 2013 Google Inc.
Patrick Rudolpha892cde2018-04-19 14:39:07 +02003 * Copyright 2018-present Facebook, Inc.
Patrick Rudolpha45e9f82018-04-19 14:39:07 +02004 *
Patrick Rudolpha892cde2018-04-19 14:39:07 +02005 * Taken from depthcharge: src/boot/fit.h
Patrick Rudolpha45e9f82018-04-19 14:39:07 +02006 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but without any warranty; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
Patrick Rudolpha892cde2018-04-19 14:39:07 +020018#ifndef __LIB_FIT_H__
19#define __LIB_FIT_H__
Patrick Rudolpha45e9f82018-04-19 14:39:07 +020020
21#include <stddef.h>
22#include <stdint.h>
Patrick Rudolpha892cde2018-04-19 14:39:07 +020023#include <device_tree.h>
24#include <list.h>
25#include <program_loading.h>
Patrick Rudolpha45e9f82018-04-19 14:39:07 +020026
Julius Werner21b0b1a2019-05-16 16:12:04 -070027struct fit_image_node {
Patrick Rudolpha45e9f82018-04-19 14:39:07 +020028 const char *name;
Julius Wernerb379f192019-05-13 16:34:16 -070029 void *data;
Patrick Rudolpha45e9f82018-04-19 14:39:07 +020030 uint32_t size;
Patrick Rudolpha892cde2018-04-19 14:39:07 +020031 int compression;
Patrick Rudolpha45e9f82018-04-19 14:39:07 +020032
Patrick Rudolpha892cde2018-04-19 14:39:07 +020033 struct list_node list_node;
34};
Patrick Rudolpha45e9f82018-04-19 14:39:07 +020035
Julius Werner21b0b1a2019-05-16 16:12:04 -070036struct fit_config_node {
Patrick Rudolpha45e9f82018-04-19 14:39:07 +020037 const char *name;
Julius Wernerb379f192019-05-13 16:34:16 -070038 struct fit_image_node *kernel;
39 struct fit_image_node *fdt;
Julius Werner21b0b1a2019-05-16 16:12:04 -070040 struct list_node overlays;
Julius Wernerb379f192019-05-13 16:34:16 -070041 struct fit_image_node *ramdisk;
Patrick Rudolpha892cde2018-04-19 14:39:07 +020042 struct fdt_property compat;
Patrick Rudolpha45e9f82018-04-19 14:39:07 +020043 int compat_rank;
44 int compat_pos;
Patrick Rudolpha892cde2018-04-19 14:39:07 +020045 const char *compat_string;
Patrick Rudolpha45e9f82018-04-19 14:39:07 +020046
Patrick Rudolpha892cde2018-04-19 14:39:07 +020047 struct list_node list_node;
48};
49
Julius Werner21b0b1a2019-05-16 16:12:04 -070050struct fit_overlay_chain {
51 struct fit_image_node *overlay;
52 struct list_node list_node;
53};
54
Patrick Rudolpha892cde2018-04-19 14:39:07 +020055/*
56 * Updates the cmdline in the devicetree.
57 */
Patrick Rudolph0a7d6902018-08-22 09:55:15 +020058void fit_update_chosen(struct device_tree *tree, const char *cmd_line);
Patrick Rudolpha892cde2018-04-19 14:39:07 +020059
60/*
61 * Add a compat string to the list of supported board ids.
62 * Has to be called before fit_load().
63 * The most common use-case would be to implement it on board level.
64 * Strings that were added first have a higher priority on finding a match.
65 */
66void fit_add_compat_string(const char *str);
67
68/*
69 * Updates the memory section in the devicetree.
70 */
71void fit_update_memory(struct device_tree *tree);
72
73/*
74 * Do architecture specific payload placements and fixups.
75 * Set entrypoint and first argument (if any).
76 * @param payload The payload, to set the entry point
77 * @param config The extracted FIT config
78 * @param kernel out-argument where to place the kernel
79 * @param fdt out-argument where to place the devicetree
80 * @param initrd out-argument where to place the initrd (optional)
81 * @return True if all config nodes could be placed, the corresponding
82 * regions have been updated and the entry point has been set.
83 * False on error.
84 */
85bool fit_payload_arch(struct prog *payload, struct fit_config_node *config,
86 struct region *kernel,
87 struct region *fdt,
88 struct region *initrd);
Patrick Rudolpha45e9f82018-04-19 14:39:07 +020089
90/*
91 * Unpack a FIT image into memory, choosing the right configuration through the
Patrick Rudolpha892cde2018-04-19 14:39:07 +020092 * compatible string set by fit_add_compat() and return the selected config
93 * node.
Patrick Rudolpha45e9f82018-04-19 14:39:07 +020094 */
Patrick Rudolpha892cde2018-04-19 14:39:07 +020095struct fit_config_node *fit_load(void *fit);
Patrick Rudolpha45e9f82018-04-19 14:39:07 +020096
Patrick Rudolpha892cde2018-04-19 14:39:07 +020097void fit_add_ramdisk(struct device_tree *tree, void *ramdisk_addr,
98 size_t ramdisk_size);
Patrick Rudolpha45e9f82018-04-19 14:39:07 +020099
Patrick Rudolpha892cde2018-04-19 14:39:07 +0200100#endif /* __LIB_FIT_H__ */