The following proposed patch to the lcp_mlehash tool fixes the diagnostics so that the -v option can be used at any time, plus ensures that an error message is output to the stderr stream when the tool aborts on an error.
Signed-off-by: Ed Braaten <ed.braa...@intel.com> --- --- tboot.241.hg/lcptools/mlehash.c 2010-10-13 11:16:20.491168002 -0700 +++ tboot.241-mlemods/lcptools/mlehash.c 2010-10-14 08:33:05.291168001 -0700 @@ -52,7 +52,7 @@ static bool verbose = false; -#define log_info(fmt, ...) verbose ? printf(fmt, ##__VA_ARGS__) : 0 +#define log_info(fmt, ...) verbose ? fprintf(stderr, fmt, ##__VA_ARGS__) : 0 /* @@ -65,7 +65,7 @@ { elf_header_t *elf; - log_info("checking whether image is an elf image ... "); + log_info("Checking whether image is an elf image..."); if ( image == NULL ) { log_info(": failed! - Pointer is zero.\n"); return false; @@ -175,7 +175,7 @@ { int i; - log_info("expanding elf image ... "); + log_info("Expanding elf image..."); if ( elf == NULL ) { log_info(": failed! - ELF header pointer is zero.\n"); return false; @@ -190,7 +190,7 @@ if (ph->p_type == PT_LOAD) { if ( ph->p_memsz > size ) { - log_info("expanded image exceeded allocated size\n"); + log_info(": failed! Expanded image exceeded allocated size.\n"); return false; } memcpy(base, (void *)elf + ph->p_offset, ph->p_filesz); @@ -200,7 +200,7 @@ } } - log_info(": succeeded!.\n"); + log_info(": succeeded!\n"); return true; } @@ -243,13 +243,13 @@ *buffer = NULL; /* check the file exists or not */ - log_info("checking whether the file exists or not ... "); + log_info("Checking whether the file '%s' exists or not...", filename); if ( stat(filename, &filestat) ) goto error; log_info(": existed!\n"); /* try uncompress the file (gzopen will handle uncompressed files too) */ - log_info("trying to uncompress the file ... "); + log_info("Trying to uncompress %s...", filename); fcompressed = gzopen(filename, "rb"); if ( !fcompressed ) { log_info(": failed!\n"); @@ -257,13 +257,13 @@ } log_info(": succeeded!\n"); - log_info("creating a temporary file to uncompress ... "); + log_info("Creating a temporary file to uncompress..."); fdecompressed = tmpfile(); if ( !fdecompressed ) goto error; log_info(": succeeded!\n"); - log_info("opening the decompressed file ... "); + log_info("Opening the decompressed file..."); while ( !gzeof(fcompressed) ) { i = gzread(fcompressed, tmpbuffer, 1024); *length += i; @@ -274,7 +274,7 @@ gzclose(fcompressed); fcompressed = NULL; - log_info("testing decompression is ... "); + log_info("Testing decompression..."); if ( *length > 0 ) { log_info(": succeeded!\n"); /* uncompression succeeded */ @@ -286,7 +286,7 @@ } /* read file into buffer */ - log_info("reading the decompressed file ... "); + log_info("Reading the decompressed file..."); *buffer = malloc(*length); if ( *buffer == NULL ) goto error; @@ -310,6 +310,7 @@ static mle_hdr_t *find_mle_hdr(void *start, size_t size) { void *end; +log_info("MLE Header size = %lu bytes\n", sizeof(mle_hdr_t)); end = start + size - sizeof(uuid_t); while ( start <= end ) { @@ -350,25 +351,25 @@ break; case 'c': if ( optarg == NULL ) { - printf("Misssing command line string for -c option\n"); + fprintf(stderr, "Missing command line string for -c option\n"); return 1; } cmdline = malloc(strlen(optarg) + 1); if ( cmdline == NULL ) { - printf("Out of memory\n"); + fprintf(stderr, "Out of memory\n"); return 1; } strcpy(cmdline, optarg); break; default: - printf("Unknonw command line option\n"); + fprintf(stderr, "Unknown command line option\n"); break; } } if ( help || (optind == argc) ) { printf("mhash [-h] [-v] [-c cmdline] mle_file\n" "\t-h Help: will print out this help message.\n" - "\t-v Verbose: display progress indications.\n" + "\t-v Verbose: display progress indications on stderr.\n" "\t-c cmdline Command line: specify quote-delimited command line.\n" "\tmle_file: file name of MLE binary (gzip or not) to hash.\n"); free(cmdline); @@ -391,7 +392,7 @@ exp_size = elf_end - elf_start; exp_start = malloc(exp_size); if ( exp_start == NULL ) { - log_info("not enough memory for expanded image\n"); + log_info("Not enough memory for expanded image\n"); goto error; } @@ -402,7 +403,7 @@ /* find the MLE header in the expanded image */ mle_hdr = find_mle_hdr(exp_start, exp_size); if ( mle_hdr == NULL ) { - log_info("no MLE header found in image\n"); + log_info("No MLE header found in image!\n"); goto error; } @@ -410,33 +411,41 @@ command line param to it */ if ( mle_hdr->cmdline_end_off > mle_hdr->cmdline_start_off && cmdline != NULL ) { + log_info("Copying '%s' to MLE command line area...", cmdline); memset(exp_start + mle_hdr->cmdline_start_off, '\0', mle_hdr->cmdline_end_off - mle_hdr->cmdline_start_off); strncpy(exp_start + mle_hdr->cmdline_start_off, cmdline, mle_hdr->cmdline_end_off - mle_hdr->cmdline_start_off - 1); + log_info(": done.\n"); } /* SHA-1 the MLE portion of the image */ + log_info("Computing SHA-1 of MLE portion of image (size=%d bytes)...", + mle_hdr->mle_end_off - mle_hdr->mle_start_off); md = EVP_sha1(); EVP_DigestInit(&ctx, md); EVP_DigestUpdate(&ctx, exp_start + mle_hdr->mle_start_off, mle_hdr->mle_end_off - mle_hdr->mle_start_off); EVP_DigestFinal(&ctx, (unsigned char *)hash, NULL); - log_info("SHA-1 = "); + log_info(": done.\n"); - /* we always print the hash regardless of verbose mode */ + /* we always print the hash to stdout regardless of verbose mode */ + log_info("SHA-1 = "); for ( i = 0; i < SHA1_LENGTH; i++ ) { printf("%02x", hash[i]); + log_info("%02x ", hash[i]); if ( i < SHA1_LENGTH - 1 ) printf(" "); } printf("\n"); + log_info("\n"); free(base); free(exp_start); return 0; error: + fprintf(stderr, "Error! Aborting...\n"); free(base); free(exp_start); return 1; ------------------------------------------------------------------------------ Nokia and AT&T present the 2010 Calling All Innovators-North America contest Create new apps & games for the Nokia N8 for consumers in U.S. and Canada $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store http://p.sf.net/sfu/nokia-dev2dev _______________________________________________ tboot-devel mailing list tboot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tboot-devel