Peer Chen | 8d782ee | 2011-01-18 21:34:18 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (c) 2011 NVIDIA Corporation. All rights reserved. |
| 3 | * |
| 4 | * See file CREDITS for list of people who contributed to this |
| 5 | * project. |
| 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 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 20 | * MA 02111-1307 USA |
| 21 | */ |
| 22 | |
| 23 | /* |
| 24 | * cbootimage.h - Definitions for the cbootimage code. |
| 25 | */ |
| 26 | |
| 27 | #ifndef INCLUDED_BUILDIMAGE_H |
| 28 | #define INCLUDED_BUILDIMAGE_H |
| 29 | |
| 30 | #include "nvboot_bct.h" |
| 31 | #include "nvbctlib.h" |
| 32 | #include <stdio.h> |
| 33 | #include <stdlib.h> |
| 34 | #include <assert.h> |
| 35 | #include <errno.h> |
| 36 | |
| 37 | #define NVBOOT_AES_BLOCK_SIZE_LOG2 4 |
Peer Chen | 8d782ee | 2011-01-18 21:34:18 -0500 | [diff] [blame] | 38 | #define MAX_BUFFER 200 |
| 39 | #define MAX_STR_LEN 20 |
| 40 | #define MAX_BOOTLOADER_SIZE (16 * 1024 * 1024) |
Peer Chen | 053d578 | 2011-03-03 10:12:58 -0800 | [diff] [blame] | 41 | #define NVBOOT_BOOTDATA_VERSION(a, b) ((((a)&0xffff) << 16) | ((b)&0xffff)) |
Peer Chen | 8d782ee | 2011-01-18 21:34:18 -0500 | [diff] [blame] | 42 | |
| 43 | /* |
| 44 | * Enumerations |
| 45 | */ |
| 46 | |
| 47 | typedef enum |
| 48 | { |
| 49 | file_type_bl = 0, |
| 50 | file_type_bct, |
| 51 | file_type_addon |
| 52 | } file_type; |
| 53 | /* |
| 54 | * Structures |
| 55 | */ |
| 56 | typedef struct item_rec |
| 57 | { |
| 58 | u_int8_t unique_name[4]; |
| 59 | u_int32_t Location; |
| 60 | u_int32_t size; |
| 61 | u_int32_t attribute; |
| 62 | u_int32_t reserve[4]; |
| 63 | u_int32_t item_checksum[4]; |
| 64 | }item; |
| 65 | |
| 66 | typedef struct addon_item_rec |
| 67 | { |
| 68 | struct item_rec item; |
| 69 | char addon_filename[MAX_BUFFER]; |
| 70 | int item_index; |
| 71 | struct addon_item_rec *next; |
| 72 | }addon_item; |
| 73 | |
| 74 | typedef struct table_rec |
| 75 | { |
| 76 | u_int8_t magic_id[8]; |
| 77 | u_int32_t table_checksum[4]; |
| 78 | u_int32_t table_size; |
| 79 | |
| 80 | }table; |
| 81 | |
| 82 | typedef struct addon_table_rec |
| 83 | { |
| 84 | struct table_rec table; |
| 85 | u_int8_t addon_item_no; |
| 86 | struct addon_item_rec *addon_item_list; |
| 87 | }addon_table; |
| 88 | |
| 89 | typedef struct build_image_context_rec |
| 90 | { |
| 91 | FILE *config_file; |
| 92 | char *image_filename; |
| 93 | FILE *raw_file; |
| 94 | nvbct_lib_fns bctlib; |
| 95 | u_int32_t block_size; |
| 96 | u_int32_t block_size_log2; |
| 97 | u_int32_t page_size; |
| 98 | u_int32_t page_size_log2; |
| 99 | u_int32_t pages_per_blk; |
| 100 | u_int32_t partition_size; |
| 101 | u_int32_t redundancy; |
| 102 | u_int32_t version; |
| 103 | /* Allocation data. */ |
| 104 | struct blk_data_rec *memory; /* Representation of memory */ |
| 105 | /* block number for the (first) journal block */ |
| 106 | u_int32_t journal_blk; |
| 107 | |
| 108 | char *newbl_filename; |
| 109 | u_int32_t newbl_load_addr; |
| 110 | u_int32_t newbl_entry_point; |
| 111 | u_int32_t newbl_attr; |
Peer Chen | 7557d9b | 2011-02-24 09:29:23 -0800 | [diff] [blame] | 112 | u_int8_t generate_bct; |
Peer Chen | 8d782ee | 2011-01-18 21:34:18 -0500 | [diff] [blame] | 113 | u_int8_t *bct; |
| 114 | |
| 115 | struct addon_table_rec addon_tbl; |
| 116 | char *bct_filename; |
| 117 | u_int32_t last_bl_blk; |
| 118 | u_int32_t addon_tbl_blk; |
| 119 | } build_image_context; |
| 120 | |
| 121 | /* Function prototypes */ |
| 122 | |
| 123 | int write_image_file(build_image_context *context); |
| 124 | |
| 125 | /* Global data */ |
| 126 | extern int enable_debug; |
| 127 | |
| 128 | /* Useful macros */ |
| 129 | |
| 130 | #define GET_VALUE(id, ptr) \ |
| 131 | (void)context->bctlib.get_value(nvbct_lib_id_##id, \ |
| 132 | ptr, \ |
| 133 | context->bct); |
| 134 | |
| 135 | #define SET_VALUE(id, value) \ |
| 136 | (void)context->bctlib.set_value(nvbct_lib_id_##id, \ |
| 137 | value, \ |
| 138 | context->bct); |
| 139 | |
| 140 | #endif /* #ifndef INCLUDED_BUILDIMAGE_H */ |