From: Dobrica Pavlinusic Date: Thu, 26 Jul 2007 02:15:29 +0000 (-0500) Subject: code cleanup, return meaningfull (even too chatty) messages X-Git-Url: http://git.rot13.org/?p=uloader.git;a=commitdiff_plain;h=a3a378446ad7edffbd2c8937fdc4e0a3bcdf7088 code cleanup, return meaningfull (even too chatty) messages --- diff --git a/Makefile b/Makefile index e2317de..29e5fd7 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,10 @@ # 2.4.17_mvl21-sandpoint and gcc 2.95 # Change INCLUDE to match your environment -INCLUDE = -nostdinc -I/opt/embedded/ppc/list/linux-2.4.17_mvl21-sandpoint.ref/include -I/opt/embedded/ppc/list/linux-2.4.17_mvl21-sandpoint.ref/arch/ppc -I/opt/embedded/ppc/toolchain/usr/lib/gcc-lib/powerpc-linux/2.95.3/include + +KERNEL=/rest/ppc/linux-2.4.21-per4 + +INCLUDE = -nostdinc -I$(KERNEL)/include -I$(KERNEL)/arch/ppc CFLAGS = -D__KERNEL__ -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fomit-frame-pointer -fno-strict-aliasing -fno-common -fsigned-char -msoft-float -pipe -ffixed-r2 -Wno-uninitialized -mmultiple -mstring -DMODULE @@ -40,3 +43,4 @@ uloader_boot.o: uloader_boot.S $(CC) -c -mregnames uloader_boot.S clean: rm -f uloader.o uloader_mod.o uloader_boot.o + diff --git a/uloader.o b/uloader.o deleted file mode 100644 index 456d186..0000000 Binary files a/uloader.o and /dev/null differ diff --git a/uloader_mod.c b/uloader_mod.c index 4eb0c96..ecd5b8c 100644 --- a/uloader_mod.c +++ b/uloader_mod.c @@ -41,9 +41,11 @@ MODULE_PARM_DESC(uboot, "u-boot file name (must be binary)"); 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, @@ -66,27 +68,42 @@ static struct notifier_block uloader_notifier = { #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; } @@ -116,26 +133,41 @@ static int read_file(char *filename, struct indirect_buffer **indirect_buf) 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;ipaddr[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; } @@ -203,10 +246,12 @@ int init_module(void) 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: