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 | |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 27 | struct fit_image_node |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 28 | { |
| 29 | const char *name; |
Patrick Rudolph | 0a7d690 | 2018-08-22 09:55:15 +0200 | [diff] [blame] | 30 | const void *data; |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 31 | uint32_t size; |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 32 | int compression; |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 33 | |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 34 | struct list_node list_node; |
| 35 | }; |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 36 | |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 37 | struct fit_config_node |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 38 | { |
| 39 | const char *name; |
| 40 | const char *kernel; |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 41 | struct fit_image_node *kernel_node; |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 42 | const char *fdt; |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 43 | struct fit_image_node *fdt_node; |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 44 | const char *ramdisk; |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 45 | struct fit_image_node *ramdisk_node; |
| 46 | struct fdt_property compat; |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 47 | int compat_rank; |
| 48 | int compat_pos; |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 49 | const char *compat_string; |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 50 | |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 51 | struct list_node list_node; |
| 52 | }; |
| 53 | |
| 54 | /* |
| 55 | * Updates the cmdline in the devicetree. |
| 56 | */ |
Patrick Rudolph | 0a7d690 | 2018-08-22 09:55:15 +0200 | [diff] [blame] | 57 | void fit_update_chosen(struct device_tree *tree, const char *cmd_line); |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 58 | |
| 59 | /* |
| 60 | * Add a compat string to the list of supported board ids. |
| 61 | * Has to be called before fit_load(). |
| 62 | * The most common use-case would be to implement it on board level. |
| 63 | * Strings that were added first have a higher priority on finding a match. |
| 64 | */ |
| 65 | void fit_add_compat_string(const char *str); |
| 66 | |
| 67 | /* |
| 68 | * Updates the memory section in the devicetree. |
| 69 | */ |
| 70 | void fit_update_memory(struct device_tree *tree); |
| 71 | |
| 72 | /* |
| 73 | * Do architecture specific payload placements and fixups. |
| 74 | * Set entrypoint and first argument (if any). |
| 75 | * @param payload The payload, to set the entry point |
| 76 | * @param config The extracted FIT config |
| 77 | * @param kernel out-argument where to place the kernel |
| 78 | * @param fdt out-argument where to place the devicetree |
| 79 | * @param initrd out-argument where to place the initrd (optional) |
| 80 | * @return True if all config nodes could be placed, the corresponding |
| 81 | * regions have been updated and the entry point has been set. |
| 82 | * False on error. |
| 83 | */ |
| 84 | bool fit_payload_arch(struct prog *payload, struct fit_config_node *config, |
| 85 | struct region *kernel, |
| 86 | struct region *fdt, |
| 87 | struct region *initrd); |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 88 | |
| 89 | /* |
| 90 | * Unpack a FIT image into memory, choosing the right configuration through the |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 91 | * compatible string set by fit_add_compat() and return the selected config |
| 92 | * node. |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 93 | */ |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 94 | struct fit_config_node *fit_load(void *fit); |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 95 | |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 96 | void fit_add_ramdisk(struct device_tree *tree, void *ramdisk_addr, |
| 97 | size_t ramdisk_size); |
Patrick Rudolph | a45e9f8 | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 98 | |
Patrick Rudolph | a892cde | 2018-04-19 14:39:07 +0200 | [diff] [blame] | 99 | #endif /* __LIB_FIT_H__ */ |