[U-Boot] [RFC] ARM: prevent misaligned array inits

Albert ARIBAUD albert.u.boot at aribaud.net
Thu Oct 4 22:22:41 CEST 2012


Hi Mark,

On Wed, 3 Oct 2012 09:29:09 +0200, Mark Marshall
<mark.marshall at omicron.at> wrote:

> I've just had a quick look at this in passing, but at least some of
> these changes seem wrong to me.  For example, the code in
> board/ti/omap2420h4/sys_info.c :: display_board_info
> should be:
> 
> void display_board_info(u32 btype)
> {
> 	static const char cpu_2420[] = "2420";   /* cpu type */
> 	static const char cpu_2422[] = "2422";
> 	static const char cpu_2423[] = "2423";
> 	static const char db_men[] = "Menelaus"; /* board type */
> 	static const char db_ip[] = "IP";
> 	static const char mem_sdr[] = "mSDR";    /* memory type */
> 	static const char mem_ddr[] = "mDDR";
> 	static const char t_tst[] = "TST";	    /* security level */
> 	static const char t_emu[] = "EMU";
> 	static const char t_hs[] = "HS";
> 	static const char t_gp[] = "GP";
> 	static const char unk[] = "?";
> 
> 	const char *cpu_s, *db_s, *mem_s, *sec_s;
> 	u32 cpu, rev, sec;
> 
> This produces smaller code and is probably what the original
> author wanted the compiler to do.  I've only compile tested
> this, not actually run it.
> 
> Original file:
> 
> Sections:
> Idx Name          Size      VMA       LMA       File off  Algn
>    0 .text         000004b4  00000000  00000000  00000034  2**2
>                    CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
>    1 .data         00000000  00000000  00000000  000004e8  2**0
>                    CONTENTS, ALLOC, LOAD, DATA
>    2 .bss          00000000  00000000  00000000  000004e8  2**0
>                    ALLOC
>    3 .rodata.str1.1 00000072  00000000  00000000  000004e8  2**0
>                    CONTENTS, ALLOC, LOAD, READONLY, DATA
> 
> After my changes:
> 
> Sections:
> Idx Name          Size      VMA       LMA       File off  Algn
>    0 .text         000003ac  00000000  00000000  00000034  2**2
>                    CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
>    1 .data         00000000  00000000  00000000  000003e0  2**0
>                    CONTENTS, ALLOC, LOAD, DATA
>    2 .bss          00000000  00000000  00000000  000003e0  2**0
>                    ALLOC
>    3 .rodata       00000048  00000000  00000000  000003e0  2**2
>                    CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA
>    4 .rodata.str1.1 00000047  00000000  00000000  00000428  2**0
>                    CONTENTS, ALLOC, LOAD, READONLY, DATA
> 

Thanks Mike. Indeed, there is a range of choices to replace the
original local char arrays: global arrays, static local arrays, 
char pointers, const char pointers, or even direct strings in code. I'd
originally gone for const chars because the idea was not optimizing but
getting rid of a compiler issue, however, with my toolchain, this led
to warnings about losing the const qualifier, so I went to simple char*.
I'll recheck with (const) static char[] and chose whetever gets the
best score.

> Regards,
> 
> Mark Marshall.

Amicalement,
-- 
Albert.


More information about the U-Boot mailing list