MODULE_PARM_DESC(laddr, "u-boot load address");
static char* uboot = "u-boot.bin";
-static unsigned long laddr = 0x01f00000;
+// 0x01f00000
+// 0x07f00000
+static unsigned long laddr = 0x07f00000;
-#define LOW_MEM 0x800000 /* no smaller than kernel + 1M (bss) + initrd */
+#define LOW_MEM 0x00800000 /* no smaller than kernel + 1M (bss) + initrd */
void load_uboot(unsigned long pa_load_uboot,
unsigned long pa_uboot_buf,
#define MAX_INDIRECT_BUFFER_SIZE ((PAGE_SIZE/4-1)*PAGE_SIZE)
+#define VMALLOC_SIZE ((LOW_MEM+PAGE_SIZE-1)/PAGE_SIZE)*4
+
/*
* Allocate a page with physical address >= LOWMEM
*/
static void **save;
-static int saved_pages;
+static int saved_pages = 0;
static void *alloc_high_page(void)
{
void *ptr;
if(!save)
{
- save = vmalloc(((LOW_MEM+PAGE_SIZE-1)/PAGE_SIZE)*4);
- if(!save) return 0;
+ save = vmalloc( VMALLOC_SIZE );
+ if(!save) {
+ printk(KERN_INFO "can't vmalloc(%x)\n", VMALLOC_SIZE );
+ return 0;
+ } else {
+ printk(KERN_INFO "vmalloc(%x) = %08x\n", VMALLOC_SIZE, save );
+ }
}
while(1)
{
ptr = kmalloc(PAGE_SIZE, GFP_KERNEL);
- if(!ptr) return 0;
- if(__pa(ptr) >= LOW_MEM) break;
+ if(!ptr) {
+ printk(KERN_INFO "can't kmalloc(%0x)\n", PAGE_SIZE);
+ return 0;
+ }
+ if( __pa(ptr) >= LOW_MEM ) {
+ printk(KERN_INFO "kmalloc(%x) = %08x __pa: %08x >= %08x skipped\n", PAGE_SIZE, ptr, __pa(ptr), LOW_MEM );
+ break;
+ }
+ printk(KERN_INFO "%d: kmalloc(%x) = %08x __pa: %08x\n", saved_pages, PAGE_SIZE, ptr, __pa(ptr) );
save[saved_pages++] = ptr;
}
+ printk(KERN_INFO "alloc_high_page %08x __pa: %08x\n", ptr, __pa(ptr) );
return ptr;
}
int err;
file = filp_open(filename, O_RDONLY, 0);
- if(IS_ERR(file))
+ if(IS_ERR(file)) {
+ printk(KERN_INFO "can't open filename %s\n", filename);
return PTR_ERR(file);
+ }
+ printk(KERN_INFO "opened file %s at position %x", filename, file->pos);
+ file->pos = 0;
err = -EIO;
- if(!file->f_op || !file->f_op->read)
+ if(!file->f_op || !file->f_op->read) {
+ printk(KERN_INFO "EIO\n");
goto out;
+ }
err = -EACCES;
inode = file->f_dentry->d_inode;
- if(!S_ISREG(inode->i_mode))
+ if(!S_ISREG(inode->i_mode)) {
+ printk(KERN_INFO "EACCES\n");
goto out;
+ }
err = -ENOMEM;
ibuf = (struct indirect_buffer*)alloc_high_page();
- if(!ibuf) goto out;
+ if(!ibuf) {
+ printk(KERN_INFO "ENOMEM\n");
+ goto out;
+ }
memset(ibuf, 0, PAGE_SIZE);
- if(inode->i_size > MAX_INDIRECT_BUFFER_SIZE) goto out2;
+ if(inode->i_size > MAX_INDIRECT_BUFFER_SIZE) {
+ printk(KERN_INFO "## %8x > %8x\n", inode->i_size, MAX_INDIRECT_BUFFER_SIZE);
+ goto out2;
+ }
size = (size_t)inode->i_size;
ibuf->size = size;
+ printk(KERN_INFO "loading %s %d bytes\n", filename, size);
for(i=0;i<size;i+=PAGE_SIZE)
{
err = -ENOMEM;
buf = alloc_high_page();
- if(!buf) goto out2;
+ if(!buf) {
+ printk(KERN_INFO "can't allocate page %d\n", i);
+ goto out2;
+ }
ibuf->paddr[i/PAGE_SIZE] = __pa(buf);
err = -EIO;
file->f_pos = i;
fs = get_fs();
set_fs(KERNEL_DS);
+ printk(KERN_DEBUG "KERNEL_DS\n");
got = file->f_op->read(file, buf, todo, &file->f_pos);
set_fs(fs);
- if(got != todo) goto out2;
+ printk(KERN_DEBUG "fs\n");
+ if(got != todo) {
+ printk(KERN_INFO "for block %d got %d expected %8x\n", i, got, todo);
+ goto out2;
+ }
}
*indirect_buf = ibuf;
err = 0;
+ printk(KERN_INFO "loaded %s\n", filename);
out:
filp_close(file, NULL);
+ printk(KERN_INFO "return code %d\n", err);
return err;
out2:
+ printk(KERN_INFO "failed loading %s\n", filename);
free_ibuffer(ibuf);
goto out;
}
int err;
printk(KERN_INFO "uloader module loaded\n");
- printk(KERN_INFO "uboot=%s\n", uboot);
+ printk(KERN_INFO "uboot=%s<--\n", uboot);
- if((err = read_file(uboot, &uboot_buf)))
+ if((err = read_file(uboot, &uboot_buf))) {
+ printk(KERN_INFO "Error loading %s\n", uboot);
goto out;
+ }
register_reboot_notifier(&uloader_notifier);
return 0;
out: