summaryrefslogtreecommitdiff
path: root/rbutil/mkimxboot/mkimxboot.c
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/mkimxboot/mkimxboot.c')
-rw-r--r--rbutil/mkimxboot/mkimxboot.c101
1 files changed, 99 insertions, 2 deletions
diff --git a/rbutil/mkimxboot/mkimxboot.c b/rbutil/mkimxboot/mkimxboot.c
index 436b3ebff4..909dad8641 100644
--- a/rbutil/mkimxboot/mkimxboot.c
+++ b/rbutil/mkimxboot/mkimxboot.c
@@ -597,8 +597,77 @@ static enum imx_error_t compute_md5sum_buf(void *buf, size_t sz, uint8_t file_md
597 return IMX_SUCCESS; 597 return IMX_SUCCESS;
598} 598}
599 599
600/* compute MD5 sum of a buffer */
601static enum imx_error_t compute_soft_md5sum_buf(struct sb_file_t *sb, uint8_t file_md5sum[16])
602{
603 md5_context ctx;
604 md5_starts(&ctx);
605#define hash(obj) \
606 md5_update(&ctx, (void *)&obj, sizeof(obj))
607 /* various header fiels */
608 hash(sb->timestamp);
609 hash(sb->drive_tag);
610 hash(sb->drive_tag);
611 hash(sb->first_boot_sec_id);
612 hash(sb->flags);
613 hash(sb->product_ver);
614 hash(sb->component_ver);
615
616 for(int i = 0; i < sb->nr_sections; i++)
617 {
618 struct sb_section_t *sec = &sb->sections[i];
619 hash(sec->identifier);
620 uint32_t flags = sec->other_flags;
621 if(!sec->is_data)
622 flags |= SECTION_BOOTABLE;
623 if(sec->is_cleartext)
624 flags |= SECTION_CLEARTEXT;
625 hash(flags);
626
627 for(int j = 0; j < sec->nr_insts; j++)
628 {
629 struct sb_inst_t *inst = &sec->insts[j];
630 switch(inst->inst)
631 {
632 case SB_INST_NOP:
633 /* ignore them totally because they are used for padding */
634 break;
635 case SB_INST_LOAD:
636 hash(inst->inst);
637 hash(inst->addr);
638 md5_update(&ctx, inst->data, inst->size);
639 break;
640 case SB_INST_FILL:
641 hash(inst->inst);
642 hash(inst->addr);
643 hash(inst->pattern);
644 break;
645 case SB_INST_JUMP:
646 case SB_INST_CALL:
647 hash(inst->inst);
648 hash(inst->addr);
649 hash(inst->argument);
650 break;
651 case SB_INST_MODE:
652 hash(inst->inst);
653 hash(inst->argument);
654 break;
655 case SB_INST_DATA:
656 md5_update(&ctx, inst->data, inst->size);
657 break;
658 default:
659 printf("[ERR][INTERNAL] Unexpected instruction %d\n", inst->inst);
660 return IMX_ERROR;
661 }
662 }
663 }
664#undef hash
665 md5_finish(&ctx, file_md5sum);
666 return IMX_SUCCESS;
667}
668
600/* compute MD5 of a file */ 669/* compute MD5 of a file */
601static enum imx_error_t compute_md5sum(const char *file, uint8_t file_md5sum[16]) 670enum imx_error_t compute_md5sum(const char *file, uint8_t file_md5sum[16])
602{ 671{
603 void *buf; 672 void *buf;
604 size_t sz; 673 size_t sz;
@@ -610,6 +679,32 @@ static enum imx_error_t compute_md5sum(const char *file, uint8_t file_md5sum[16]
610 return IMX_SUCCESS; 679 return IMX_SUCCESS;
611} 680}
612 681
682/* compute soft MD5 of a file */
683enum imx_error_t compute_soft_md5sum(const char *file, enum imx_model_t model,
684 uint8_t soft_md5sum[16])
685{
686 if(model == MODEL_UNKNOWN)
687 {
688 printf("[ERR] Cannot compute soft MD5 without knowing the model\n");
689 return IMX_ERROR;
690 }
691 clear_keys();
692 add_keys(imx_models[model].keys, imx_models[model].nr_keys);
693 /* read file */
694 enum sb_error_t err;
695 struct sb_file_t *sb = sb_read_file(file, false, NULL, generic_std_printf, &err);
696 if(sb == NULL)
697 {
698 printf("[ERR] Cannot load SB file: %d\n", err);
699 return err;
700 }
701 /* compute sum */
702 err = compute_soft_md5sum_buf(sb, soft_md5sum);
703 /* release file */
704 sb_free(sb);
705 return err;
706}
707
613static enum imx_error_t load_sb_file(const char *file, int md5_idx, 708static enum imx_error_t load_sb_file(const char *file, int md5_idx,
614 struct imx_option_t opt, struct sb_file_t **sb_file) 709 struct imx_option_t opt, struct sb_file_t **sb_file)
615{ 710{
@@ -792,7 +887,9 @@ enum imx_error_t mkimxboot(const char *infile, const char *bootfile,
792 if(ret != IMX_SUCCESS) 887 if(ret != IMX_SUCCESS)
793 return ret; 888 return ret;
794 printf("[INFO] MD5 sum of the file: "); 889 printf("[INFO] MD5 sum of the file: ");
795 print_hex(NULL, misc_std_printf, file_md5sum, 16, true); 890 for(int i = 0; i < 16; i++)
891 printf("%02x", file_md5sum[i]);
892 printf("\n");
796 /* find model */ 893 /* find model */
797 int md5_idx; 894 int md5_idx;
798 ret = find_model_by_md5sum(file_md5sum, &md5_idx); 895 ret = find_model_by_md5sum(file_md5sum, &md5_idx);