image: Move timestamp #ifdefs to header file

Rather than repeat the line
 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || \
	defined(USE_HOSTCC)

everywhere, put this in a header file and #define IMAGE_ENABLE_TIMESTAMP
to either 1 or 0. Then we can use a plain if() in most code and avoid
the #ifdefs.

The compiler's dead code elimination ensures that the result is the same.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Marek Vasut <marex@denx.de>
This commit is contained in:
Simon Glass 2013-05-07 06:11:51 +00:00 committed by Tom Rini
parent 88f95bbadd
commit 859e92b775
2 changed files with 29 additions and 29 deletions

View File

@ -39,9 +39,7 @@
#include <logbuff.h> #include <logbuff.h>
#endif #endif
#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
#include <rtc.h> #include <rtc.h>
#endif
#include <environment.h> #include <environment.h>
#include <image.h> #include <image.h>
@ -163,10 +161,6 @@ static const table_entry_t uimage_comp[] = {
{ -1, "", "", }, { -1, "", "", },
}; };
#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
static void genimg_print_time(time_t timestamp);
#endif
/*****************************************************************************/ /*****************************************************************************/
/* Legacy format routines */ /* Legacy format routines */
/*****************************************************************************/ /*****************************************************************************/
@ -312,10 +306,10 @@ void image_print_contents(const void *ptr)
#endif #endif
printf("%sImage Name: %.*s\n", p, IH_NMLEN, image_get_name(hdr)); printf("%sImage Name: %.*s\n", p, IH_NMLEN, image_get_name(hdr));
#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) if (IMAGE_ENABLE_TIMESTAMP) {
printf("%sCreated: ", p); printf("%sCreated: ", p);
genimg_print_time((time_t)image_get_time(hdr)); genimg_print_time((time_t)image_get_time(hdr));
#endif }
printf("%sImage Type: ", p); printf("%sImage Type: ", p);
image_print_type(hdr); image_print_type(hdr);
printf("%sData Size: ", p); printf("%sData Size: ", p);
@ -524,8 +518,8 @@ void genimg_print_size(uint32_t size)
#endif #endif
} }
#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) #if IMAGE_ENABLE_TIMESTAMP
static void genimg_print_time(time_t timestamp) void genimg_print_time(time_t timestamp)
{ {
#ifndef USE_HOSTCC #ifndef USE_HOSTCC
struct rtc_time tm; struct rtc_time tm;
@ -538,7 +532,7 @@ static void genimg_print_time(time_t timestamp)
printf("%s", ctime(&timestamp)); printf("%s", ctime(&timestamp));
#endif #endif
} }
#endif /* CONFIG_TIMESTAMP || CONFIG_CMD_DATE || USE_HOSTCC */ #endif
/** /**
* get_table_entry_name - translate entry id to long name * get_table_entry_name - translate entry id to long name
@ -1911,9 +1905,7 @@ void fit_print_contents(const void *fit)
int count = 0; int count = 0;
int ret; int ret;
const char *p; const char *p;
#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
time_t timestamp; time_t timestamp;
#endif
#ifdef USE_HOSTCC #ifdef USE_HOSTCC
p = ""; p = "";
@ -1929,14 +1921,14 @@ void fit_print_contents(const void *fit)
else else
printf("%s\n", desc); printf("%s\n", desc);
#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) if (IMAGE_ENABLE_TIMESTAMP) {
ret = fit_get_timestamp(fit, 0, &timestamp); ret = fit_get_timestamp(fit, 0, &timestamp);
printf("%sCreated: ", p); printf("%sCreated: ", p);
if (ret) if (ret)
printf("unavailable\n"); printf("unavailable\n");
else else
genimg_print_time(timestamp); genimg_print_time(timestamp);
#endif }
/* Find images parent node offset */ /* Find images parent node offset */
images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH); images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
@ -3047,13 +3039,13 @@ int fit_check_format(const void *fit)
return 0; return 0;
} }
#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) if (IMAGE_ENABLE_TIMESTAMP) {
/* mandatory / node 'timestamp' property */ /* mandatory / node 'timestamp' property */
if (fdt_getprop(fit, 0, FIT_TIMESTAMP_PROP, NULL) == NULL) { if (fdt_getprop(fit, 0, FIT_TIMESTAMP_PROP, NULL) == NULL) {
debug("Wrong FIT format: no timestamp\n"); debug("Wrong FIT format: no timestamp\n");
return 0; return 0;
}
} }
#endif
/* mandatory subimages parent '/images' node */ /* mandatory subimages parent '/images' node */
if (fdt_path_offset(fit, FIT_IMAGES_PATH) < 0) { if (fdt_path_offset(fit, FIT_IMAGES_PATH) < 0) {

View File

@ -333,6 +333,14 @@ int genimg_get_type_id(const char *name);
int genimg_get_comp_id(const char *name); int genimg_get_comp_id(const char *name);
void genimg_print_size(uint32_t size); void genimg_print_size(uint32_t size);
#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || \
defined(USE_HOSTCC)
#define IMAGE_ENABLE_TIMESTAMP 1
#else
#define IMAGE_ENABLE_TIMESTAMP 0
#endif
void genimg_print_time(time_t timestamp);
#ifndef USE_HOSTCC #ifndef USE_HOSTCC
/* Image format types, returned by _get_format() routine */ /* Image format types, returned by _get_format() routine */
#define IMAGE_FORMAT_INVALID 0x00 #define IMAGE_FORMAT_INVALID 0x00