summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@google.com>2011-04-25 10:51:22 -0700
committerBill Richardson <wfrichar@google.com>2011-04-25 10:51:22 -0700
commit573d4f6d80730ac56d23b2c5c8620a9fd843e816 (patch)
treee672a36fc57d1b9bd6f45f8fd2e12f9af13fcf4c
parent8511f7891b5eca7ae93a147964201a4b57210ff6 (diff)
downloadvboot-573d4f6d80730ac56d23b2c5c8620a9fd843e816.tar.gz
Build EFI compression utilities on host
Change-Id: Ia135e3dd3d67ac6ed64bc104e86a0692f7d8be33 Build eficompress and efidecompress utilities on host. Change-Id: I2d6723ac0d1673b555a7ae27f7ddbe830dcc75ef R=rpangler@chromium.org BUG=chromium-os:13037 TEST=none Review URL: http://codereview.chromium.org/6880176
-rw-r--r--utility/Makefile8
-rw-r--r--utility/eficompress.c123
-rw-r--r--utility/efidecompress.c154
3 files changed, 284 insertions, 1 deletions
diff --git a/utility/Makefile b/utility/Makefile
index fbbd0658..a60ef21a 100644
--- a/utility/Makefile
+++ b/utility/Makefile
@@ -40,7 +40,7 @@ TARGET_NAMES = crossystem \
pack_firmware_image
ifeq ($(MINIMAL),)
-TARGET_NAMES += bmpblk_utility
+TARGET_NAMES += bmpblk_utility eficompress efidecompress
endif
TARGET_BINS = $(addprefix ${BUILD_ROOT}/,$(TARGET_NAMES))
@@ -69,9 +69,15 @@ ${BUILD_ROOT}/bmpblk_util.o: bmpblk_util.c
${BUILD_ROOT}/eficompress.o: eficompress.c
$(CC) $(CFLAGS) -c $< -o $@
+${BUILD_ROOT}/eficompress: eficompress.c
+ $(CC) $(CFLAGS) -DSTANDALONE $< -o $@
+
${BUILD_ROOT}/efidecompress.o: efidecompress.c
$(CC) $(CFLAGS) -c $< -o $@
+${BUILD_ROOT}/efidecompress: efidecompress.c
+ $(CC) $(CFLAGS) -DSTANDALONE $< -o $@
+
${BUILD_ROOT}/bmpblk_utility: ${BUILD_ROOT}/bmpblk_utility.o \
${BUILD_ROOT}/bmpblk_util.o \
${BUILD_ROOT}/eficompress.o \
diff --git a/utility/eficompress.c b/utility/eficompress.c
index b0cf4fb3..b5987006 100644
--- a/utility/eficompress.c
+++ b/utility/eficompress.c
@@ -1607,3 +1607,126 @@ Returns:
//
return k;
}
+
+
+#ifdef STANDALONE
+int main(int argc, char *argv[])
+{
+ char *progname;
+ int retval = 1;
+
+ progname = strrchr(argv[0], '/');
+ if (progname)
+ progname++;
+ else
+ progname = argv[0];
+
+ if (argc != 3)
+ {
+ fprintf(stderr, "\nUsage: %s INFILE OUTFILE\n\n", progname);
+ exit(1);
+ }
+
+ char *infile = argv[1];
+ char *outfile = argv[2];
+
+ struct stat istat;
+ if (0 != stat(infile, &istat)) {
+ fprintf(stderr, "%s: can't stat %s: %s\n",
+ progname,
+ infile,
+ strerror(errno));
+ exit(1);
+ }
+ uint32_t isize = (uint32_t)istat.st_size;
+
+ printf("%s is %d bytes\n", infile, isize);
+
+ FILE *ifp = fopen(infile, "rb");
+ if (!ifp)
+ {
+ fprintf(stderr, "%s: can't read %s: %s\n",
+ progname,
+ infile,
+ strerror(errno));
+ exit(1);
+ }
+ printf("opened %s\n", infile);
+
+ // read input file into buffer
+ uint8_t *ibuf = malloc(isize);
+ if (!ibuf) {
+ fprintf(stderr, "%s: can't malloc %d bytes: %s\n",
+ progname,
+ isize,
+ strerror(errno));
+ goto done1;
+ }
+ if (1 != fread(ibuf, isize, 1, ifp)) {
+ fprintf(stderr, "%s: can't read %d bytes: %s\n",
+ progname,
+ isize,
+ strerror(errno));
+ goto done2;
+ }
+
+ // assume compression will actually work
+ uint32_t osize = isize;
+ uint8_t *obuf = malloc(osize);
+ if (!obuf) {
+ fprintf(stderr, "%s: can't allocate %d bytes: %s\n",
+ progname,
+ osize,
+ strerror(errno));
+ goto done2;
+ }
+
+ // try it and see
+ EFI_STATUS r = EfiCompress(ibuf, isize, obuf, &osize);
+ if (r != EFI_SUCCESS) {
+ fprintf(stderr, "%s: compression failed with code %d\n",
+ progname,
+ r);
+ goto done3;
+ }
+
+ printf("Compressed %d bytes to %d bytes\n", isize, osize);
+
+ // Write it out
+ FILE *ofp = fopen(outfile, "wb");
+ if (!ofp)
+ {
+ fprintf(stderr, "%s: can't open %s for writing: %s\n",
+ progname,
+ outfile,
+ strerror(errno));
+ goto done3;
+ }
+ printf("opened %s\n", outfile);
+
+ if (1 != fwrite(obuf, osize, 1, ofp)) {
+ fprintf(stderr, "%s: can't write %d bytes: %s\n",
+ progname,
+ osize,
+ strerror(errno));
+ goto done4;
+ }
+
+ printf("wrote %d bytes to %s\n", osize, outfile);
+ retval = 0;
+
+done4:
+ fclose(ofp);
+
+done3:
+ free(obuf);
+
+done2:
+ free(ibuf);
+
+done1:
+ fclose(ifp);
+
+ return retval;
+}
+#endif // STANDALONE
diff --git a/utility/efidecompress.c b/utility/efidecompress.c
index 8ec4a089..5e7e14d7 100644
--- a/utility/efidecompress.c
+++ b/utility/efidecompress.c
@@ -1006,3 +1006,157 @@ Returns:
2
);
}
+
+
+#ifdef STANDALONE
+int main(int argc, char *argv[])
+{
+ char *progname;
+ int retval = 1;
+
+ progname = strrchr(argv[0], '/');
+ if (progname)
+ progname++;
+ else
+ progname = argv[0];
+
+ if (argc != 3)
+ {
+ fprintf(stderr, "\nUsage: %s INFILE OUTFILE\n\n", progname);
+ exit(1);
+ }
+
+ char *infile = argv[1];
+ char *outfile = argv[2];
+
+ struct stat istat;
+ if (0 != stat(infile, &istat)) {
+ fprintf(stderr, "%s: can't stat %s: %s\n",
+ progname,
+ infile,
+ strerror(errno));
+ exit(1);
+ }
+ uint32_t isize = (uint32_t)istat.st_size;
+
+ printf("%s is %d bytes\n", infile, isize);
+
+ FILE *ifp = fopen(infile, "rb");
+ if (!ifp)
+ {
+ fprintf(stderr, "%s: can't read %s: %s\n",
+ progname,
+ infile,
+ strerror(errno));
+ exit(1);
+ }
+ printf("opened %s\n", infile);
+
+ // read input file into buffer
+ uint8_t *ibuf = malloc(isize);
+ if (!ibuf) {
+ fprintf(stderr, "%s: can't allocate %d bytes: %s\n",
+ progname,
+ isize,
+ strerror(errno));
+ goto done1;
+ }
+ if (1 != fread(ibuf, isize, 1, ifp)) {
+ fprintf(stderr, "%s: can't read %d bytes: %s\n",
+ progname,
+ isize,
+ strerror(errno));
+ goto done2;
+ }
+
+
+ // Determine required parameters
+ uint32_t ssize=0, osize=0;
+ EFI_STATUS r = GetInfo(ibuf, isize, &osize, &ssize);
+ if (r != EFI_SUCCESS) {
+ fprintf(stderr, "%s: GetInfo failed with code %d\n",
+ progname,
+ r);
+ goto done2;
+ }
+ printf("need %d bytes of scratch to produce %d bytes of data\n",
+ ssize, osize);
+
+ uint8_t *sbuf = malloc(ssize);
+ if (!sbuf) {
+ fprintf(stderr, "%s: can't allocate %d bytes: %s\n",
+ progname,
+ ssize,
+ strerror(errno));
+ goto done2;
+ }
+
+ uint8_t *obuf = malloc(osize);
+ if (!obuf) {
+ fprintf(stderr, "%s: can't allocate %d bytes: %s\n",
+ progname,
+ osize,
+ strerror(errno));
+ goto done3;
+ }
+
+ // Try new version first
+ r = TianoDecompress(ibuf, isize, obuf, osize, sbuf, ssize);
+ if (r != EFI_SUCCESS) {
+ fprintf(stderr, "%s: TianoDecompress failed with code %d\n",
+ progname,
+ r);
+
+ // Try old version
+ r = EfiDecompress(ibuf, isize, obuf, osize, sbuf, ssize);
+ if (r != EFI_SUCCESS) {
+ fprintf(stderr, "%s: TianoDecompress failed with code %d\n",
+ progname,
+ r);
+ goto done4;
+ }
+ }
+
+ printf("Uncompressed %d bytes to %d bytes\n", isize, osize);
+
+ // Write it out
+ FILE *ofp = fopen(outfile, "wb");
+ if (!ofp)
+ {
+ fprintf(stderr, "%s: can't open %s for writing: %s\n",
+ progname,
+ outfile,
+ strerror(errno));
+ goto done4;
+ }
+ printf("opened %s\n", outfile);
+
+ if (1 != fwrite(obuf, osize, 1, ofp)) {
+ fprintf(stderr, "%s: can't write %d bytes: %s\n",
+ progname,
+ osize,
+ strerror(errno));
+ goto done5;
+ }
+
+ printf("wrote %d bytes to %s\n", osize, outfile);
+ retval = 0;
+
+done5:
+ fclose(ofp);
+
+done4:
+ free(obuf);
+
+done3:
+ free(sbuf);
+
+done2:
+ free(ibuf);
+
+done1:
+ fclose(ifp);
+
+ return retval;
+}
+#endif // STANDALONE