Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #ifdef VIRTUAL_PNOR_ENABLED |
| 4 | |
Ratan Gupta | 8441a39 | 2017-05-05 21:42:53 +0530 | [diff] [blame] | 5 | #include <limits.h> |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 6 | #include "pnor_partition_defs.h" |
| 7 | |
| 8 | struct mbox_context; |
| 9 | struct vpnor_partition_table; |
| 10 | |
Ratan Gupta | 8441a39 | 2017-05-05 21:42:53 +0530 | [diff] [blame] | 11 | struct vpnor_partition_paths |
| 12 | { |
| 13 | char ro_loc[PATH_MAX]; |
Ratan Gupta | c0ef987 | 2017-06-06 14:31:37 +0530 | [diff] [blame] | 14 | char rw_loc[PATH_MAX]; |
| 15 | char prsv_loc[PATH_MAX]; |
Adriana Kobylak | c71dfd7 | 2017-07-22 11:10:43 -0500 | [diff] [blame] | 16 | char patch_loc[PATH_MAX]; |
Ratan Gupta | 8441a39 | 2017-05-05 21:42:53 +0530 | [diff] [blame] | 17 | }; |
| 18 | |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 19 | #ifdef __cplusplus |
| 20 | extern "C" { |
| 21 | #endif |
| 22 | |
| 23 | /** @brief Create a virtual PNOR partition table. |
| 24 | * |
| 25 | * @param[in] context - mbox context pointer |
| 26 | * |
| 27 | * This API should be called before calling any other APIs below. If a table |
| 28 | * already exists, this function will not do anything further. This function |
| 29 | * will not do anything if the context is NULL. |
Andrew Jeffery | f96bd16 | 2018-02-26 13:05:00 +1030 | [diff] [blame] | 30 | * |
| 31 | * Returns 0 if the call succeeds, else a negative error code. |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 32 | */ |
Andrew Jeffery | f96bd16 | 2018-02-26 13:05:00 +1030 | [diff] [blame] | 33 | int init_vpnor(struct mbox_context *context); |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 34 | |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 35 | /** @brief Create a virtual PNOR partition table. |
| 36 | * |
| 37 | * @param[in] context - mbox context pointer |
| 38 | * @param[in] path - location of the partition file |
| 39 | * |
| 40 | * This API is same as above one but it reads the partition file from |
| 41 | * from the given location(path). |
Andrew Jeffery | f96bd16 | 2018-02-26 13:05:00 +1030 | [diff] [blame] | 42 | * |
| 43 | * Returns 0 if the call succeeds, else a negative error code. |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 44 | */ |
| 45 | |
Andrew Jeffery | f96bd16 | 2018-02-26 13:05:00 +1030 | [diff] [blame] | 46 | int vpnor_create_partition_table_from_path(struct mbox_context *context, |
| 47 | const char* path); |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 48 | |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 49 | |
| 50 | /** @brief Get partition table size, in blocks (1 block = 4KB) |
| 51 | * |
| 52 | * @param[in] context - mbox context pointer |
| 53 | * |
| 54 | * @returns partition table size. 0 if no table exists, or if the |
| 55 | * context is NULL. |
| 56 | */ |
| 57 | size_t vpnor_get_partition_table_size(const struct mbox_context *context); |
| 58 | |
| 59 | |
| 60 | /** @brief Get virtual PNOR partition table with host-compatible byte-ordering |
| 61 | * |
| 62 | * @param[in] context - mbox context pointer |
| 63 | * |
| 64 | * @returns pointer to partition table, NULL if partition table doesn't |
| 65 | * exist or if the context is NULL. |
| 66 | */ |
| 67 | const struct pnor_partition_table* vpnor_get_partition_table( |
| 68 | const struct mbox_context *context); |
| 69 | |
| 70 | |
| 71 | /** @brief Get a specific partition, by PNOR offset. The returned |
| 72 | * partition is such that the offset lies in that partition's |
| 73 | * boundary. |
| 74 | * |
| 75 | * @param[in] context - mbox context pointer |
| 76 | * @param[in] offset - PNOR offset |
| 77 | * |
| 78 | * @returns const pointer to pnor_partition, NULL if partition table doesn't |
| 79 | * exist or if the context is NULL |
| 80 | */ |
| 81 | const struct pnor_partition* vpnor_get_partition( |
| 82 | const struct mbox_context *context, |
| 83 | const size_t offset); |
| 84 | |
| 85 | |
Deepak Kodihalli | 017e45c | 2017-07-12 01:06:30 -0500 | [diff] [blame] | 86 | /** @brief Copy bootloader partition (alongwith TOC) to LPC memory |
| 87 | * |
| 88 | * @param[in] context - mbox context pointer |
Andrew Jeffery | f96bd16 | 2018-02-26 13:05:00 +1030 | [diff] [blame] | 89 | * |
| 90 | * @returns 0 on success, negative error code on failure |
Deepak Kodihalli | 017e45c | 2017-07-12 01:06:30 -0500 | [diff] [blame] | 91 | */ |
Andrew Jeffery | f96bd16 | 2018-02-26 13:05:00 +1030 | [diff] [blame] | 92 | int vpnor_copy_bootloader_partition(const struct mbox_context *context); |
Deepak Kodihalli | 017e45c | 2017-07-12 01:06:30 -0500 | [diff] [blame] | 93 | |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 94 | /** @brief Destroy partition table, if it exists. |
| 95 | * |
| 96 | * @param[in] context - mbox context pointer |
| 97 | */ |
Deepak Kodihalli | 64ec3e4 | 2017-07-17 06:15:16 -0500 | [diff] [blame] | 98 | void destroy_vpnor(struct mbox_context *context); |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 99 | |
| 100 | #ifdef __cplusplus |
| 101 | } |
| 102 | #endif |
| 103 | |
| 104 | #endif |