Commit 859e92b775fd8ebcfacc591eaf621b677c95b6f7
Committed by
Tom Rini
1 parent
88f95bbadd
Exists in
master
and in
53 other branches
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>
Showing 2 changed files with 29 additions and 29 deletions Side-by-side Diff
common/image.c
... | ... | @@ -39,9 +39,7 @@ |
39 | 39 | #include <logbuff.h> |
40 | 40 | #endif |
41 | 41 | |
42 | -#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) | |
43 | 42 | #include <rtc.h> |
44 | -#endif | |
45 | 43 | |
46 | 44 | #include <environment.h> |
47 | 45 | #include <image.h> |
... | ... | @@ -163,10 +161,6 @@ |
163 | 161 | { -1, "", "", }, |
164 | 162 | }; |
165 | 163 | |
166 | -#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) | |
167 | -static void genimg_print_time(time_t timestamp); | |
168 | -#endif | |
169 | - | |
170 | 164 | /*****************************************************************************/ |
171 | 165 | /* Legacy format routines */ |
172 | 166 | /*****************************************************************************/ |
... | ... | @@ -312,10 +306,10 @@ |
312 | 306 | #endif |
313 | 307 | |
314 | 308 | printf("%sImage Name: %.*s\n", p, IH_NMLEN, image_get_name(hdr)); |
315 | -#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) | |
316 | - printf("%sCreated: ", p); | |
317 | - genimg_print_time((time_t)image_get_time(hdr)); | |
318 | -#endif | |
309 | + if (IMAGE_ENABLE_TIMESTAMP) { | |
310 | + printf("%sCreated: ", p); | |
311 | + genimg_print_time((time_t)image_get_time(hdr)); | |
312 | + } | |
319 | 313 | printf("%sImage Type: ", p); |
320 | 314 | image_print_type(hdr); |
321 | 315 | printf("%sData Size: ", p); |
... | ... | @@ -524,8 +518,8 @@ |
524 | 518 | #endif |
525 | 519 | } |
526 | 520 | |
527 | -#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) | |
528 | -static void genimg_print_time(time_t timestamp) | |
521 | +#if IMAGE_ENABLE_TIMESTAMP | |
522 | +void genimg_print_time(time_t timestamp) | |
529 | 523 | { |
530 | 524 | #ifndef USE_HOSTCC |
531 | 525 | struct rtc_time tm; |
... | ... | @@ -538,7 +532,7 @@ |
538 | 532 | printf("%s", ctime(×tamp)); |
539 | 533 | #endif |
540 | 534 | } |
541 | -#endif /* CONFIG_TIMESTAMP || CONFIG_CMD_DATE || USE_HOSTCC */ | |
535 | +#endif | |
542 | 536 | |
543 | 537 | /** |
544 | 538 | * get_table_entry_name - translate entry id to long name |
545 | 539 | |
... | ... | @@ -1911,9 +1905,7 @@ |
1911 | 1905 | int count = 0; |
1912 | 1906 | int ret; |
1913 | 1907 | const char *p; |
1914 | -#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) | |
1915 | 1908 | time_t timestamp; |
1916 | -#endif | |
1917 | 1909 | |
1918 | 1910 | #ifdef USE_HOSTCC |
1919 | 1911 | p = ""; |
... | ... | @@ -1929,14 +1921,14 @@ |
1929 | 1921 | else |
1930 | 1922 | printf("%s\n", desc); |
1931 | 1923 | |
1932 | -#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) | |
1933 | - ret = fit_get_timestamp(fit, 0, ×tamp); | |
1934 | - printf("%sCreated: ", p); | |
1935 | - if (ret) | |
1936 | - printf("unavailable\n"); | |
1937 | - else | |
1938 | - genimg_print_time(timestamp); | |
1939 | -#endif | |
1924 | + if (IMAGE_ENABLE_TIMESTAMP) { | |
1925 | + ret = fit_get_timestamp(fit, 0, ×tamp); | |
1926 | + printf("%sCreated: ", p); | |
1927 | + if (ret) | |
1928 | + printf("unavailable\n"); | |
1929 | + else | |
1930 | + genimg_print_time(timestamp); | |
1931 | + } | |
1940 | 1932 | |
1941 | 1933 | /* Find images parent node offset */ |
1942 | 1934 | images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH); |
1943 | 1935 | |
... | ... | @@ -3047,13 +3039,13 @@ |
3047 | 3039 | return 0; |
3048 | 3040 | } |
3049 | 3041 | |
3050 | -#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) | |
3051 | - /* mandatory / node 'timestamp' property */ | |
3052 | - if (fdt_getprop(fit, 0, FIT_TIMESTAMP_PROP, NULL) == NULL) { | |
3053 | - debug("Wrong FIT format: no timestamp\n"); | |
3054 | - return 0; | |
3042 | + if (IMAGE_ENABLE_TIMESTAMP) { | |
3043 | + /* mandatory / node 'timestamp' property */ | |
3044 | + if (fdt_getprop(fit, 0, FIT_TIMESTAMP_PROP, NULL) == NULL) { | |
3045 | + debug("Wrong FIT format: no timestamp\n"); | |
3046 | + return 0; | |
3047 | + } | |
3055 | 3048 | } |
3056 | -#endif | |
3057 | 3049 | |
3058 | 3050 | /* mandatory subimages parent '/images' node */ |
3059 | 3051 | if (fdt_path_offset(fit, FIT_IMAGES_PATH) < 0) { |
include/image.h
... | ... | @@ -333,6 +333,14 @@ |
333 | 333 | int genimg_get_comp_id(const char *name); |
334 | 334 | void genimg_print_size(uint32_t size); |
335 | 335 | |
336 | +#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || \ | |
337 | + defined(USE_HOSTCC) | |
338 | +#define IMAGE_ENABLE_TIMESTAMP 1 | |
339 | +#else | |
340 | +#define IMAGE_ENABLE_TIMESTAMP 0 | |
341 | +#endif | |
342 | +void genimg_print_time(time_t timestamp); | |
343 | + | |
336 | 344 | #ifndef USE_HOSTCC |
337 | 345 | /* Image format types, returned by _get_format() routine */ |
338 | 346 | #define IMAGE_FORMAT_INVALID 0x00 |