public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 2/2] arm: add initial support for Amlogic Meson and ODROID-C2
Date: Wed, 13 Apr 2016 00:26:43 +0200	[thread overview]
Message-ID: <570D7623.8020603@denx.de> (raw)
In-Reply-To: <20160412214945.GA3006@gmail.com>

On 04/12/2016 11:50 PM, Beniamino Galvani wrote:
> On Mon, Apr 11, 2016 at 11:08:02PM +0200, Marek Vasut wrote:
>>>>> +	val = fdt_getprop(gd->fdt_blob, offset, "reg", &len);
>>>>> +	if (len < sizeof(*val) * 4)
>>>>> +		return -EINVAL;
>>>>> +
>>>>> +	/* Don't use fdt64_t to avoid unaligned access */
>>>>
>>>> This looks iffy, can you elaborate on this issue ?
>>>
>>> I was getting a "Synchronous Abort handler, esr 0x96000021" which
>>> seemed to indicate a alignment fault, but thinking again about it I'm
>>> not sure anymore of the real cause. fdt64_t and fdt64_to_cpu() don't
>>> work here, I will try to investigate better why. Suggestions are
>>> welcome :)
>>
>> Toolchain issues ? Stack alignment issue ?
> 
> So, after some investigation, the reason is that the code runs when
> caches are still disabled and thus all the memory is treated as
> Device-nGnRnE, requiring aligned accesses.

You mean 8-byte aligned accesses, correct ?

> The return value of
> fdt_getprop() is guaranteed to be aligned to a 4 byte boundary (but
> not 8)

The return value of fdt_getprop() is a pointer, thus 8byte long on
aarch64 and thus aligned to 8 bytes on the stack unless there is
some real problem.

> and therefore a 32-bit type must be used to avoid alignment
> faults. Probably the comment should be updated to explain this better.

Take a look at what uniphier does : arch/arm/mach-uniphier/dram_init.c
Does that approach with fdt64_t work for you?

> Beniamino
> 
Code in question:

+int dram_init(void)
+{
+	const fdt32_t *val;
+	int offset;
+	int len;
+
+	offset = fdt_path_offset(gd->fdt_blob, "/memory");
+	if (offset < 0)
+		return -EINVAL;
+
+	val = fdt_getprop(gd->fdt_blob, offset, "reg", &len);
+	if (len < sizeof(*val) * 4)
+		return -EINVAL;
+
+	/* Don't use fdt64_t to avoid unaligned access */
+	gd->ram_size = (uint64_t)fdt32_to_cpu(val[2]) << 32;
+	gd->ram_size |= fdt32_to_cpu(val[3]);
+
+	return 0;
+}

-- 
Best regards,
Marek Vasut

  reply	other threads:[~2016-04-12 22:26 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-10 15:30 [U-Boot] [PATCH v3 0/2] Amlogic Meson GXBaby and ODROID-C2 support Beniamino Galvani
2016-04-10 15:30 ` [U-Boot] [PATCH v3 1/2] net: designware: fix descriptor layout and warnings on 64-bit archs Beniamino Galvani
2016-04-10 23:59   ` Marek Vasut
2016-04-11 20:46     ` Beniamino Galvani
2016-04-10 15:30 ` [U-Boot] [PATCH v3 2/2] arm: add initial support for Amlogic Meson and ODROID-C2 Beniamino Galvani
2016-04-11  0:08   ` Marek Vasut
2016-04-11 21:02     ` Beniamino Galvani
2016-04-11 21:08       ` Marek Vasut
2016-04-12 21:50         ` Beniamino Galvani
2016-04-12 22:26           ` Marek Vasut [this message]
2016-04-13 11:22             ` Beniamino Galvani
2016-04-13 11:52               ` Marek Vasut
2016-04-13 21:38                 ` Alexander Graf
2016-04-13 22:34                   ` Tom Rini
2016-04-13 22:42                     ` Alexander Graf
2016-04-13 22:51                       ` Tom Rini
2016-04-13 22:53                         ` Alexander Graf
2016-04-13 23:12                           ` Marek Vasut
2016-04-14  7:08                             ` Alexander Graf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=570D7623.8020603@denx.de \
    --to=marex@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox