From: Manfred Schlaegl Date: Thu, 18 May 2017 17:54:02 +0200 Subject: [U-Boot] [PATCH] ARM: fixed relocation using proper alignment In-Reply-To: References: <81d82db6-d9a9-4400-0acf-5014f38c1668@ti.com> <98fa25c0-16df-8337-6bc7-29b4ad41ea96@ginzinger.com> <60f6afe3-d339-6335-e97f-b5ace9dce5ef@ti.com> <20170518165916.211429c2@ipc1.ka-ro> <34e3cff3-30d8-7a69-15c1-b533a17be505@ginzinger.com> Message-ID: <9ed4e643-119a-e8cf-b665-62e09f210349@ginzinger.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: quoted-printable To: u-boot@lists.denx.de On 2017-05-18 17:37, Jagan Teki wrote: > On Thu, May 18, 2017 at 9:04 PM, Manfred Schlaegl > wrote: >> On 2017-05-18 16:59, Lothar Wa=C3=9Fmann wrote: >>> Manfred Schlaegl wrote: >>> >>>> On 2017-05-17 06:13, Lokesh Vutla wrote: >>>>> >>>>> >>>>> On Tuesday 16 May 2017 07:59 PM, Manfred Schlaegl wrote: >>>>>> On 2017-05-11 08:53, Lokesh Vutla wrote: >>>>>>> >>>>>>> >>>>>>> On Wednesday 10 May 2017 07:11 PM, Manfred Schlaegl wrote: >>>>>>>> Using u-boot-2017.05 on i.MX6UL we ran into following problem: >>>>>>>> Initially U-Boot could be started normally. >>>>>>>> If we added one random command in configuration, the newly generat= ed >>>>>>>> image hung at startup (last output was DRAM: 256 MiB). >>>>>>>> >>>>>>>> We tracked this down to a data abort within relocation (relocated_= code). >>>>>>>> >>> [...] >>>>>> In a good case (rel_dyn_start aligned to 8 byte), u-boot is starting= up normally >>>>>> rel_dyn_start is 0x8785FC28 >>>>>> rel_dyn_end is 0x87857BD0 >>>>>> A dump of this memory area shows no abnormality >>>>>> >>>>>> In a bad case (same source, but rel_dyn_start aligned to 4 byte), th= e data abort happens >>>>>> rel_dyn_start is 0x8785FC24 >>>>>> rel_dyn_end is 0x87857BCC >>>>>> So we have the same size of 32856 bytes but a memory dump showed exa= ctly one difference, which is >>>>>> very interesting: >>>>>> >>>>>> At offset 0x610 (relative to rel_dyn_start) we have following differ= ence >>>>>> -00000610 30 3e 80 87 17 00 00 00 34 3e 80 87 00 00 00 00 |0>....= ..4>......| >>>>>> +00000610 30 3e 80 87 17 00 00 00 00 00 00 00 17 00 00 00 |0>....= ..........| >>>>> >>>>> Looks like someone is corrupting the data(assuming). Is it all 0's ju= st >>>>> at this location or continuously after this? >>>> >>>> No. Above diff is the only difference of the good and bad case in memo= ry located between >>>> rel_dyn_start and rel_dyn_end. >>>> >>>> To see if it might be a corruption I compared the the rel_dyn with the= created u-boot.img and >>>> found the same difference >>>> -00000610 30 3e 80 87 17 00 00 00 34 3e 80 87 17 00 00 00 |0>......= 4>......| <--- generated image >>>> +00000610 30 3e 80 87 17 00 00 00 00 00 00 00 17 00 00 00 |0>......= ........| <--- memory dump >>>> >>>> So it must be some kind of corruption. >>>> >>> This can be caused by a static variable, that is written to prior to >>> relocation. Since the .rel section overlays the .bss section, the write >>> to a variable in the BSS will corrupt the relocation data. >>> >> >> Yes! That's it! >> >> Using a watchpoint I tracked the corruption down to an early write to a = static variable in our custom code. >> >> So finally: >> The whole thing was a problem in a custom modification and was solved th= ere. It has no implication on u-boot itself. >=20 > Any pointers on which kind of custom modification, because I could see > the similar issue with upstream u-boot. >=20 > thanks! >=20 For compatibility reasons we use a custom environment implementation. In th= is implementation we had an write access to a static variable in env_init. env_init is called before relocation. As Lothar stated out .bss overlaps .rel at this stage, so we corrupted .rel. Hope that helped! Best regards, Manfred