[PATCH 2/2] uimage: disable zero page when loading to SDRAM at address 0x0

Sascha Hauer s.hauer at pengutronix.de
Thu Oct 15 04:35:22 EDT 2020


On Thu, Oct 15, 2020 at 09:40:05AM +0200, Michael Tretter wrote:
> On Wed, 14 Oct 2020 18:33:25 +0200, Ahmad Fatoum wrote:
> > On 10/14/20 5:08 PM, Michael Tretter wrote:
> > > If the SDRAM is mapped to address 0x0 and an image should be loaded to
> > > to the SDRAM without offset, Barebox would normally trap the access as a
> > > null pointer.
> > > 
> > > However, since Linux kernel commit cfa7ede20f13 ("arm64: set TEXT_OFFSET
> > > to 0x0 in preparation for removing it entirely") no offset is the
> > > default for arm64. Therefore, copying the image to 0x0 of the SDRAM is
> > > necessary.
> > > 
> > > Disable the zero page trap for copying an image to address 0x0.
> > > 
> > > Signed-off-by: Michael Tretter <m.tretter at pengutronix.de>
> > > ---
> > >  common/uimage.c | 18 ++++++++++++++++--
> > >  1 file changed, 16 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/common/uimage.c b/common/uimage.c
> > > index a84b8fddc4e7..b1e9b402e98a 100644
> > > --- a/common/uimage.c
> > > +++ b/common/uimage.c
> > > @@ -27,6 +27,7 @@
> > >  #include <rtc.h>
> > >  #include <filetype.h>
> > >  #include <memory.h>
> > > +#include <zero_page.h>
> > >  
> > >  static inline int uimage_is_multi_image(struct uimage_handle *handle)
> > >  {
> > > @@ -359,7 +360,13 @@ static int uimage_sdram_flush(void *buf, unsigned int len)
> > >  		}
> > >  	}
> > >  
> > > -	memcpy(uimage_buf + uimage_size, buf, len);
> > > +	if (zero_page_contains((unsigned long)uimage_buf + uimage_size)) {
> > > +		zero_page_disable();
> > > +		memcpy(uimage_buf + uimage_size, buf, len);
> > > +		zero_page_enable();
> > 
> > If this remains, please add a memcpy_notrap or something.
> 
> Should I check the destination before calling memcpy_notrap or should I always
> call the memcpy_notrap if there is a possibility to copy to 0x0 and check for
> the destination within the function?
> 
> I fear that having such a "simple" function would encourage to use it more
> often. I would prefer to make the code to use it more clumsy and make it
> (similar to data_abort_mask()) the responsibility of the caller to be aware
> that bad things might happen when the zero_page is disabled.

That's more a reason to hide that behind a function, because then you
can easily catch and if necessary fix all users. Way easier than fixing
all open coded places.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list