Changeset dcc2c5d in mainline for boot/generic/src/payload.c
- Timestamp:
- 2018-10-12T17:44:35Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 68a0d60
- Parents:
- d4eba6d
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-10-12 17:38:51)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-10-12 17:44:35)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/generic/src/payload.c
rd4eba6d rdcc2c5d 41 41 #include <halt.h> 42 42 43 static void basename(char *s)44 { 45 c har *last = s;43 static const char *ext(const char *s) 44 { 45 const char *last = s; 46 46 47 47 while (*s) { … … 53 53 54 54 if (*last == '.') 55 *last = '\0'; 55 return last; 56 57 return NULL; 58 } 59 60 static void basename(char *s) 61 { 62 char *e = (char *) ext(s); 63 if (str_cmp(e, ".gz") == 0) 64 *e = '\0'; 65 } 66 67 static bool isgzip(const char *s) 68 { 69 return str_cmp(ext(s), ".gz") == 0; 56 70 } 57 71 … … 68 82 const char *name; 69 83 const uint8_t *data; 70 size_t compressed_size;71 size_t un compressed_size;72 73 if (!tar_info(*cstart, cend, &name, & compressed_size))84 size_t packed_size; 85 size_t unpacked_size; 86 87 if (!tar_info(*cstart, cend, &name, &packed_size)) 74 88 return false; 75 89 76 90 data = *cstart + TAR_BLOCK_SIZE; 77 *cstart += TAR_BLOCK_SIZE + ALIGN_UP(compressed_size, TAR_BLOCK_SIZE); 78 79 uncompressed_size = gzip_size(data, compressed_size); 91 *cstart += TAR_BLOCK_SIZE + ALIGN_UP(packed_size, TAR_BLOCK_SIZE); 92 93 bool gz = isgzip(name); 94 95 unpacked_size = gz ? gzip_size(data, packed_size) : packed_size; 80 96 81 97 /* Components must be page-aligned. */ … … 83 99 actual_ustart += new_ustart - ustart; 84 100 ustart = new_ustart; 85 uint8_t *comp_end = ustart + un compressed_size;101 uint8_t *comp_end = ustart + unpacked_size; 86 102 87 103 /* Check limits and overlap. */ … … 92 108 actual_ustart += new_ustart - ustart; 93 109 ustart = new_ustart; 94 comp_end = ustart + un compressed_size;110 comp_end = ustart + unpacked_size; 95 111 } 96 112 … … 102 118 103 119 printf(" %p|%p: %s image (%zu/%zu bytes)\n", (void *) actual_ustart, 104 ustart, name, un compressed_size, compressed_size);120 ustart, name, unpacked_size, packed_size); 105 121 106 122 if (task) { 107 123 task->addr = (void *) actual_ustart; 108 task->size = un compressed_size;124 task->size = unpacked_size; 109 125 str_cpy(task->name, BOOTINFO_TASK_NAME_BUFLEN, name); 110 126 /* Remove .gz extension */ 111 basename(task->name); 112 } 113 114 int rc = gzip_expand(data, compressed_size, ustart, uncompressed_size); 115 if (rc != EOK) { 116 printf("\n%s: Inflating error %d\n", name, rc); 117 halt(); 127 if (gz) 128 basename(task->name); 129 } 130 131 if (gz) { 132 int rc = gzip_expand(data, packed_size, ustart, unpacked_size); 133 if (rc != EOK) { 134 printf("\n%s: Inflating error %d\n", name, rc); 135 halt(); 136 } 137 } else { 138 memcpy(ustart, data, unpacked_size); 118 139 } 119 140 120 141 if (clear_cache) 121 clear_cache(ustart, uncompressed_size); 142 clear_cache(ustart, unpacked_size); 143 122 144 return true; 123 145 } 124 146 125 /* @return Bytes needed for un compressed payload. */126 size_t payload_un compressed_size(void)147 /* @return Bytes needed for unpacked payload. */ 148 size_t payload_unpacked_size(void) 127 149 { 128 150 size_t sz = 0; 129 151 uint8_t *start = payload_start; 130 152 const char *name; 131 size_t compressed_size;132 133 while (tar_info(start, payload_end, &name, & compressed_size)) {153 size_t packed_size; 154 155 while (tar_info(start, payload_end, &name, &packed_size)) { 134 156 sz = ALIGN_UP(sz, PAGE_SIZE); 135 sz += gzip_size(start + TAR_BLOCK_SIZE, compressed_size); 136 137 start += TAR_BLOCK_SIZE + 138 ALIGN_UP(compressed_size, TAR_BLOCK_SIZE); 157 if (isgzip(name)) 158 sz += gzip_size(start + TAR_BLOCK_SIZE, packed_size); 159 else 160 sz += packed_size; 161 162 start += TAR_BLOCK_SIZE + ALIGN_UP(packed_size, TAR_BLOCK_SIZE); 139 163 } 140 164 … … 186 210 /* 187 211 * First, move the payload to the very end of available memory, 188 * to make space for the decompressed data.212 * to make space for the unpacked data. 189 213 */ 190 214 real_payload_start = (uint8_t *) ALIGN_DOWN((uintptr_t)(mem_end - payload_size), PAGE_SIZE);
Note:
See TracChangeset
for help on using the changeset viewer.