[U-Boot] [PATCH v3] mkimage: add "-V" option to print version information

Albert ARIBAUD albert.aribaud at free.fr
Sat Feb 12 07:47:38 CET 2011


Le 12/02/2011 00:11, Kim Phillips a écrit :
> On Fri, 11 Feb 2011 23:41:43 +0100
> Wolfgang Denk<wd at denx.de>  wrote:
>
>> +			case 'V':
>> +				/*
>> +				 * Skip the "U-Boot " part in
>> +				 * U_BOOT_VERSION by adding 7
>> +				 */
>> +				printf("mkimage version %s\n",
>> +					U_BOOT_VERSION + 7);

Now I get it. :)

I might argue that this is kind of a hack, and that rather than trying 
to prune the U_BOOT_VERSION string, one should define two macros, for 
instance:

	#define PLAIN_VERSION "whatever"
	#define U_BOOT_VERSION "U-Boot " PLAIN_VERSION

... which has the advantage of not affecting the existing code, or a 
cleaner, but more invasive, change...

	#define U_BOOT_VERSION "whatever" /* without "U-Boot " */
	#define U_BOOT_VERSION_BANNER "U-Boot " U_BOOT_VERSION

... and use the right macro for the right need.

> I'd have done it without magic nor comments as
>
> U_BOOT_VERSION[sizeof("U-Boot ") + 1]
>
> or even
>
> U_BOOT_VERSION[strlen("U-Boot ")]

The second one calls strlen() at run-time, plus it allocates the "U-Boot 
" string for no justifiable reason -- assuming the first one can be 
compile-time evaluated by the compiler, of course.

> Kim

Amicalement,
-- 
Albert.


More information about the U-Boot mailing list