[uClinux-dev] XIP broken in 2.4.31-uc0 ? (fwd)

David McCullough davidm at snapgear.com
Thu Oct 6 00:10:09 EDT 2005


Erwin,

Can you back out the previous patches you have tried and get the latest
updates from cvs for these files:

	linux-2.4.x/mmnommu/mmap.c
	linux-2.4.x/fs/proc/nommu.c
	linux-2.4.x/lib/rbtree.c
	linux-2.4.x/fs/binfmt_flat.c
	linux-2.4.x/drivers/block/blkmem.c

Otherwise I have attached a patch just in case :-)

This should see XIP working without errors and fix various problems
surrounding it and the VMA house keeping.  It is running ok for me on
Xcopilot and the ARMulator.  Actually it was previously running for the
simple "it boots test", unfortunately I didn't try much harder than that
before pushing out 2.4.31 :-(

Cheers,
Davidm


Jivin Erwin Authried lays it down ...
> Am Don, den 22.09.2005 schrieb Erwin Authried um 11:57:
> > Am Mit, den 21.09.2005 schrieb Michael Leslie um 22:27:
> > > Hi Erwin,
> > > 
> > > I sent Greg a couple of patches for this just recently, based on 
> > > suggestions from Greg and David Howells. Part of the solution also 
> > > required satisfying the requirements of MAGIC_ROM_PTR in the arch/ code.
> > > 
> > > I've attached the patches that got XIP going for me on Motorola 68VZ328.
> > > They also seem _not_ to break non-XIP (I've tested on Coldfire).
> > > 
> > > I hope these help.
> > > 
> > > 
> > > Regards,
> > > 
> > > Michael Leslie,
> > > Arcturus Networks Inc.
> > > 
> > Hello Michael,
> > 
> > thanks a lot! The patch still doesn't solve the problem completely. Now
> > I'm getting a alignment exception in put_vma when I invoke the
> > application a second time. from the backtrace, the functions are:
> > 
> > sys_exit -> do_exit -> mmput -> exit_mmap -> put_vma
> > 
> > I verified that there's no problem when the load-to-ram flag is set. The
> > same application works with XIP on an older kernel (2.4.27-uc1).
> > 
> > Regards,
> > Erwin
> > 
> I found the reason for the problem now. The execption occured in kfree
> that's called from put_vma, instead of in put_vma as reported before.
> kfree crashed because it was called with the address of the
> application's entry point in flash. 
> The base address of romfs is calculated in blkmem.c, with
> ioremap_nocache(). In most uclinux architectures, ioremap is just a 1:1
> translation. In my case (w90n740), ioremap returns a pointer to
> noncacheable memory, by setting Bit 31 in the address. I guess that this
> causes  is_in_rom() to return false. At least, after removing the
> ioremap_nocache line in blkmem.c, everything worked fine. 
> But still, I have some doubts about blkmem:
> 
> * ioremap_nocache returns a pointer to memory fro non-cached access by
> definition. That will slow down XIP execution considerably if ioremap
> isn't a dummy macro.
> 
> * If blkmem isn't inside flash, kfree would try to free non-malloced
> memory (just a guess, I haven't verified that) when the application
> exits.
> 
> Regards,
> Erwin
> 
> 
> _______________________________________________
> uClinux-dev mailing list
> uClinux-dev at uclinux.org
> http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
> This message was resent by uclinux-dev at uclinux.org

-- 
David McCullough, davidm at cyberguard.com.au, Custom Embedded Solutions + Security
Ph:+61 734352815 Fx:+61 738913630 http://www.uCdot.org http://www.cyberguard.com
-------------- next part --------------
Index: linux-2.4.x/mmnommu/mmap.c
===================================================================
RCS file: /var/cvs/uClinux-2.4.x/mmnommu/mmap.c,v
retrieving revision 1.28
diff -u -r1.28 mmap.c
--- linux-2.4.x/mmnommu/mmap.c	25 Jul 2005 01:54:56 -0000	1.28
+++ linux-2.4.x/mmnommu/mmap.c	6 Oct 2005 03:57:38 -0000
@@ -1419,6 +1419,22 @@
 				membacked = mapping->membacked;
 		}
 
+		/*
+		 * keep romptr alive a little longer until everything is converted
+		 * to membacked
+		 */
+		if (file->f_op->romptr && !(prot & PROT_WRITE)) {
+			struct vm_area_struct my_vma;
+			memset(&my_vma, 0, sizeof(my_vma));
+			my_vma.vm_file	= file;
+			my_vma.vm_flags	= calc_vm_flags(prot,flags);
+			my_vma.vm_start	= addr;
+			my_vma.vm_end	= addr + len;
+			my_vma.vm_pgoff	= pgoff;
+			if (file->f_op->romptr(file, &my_vma) == 0)
+				membacked = 1;
+		}
+
 		if (flags & MAP_SHARED) {
 			/* do checks for writing, appending and locking */
 			if ((prot & PROT_WRITE) && !(file->f_mode & FMODE_WRITE))
Index: linux-2.4.x/fs/proc/nommu.c
===================================================================
RCS file: /var/cvs/uClinux-2.4.x/fs/proc/nommu.c,v
retrieving revision 1.1
diff -u -r1.1 nommu.c
--- linux-2.4.x/fs/proc/nommu.c	14 Jul 2005 00:46:16 -0000	1.1
+++ linux-2.4.x/fs/proc/nommu.c	6 Oct 2005 03:57:38 -0000
@@ -90,6 +90,7 @@
 			next = _rb;
 			break;
 		}
+		pos--;
 	}
 
 	return next;
Index: linux-2.4.x/lib/rbtree.c
===================================================================
RCS file: /var/cvs/uClinux-2.4.x/lib/rbtree.c,v
retrieving revision 1.1.1.3
diff -u -r1.1.1.3 rbtree.c
--- linux-2.4.x/lib/rbtree.c	1 Feb 2005 11:48:49 -0000	1.1.1.3
+++ linux-2.4.x/lib/rbtree.c	6 Oct 2005 03:57:39 -0000
@@ -332,6 +332,7 @@
 		node = node->rb_right;
 		while (node->rb_left)
 			node = node->rb_left;
+		return node;
 	}
 
 	/* No right-hand children.  Everything down and left is
@@ -355,6 +356,7 @@
 		node = node->rb_left;
 		while (node->rb_right)
 			node = node->rb_right;	 
+		return node;
 	}
 
 	/* No left-hand children. Go up till we find an ancestor which
Index: linux-2.4.x/fs/binfmt_flat.c
===================================================================
RCS file: /var/cvs/uClinux-2.4.x/fs/binfmt_flat.c,v
retrieving revision 1.45
diff -u -r1.45 binfmt_flat.c
--- linux-2.4.x/fs/binfmt_flat.c	15 Jul 2005 03:10:50 -0000	1.45
+++ linux-2.4.x/fs/binfmt_flat.c	6 Oct 2005 03:57:41 -0000
@@ -759,7 +759,7 @@
 
 		down_write(&current->mm->mmap_sem);
 		textpos = do_mmap(bprm->file, 0, text_len, PROT_READ|PROT_EXEC,
-				0, 0);
+				MAP_PRIVATE, 0);
 		up_write(&current->mm->mmap_sem);
 		if (!textpos  || textpos >= (unsigned long) -4096) {
 			if (!textpos)
Index: linux-2.4.x/drivers/block/blkmem.c
===================================================================
RCS file: /cvs/sw/linux-2.4.x/drivers/block/blkmem.c,v
retrieving revision 1.57
diff -u -r1.57 -r1.58 blkmem.c
--- linux-2.4.x/drivers/block/blkmem.c	2 Sep 2005 05:22:21 -0000	1.57
+++ linux-2.4.x/drivers/block/blkmem.c	5 Oct 2005 00:22:46 -0000	1.58
@@ -2779,11 +2779,15 @@
 blkmem_romptr( kdev_t dev, struct vm_area_struct * vma)
 {
   struct arena_t * a = arena + MINOR(dev);
+  int len;
 
   if (a->read_func)
     return -ENOSYS; /* Can't do it, as this arena isn't in the main address space */
 
+  len = vma->vm_end - vma->vm_start;
+
   vma->vm_start = a->address + (vma->vm_pgoff << PAGE_SHIFT);
+  vma->vm_end   = vma->vm_start + len;
   return 0;
 }
 #endif


More information about the uClinux-dev mailing list