[U-Boot] [PATCH 3/5] Data type defined for pointer addresses

Bansal Aneesh aneesh.bansal at freescale.com
Mon Dec 7 18:02:04 CET 2015


It is required because the variable is 32 bit in length and it must be typecasted to a pointer before passing to some functions.

The pointer length is 64 bit on 64 bit cores and 32 bit on 32 bit cores.

So if I have (u8*)csf_hdr_addr, a warning is given on 64 bit cores like ARMv8 on LS1043. Thus the variable must be typecasted to 'unsigned long'  which is 64 or 32 bit depending on the core before typecasting to a pointer. Currently there is no typedef for 'unsigned long' in uboot. That is the reason I thought of adding it.

Is there any other way of achieving this?


Regards,
Aneesh Bansal
Sent from Samsung Mobile.

-------- Original message --------
From: York Sun
Date:07/12/2015 10:20 PM (GMT+05:30)
To: Bansal Aneesh-B39320 , u-boot at lists.denx.de, Tom Rini , Wolfgang Denk , Wood Scott-B07421 , Simon Glass
Cc: Gupta Ruchika-R66431 , Kushwaha Prabhakar-B32579
Subject: Re: [PATCH 3/5] Data type defined for pointer addresses

Guys,

Please comment on this new typedef. I am not comfortable to accept it.

On 11/18/2015 09:41 PM, Aneesh Bansal wrote:
> A new data type uintptr_t has been defined for creating
> pointers (32 or 64 bit depending on Core) from 32 bit variables
> storing the address.
> If a 32 bit variable (u32) is typecasted to a pointer (void *),
> compiler gives a warning in case size of pointer on the core is 64 bit.
>
> Signed-off-by: Aneesh Bansal <aneesh.bansal at freescale.com>
> ---
>  arch/arm/include/asm/types.h     | 2 ++
>  arch/powerpc/include/asm/types.h | 1 +
>  2 files changed, 3 insertions(+)
>
> diff --git a/arch/arm/include/asm/types.h b/arch/arm/include/asm/types.h
> index 388058e..5555765 100644
> --- a/arch/arm/include/asm/types.h
> +++ b/arch/arm/include/asm/types.h
> @@ -56,6 +56,8 @@ typedef unsigned long phys_addr_t;
>  typedef unsigned long phys_size_t;
>  #endif
>
> +typedef unsigned long uintptr_t;

It is used in next patch of this series
http://patchwork.ozlabs.org/patch/552669/, in two-step casting such as

(u8 *)(uintptr_t)csf_hdr_addr

As OP indicated, the variable is u32. Casting to a pointer causes compiling
warning. Is this the right approach?

York


More information about the U-Boot mailing list