1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-26 22:52:34 +02:00
flashrom/cli_output.c
Edward O'Callaghan 00635b0da2 Revert "libflashrom: Return progress state to the library user"
This reverts commit 40892b0c08fbc8029921e91511dd3f91fc956f90.

The feature of returning progress for libflashrom users was
introduced in original commit, however later a bug was found and
reported as https://ticket.coreboot.org/issues/390.

Reverting in a release branch to unblock release candidate, since
it is unknown how much time needed to fix the bug. Meanwhile the
feature remains in a master branch and will be fixed under
ticket 390.

TEST=scenarios below run successfully
1) flashrom -h does not show --progress
2) flashrom -p dummy:emulate=W25Q128FV -r /tmp/dump.bin
3) flashrom -p dummy:emulate=W25Q128FV -v /tmp/dump.bin
4) flashrom -p dummy:emulate=W25Q128FV -E
5) head -c 16777216 </dev/urandom >/tmp/image.bin
flashrom -p dummy:image=/tmp/image.bin,emulate=W25Q128FV \
	 -w /tmp/dump.bin

Change-Id: Id3d7ffcaf266a60a44eb453fd09b7c63c05349c2
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/69283
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Felix Singer <felixsinger@posteo.net>
2022-11-10 17:23:07 +00:00

96 lines
2.5 KiB
C

/*
* This file is part of the flashrom project.
*
* Copyright (C) 2009 Sean Nelson <audiohacked@gmail.com>
* Copyright (C) 2011 Carl-Daniel Hailfinger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include "flash.h"
enum flashrom_log_level verbose_screen = FLASHROM_MSG_INFO;
enum flashrom_log_level verbose_logfile = FLASHROM_MSG_DEBUG2;
static FILE *logfile = NULL;
int close_logfile(void)
{
if (!logfile)
return 0;
/* No need to call fflush() explicitly, fclose() already does that. */
if (fclose(logfile)) {
/* fclose returned an error. Stop writing to be safe. */
logfile = NULL;
msg_gerr("Closing the log file returned error %s\n", strerror(errno));
return 1;
}
logfile = NULL;
return 0;
}
int open_logfile(const char * const filename)
{
if (!filename) {
msg_gerr("No logfile name specified.\n");
return 1;
}
if ((logfile = fopen(filename, "w")) == NULL) {
msg_gerr("Error: opening log file \"%s\" failed: %s\n", filename, strerror(errno));
return 1;
}
return 0;
}
void start_logging(void)
{
enum flashrom_log_level oldverbose_screen = verbose_screen;
/* Shut up the console. */
verbose_screen = FLASHROM_MSG_ERROR;
print_version();
verbose_screen = oldverbose_screen;
}
/* Please note that level is the verbosity, not the importance of the message. */
int flashrom_print_cb(enum flashrom_log_level level, const char *fmt, va_list ap)
{
int ret = 0;
FILE *output_type = stdout;
va_list logfile_args;
va_copy(logfile_args, ap);
if (level < FLASHROM_MSG_INFO)
output_type = stderr;
if (level <= verbose_screen) {
ret = vfprintf(output_type, fmt, ap);
/* msg_*spew often happens inside chip accessors in possibly
* time-critical operations. Don't slow them down by flushing. */
if (level != FLASHROM_MSG_SPEW)
fflush(output_type);
}
if ((level <= verbose_logfile) && logfile) {
ret = vfprintf(logfile, fmt, logfile_args);
if (level != FLASHROM_MSG_SPEW)
fflush(logfile);
}
va_end(logfile_args);
return ret;
}