Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[POWERPC] Consolidate cuboot initialization code

The various cuboot platforms (i.e. pre-device tree aware u-boot for
83xx, 85xx and Ebony) share a certain amount of code for parsing the
boot parameters. To a certain extent that's inevitable, since they
platforms have different definitions of the bd_t structure. However,
with some macro work and a helper function, this patch improves the
situation a bit.

In the process, this fixes a bug on Ebony, which was incorrectly
handling the parameters passed form u-boot for the command line (the
bug was copied from 83xx and 85xx which have subsequently been fixed).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Paul Mackerras <paulus@samba.org>

authored by

David Gibson and committed by
Paul Mackerras
85aecac8 b2ba34f3

+56 -37
+1 -1
arch/powerpc/boot/Makefile
··· 44 44 src-wlib := string.S crt0.S stdio.c main.c flatdevtree.c flatdevtree_misc.c \ 45 45 ns16550.c serial.c simple_alloc.c div64.S util.S \ 46 46 gunzip_util.c elf_util.c $(zlib) devtree.c oflib.c ofconsole.c \ 47 - 44x.c ebony.c mv64x60.c mpsc.c mv64x60_i2c.c 47 + 44x.c ebony.c mv64x60.c mpsc.c mv64x60_i2c.c cuboot.c 48 48 src-plat := of.c cuboot-83xx.c cuboot-85xx.c holly.c \ 49 49 cuboot-ebony.c treeboot-ebony.c prpmc2800.c 50 50 src-boot := $(src-wlib) $(src-plat) empty.c
+2 -11
arch/powerpc/boot/cuboot-83xx.c
··· 12 12 13 13 #include "ops.h" 14 14 #include "stdio.h" 15 + #include "cuboot.h" 15 16 16 17 #define TARGET_83xx 17 18 #include "ppcboot.h" 18 19 19 20 static bd_t bd; 20 - extern char _end[]; 21 21 extern char _dtb_start[], _dtb_end[]; 22 22 23 23 static void platform_fixups(void) ··· 52 52 void platform_init(unsigned long r3, unsigned long r4, unsigned long r5, 53 53 unsigned long r6, unsigned long r7) 54 54 { 55 - unsigned long end_of_ram = bd.bi_memstart + bd.bi_memsize; 56 - unsigned long avail_ram = end_of_ram - (unsigned long)_end; 57 - 58 - memcpy(&bd, (bd_t *)r3, sizeof(bd)); 59 - loader_info.initrd_addr = r4; 60 - loader_info.initrd_size = r4 ? r5 - r4 : 0; 61 - loader_info.cmdline = (char *)r6; 62 - loader_info.cmdline_len = r7 - r6; 63 - 64 - simple_alloc_init(_end, avail_ram - 1024*1024, 32, 64); 55 + CUBOOT_INIT(); 65 56 ft_init(_dtb_start, _dtb_end - _dtb_start, 32); 66 57 serial_console_init(); 67 58 platform_ops.fixups = platform_fixups;
+2 -11
arch/powerpc/boot/cuboot-85xx.c
··· 12 12 13 13 #include "ops.h" 14 14 #include "stdio.h" 15 + #include "cuboot.h" 15 16 16 17 #define TARGET_85xx 17 18 #include "ppcboot.h" 18 19 19 20 static bd_t bd; 20 - extern char _end[]; 21 21 extern char _dtb_start[], _dtb_end[]; 22 22 23 23 static void platform_fixups(void) ··· 53 53 void platform_init(unsigned long r3, unsigned long r4, unsigned long r5, 54 54 unsigned long r6, unsigned long r7) 55 55 { 56 - unsigned long end_of_ram = bd.bi_memstart + bd.bi_memsize; 57 - unsigned long avail_ram = end_of_ram - (unsigned long)_end; 58 - 59 - memcpy(&bd, (bd_t *)r3, sizeof(bd)); 60 - loader_info.initrd_addr = r4; 61 - loader_info.initrd_size = r4 ? r5 - r4 : 0; 62 - loader_info.cmdline = (char *)r6; 63 - loader_info.cmdline_len = r7 - r6; 64 - 65 - simple_alloc_init(_end, avail_ram - 1024*1024, 32, 64); 56 + CUBOOT_INIT(); 66 57 ft_init(_dtb_start, _dtb_end - _dtb_start, 32); 67 58 serial_console_init(); 68 59 platform_ops.fixups = platform_fixups;
+2 -14
arch/powerpc/boot/cuboot-ebony.c
··· 15 15 #include "ops.h" 16 16 #include "stdio.h" 17 17 #include "44x.h" 18 + #include "cuboot.h" 18 19 19 20 #define TARGET_44x 20 21 #include "ppcboot.h" 21 22 22 23 static bd_t bd; 23 - extern char _end[]; 24 - 25 - BSS_STACK(4096); 26 24 27 25 void platform_init(unsigned long r3, unsigned long r4, unsigned long r5, 28 26 unsigned long r6, unsigned long r7) 29 27 { 30 - unsigned long end_of_ram = bd.bi_memstart + bd.bi_memsize; 31 - unsigned long avail_ram = end_of_ram - (unsigned long)_end; 32 - 33 - memcpy(&bd, (bd_t *)r3, sizeof(bd)); 34 - loader_info.initrd_addr = r4; 35 - loader_info.initrd_size = r4 ? r5 : 0; 36 - loader_info.cmdline = (char *)r6; 37 - loader_info.cmdline_len = r7 - r6; 38 - 39 - simple_alloc_init(_end, avail_ram, 32, 64); 40 - 28 + CUBOOT_INIT(); 41 29 ebony_init(&bd.bi_enetaddr, &bd.bi_enet1addr); 42 30 }
+35
arch/powerpc/boot/cuboot.c
··· 1 + /* 2 + * Compatibility for old (not device tree aware) U-Boot versions 3 + * 4 + * Author: Scott Wood <scottwood@freescale.com> 5 + * Consolidated using macros by David Gibson <david@gibson.dropbear.id.au> 6 + * 7 + * Copyright 2007 David Gibson, IBM Corporation. 8 + * Copyright (c) 2007 Freescale Semiconductor, Inc. 9 + * 10 + * This program is free software; you can redistribute it and/or modify it 11 + * under the terms of the GNU General Public License version 2 as published 12 + * by the Free Software Foundation. 13 + */ 14 + 15 + #include "ops.h" 16 + #include "stdio.h" 17 + 18 + #include "ppcboot.h" 19 + 20 + extern char _end[]; 21 + extern char _dtb_start[], _dtb_end[]; 22 + 23 + void cuboot_init(unsigned long r4, unsigned long r5, 24 + unsigned long r6, unsigned long r7, 25 + unsigned long end_of_ram) 26 + { 27 + unsigned long avail_ram = end_of_ram - (unsigned long)_end; 28 + 29 + loader_info.initrd_addr = r4; 30 + loader_info.initrd_size = r4 ? r5 - r4 : 0; 31 + loader_info.cmdline = (char *)r6; 32 + loader_info.cmdline_len = r7 - r6; 33 + 34 + simple_alloc_init(_end, avail_ram - 1024*1024, 32, 64); 35 + }
+14
arch/powerpc/boot/cuboot.h
··· 1 + #ifndef _PPC_BOOT_CUBOOT_H_ 2 + #define _PPC_BOOT_CUBOOT_H_ 3 + 4 + void cuboot_init(unsigned long r4, unsigned long r5, 5 + unsigned long r6, unsigned long r7, 6 + unsigned long end_of_ram); 7 + 8 + #define CUBOOT_INIT() \ 9 + do { \ 10 + memcpy(&bd, (bd_t *)r3, sizeof(bd)); \ 11 + cuboot_init(r4, r5, r6, r7, bd.bi_memstart + bd.bi_memsize); \ 12 + } while (0) 13 + 14 + #endif /* _PPC_BOOT_CUBOOT_H_ */