Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | a131c1f | 2015-08-30 16:55:24 -0600 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2015 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
| 5 | * |
Philipp Tomsich | 2fb371f | 2017-05-30 23:32:08 +0200 | [diff] [blame] | 6 | * (C) 2017 Theobroma Systems Design und Consulting GmbH |
| 7 | * |
Simon Glass | a131c1f | 2015-08-30 16:55:24 -0600 | [diff] [blame] | 8 | * Helper functions for Rockchip images |
| 9 | */ |
| 10 | |
| 11 | #include "imagetool.h" |
| 12 | #include <image.h> |
| 13 | #include <rc4.h> |
| 14 | #include "mkimage.h" |
| 15 | #include "rkcommon.h" |
| 16 | |
Philipp Tomsich | a1a2dfb | 2017-04-17 17:48:04 +0200 | [diff] [blame] | 17 | #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
| 18 | |
Simon Glass | a131c1f | 2015-08-30 16:55:24 -0600 | [diff] [blame] | 19 | enum { |
| 20 | RK_SIGNATURE = 0x0ff0aa55, |
| 21 | }; |
| 22 | |
| 23 | /** |
| 24 | * struct header0_info - header block for boot ROM |
| 25 | * |
| 26 | * This is stored at SD card block 64 (where each block is 512 bytes, or at |
| 27 | * the start of SPI flash. It is encoded with RC4. |
| 28 | * |
| 29 | * @signature: Signature (must be RKSD_SIGNATURE) |
| 30 | * @disable_rc4: 0 to use rc4 for boot image, 1 to use plain binary |
Jeffy Chen | 3641339 | 2015-11-17 14:20:30 +0800 | [diff] [blame] | 31 | * @init_offset: Offset in blocks of the SPL code from this header |
Simon Glass | a131c1f | 2015-08-30 16:55:24 -0600 | [diff] [blame] | 32 | * block. E.g. 4 means 2KB after the start of this header. |
| 33 | * Other fields are not used by U-Boot |
| 34 | */ |
| 35 | struct header0_info { |
| 36 | uint32_t signature; |
| 37 | uint8_t reserved[4]; |
| 38 | uint32_t disable_rc4; |
Jeffy Chen | 3641339 | 2015-11-17 14:20:30 +0800 | [diff] [blame] | 39 | uint16_t init_offset; |
| 40 | uint8_t reserved1[492]; |
| 41 | uint16_t init_size; |
| 42 | uint16_t init_boot_size; |
Simon Glass | a131c1f | 2015-08-30 16:55:24 -0600 | [diff] [blame] | 43 | uint8_t reserved2[2]; |
| 44 | }; |
| 45 | |
Jeffy Chen | 7bf274b | 2015-11-27 12:07:17 +0800 | [diff] [blame] | 46 | /** |
Philipp Tomsich | 111bcc4 | 2017-03-15 12:08:43 +0100 | [diff] [blame] | 47 | * struct header1_info |
| 48 | */ |
| 49 | struct header1_info { |
| 50 | uint32_t magic; |
Philipp Tomsich | 111bcc4 | 2017-03-15 12:08:43 +0100 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | /** |
Jeffy Chen | 7bf274b | 2015-11-27 12:07:17 +0800 | [diff] [blame] | 54 | * struct spl_info - spl info for each chip |
| 55 | * |
| 56 | * @imagename: Image name(passed by "mkimage -n") |
| 57 | * @spl_hdr: Boot ROM requires a 4-bytes spl header |
| 58 | * @spl_size: Spl size(include extra 4-bytes spl header) |
Heiko Stübner | cfbcdad | 2017-02-18 19:46:27 +0100 | [diff] [blame] | 59 | * @spl_rc4: RC4 encode the SPL binary (same key as header) |
Jeffy Chen | 7bf274b | 2015-11-27 12:07:17 +0800 | [diff] [blame] | 60 | */ |
Philipp Tomsich | 111bcc4 | 2017-03-15 12:08:43 +0100 | [diff] [blame] | 61 | |
Jeffy Chen | 7bf274b | 2015-11-27 12:07:17 +0800 | [diff] [blame] | 62 | struct spl_info { |
| 63 | const char *imagename; |
| 64 | const char *spl_hdr; |
| 65 | const uint32_t spl_size; |
Heiko Stübner | cfbcdad | 2017-02-18 19:46:27 +0100 | [diff] [blame] | 66 | const bool spl_rc4; |
Jeffy Chen | 7bf274b | 2015-11-27 12:07:17 +0800 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | static struct spl_info spl_infos[] = { |
Kever Yang | c6e66b1 | 2019-07-12 11:43:34 +0200 | [diff] [blame] | 70 | { "px30", "RK33", 0x2800, false }, |
Philipp Tomsich | 95d363c | 2017-10-10 16:21:18 +0200 | [diff] [blame] | 71 | { "rk3036", "RK30", 0x1000, false }, |
| 72 | { "rk3128", "RK31", 0x1800, false }, |
| 73 | { "rk3188", "RK31", 0x8000 - 0x800, true }, |
| 74 | { "rk322x", "RK32", 0x8000 - 0x1000, false }, |
| 75 | { "rk3288", "RK32", 0x8000, false }, |
Andy Yan | 644c6be | 2019-11-14 11:22:34 +0800 | [diff] [blame] | 76 | { "rk3308", "RK33", 0x40000 - 0x1000, false}, |
Philipp Tomsich | 95d363c | 2017-10-10 16:21:18 +0200 | [diff] [blame] | 77 | { "rk3328", "RK32", 0x8000 - 0x1000, false }, |
| 78 | { "rk3368", "RK33", 0x8000 - 0x1000, false }, |
| 79 | { "rk3399", "RK33", 0x30000 - 0x2000, false }, |
| 80 | { "rv1108", "RK11", 0x1800, false }, |
Jeffy Chen | 7bf274b | 2015-11-27 12:07:17 +0800 | [diff] [blame] | 81 | }; |
| 82 | |
Simon Glass | a131c1f | 2015-08-30 16:55:24 -0600 | [diff] [blame] | 83 | static unsigned char rc4_key[16] = { |
| 84 | 124, 78, 3, 4, 85, 5, 9, 7, |
| 85 | 45, 44, 123, 56, 23, 13, 23, 17 |
| 86 | }; |
| 87 | |
Jeffy Chen | 7bf274b | 2015-11-27 12:07:17 +0800 | [diff] [blame] | 88 | static struct spl_info *rkcommon_get_spl_info(char *imagename) |
| 89 | { |
| 90 | int i; |
| 91 | |
Philipp Tomsich | 24aae93 | 2017-04-17 17:48:05 +0200 | [diff] [blame] | 92 | if (!imagename) |
| 93 | return NULL; |
| 94 | |
Jeffy Chen | 7bf274b | 2015-11-27 12:07:17 +0800 | [diff] [blame] | 95 | for (i = 0; i < ARRAY_SIZE(spl_infos); i++) |
| 96 | if (!strncmp(imagename, spl_infos[i].imagename, 6)) |
| 97 | return spl_infos + i; |
| 98 | |
| 99 | return NULL; |
| 100 | } |
| 101 | |
| 102 | int rkcommon_check_params(struct image_tool_params *params) |
| 103 | { |
| 104 | int i; |
| 105 | |
| 106 | if (rkcommon_get_spl_info(params->imagename) != NULL) |
Philipp Tomsich | 24aae93 | 2017-04-17 17:48:05 +0200 | [diff] [blame] | 107 | return EXIT_SUCCESS; |
| 108 | |
| 109 | /* |
| 110 | * If this is a operation (list or extract), the don't require |
| 111 | * imagename to be set. |
| 112 | */ |
| 113 | if (params->lflag || params->iflag) |
| 114 | return EXIT_SUCCESS; |
Jeffy Chen | 7bf274b | 2015-11-27 12:07:17 +0800 | [diff] [blame] | 115 | |
| 116 | fprintf(stderr, "ERROR: imagename (%s) is not supported!\n", |
Philipp Tomsich | 24aae93 | 2017-04-17 17:48:05 +0200 | [diff] [blame] | 117 | params->imagename ? params->imagename : "NULL"); |
Jeffy Chen | 7bf274b | 2015-11-27 12:07:17 +0800 | [diff] [blame] | 118 | |
| 119 | fprintf(stderr, "Available imagename:"); |
| 120 | for (i = 0; i < ARRAY_SIZE(spl_infos); i++) |
| 121 | fprintf(stderr, "\t%s", spl_infos[i].imagename); |
| 122 | fprintf(stderr, "\n"); |
| 123 | |
Philipp Tomsich | 24aae93 | 2017-04-17 17:48:05 +0200 | [diff] [blame] | 124 | return EXIT_FAILURE; |
Jeffy Chen | 7bf274b | 2015-11-27 12:07:17 +0800 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | const char *rkcommon_get_spl_hdr(struct image_tool_params *params) |
| 128 | { |
| 129 | struct spl_info *info = rkcommon_get_spl_info(params->imagename); |
| 130 | |
| 131 | /* |
| 132 | * info would not be NULL, because of we checked params before. |
| 133 | */ |
| 134 | return info->spl_hdr; |
| 135 | } |
| 136 | |
Philipp Tomsich | 111bcc4 | 2017-03-15 12:08:43 +0100 | [diff] [blame] | 137 | |
Jeffy Chen | 7bf274b | 2015-11-27 12:07:17 +0800 | [diff] [blame] | 138 | int rkcommon_get_spl_size(struct image_tool_params *params) |
| 139 | { |
| 140 | struct spl_info *info = rkcommon_get_spl_info(params->imagename); |
| 141 | |
| 142 | /* |
| 143 | * info would not be NULL, because of we checked params before. |
| 144 | */ |
| 145 | return info->spl_size; |
| 146 | } |
| 147 | |
Heiko Stübner | cfbcdad | 2017-02-18 19:46:27 +0100 | [diff] [blame] | 148 | bool rkcommon_need_rc4_spl(struct image_tool_params *params) |
| 149 | { |
| 150 | struct spl_info *info = rkcommon_get_spl_info(params->imagename); |
| 151 | |
| 152 | /* |
| 153 | * info would not be NULL, because of we checked params before. |
| 154 | */ |
| 155 | return info->spl_rc4; |
| 156 | } |
| 157 | |
Philipp Tomsich | 111bcc4 | 2017-03-15 12:08:43 +0100 | [diff] [blame] | 158 | static void rkcommon_set_header0(void *buf, uint file_size, |
| 159 | struct image_tool_params *params) |
Simon Glass | a131c1f | 2015-08-30 16:55:24 -0600 | [diff] [blame] | 160 | { |
Philipp Tomsich | 111bcc4 | 2017-03-15 12:08:43 +0100 | [diff] [blame] | 161 | struct header0_info *hdr = buf; |
Simon Glass | a131c1f | 2015-08-30 16:55:24 -0600 | [diff] [blame] | 162 | |
Philipp Tomsich | 111bcc4 | 2017-03-15 12:08:43 +0100 | [diff] [blame] | 163 | memset(buf, '\0', RK_INIT_OFFSET * RK_BLK_SIZE); |
Simon Glass | a131c1f | 2015-08-30 16:55:24 -0600 | [diff] [blame] | 164 | hdr->signature = RK_SIGNATURE; |
Heiko Stübner | cfbcdad | 2017-02-18 19:46:27 +0100 | [diff] [blame] | 165 | hdr->disable_rc4 = !rkcommon_need_rc4_spl(params); |
Jeffy Chen | 3641339 | 2015-11-17 14:20:30 +0800 | [diff] [blame] | 166 | hdr->init_offset = RK_INIT_OFFSET; |
Simon Glass | a131c1f | 2015-08-30 16:55:24 -0600 | [diff] [blame] | 167 | |
Philipp Tomsich | a1a2dfb | 2017-04-17 17:48:04 +0200 | [diff] [blame] | 168 | hdr->init_size = DIV_ROUND_UP(file_size, RK_BLK_SIZE); |
| 169 | /* |
| 170 | * The init_size has to be a multiple of 4 blocks (i.e. of 2K) |
| 171 | * or the BootROM will not boot the image. |
| 172 | * |
| 173 | * Note: To verify that this is not a legacy constraint, we |
| 174 | * rechecked this against the RK3399 BootROM. |
| 175 | */ |
| 176 | hdr->init_size = ROUND(hdr->init_size, 4); |
| 177 | /* |
Philipp Tomsich | a1c29d4 | 2017-05-30 23:32:10 +0200 | [diff] [blame] | 178 | * init_boot_size needs to be set, as it is read by the BootROM |
| 179 | * to determine the size of the next-stage bootloader (e.g. U-Boot |
| 180 | * proper), when used with the back-to-bootrom functionality. |
| 181 | * |
| 182 | * see https://lists.denx.de/pipermail/u-boot/2017-May/293267.html |
| 183 | * for a more detailed explanation by Andy Yan |
Philipp Tomsich | a1a2dfb | 2017-04-17 17:48:04 +0200 | [diff] [blame] | 184 | */ |
Philipp Tomsich | a1c29d4 | 2017-05-30 23:32:10 +0200 | [diff] [blame] | 185 | hdr->init_boot_size = hdr->init_size + RK_MAX_BOOT_SIZE / RK_BLK_SIZE; |
Simon Glass | a131c1f | 2015-08-30 16:55:24 -0600 | [diff] [blame] | 186 | |
| 187 | rc4_encode(buf, RK_BLK_SIZE, rc4_key); |
Philipp Tomsich | 111bcc4 | 2017-03-15 12:08:43 +0100 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | int rkcommon_set_header(void *buf, uint file_size, |
| 191 | struct image_tool_params *params) |
| 192 | { |
| 193 | struct header1_info *hdr = buf + RK_SPL_HDR_START; |
| 194 | |
| 195 | if (file_size > rkcommon_get_spl_size(params)) |
| 196 | return -ENOSPC; |
| 197 | |
| 198 | rkcommon_set_header0(buf, file_size, params); |
| 199 | |
Philipp Tomsich | 2fb371f | 2017-05-30 23:32:08 +0200 | [diff] [blame] | 200 | /* Set up the SPL name (i.e. copy spl_hdr over) */ |
Philipp Tomsich | 111bcc4 | 2017-03-15 12:08:43 +0100 | [diff] [blame] | 201 | memcpy(&hdr->magic, rkcommon_get_spl_hdr(params), RK_SPL_HDR_SIZE); |
| 202 | |
Philipp Tomsich | 111bcc4 | 2017-03-15 12:08:43 +0100 | [diff] [blame] | 203 | if (rkcommon_need_rc4_spl(params)) |
| 204 | rkcommon_rc4_encode_spl(buf, RK_SPL_HDR_START, |
| 205 | params->file_size - RK_SPL_HDR_START); |
Simon Glass | a131c1f | 2015-08-30 16:55:24 -0600 | [diff] [blame] | 206 | |
| 207 | return 0; |
| 208 | } |
Heiko Stübner | cfbcdad | 2017-02-18 19:46:27 +0100 | [diff] [blame] | 209 | |
Philipp Tomsich | 2fb371f | 2017-05-30 23:32:08 +0200 | [diff] [blame] | 210 | static inline unsigned rkcommon_offset_to_spi(unsigned offset) |
| 211 | { |
| 212 | /* |
| 213 | * While SD/MMC images use a flat addressing, SPI images are padded |
| 214 | * to use the first 2K of every 4K sector only. |
| 215 | */ |
| 216 | return ((offset & ~0x7ff) << 1) + (offset & 0x7ff); |
| 217 | } |
| 218 | |
Philipp Tomsich | 2fb371f | 2017-05-30 23:32:08 +0200 | [diff] [blame] | 219 | static int rkcommon_parse_header(const void *buf, struct header0_info *header0, |
| 220 | struct spl_info **spl_info) |
| 221 | { |
| 222 | unsigned hdr1_offset; |
| 223 | struct header1_info *hdr1_sdmmc, *hdr1_spi; |
| 224 | int i; |
| 225 | |
| 226 | if (spl_info) |
| 227 | *spl_info = NULL; |
| 228 | |
| 229 | /* |
| 230 | * The first header (hdr0) is always RC4 encoded, so try to decrypt |
| 231 | * with the well-known key. |
| 232 | */ |
| 233 | memcpy((void *)header0, buf, sizeof(struct header0_info)); |
| 234 | rc4_encode((void *)header0, sizeof(struct header0_info), rc4_key); |
| 235 | |
| 236 | if (header0->signature != RK_SIGNATURE) |
| 237 | return -EPROTO; |
| 238 | |
| 239 | /* We don't support RC4 encoded image payloads here, yet... */ |
| 240 | if (header0->disable_rc4 == 0) |
| 241 | return -ENOSYS; |
| 242 | |
| 243 | hdr1_offset = header0->init_offset * RK_BLK_SIZE; |
| 244 | hdr1_sdmmc = (struct header1_info *)(buf + hdr1_offset); |
| 245 | hdr1_spi = (struct header1_info *)(buf + |
| 246 | rkcommon_offset_to_spi(hdr1_offset)); |
| 247 | |
| 248 | for (i = 0; i < ARRAY_SIZE(spl_infos); i++) { |
| 249 | if (!memcmp(&hdr1_sdmmc->magic, spl_infos[i].spl_hdr, 4)) { |
| 250 | if (spl_info) |
| 251 | *spl_info = &spl_infos[i]; |
| 252 | return IH_TYPE_RKSD; |
| 253 | } else if (!memcmp(&hdr1_spi->magic, spl_infos[i].spl_hdr, 4)) { |
| 254 | if (spl_info) |
| 255 | *spl_info = &spl_infos[i]; |
| 256 | return IH_TYPE_RKSPI; |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | return -1; |
| 261 | } |
| 262 | |
| 263 | int rkcommon_verify_header(unsigned char *buf, int size, |
| 264 | struct image_tool_params *params) |
| 265 | { |
| 266 | struct header0_info header0; |
| 267 | struct spl_info *img_spl_info, *spl_info; |
| 268 | int ret; |
| 269 | |
| 270 | ret = rkcommon_parse_header(buf, &header0, &img_spl_info); |
| 271 | |
| 272 | /* If this is the (unimplemented) RC4 case, then rewrite the result */ |
| 273 | if (ret == -ENOSYS) |
| 274 | return 0; |
| 275 | |
| 276 | if (ret < 0) |
| 277 | return ret; |
| 278 | |
| 279 | /* |
| 280 | * If no 'imagename' is specified via the commandline (e.g. if this is |
| 281 | * 'dumpimage -l' w/o any further constraints), we accept any spl_info. |
| 282 | */ |
| 283 | if (params->imagename == NULL) |
| 284 | return 0; |
| 285 | |
| 286 | /* Match the 'imagename' against the 'spl_hdr' found */ |
| 287 | spl_info = rkcommon_get_spl_info(params->imagename); |
| 288 | if (spl_info && img_spl_info) |
| 289 | return strcmp(spl_info->spl_hdr, img_spl_info->spl_hdr); |
| 290 | |
| 291 | return -ENOENT; |
| 292 | } |
| 293 | |
| 294 | void rkcommon_print_header(const void *buf) |
| 295 | { |
| 296 | struct header0_info header0; |
| 297 | struct spl_info *spl_info; |
| 298 | uint8_t image_type; |
| 299 | int ret; |
| 300 | |
| 301 | ret = rkcommon_parse_header(buf, &header0, &spl_info); |
| 302 | |
| 303 | /* If this is the (unimplemented) RC4 case, then fail silently */ |
| 304 | if (ret == -ENOSYS) |
| 305 | return; |
| 306 | |
| 307 | if (ret < 0) { |
| 308 | fprintf(stderr, "Error: image verification failed\n"); |
| 309 | return; |
| 310 | } |
| 311 | |
| 312 | image_type = ret; |
| 313 | |
| 314 | printf("Image Type: Rockchip %s (%s) boot image\n", |
| 315 | spl_info->spl_hdr, |
| 316 | (image_type == IH_TYPE_RKSD) ? "SD/MMC" : "SPI"); |
| 317 | printf("Data Size: %d bytes\n", header0.init_size * RK_BLK_SIZE); |
| 318 | } |
| 319 | |
Heiko Stübner | cfbcdad | 2017-02-18 19:46:27 +0100 | [diff] [blame] | 320 | void rkcommon_rc4_encode_spl(void *buf, unsigned int offset, unsigned int size) |
| 321 | { |
| 322 | unsigned int remaining = size; |
| 323 | |
| 324 | while (remaining > 0) { |
| 325 | int step = (remaining > RK_BLK_SIZE) ? RK_BLK_SIZE : remaining; |
| 326 | |
| 327 | rc4_encode(buf + offset, step, rc4_key); |
| 328 | offset += RK_BLK_SIZE; |
| 329 | remaining -= step; |
| 330 | } |
| 331 | } |
Philipp Tomsich | 111bcc4 | 2017-03-15 12:08:43 +0100 | [diff] [blame] | 332 | |
Philipp Tomsich | 366aad4 | 2017-04-17 17:48:01 +0200 | [diff] [blame] | 333 | int rkcommon_vrec_header(struct image_tool_params *params, |
| 334 | struct image_type_params *tparams, |
| 335 | unsigned int alignment) |
Philipp Tomsich | 111bcc4 | 2017-03-15 12:08:43 +0100 | [diff] [blame] | 336 | { |
Philipp Tomsich | 366aad4 | 2017-04-17 17:48:01 +0200 | [diff] [blame] | 337 | unsigned int unpadded_size; |
| 338 | unsigned int padded_size; |
| 339 | |
Philipp Tomsich | 111bcc4 | 2017-03-15 12:08:43 +0100 | [diff] [blame] | 340 | /* |
| 341 | * The SPL image looks as follows: |
| 342 | * |
| 343 | * 0x0 header0 (see rkcommon.c) |
| 344 | * 0x800 spl_name ('RK30', ..., 'RK33') |
Philipp Tomsich | ea3729e | 2017-04-17 17:48:02 +0200 | [diff] [blame] | 345 | * (start of the payload for AArch64 payloads: we expect the |
| 346 | * first 4 bytes to be available for overwriting with our |
| 347 | * spl_name) |
Philipp Tomsich | 111bcc4 | 2017-03-15 12:08:43 +0100 | [diff] [blame] | 348 | * 0x804 first instruction to be executed |
Philipp Tomsich | ea3729e | 2017-04-17 17:48:02 +0200 | [diff] [blame] | 349 | * (start of the image/payload for 32bit payloads) |
Philipp Tomsich | 111bcc4 | 2017-03-15 12:08:43 +0100 | [diff] [blame] | 350 | * |
Philipp Tomsich | ea3729e | 2017-04-17 17:48:02 +0200 | [diff] [blame] | 351 | * For AArch64 (ARMv8) payloads, natural alignment (8-bytes) is |
| 352 | * required for its sections (so the image we receive needs to |
| 353 | * have the first 4 bytes reserved for the spl_name). Reserving |
| 354 | * these 4 bytes is done using the BOOT0_HOOK infrastructure. |
Philipp Tomsich | 111bcc4 | 2017-03-15 12:08:43 +0100 | [diff] [blame] | 355 | * |
Philipp Tomsich | 95d363c | 2017-10-10 16:21:18 +0200 | [diff] [blame] | 356 | * The header is always at 0x800 (as we now use a payload |
| 357 | * prepadded using the boot0 hook for all targets): the first |
| 358 | * 4 bytes of these images can safely be overwritten using the |
| 359 | * boot magic. |
Philipp Tomsich | 111bcc4 | 2017-03-15 12:08:43 +0100 | [diff] [blame] | 360 | */ |
Philipp Tomsich | 95d363c | 2017-10-10 16:21:18 +0200 | [diff] [blame] | 361 | tparams->header_size = RK_SPL_HDR_START; |
Philipp Tomsich | 111bcc4 | 2017-03-15 12:08:43 +0100 | [diff] [blame] | 362 | |
| 363 | /* Allocate, clear and install the header */ |
| 364 | tparams->hdr = malloc(tparams->header_size); |
Simon Glass | 22929be | 2017-06-07 10:28:47 -0600 | [diff] [blame] | 365 | if (!tparams->hdr) |
| 366 | return -ENOMEM; |
Philipp Tomsich | 111bcc4 | 2017-03-15 12:08:43 +0100 | [diff] [blame] | 367 | memset(tparams->hdr, 0, tparams->header_size); |
Philipp Tomsich | 366aad4 | 2017-04-17 17:48:01 +0200 | [diff] [blame] | 368 | |
| 369 | /* |
| 370 | * If someone passed in 0 for the alignment, we'd better handle |
| 371 | * it correctly... |
| 372 | */ |
| 373 | if (!alignment) |
| 374 | alignment = 1; |
| 375 | |
| 376 | unpadded_size = tparams->header_size + params->file_size; |
| 377 | padded_size = ROUND(unpadded_size, alignment); |
| 378 | |
| 379 | return padded_size - unpadded_size; |
Philipp Tomsich | 111bcc4 | 2017-03-15 12:08:43 +0100 | [diff] [blame] | 380 | } |