Commit 68af10022442153f6f87958053fee030ad1cb57f
1 parent
b215fbd868
Exists in
v2017.01-smarct4x
and in
25 other branches
binman: Drop microcode features from ifdtool
Now that binman supports creating images with microcode, drop the code from ifdtool. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Tested-by: Bin Meng <bmeng.cn@gmail.com>
Showing 1 changed file with 5 additions and 249 deletions Side-by-side Diff
tools/ifdtool.c
... | ... | @@ -33,16 +33,9 @@ |
33 | 33 | #define FLREG_BASE(reg) ((reg & 0x00000fff) << 12); |
34 | 34 | #define FLREG_LIMIT(reg) (((reg & 0x0fff0000) >> 4) | 0xfff); |
35 | 35 | |
36 | -enum input_file_type_t { | |
37 | - IF_normal, | |
38 | - IF_fdt, | |
39 | - IF_uboot, | |
40 | -}; | |
41 | - | |
42 | 36 | struct input_file { |
43 | 37 | char *fname; |
44 | 38 | unsigned int addr; |
45 | - enum input_file_type_t type; | |
46 | 39 | }; |
47 | 40 | |
48 | 41 | /** |
... | ... | @@ -760,219 +753,6 @@ |
760 | 753 | return write_size; |
761 | 754 | } |
762 | 755 | |
763 | -static int scan_ucode(const void *blob, char *ucode_base, int *countp, | |
764 | - const char **datap, int *data_sizep) | |
765 | -{ | |
766 | - const char *data = NULL; | |
767 | - int node, count; | |
768 | - int data_size; | |
769 | - char *ucode; | |
770 | - | |
771 | - for (node = 0, count = 0, ucode = ucode_base; node >= 0; count++) { | |
772 | - node = fdt_node_offset_by_compatible(blob, node, | |
773 | - "intel,microcode"); | |
774 | - if (node < 0) | |
775 | - break; | |
776 | - | |
777 | - data = fdt_getprop(blob, node, "data", &data_size); | |
778 | - if (!data) { | |
779 | - debug("Missing microcode data in FDT '%s': %s\n", | |
780 | - fdt_get_name(blob, node, NULL), | |
781 | - fdt_strerror(data_size)); | |
782 | - return -ENOENT; | |
783 | - } | |
784 | - | |
785 | - if (ucode_base) | |
786 | - memcpy(ucode, data, data_size); | |
787 | - ucode += data_size; | |
788 | - } | |
789 | - | |
790 | - if (countp) | |
791 | - *countp = count; | |
792 | - if (datap) | |
793 | - *datap = data; | |
794 | - if (data_sizep) | |
795 | - *data_sizep = data_size; | |
796 | - | |
797 | - return ucode - ucode_base; | |
798 | -} | |
799 | - | |
800 | -static int remove_ucode(char *blob) | |
801 | -{ | |
802 | - int node, count; | |
803 | - int ret; | |
804 | - | |
805 | - /* Keep going until we find no more microcode to remove */ | |
806 | - do { | |
807 | - for (node = 0, count = 0; node >= 0;) { | |
808 | - int ret; | |
809 | - | |
810 | - node = fdt_node_offset_by_compatible(blob, node, | |
811 | - "intel,microcode"); | |
812 | - if (node < 0) | |
813 | - break; | |
814 | - | |
815 | - ret = fdt_delprop(blob, node, "data"); | |
816 | - | |
817 | - /* | |
818 | - * -FDT_ERR_NOTFOUND means we already removed the | |
819 | - * data for this one, so we just continue. | |
820 | - * 0 means we did remove it, so offsets may have | |
821 | - * changed and we need to restart our scan. | |
822 | - * Anything else indicates an error we should report. | |
823 | - */ | |
824 | - if (ret == -FDT_ERR_NOTFOUND) | |
825 | - continue; | |
826 | - else if (!ret) | |
827 | - node = 0; | |
828 | - else | |
829 | - return ret; | |
830 | - } | |
831 | - } while (count); | |
832 | - | |
833 | - /* Pack down to remove excees space */ | |
834 | - ret = fdt_pack(blob); | |
835 | - if (ret) | |
836 | - return ret; | |
837 | - | |
838 | - return fdt_totalsize(blob); | |
839 | -} | |
840 | - | |
841 | -static int write_ucode(char *image, int size, struct input_file *fdt, | |
842 | - int fdt_size, unsigned int ucode_ptr, | |
843 | - int collate_ucode) | |
844 | -{ | |
845 | - const char *data = NULL; | |
846 | - char *ucode_buf; | |
847 | - const void *blob; | |
848 | - char *ucode_base; | |
849 | - uint32_t *ptr; | |
850 | - int ucode_size; | |
851 | - int data_size; | |
852 | - int offset; | |
853 | - int count; | |
854 | - int ret; | |
855 | - | |
856 | - blob = (void *)image + (uint32_t)(fdt->addr + size); | |
857 | - | |
858 | - debug("DTB at %lx\n", (char *)blob - image); | |
859 | - | |
860 | - /* Find out about the micrcode we have */ | |
861 | - ucode_size = scan_ucode(blob, NULL, &count, &data, &data_size); | |
862 | - if (ucode_size < 0) | |
863 | - return ucode_size; | |
864 | - if (!count) { | |
865 | - debug("No microcode found in FDT\n"); | |
866 | - return -ENOENT; | |
867 | - } | |
868 | - | |
869 | - if (count > 1 && !collate_ucode) { | |
870 | - fprintf(stderr, | |
871 | - "Cannot handle multiple microcode blocks - please use -C flag to collate them\n"); | |
872 | - return -EMLINK; | |
873 | - } | |
874 | - | |
875 | - /* | |
876 | - * Collect the microcode into a buffer, remove it from the device | |
877 | - * tree and place it immediately above the (now smaller) device tree. | |
878 | - */ | |
879 | - if (collate_ucode && count > 1) { | |
880 | - ucode_buf = malloc(ucode_size); | |
881 | - if (!ucode_buf) { | |
882 | - fprintf(stderr, | |
883 | - "Out of memory for microcode (%d bytes)\n", | |
884 | - ucode_size); | |
885 | - return -ENOMEM; | |
886 | - } | |
887 | - ret = scan_ucode(blob, ucode_buf, NULL, NULL, NULL); | |
888 | - if (ret < 0) | |
889 | - return ret; | |
890 | - | |
891 | - /* Remove the microcode from the device tree */ | |
892 | - ret = remove_ucode((char *)blob); | |
893 | - if (ret < 0) { | |
894 | - debug("Could not remove FDT microcode: %s\n", | |
895 | - fdt_strerror(ret)); | |
896 | - return -EINVAL; | |
897 | - } | |
898 | - debug("Collated %d microcode block(s)\n", count); | |
899 | - debug("Device tree reduced from %x to %x bytes\n", | |
900 | - fdt_size, ret); | |
901 | - fdt_size = ret; | |
902 | - | |
903 | - /* | |
904 | - * Place microcode area immediately above the FDT, aligned | |
905 | - * to a 16-byte boundary. | |
906 | - */ | |
907 | - ucode_base = (char *)(((unsigned long)blob + fdt_size + 15) & | |
908 | - ~15); | |
909 | - | |
910 | - data = ucode_base; | |
911 | - data_size = ucode_size; | |
912 | - memcpy(ucode_base, ucode_buf, ucode_size); | |
913 | - free(ucode_buf); | |
914 | - } | |
915 | - | |
916 | - offset = (uint32_t)(ucode_ptr + size); | |
917 | - ptr = (void *)image + offset; | |
918 | - | |
919 | - ptr[0] = (data - image) - size; | |
920 | - ptr[1] = data_size; | |
921 | - debug("Wrote microcode pointer at %x: addr=%x, size=%x\n", ucode_ptr, | |
922 | - ptr[0], ptr[1]); | |
923 | - | |
924 | - return (collate_ucode ? data + data_size : (char *)blob + fdt_size) - | |
925 | - image; | |
926 | -} | |
927 | - | |
928 | -/** | |
929 | - * write_uboot() - Write U-Boot, device tree and microcode pointer | |
930 | - * | |
931 | - * This writes U-Boot into a place in the flash, followed by its device tree. | |
932 | - * The microcode pointer is written so that U-Boot can find the microcode in | |
933 | - * the device tree very early in boot. | |
934 | - * | |
935 | - * @image: Pointer to image | |
936 | - * @size: Size of image in bytes | |
937 | - * @uboot: Input file information for u-boot.bin | |
938 | - * @fdt: Input file information for u-boot.dtb | |
939 | - * @ucode_ptr: Address in U-Boot where the microcode pointer should be placed | |
940 | - * @return 0 if OK, -ve on error | |
941 | - */ | |
942 | -static int write_uboot(char *image, int size, struct input_file *uboot, | |
943 | - struct input_file *fdt, unsigned int ucode_ptr, | |
944 | - int collate_ucode, int *offset_uboot_top, | |
945 | - int *offset_uboot_start) | |
946 | -{ | |
947 | - int uboot_size, fdt_size; | |
948 | - int uboot_top; | |
949 | - | |
950 | - uboot_size = write_data(image, size, uboot->addr, uboot->fname, 0, 0); | |
951 | - if (uboot_size < 0) | |
952 | - return uboot_size; | |
953 | - fdt->addr = uboot->addr + uboot_size; | |
954 | - debug("U-Boot size %#x, FDT at %#x\n", uboot_size, fdt->addr); | |
955 | - fdt_size = write_data(image, size, fdt->addr, fdt->fname, 0, 0); | |
956 | - if (fdt_size < 0) | |
957 | - return fdt_size; | |
958 | - | |
959 | - uboot_top = (uint32_t)(fdt->addr + size) + fdt_size; | |
960 | - | |
961 | - if (ucode_ptr) { | |
962 | - uboot_top = write_ucode(image, size, fdt, fdt_size, ucode_ptr, | |
963 | - collate_ucode); | |
964 | - if (uboot_top < 0) | |
965 | - return uboot_top; | |
966 | - } | |
967 | - | |
968 | - if (offset_uboot_top && offset_uboot_start) { | |
969 | - *offset_uboot_top = uboot_top; | |
970 | - *offset_uboot_start = (uint32_t)(uboot->addr + size); | |
971 | - } | |
972 | - | |
973 | - return 0; | |
974 | -} | |
975 | - | |
976 | 756 | static void print_version(void) |
977 | 757 | { |
978 | 758 | printf("ifdtool v%s -- ", IFDTOOL_VERSION); |
... | ... | @@ -1034,7 +814,7 @@ |
1034 | 814 | int mode_dump = 0, mode_extract = 0, mode_inject = 0; |
1035 | 815 | int mode_spifreq = 0, mode_em100 = 0, mode_locked = 0; |
1036 | 816 | int mode_unlocked = 0, mode_write = 0, mode_write_descriptor = 0; |
1037 | - int create = 0, collate_ucode = 0; | |
817 | + int create = 0; | |
1038 | 818 | char *region_type_string = NULL, *inject_fname = NULL; |
1039 | 819 | char *desc_fname = NULL, *addr_str = NULL; |
1040 | 820 | int region_type = -1, inputfreq = 0; |
1041 | 821 | |
... | ... | @@ -1047,14 +827,12 @@ |
1047 | 827 | char *outfile = NULL; |
1048 | 828 | struct stat buf; |
1049 | 829 | int size = 0; |
1050 | - unsigned int ucode_ptr = 0; | |
1051 | 830 | bool have_uboot = false; |
1052 | 831 | int bios_fd; |
1053 | 832 | char *image; |
1054 | 833 | int ret; |
1055 | 834 | static struct option long_options[] = { |
1056 | 835 | {"create", 0, NULL, 'c'}, |
1057 | - {"collate-microcode", 0, NULL, 'C'}, | |
1058 | 836 | {"dump", 0, NULL, 'd'}, |
1059 | 837 | {"descriptor", 1, NULL, 'D'}, |
1060 | 838 | {"em100", 0, NULL, 'e'}, |
... | ... | @@ -1062,7 +840,6 @@ |
1062 | 840 | {"fdt", 1, NULL, 'f'}, |
1063 | 841 | {"inject", 1, NULL, 'i'}, |
1064 | 842 | {"lock", 0, NULL, 'l'}, |
1065 | - {"microcode", 1, NULL, 'm'}, | |
1066 | 843 | {"romsize", 1, NULL, 'r'}, |
1067 | 844 | {"spifreq", 1, NULL, 's'}, |
1068 | 845 | {"unlock", 0, NULL, 'u'}, |
1069 | 846 | |
... | ... | @@ -1073,15 +850,12 @@ |
1073 | 850 | {0, 0, 0, 0} |
1074 | 851 | }; |
1075 | 852 | |
1076 | - while ((opt = getopt_long(argc, argv, "cCdD:ef:hi:lm:r:s:uU:vw:x?", | |
853 | + while ((opt = getopt_long(argc, argv, "cdD:ef:hi:lr:s:uU:vw:x?", | |
1077 | 854 | long_options, &option_index)) != EOF) { |
1078 | 855 | switch (opt) { |
1079 | 856 | case 'c': |
1080 | 857 | create = 1; |
1081 | 858 | break; |
1082 | - case 'C': | |
1083 | - collate_ucode = 1; | |
1084 | - break; | |
1085 | 859 | case 'd': |
1086 | 860 | mode_dump = 1; |
1087 | 861 | break; |
... | ... | @@ -1119,9 +893,6 @@ |
1119 | 893 | case 'l': |
1120 | 894 | mode_locked = 1; |
1121 | 895 | break; |
1122 | - case 'm': | |
1123 | - ucode_ptr = strtoul(optarg, NULL, 0); | |
1124 | - break; | |
1125 | 896 | case 'r': |
1126 | 897 | rom_size = strtol(optarg, NULL, 0); |
1127 | 898 | debug("ROM size %d\n", rom_size); |
... | ... | @@ -1166,12 +937,6 @@ |
1166 | 937 | exit(EXIT_FAILURE); |
1167 | 938 | } |
1168 | 939 | ifile->addr = strtoll(optarg, NULL, 0); |
1169 | - ifile->type = opt == 'f' ? IF_fdt : | |
1170 | - opt == 'U' ? IF_uboot : IF_normal; | |
1171 | - if (ifile->type == IF_fdt) | |
1172 | - fdt = ifile; | |
1173 | - else if (ifile->type == IF_uboot) | |
1174 | - have_uboot = true; | |
1175 | 940 | wr_num++; |
1176 | 941 | } else { |
1177 | 942 | fprintf(stderr, |
... | ... | @@ -1302,18 +1067,9 @@ |
1302 | 1067 | |
1303 | 1068 | for (wr_idx = 0; wr_idx < wr_num; wr_idx++) { |
1304 | 1069 | ifile = &input_file[wr_idx]; |
1305 | - if (ifile->type == IF_fdt) { | |
1306 | - continue; | |
1307 | - } else if (ifile->type == IF_uboot) { | |
1308 | - ret = write_uboot(image, size, ifile, fdt, | |
1309 | - ucode_ptr, collate_ucode, | |
1310 | - &offset_uboot_top, | |
1311 | - &offset_uboot_start); | |
1312 | - } else { | |
1313 | - ret = write_data(image, size, ifile->addr, | |
1314 | - ifile->fname, offset_uboot_top, | |
1315 | - offset_uboot_start); | |
1316 | - } | |
1070 | + ret = write_data(image, size, ifile->addr, | |
1071 | + ifile->fname, offset_uboot_top, | |
1072 | + offset_uboot_start); | |
1317 | 1073 | if (ret < 0) |
1318 | 1074 | break; |
1319 | 1075 | } |