Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(355)

Side by Side Diff: utility/efidecompress.c

Issue 6880176: Build EFI compression utilities on host (Closed) Base URL: ssh://gitrw.chromium.org:9222/vboot_reference.git@master
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utility/eficompress.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be 2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. 3 * found in the LICENSE file.
4 */ 4 */
5 5
6 /*++ 6 /*++
7 7
8 Copyright (c) 2004 - 2006, Intel Corporation 8 Copyright (c) 2004 - 2006, Intel Corporation
9 All rights reserved. This program and the accompanying materials 9 All rights reserved. This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD Licens e 10 are licensed and made available under the terms and conditions of the BSD Licens e
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 return Decompress ( 999 return Decompress (
1000 Source, 1000 Source,
1001 SrcSize, 1001 SrcSize,
1002 Destination, 1002 Destination,
1003 DstSize, 1003 DstSize,
1004 Scratch, 1004 Scratch,
1005 ScratchSize, 1005 ScratchSize,
1006 2 1006 2
1007 ); 1007 );
1008 } 1008 }
1009
1010
1011 #ifdef STANDALONE
1012 int main(int argc, char *argv[])
1013 {
1014 char *progname;
1015 int retval = 1;
1016
1017 progname = strrchr(argv[0], '/');
1018 if (progname)
1019 progname++;
1020 else
1021 progname = argv[0];
1022
1023 if (argc != 3)
1024 {
1025 fprintf(stderr, "\nUsage: %s INFILE OUTFILE\n\n", progname);
1026 exit(1);
1027 }
1028
1029 char *infile = argv[1];
1030 char *outfile = argv[2];
1031
1032 struct stat istat;
1033 if (0 != stat(infile, &istat)) {
1034 fprintf(stderr, "%s: can't stat %s: %s\n",
1035 progname,
1036 infile,
1037 strerror(errno));
1038 exit(1);
1039 }
1040 uint32_t isize = (uint32_t)istat.st_size;
1041
1042 printf("%s is %d bytes\n", infile, isize);
1043
1044 FILE *ifp = fopen(infile, "rb");
1045 if (!ifp)
1046 {
1047 fprintf(stderr, "%s: can't read %s: %s\n",
1048 progname,
1049 infile,
1050 strerror(errno));
1051 exit(1);
1052 }
1053 printf("opened %s\n", infile);
1054
1055 // read input file into buffer
1056 uint8_t *ibuf = malloc(isize);
1057 if (!ibuf) {
1058 fprintf(stderr, "%s: can't allocate %d bytes: %s\n",
1059 progname,
1060 isize,
1061 strerror(errno));
1062 goto done1;
1063 }
1064 if (1 != fread(ibuf, isize, 1, ifp)) {
1065 fprintf(stderr, "%s: can't read %d bytes: %s\n",
1066 progname,
1067 isize,
1068 strerror(errno));
1069 goto done2;
1070 }
1071
1072
1073 // Determine required parameters
1074 uint32_t ssize=0, osize=0;
1075 EFI_STATUS r = GetInfo(ibuf, isize, &osize, &ssize);
1076 if (r != EFI_SUCCESS) {
1077 fprintf(stderr, "%s: GetInfo failed with code %d\n",
1078 progname,
1079 r);
1080 goto done2;
1081 }
1082 printf("need %d bytes of scratch to produce %d bytes of data\n",
1083 ssize, osize);
1084
1085 uint8_t *sbuf = malloc(ssize);
1086 if (!sbuf) {
1087 fprintf(stderr, "%s: can't allocate %d bytes: %s\n",
1088 progname,
1089 ssize,
1090 strerror(errno));
1091 goto done2;
1092 }
1093
1094 uint8_t *obuf = malloc(osize);
1095 if (!obuf) {
1096 fprintf(stderr, "%s: can't allocate %d bytes: %s\n",
1097 progname,
1098 osize,
1099 strerror(errno));
1100 goto done3;
1101 }
1102
1103 // Try new version first
1104 r = TianoDecompress(ibuf, isize, obuf, osize, sbuf, ssize);
1105 if (r != EFI_SUCCESS) {
1106 fprintf(stderr, "%s: TianoDecompress failed with code %d\n",
1107 progname,
1108 r);
1109
1110 // Try old version
1111 r = EfiDecompress(ibuf, isize, obuf, osize, sbuf, ssize);
1112 if (r != EFI_SUCCESS) {
1113 fprintf(stderr, "%s: TianoDecompress failed with code %d\n",
1114 progname,
1115 r);
1116 goto done4;
1117 }
1118 }
1119
1120 printf("Uncompressed %d bytes to %d bytes\n", isize, osize);
1121
1122 // Write it out
1123 FILE *ofp = fopen(outfile, "wb");
1124 if (!ofp)
1125 {
1126 fprintf(stderr, "%s: can't open %s for writing: %s\n",
1127 progname,
1128 outfile,
1129 strerror(errno));
1130 goto done4;
1131 }
1132 printf("opened %s\n", outfile);
1133
1134 if (1 != fwrite(obuf, osize, 1, ofp)) {
1135 fprintf(stderr, "%s: can't write %d bytes: %s\n",
1136 progname,
1137 osize,
1138 strerror(errno));
1139 goto done5;
1140 }
1141
1142 printf("wrote %d bytes to %s\n", osize, outfile);
1143 retval = 0;
1144
1145 done5:
1146 fclose(ofp);
1147
1148 done4:
1149 free(obuf);
1150
1151 done3:
1152 free(sbuf);
1153
1154 done2:
1155 free(ibuf);
1156
1157 done1:
1158 fclose(ifp);
1159
1160 return retval;
1161 }
1162 #endif // STANDALONE
OLDNEW
« no previous file with comments | « utility/eficompress.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698