Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 3 | * Copyright 2018-present Facebook, Inc. |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 4 | * |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 5 | * Taken from depthcharge: src/boot/fit.h |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 6 | * |
| 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 Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 18 | #ifndef __LIB_FIT_H__ |
| 19 | #define __LIB_FIT_H__ |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 20 | |
| 21 | #include <stddef.h> |
| 22 | #include <stdint.h> |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 23 | #include <device_tree.h> |
| 24 | #include <list.h> |
| 25 | #include <program_loading.h> |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 26 | |
Julius Werner | 21b0b1a | 2019-05-16 16:12:04 -0700 | [diff] [blame] | 27 | struct fit_image_node { |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 28 | const char *name; |
Julius Werner | b379f19 | 2019-05-13 16:34:16 -0700 | [diff] [blame] | 29 | void *data; |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 30 | uint32_t size; |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 31 | int compression; |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 32 | |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 33 | struct list_node list_node; |
| 34 | }; |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 35 | |
Julius Werner | 21b0b1a | 2019-05-16 16:12:04 -0700 | [diff] [blame] | 36 | struct fit_config_node { |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 37 | const char *name; |
Julius Werner | b379f19 | 2019-05-13 16:34:16 -0700 | [diff] [blame] | 38 | struct fit_image_node *kernel; |
| 39 | struct fit_image_node *fdt; |
Julius Werner | 21b0b1a | 2019-05-16 16:12:04 -0700 | [diff] [blame] | 40 | struct list_node overlays; |
Julius Werner | b379f19 | 2019-05-13 16:34:16 -0700 | [diff] [blame] | 41 | struct fit_image_node *ramdisk; |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 42 | struct fdt_property compat; |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 43 | int compat_rank; |
| 44 | int compat_pos; |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 45 | const char *compat_string; |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 46 | |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 47 | struct list_node list_node; |
| 48 | }; |
| 49 | |
Julius Werner | 21b0b1a | 2019-05-16 16:12:04 -0700 | [diff] [blame] | 50 | struct fit_overlay_chain { |
| 51 | struct fit_image_node *overlay; |
| 52 | struct list_node list_node; |
| 53 | }; |
| 54 | |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 55 | /* |
| 56 | * Updates the cmdline in the devicetree. |
| 57 | */ |
Patrick Rudolph | 0a7d690 | 2018-08-22 09:55:15 +0200 | [diff] [blame] | 58 | void fit_update_chosen(struct device_tree *tree, const char *cmd_line); |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 59 | |
| 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 | */ |
| 66 | void fit_add_compat_string(const char *str); |
| 67 | |
| 68 | /* |
| 69 | * Updates the memory section in the devicetree. |
| 70 | */ |
| 71 | void 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 | */ |
| 85 | bool fit_payload_arch(struct prog *payload, struct fit_config_node *config, |
| 86 | struct region *kernel, |
| 87 | struct region *fdt, |
| 88 | struct region *initrd); |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 89 | |
| 90 | /* |
| 91 | * Unpack a FIT image into memory, choosing the right configuration through the |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 92 | * compatible string set by fit_add_compat() and return the selected config |
| 93 | * node. |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 94 | */ |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 95 | struct fit_config_node *fit_load(void *fit); |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 96 | |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 97 | void fit_add_ramdisk(struct device_tree *tree, void *ramdisk_addr, |
| 98 | size_t ramdisk_size); |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 99 | |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 100 | #endif /* __LIB_FIT_H__ */ |