Lines Matching +full:- +full:e

4  * SPDX-License-Identifier:     GPL-2.0+
12 #include <u-boot/sha256.h>
22 #define TFTPUD_E(fmt, args...) printf("[TFTPUD-ERROR]: "fmt, ##args)
80 if (ret == -EINVAL) { in tftpfw_version_get()
109 struct image_element *e; in update_cleanup() local
112 list_for_each(node, &hdr->images) { in update_cleanup()
113 e = list_entry(node, struct image_element, node); in update_cleanup()
114 free(e); in update_cleanup()
117 if (hdr->shared_buf) in update_cleanup()
118 free(hdr->shared_buf); in update_cleanup()
134 struct image_element *e; in update_populate_image() local
150 return -ENODEV; in update_populate_image()
159 e = malloc(sizeof(*e)); in update_populate_image()
160 if (!e) in update_populate_image()
161 return -ENOMEM; in update_populate_image()
163 e->remain_tries = MAX_REMAIN_TRIES; in update_populate_image()
164 e->buf = hdr->shared_buf; in update_populate_image()
165 e->size = fdtdec_get_uint(fit, noffset, "data-size", -ENODATA); in update_populate_image()
166 if (e->size == -ENODATA) in update_populate_image()
167 return -ENODATA; in update_populate_image()
170 strcpy(e->file_name, name); in update_populate_image()
171 strcat(e->file_name, ".part.img"); in update_populate_image()
172 noseq_name = strstr(name, "-"); in update_populate_image()
174 return -EINVAL; in update_populate_image()
176 dp = strstr(noseq_name, "-"); in update_populate_image()
178 return -EINVAL; in update_populate_image()
180 strlcpy(e->part_name, noseq_name, strlen(noseq_name) - strlen(dp)); in update_populate_image()
181 ret = part_get_info_by_name_strict(dev_desc, e->part_name, &part); in update_populate_image()
183 TFTPUD_E("No partition '%s'\n", e->part_name); in update_populate_image()
184 return -EINVAL; in update_populate_image()
188 if (!strcmp(last_part_name, e->part_name)) in update_populate_image()
189 lba_offset = last_lba_offset + hdr->lba_step; in update_populate_image()
193 e->lba_start = part.start; in update_populate_image()
194 e->lba_offset = lba_offset; in update_populate_image()
195 e->lba_cnt = DIV_ROUND_UP(e->size, 512); in update_populate_image()
196 e->hash_noffset = fdt_subnode_offset(fit, noffset, "hash"); in update_populate_image()
197 if (e->hash_noffset < 0) in update_populate_image()
198 return e->hash_noffset; in update_populate_image()
200 list_add_tail(&e->node, &hdr->images); in update_populate_image()
201 last_part_name = e->part_name; in update_populate_image()
204 printf(" file: %s\n", e->file_name); in update_populate_image()
205 printf(" partition: %s\n", e->part_name); in update_populate_image()
206 printf(" buf: 0x%08lx\n", (ulong)e->buf); in update_populate_image()
207 printf(" size: 0x%08x\n", e->size); in update_populate_image()
208 printf(" lba_start: 0x%08x\n", e->lba_start); in update_populate_image()
209 printf(" lba_offset: 0x%08x\n", e->lba_offset); in update_populate_image()
210 printf(" lba_cnt: 0x%08x\n", e->lba_cnt); in update_populate_image()
211 printf(" remain_tries: %d\n", e->remain_tries); in update_populate_image()
212 printf(" hash_noffset: 0x%08x\n\n", e->hash_noffset); in update_populate_image()
256 ret = memcmp(hash, csum, SHA256_HASH_SIZE) ? -EINVAL : 0; in hdr_checksum_verify()
277 printf(" version: %d\n", hdr->version); in print_hdr_local()
278 printf(" rollback_idx: %d\n", hdr->rollback_idx); in print_hdr_local()
279 printf(" force_update: %d\n", hdr->force_update); in print_hdr_local()
280 printf(" MB: %d\n", hdr->mb); in print_hdr_local()
281 printf(" lba_step: 0x%08x\n", hdr->lba_step); in print_hdr_local()
282 printf(" shared_buf: 0x%08lx - 0x%08lx\n", in print_hdr_local()
283 (ulong)hdr->shared_buf, (ulong)hdr->shared_buf + hdr->mb * SZ_1M); in print_hdr_local()
284 printf(" spec_partition: %s\n\n", hdr->spec_partition); in print_hdr_local()
287 printf(" version: %d\n", local->version); in print_hdr_local()
288 printf(" rollback_idx: %d\n", local->rollback_idx); in print_hdr_local()
289 printf(" current_slot: %s\n", local->current_slot); in print_hdr_local()
300 hdr->version = fdtdec_get_uint(fit, 0, "version", 0); in hdr_param_verify()
301 hdr->rollback_idx = fdtdec_get_uint(fit, conf, "rollback-index", 0); in hdr_param_verify()
302 hdr->force_update = fdtdec_get_uint(fit, conf, "force_update", 0); in hdr_param_verify()
303 hdr->mb = fdtdec_get_uint(fit, conf, "image-size-MB", 0); in hdr_param_verify()
304 size = hdr->mb * SZ_1M; in hdr_param_verify()
305 hdr->lba_step = size / 512; in hdr_param_verify()
307 hdr->shared_buf = malloc(size); in hdr_param_verify()
308 if (!hdr->shared_buf) in hdr_param_verify()
309 return -ENOMEM; in hdr_param_verify()
315 return local->version; in hdr_param_verify()
317 local->version = ret; in hdr_param_verify()
322 &remote_rollback_idx, &local->rollback_idx); in hdr_param_verify()
324 TFTPUD_E("Failed to get local rollback-index, ret=%d\n", ret); in hdr_param_verify()
328 local->rollback_idx = -1; in hdr_param_verify()
331 ret = rk_avb_get_current_slot(local->current_slot); in hdr_param_verify()
337 strcpy(local->current_slot, "-"); in hdr_param_verify()
343 if (hdr->force_update) { in hdr_param_verify()
347 if (hdr->version < local->version) { in hdr_param_verify()
349 hdr->version, local->version); in hdr_param_verify()
350 return -EINVAL; in hdr_param_verify()
353 if (remote_rollback_idx < local->rollback_idx) { in hdr_param_verify()
354 TFTPUD_E("Invalid rollback-index: %d(remote) < %d(local)\n", in hdr_param_verify()
355 remote_rollback_idx, local->rollback_idx); in hdr_param_verify()
356 return -EINVAL; in hdr_param_verify()
385 /* Non-secure: verify hash */ in update_verify_hdr()
408 ret = tftpfw_version_set(hdr->version); in update_local_info()
413 printf("fw_version=%d ", hdr->version); in update_local_info()
416 ret = fit_write_trusty_rollback_index(hdr->rollback_idx); in update_local_info()
419 printf("rollback_idx=%d ", hdr->rollback_idx); in update_local_info()
427 struct image_element *e) in update_ignore_image() argument
433 slot_suffix = (char *)e->part_name + strlen(e->part_name) - 2; in update_ignore_image()
434 if (!strcmp(hdr->current_slot, slot_suffix)) in update_ignore_image()
438 if (hdr->spec_partition && strcmp(e->part_name, hdr->spec_partition)) in update_ignore_image()
444 static int download_image(void *fit, struct image_element *e) in download_image() argument
452 printf("[TFTPUD-0]: download \"%s\" at 0x%lx\n", in download_image()
453 e->file_name, (ulong)e->buf); in download_image()
455 ret = tftp_download(e->buf, e->file_name); in download_image()
463 return -ENOENT; in download_image()
466 if (filesize != e->size) { in download_image()
467 TFTPUD_E("Expected filesize 0x%08lx != 0x%08x\n", filesize, e->size); in download_image()
468 return -EINVAL; in download_image()
472 printf("[TFTPUD-1]: verify "); in download_image()
473 ret = fit_image_check_hash(fit, e->hash_noffset, e->buf, e->size, &msg); in download_image()
474 printf("[%s]\n", ret ? "-" : "+"); in download_image()
479 static int update_flash_image(struct image_element *e) in update_flash_image() argument
487 return -ENODEV; in update_flash_image()
490 printf("[TFTPUD-2]: Flash to \"%s\" partition at LBA offset 0x%08x, " in update_flash_image()
492 e->part_name, e->lba_offset, e->lba_cnt); in update_flash_image()
494 if (dev_desc->if_type == IF_TYPE_MTD) { in update_flash_image()
495 dev_desc->op_flag |= BLK_MTD_CONT_WRITE; in update_flash_image()
496 ret = blk_dwrite(dev_desc, e->lba_start + e->lba_offset, in update_flash_image()
497 e->lba_cnt, (void *)e->buf); in update_flash_image()
498 dev_desc->op_flag &= ~(BLK_MTD_CONT_WRITE); in update_flash_image()
500 ret = blk_dwrite(dev_desc, e->lba_start + e->lba_offset, in update_flash_image()
501 e->lba_cnt, (void *)e->buf); in update_flash_image()
504 if (ret != e->lba_cnt) in update_flash_image()
512 static int update_download_image(void *fit, struct image_element *e) in update_download_image() argument
516 for (i = 0; i < e->remain_tries; i++) { in update_download_image()
517 ret = download_image(fit, e); in update_download_image()
521 TFTPUD_E("retry-%d download\n", i); in update_download_image()
525 return -ENODATA; in update_download_image()
530 struct image_element *e; in update_write_gpt() local
550 e = malloc(sizeof(*e)); in update_write_gpt()
551 if (!e) in update_write_gpt()
552 return -ENOMEM; in update_write_gpt()
554 e->remain_tries = MAX_REMAIN_TRIES; in update_write_gpt()
555 e->buf = hdr->shared_buf; in update_write_gpt()
556 e->size = fdtdec_get_uint(fit, noffset, "data-size", -ENODATA); in update_write_gpt()
557 if (e->size == -ENODATA) { in update_write_gpt()
558 ret = -EINVAL; in update_write_gpt()
562 strcpy(e->file_name, name); in update_write_gpt()
563 e->hash_noffset = fdt_subnode_offset(fit, noffset, "hash"); in update_write_gpt()
564 if (e->hash_noffset < 0) in update_write_gpt()
565 return e->hash_noffset; in update_write_gpt()
567 printf("\n# %s:\n", e->file_name); in update_write_gpt()
568 printf(" buf: 0x%08lx\n", (ulong)e->buf); in update_write_gpt()
569 printf(" size: 0x%08x\n", e->size); in update_write_gpt()
570 printf(" remain_tries: %d\n", e->remain_tries); in update_write_gpt()
571 printf(" hash_noffset: 0x%08x\n\n", e->hash_noffset); in update_write_gpt()
574 ret = update_download_image(fit, e); in update_write_gpt()
577 e->file_name, ret); in update_write_gpt()
582 gpt_parts = (char *)e->buf; in update_write_gpt()
583 p = gpt_parts + e->size - 1; in update_write_gpt()
587 printf("[TFTPUD-2]: Write gpt ...\n"); in update_write_gpt()
593 ret = -EIO; in update_write_gpt()
599 ret = -EIO; in update_write_gpt()
604 free(e); in update_write_gpt()
614 struct image_element *e; in do_tftp_full_update() local
642 dup_str[part_str - dir_part_str] = 0; in do_tftp_full_update()
658 hdr->spec_partition = part_str; in do_tftp_full_update()
659 INIT_LIST_HEAD(&hdr->images); in do_tftp_full_update()
664 ret = -EINVAL; in do_tftp_full_update()
687 list_for_each(node, &hdr->images) { in do_tftp_full_update()
688 e = list_entry(node, struct image_element, node); in do_tftp_full_update()
692 if (update_ignore_image(fit, hdr, e)) in do_tftp_full_update()
695 ret = update_download_image(fit, e); in do_tftp_full_update()
698 e->file_name, ret); in do_tftp_full_update()
702 ret = update_flash_image(e); in do_tftp_full_update()
705 e->file_name, ret); in do_tftp_full_update()
713 if (hdr->spec_partition) { in do_tftp_full_update()
714 TFTPUD_E("No %s partition was found\n", hdr->spec_partition); in do_tftp_full_update()
721 if (!hdr->spec_partition) in do_tftp_full_update()
738 "[[server-dir:][partition]"