rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2016 MediaTek Inc. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files |
| 6 | * (the "Software"), to deal in the Software without restriction, |
| 7 | * including without limitation the rights to use, copy, modify, merge, |
| 8 | * publish, distribute, sublicense, and/or sell copies of the Software, |
| 9 | * and to permit persons to whom the Software is furnished to do so, |
| 10 | * subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be |
| 13 | * included in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | */ |
| 23 | #pragma once |
| 24 | |
| 25 | #include <stdbool.h> |
| 26 | #include <sys/types.h> |
| 27 | |
| 28 | /** |
| 29 | * fit_get_image() - load fit image from a partition |
| 30 | * |
| 31 | * the function will use bio to access a partition from a storage and |
| 32 | * check fdt header. If pass, allocate memory buffer to read the fit image |
| 33 | * to load_buf |
| 34 | * |
| 35 | * @label: partition name |
| 36 | * @load_buf: pointer to buffer pointer, the address of allocated memory |
| 37 | * buffer with fit image loaded was passing back to the caller |
| 38 | * via this argument. |
| 39 | * |
| 40 | * returns: |
| 41 | * 0, on success |
| 42 | * otherwise, on failure |
| 43 | * |
| 44 | */ |
| 45 | int fit_get_image(const char *label, void **load_buf); |
| 46 | |
| 47 | /** |
| 48 | * fit_image_get_data() - get data property of a subimage node |
| 49 | * @fit: fit image start address |
| 50 | * @noffset: the offset to the subimage node |
| 51 | * @data: return data pointer |
| 52 | * @size: return data size |
| 53 | * |
| 54 | * returns: |
| 55 | * 0, on success |
| 56 | * otherwise, on failure |
| 57 | */ |
| 58 | int fit_image_get_data(const void *fit, int noffset, |
| 59 | const void **data, uint32_t *size); |
| 60 | /** |
| 61 | * fit_conf_verify_sig() - verify fit configuration signature |
| 62 | * |
| 63 | * @conf: configuration name |
| 64 | * @fit: fit image start address |
| 65 | * |
| 66 | * returns: |
| 67 | * 0, on success |
| 68 | * otherwise, on failure |
| 69 | */ |
| 70 | int fit_conf_verify_sig(const char *conf, void *fit); |
| 71 | |
| 72 | /** |
| 73 | * fit_load_image() - load fit image to proper address |
| 74 | * |
| 75 | * This checks FIT configuration to find sub-image nodes image |
| 76 | * and load the image to right address |
| 77 | * |
| 78 | * @conf: configuration name |
| 79 | * @img_pro: image property name |
| 80 | * @fit: fit image start address |
| 81 | * @load: returned load address |
| 82 | * @load_size: returned loaded raw image size |
| 83 | * @entry: returned entry address |
| 84 | * @need_verified: whether to check image integrity |
| 85 | * |
| 86 | * returns: |
| 87 | * 0, on success |
| 88 | * otherwise, on failure |
| 89 | * |
| 90 | */ |
| 91 | int fit_load_image(const char *conf, const char *img_pro, void *fit, |
| 92 | addr_t *load, size_t *load_size, paddr_t *entry, |
| 93 | bool need_verified); |
| 94 | |
| 95 | /** |
| 96 | * fit_load_loadable_image() - load "loadable" images to "load" address |
| 97 | * |
| 98 | * This function finds "sub_node_name" loadable image nodes, do integrity check |
| 99 | * per hash_check_enabled(), and load images to "load" address. |
| 100 | * |
| 101 | * @fit: fit image start address |
| 102 | * @sub_node_name: loadable image subnode name |
| 103 | * @load: returned loadable image load address |
| 104 | * |
| 105 | * return: |
| 106 | * 0: success |
| 107 | * otherwise: failure error code |
| 108 | * |
| 109 | */ |
| 110 | int fit_load_loadable_image(void *fit, const char *sub_node_name, addr_t *load); |