| OLD | NEW |
| 1 /** | 1 /** |
| 2 * Copyright (c) 2011 NVIDIA Corporation. All rights reserved. | 2 * Copyright (c) 2011 NVIDIA Corporation. All rights reserved. |
| 3 * | 3 * |
| 4 * See file CREDITS for list of people who contributed to this | 4 * See file CREDITS for list of people who contributed to this |
| 5 * project. | 5 * project. |
| 6 * | 6 * |
| 7 * This program is free software; you can redistribute it and/or | 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 | 8 * modify it under the terms of the GNU General Public License as |
| 9 * published by the Free Software Foundation; either version 2 of | 9 * published by the Free Software Foundation; either version 2 of |
| 10 * the License, or (at your option) any later version. | 10 * the License, or (at your option) any later version. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 set_bl_data(build_image_context *context, | 73 set_bl_data(build_image_context *context, |
| 74 u_int32_t instance, | 74 u_int32_t instance, |
| 75 u_int32_t start_blk, | 75 u_int32_t start_blk, |
| 76 u_int32_t start_page, | 76 u_int32_t start_page, |
| 77 u_int32_t length); | 77 u_int32_t length); |
| 78 | 78 |
| 79 static int write_bootloaders(build_image_context *context); | 79 static int write_bootloaders(build_image_context *context); |
| 80 | 80 |
| 81 static void find_new_journal_blk(build_image_context *context); | 81 static void find_new_journal_blk(build_image_context *context); |
| 82 static int finish_update(build_image_context *context); | 82 static int finish_update(build_image_context *context); |
| 83 static void init_bad_block_table(build_image_context *context); |
| 84 |
| 83 static u_int32_t | 85 static u_int32_t |
| 84 iceil_log2(u_int32_t a, u_int32_t b) | 86 iceil_log2(u_int32_t a, u_int32_t b) |
| 85 { | 87 { |
| 86 return (a + (1 << b) - 1) >> b; | 88 return (a + (1 << b) - 1) >> b; |
| 87 } | 89 } |
| 88 | 90 |
| 91 /* Returns the smallest power of 2 >= a */ |
| 92 static u_int32_t |
| 93 ceil_log2(u_int32_t a) |
| 94 { |
| 95 u_int32_t result; |
| 96 |
| 97 result = log2(a); |
| 98 if ((1UL << result) < a) |
| 99 result++; |
| 100 |
| 101 return result; |
| 102 } |
| 103 |
| 104 static void init_bad_block_table(build_image_context *context) |
| 105 { |
| 106 u_int32_t bytes_per_entry; |
| 107 nvboot_badblock_table *table; |
| 108 nvboot_config_table *bct; |
| 109 |
| 110 bct = (nvboot_config_table *)(context->bct); |
| 111 |
| 112 assert(context != NULL); |
| 113 assert(bct != NULL); |
| 114 |
| 115 table = &(bct->badblock_table); |
| 116 |
| 117 bytes_per_entry = ICEIL(context->partition_size, |
| 118 NVBOOT_BAD_BLOCK_TABLE_SIZE); |
| 119 table->block_size_log2 = context->block_size_log2; |
| 120 table->virtual_blk_size_log2 = NV_MAX(ceil_log2(bytes_per_entry), |
| 121 table->block_size_log2); |
| 122 table->entries_used = iceil_log2(context->partition_size, |
| 123 table->virtual_blk_size_log2); |
| 124 } |
| 125 |
| 89 static block_data *new_block(u_int32_t blk_number, u_int32_t block_size) | 126 static block_data *new_block(u_int32_t blk_number, u_int32_t block_size) |
| 90 { | 127 { |
| 91 block_data *new_block = malloc(sizeof(block_data)); | 128 block_data *new_block = malloc(sizeof(block_data)); |
| 92 if (new_block == NULL) | 129 if (new_block == NULL) |
| 93 return NULL; | 130 return NULL; |
| 94 | 131 |
| 95 new_block->blk_number = blk_number; | 132 new_block->blk_number = blk_number; |
| 96 new_block->pages_used = 0; | 133 new_block->pages_used = 0; |
| 97 new_block->data = malloc(block_size); | 134 new_block->data = malloc(block_size); |
| 98 if (new_block->data == NULL) { | 135 if (new_block->data == NULL) { |
| (...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 | 934 |
| 898 SET_VALUE(boot_data_version, NVBOOT_BOOTDATA_VERSION(2, 1)); | 935 SET_VALUE(boot_data_version, NVBOOT_BOOTDATA_VERSION(2, 1)); |
| 899 GET_VALUE(bct_size, &bct_size); | 936 GET_VALUE(bct_size, &bct_size); |
| 900 GET_VALUE(hash_size, &hash_size); | 937 GET_VALUE(hash_size, &hash_size); |
| 901 GET_VALUE(reserved_size, &reserved_size); | 938 GET_VALUE(reserved_size, &reserved_size); |
| 902 GET_VALUE(reserved_offset, &reserved_offset); | 939 GET_VALUE(reserved_offset, &reserved_offset); |
| 903 | 940 |
| 904 pages_per_bct = iceil_log2(bct_size, context->page_size_log2); | 941 pages_per_bct = iceil_log2(bct_size, context->page_size_log2); |
| 905 pages_per_blk = (1 << (context->block_size_log2 | 942 pages_per_blk = (1 << (context->block_size_log2 |
| 906 - context->page_size_log2)); | 943 - context->page_size_log2)); |
| 907 | 944 » /* Initialize the bad block table field. */ |
| 945 » init_bad_block_table(context); |
| 908 /* Fill the reserved data w/the padding pattern. */ | 946 /* Fill the reserved data w/the padding pattern. */ |
| 909 write_padding(context->bct + reserved_offset, reserved_size); | 947 write_padding(context->bct + reserved_offset, reserved_size); |
| 910 | 948 |
| 911 /* Device is new */ | 949 /* Device is new */ |
| 912 /* Find the new journal block starting at block 1. */ | 950 /* Find the new journal block starting at block 1. */ |
| 913 find_new_journal_blk(context); | 951 find_new_journal_blk(context); |
| 914 | 952 |
| 915 e = erase_block(context, context->journal_blk); | 953 e = erase_block(context, context->journal_blk); |
| 916 if (e != 0) | 954 if (e != 0) |
| 917 goto fail; | 955 goto fail; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 size_t bytes = pages_to_write * context->page_size; | 1059 size_t bytes = pages_to_write * context->page_size; |
| 1022 | 1060 |
| 1023 if (fwrite(data, 1, bytes, context->raw_file) != bytes) | 1061 if (fwrite(data, 1, bytes, context->raw_file) != bytes) |
| 1024 return -1; | 1062 return -1; |
| 1025 } | 1063 } |
| 1026 } | 1064 } |
| 1027 | 1065 |
| 1028 free(empty_blk); | 1066 free(empty_blk); |
| 1029 return 0; | 1067 return 0; |
| 1030 } | 1068 } |
| OLD | NEW |