blob: a1e970d502d0984262aca2ebcef0364422edee00 [file] [log] [blame]
Patrick Georgiafd4c872020-05-05 23:43:18 +02001/* Taken from depthcharge: src/boot/fit.h */
Patrick Georgiac959032020-05-05 22:49:26 +02002/* SPDX-License-Identifier: GPL-2.0-or-later */
Patrick Rudolpha45e9f82018-04-19 14:39:07 +02003
Patrick Rudolpha892cde2018-04-19 14:39:07 +02004#ifndef __LIB_FIT_H__
5#define __LIB_FIT_H__
Patrick Rudolpha45e9f82018-04-19 14:39:07 +02006
7#include <stddef.h>
8#include <stdint.h>
Patrick Rudolpha892cde2018-04-19 14:39:07 +02009#include <device_tree.h>
10#include <list.h>
11#include <program_loading.h>
Patrick Rudolpha45e9f82018-04-19 14:39:07 +020012
Julius Werner21b0b1a2019-05-16 16:12:04 -070013struct fit_image_node {
Patrick Rudolpha45e9f82018-04-19 14:39:07 +020014 const char *name;
Julius Wernerb379f192019-05-13 16:34:16 -070015 void *data;
Patrick Rudolpha45e9f82018-04-19 14:39:07 +020016 uint32_t size;
Patrick Rudolpha892cde2018-04-19 14:39:07 +020017 int compression;
Patrick Rudolpha45e9f82018-04-19 14:39:07 +020018
Patrick Rudolpha892cde2018-04-19 14:39:07 +020019 struct list_node list_node;
20};
Patrick Rudolpha45e9f82018-04-19 14:39:07 +020021
Julius Werner21b0b1a2019-05-16 16:12:04 -070022struct fit_config_node {
Patrick Rudolpha45e9f82018-04-19 14:39:07 +020023 const char *name;
Julius Wernerb379f192019-05-13 16:34:16 -070024 struct fit_image_node *kernel;
25 struct fit_image_node *fdt;
Julius Werner21b0b1a2019-05-16 16:12:04 -070026 struct list_node overlays;
Julius Wernerb379f192019-05-13 16:34:16 -070027 struct fit_image_node *ramdisk;
Patrick Rudolpha892cde2018-04-19 14:39:07 +020028 struct fdt_property compat;
Patrick Rudolpha45e9f82018-04-19 14:39:07 +020029 int compat_rank;
30 int compat_pos;
Patrick Rudolpha892cde2018-04-19 14:39:07 +020031 const char *compat_string;
Patrick Rudolpha45e9f82018-04-19 14:39:07 +020032
Patrick Rudolpha892cde2018-04-19 14:39:07 +020033 struct list_node list_node;
34};
35
Julius Werner21b0b1a2019-05-16 16:12:04 -070036struct fit_overlay_chain {
37 struct fit_image_node *overlay;
38 struct list_node list_node;
39};
40
Patrick Rudolpha892cde2018-04-19 14:39:07 +020041/*
42 * Updates the cmdline in the devicetree.
43 */
Patrick Rudolph0a7d6902018-08-22 09:55:15 +020044void fit_update_chosen(struct device_tree *tree, const char *cmd_line);
Patrick Rudolpha892cde2018-04-19 14:39:07 +020045
46/*
47 * Add a compat string to the list of supported board ids.
48 * Has to be called before fit_load().
49 * The most common use-case would be to implement it on board level.
50 * Strings that were added first have a higher priority on finding a match.
51 */
52void fit_add_compat_string(const char *str);
53
54/*
55 * Updates the memory section in the devicetree.
56 */
57void fit_update_memory(struct device_tree *tree);
58
59/*
60 * Do architecture specific payload placements and fixups.
61 * Set entrypoint and first argument (if any).
62 * @param payload The payload, to set the entry point
63 * @param config The extracted FIT config
64 * @param kernel out-argument where to place the kernel
65 * @param fdt out-argument where to place the devicetree
66 * @param initrd out-argument where to place the initrd (optional)
67 * @return True if all config nodes could be placed, the corresponding
68 * regions have been updated and the entry point has been set.
69 * False on error.
70 */
71bool fit_payload_arch(struct prog *payload, struct fit_config_node *config,
72 struct region *kernel,
73 struct region *fdt,
74 struct region *initrd);
Patrick Rudolpha45e9f82018-04-19 14:39:07 +020075
76/*
77 * Unpack a FIT image into memory, choosing the right configuration through the
Patrick Rudolpha892cde2018-04-19 14:39:07 +020078 * compatible string set by fit_add_compat() and return the selected config
79 * node.
Patrick Rudolpha45e9f82018-04-19 14:39:07 +020080 */
Patrick Rudolpha892cde2018-04-19 14:39:07 +020081struct fit_config_node *fit_load(void *fit);
Patrick Rudolpha45e9f82018-04-19 14:39:07 +020082
Patrick Rudolpha892cde2018-04-19 14:39:07 +020083void fit_add_ramdisk(struct device_tree *tree, void *ramdisk_addr,
84 size_t ramdisk_size);
Patrick Rudolpha45e9f82018-04-19 14:39:07 +020085
Patrick Rudolpha892cde2018-04-19 14:39:07 +020086#endif /* __LIB_FIT_H__ */