OLD | NEW |
(Empty) | |
| 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 #include "cbootimage.h" |
| 24 #include "data_layout.h" |
| 25 #include "set.h" |
| 26 |
| 27 static int |
| 28 query_alloc(build_image_context *context, |
| 29 nvbct_lib_id size_id, |
| 30 u_int8_t **dst) |
| 31 { |
| 32 u_int32_t size; |
| 33 |
| 34 /* Note: 3rd argument not used in this particular query. */ |
| 35 if (context->bctlib.get_value(size_id, |
| 36 &size, context->bct) != 0) |
| 37 return -ENODATA; |
| 38 *dst = malloc(size); |
| 39 |
| 40 if (*dst == NULL) |
| 41 return -ENOMEM; |
| 42 |
| 43 memset(*dst, 0, size); |
| 44 |
| 45 return 0; |
| 46 } |
| 47 |
| 48 void |
| 49 cleanup_context(build_image_context *context) |
| 50 { |
| 51 destroy_block_list(context->memory); |
| 52 destroy_addon_list(context->addon_tbl.addon_item_list); |
| 53 free(context->bct); |
| 54 } |
| 55 |
| 56 int |
| 57 init_context(build_image_context *context) |
| 58 { |
| 59 int e = 0; |
| 60 |
| 61 /* Set defaults */ |
| 62 context->memory = new_block_list(); |
| 63 context->journal_blk = 1; /* Default to 1st block */ |
| 64 |
| 65 /* Allocate space for the bct. |
| 66 * Note that this is different from the old code which pointed directly |
| 67 * into a memory image. |
| 68 */ |
| 69 e = query_alloc(context, nvbct_lib_id_bct_size, &(context->bct)); |
| 70 if (e != 0) |
| 71 goto fail; |
| 72 |
| 73 context_set_value(context, token_page_size, 2048); |
| 74 context_set_value(context, token_redundancy, 1); |
| 75 context_set_value(context, token_version, 1); |
| 76 |
| 77 return 0; |
| 78 |
| 79 fail: |
| 80 cleanup_context(context); |
| 81 |
| 82 return e; |
| 83 } |
OLD | NEW |