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

[POWERPC] Use embedded libfdt in the bootwrapper

This incorporates libfdt (from the source embedded in an earlier
commit) into the wrapper.a library used by the bootwrapper. This
includes adding a libfdt_env.h file, which the libfdt sources need in
order to integrate into the bootwrapper environment, and a
libfdt-wrapper.c which provides glue to connect the bootwrapper's
abstract device tree callbacks to the libfdt functions.

In addition, this changes the various wrapper and platform files to
use libfdt functions instead of the older flatdevtree.c library.

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
2f0dfeaa 1cade994

+219 -16
+5 -1
arch/powerpc/boot/Makefile
··· 33 33 BOOTCFLAGS += -fno-stack-protector 34 34 endif 35 35 36 - BOOTCFLAGS += -I$(obj) -I$(srctree)/$(obj) 36 + BOOTCFLAGS += -I$(obj) -I$(srctree)/$(obj) -I$(srctree)/$(src)/libfdt 37 37 38 38 $(obj)/4xx.o: BOOTCFLAGS += -mcpu=440 39 39 $(obj)/ebony.o: BOOTCFLAGS += -mcpu=440 ··· 46 46 $(addprefix $(obj)/,$(zlib) gunzip_util.o main.o): \ 47 47 $(addprefix $(obj)/,$(zliblinuxheader)) $(addprefix $(obj)/,$(zlibheader)) 48 48 49 + src-libfdt := fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c 49 50 src-wlib := string.S crt0.S stdio.c main.c flatdevtree.c flatdevtree_misc.c \ 51 + $(addprefix libfdt/,$(src-libfdt)) libfdt-wrapper.c \ 50 52 ns16550.c serial.c simple_alloc.c div64.S util.S \ 51 53 gunzip_util.c elf_util.c $(zlib) devtree.c oflib.c ofconsole.c \ 52 54 4xx.c ebony.c mv64x60.c mpsc.c mv64x60_i2c.c cuboot.c bamboo.c \ ··· 103 101 cmd_bootar = $(CROSS32AR) -cr $@.$$$$ $(filter-out FORCE,$^); mv $@.$$$$ $@ 104 102 105 103 $(patsubst %.c,%.o, $(filter %.c, $(src-boot))): %.o: %.c FORCE 104 + $(Q)mkdir -p $(dir $@) 106 105 $(call if_changed_dep,bootcc) 107 106 $(patsubst %.S,%.o, $(filter %.S, $(src-boot))): %.o: %.S FORCE 107 + $(Q)mkdir -p $(dir $@) 108 108 $(call if_changed_dep,bootas) 109 109 110 110 $(obj)/wrapper.a: $(obj-wlib) FORCE
+1 -1
arch/powerpc/boot/bamboo.c
··· 42 42 platform_ops.exit = ibm44x_dbcr_reset; 43 43 bamboo_mac0 = mac0; 44 44 bamboo_mac1 = mac1; 45 - ft_init(_dtb_start, 0, 32); 45 + fdt_init(_dtb_start); 46 46 serial_console_init(); 47 47 }
+1 -1
arch/powerpc/boot/cuboot-52xx.c
··· 53 53 unsigned long r6, unsigned long r7) 54 54 { 55 55 CUBOOT_INIT(); 56 - ft_init(_dtb_start, _dtb_end - _dtb_start, 32); 56 + fdt_init(_dtb_start); 57 57 serial_console_init(); 58 58 platform_ops.fixups = platform_fixups; 59 59 }
+1 -1
arch/powerpc/boot/cuboot-83xx.c
··· 52 52 unsigned long r6, unsigned long r7) 53 53 { 54 54 CUBOOT_INIT(); 55 - ft_init(_dtb_start, _dtb_end - _dtb_start, 32); 55 + fdt_init(_dtb_start); 56 56 serial_console_init(); 57 57 platform_ops.fixups = platform_fixups; 58 58 }
+1 -1
arch/powerpc/boot/cuboot-85xx.c
··· 53 53 unsigned long r6, unsigned long r7) 54 54 { 55 55 CUBOOT_INIT(); 56 - ft_init(_dtb_start, _dtb_end - _dtb_start, 32); 56 + fdt_init(_dtb_start); 57 57 serial_console_init(); 58 58 platform_ops.fixups = platform_fixups; 59 59 }
+1 -1
arch/powerpc/boot/cuboot-8xx.c
··· 41 41 unsigned long r6, unsigned long r7) 42 42 { 43 43 CUBOOT_INIT(); 44 - ft_init(_dtb_start, _dtb_end - _dtb_start, 32); 44 + fdt_init(_dtb_start); 45 45 serial_console_init(); 46 46 platform_ops.fixups = platform_fixups; 47 47 }
+1 -1
arch/powerpc/boot/cuboot-hpc2.c
··· 42 42 unsigned long r6, unsigned long r7) 43 43 { 44 44 CUBOOT_INIT(); 45 - ft_init(_dtb_start, _dtb_end - _dtb_start, 32); 45 + fdt_init(_dtb_start); 46 46 serial_console_init(); 47 47 platform_ops.fixups = platform_fixups; 48 48 }
+1 -1
arch/powerpc/boot/cuboot-pq2.c
··· 255 255 unsigned long r6, unsigned long r7) 256 256 { 257 257 CUBOOT_INIT(); 258 - ft_init(_dtb_start, _dtb_end - _dtb_start, 32); 258 + fdt_init(_dtb_start); 259 259 serial_console_init(); 260 260 platform_ops.fixups = pq2_platform_fixups; 261 261 }
+1 -1
arch/powerpc/boot/cuboot-sequoia.c
··· 51 51 CUBOOT_INIT(); 52 52 platform_ops.fixups = sequoia_fixups; 53 53 platform_ops.exit = ibm44x_dbcr_reset; 54 - ft_init(_dtb_start, 0, 32); 54 + fdt_init(_dtb_start); 55 55 serial_console_init(); 56 56 }
+1 -1
arch/powerpc/boot/ebony.c
··· 146 146 platform_ops.exit = ibm44x_dbcr_reset; 147 147 ebony_mac0 = mac0; 148 148 ebony_mac1 = mac1; 149 - ft_init(_dtb_start, _dtb_end - _dtb_start, 32); 149 + fdt_init(_dtb_start); 150 150 serial_console_init(); 151 151 }
+1 -1
arch/powerpc/boot/ep88xc.c
··· 45 45 mem_size *= 1024 * 1024; 46 46 simple_alloc_init(_end, mem_size - (unsigned long)_end, 32, 64); 47 47 48 - ft_init(_dtb_start, _dtb_end - _dtb_start, 32); 48 + fdt_init(_dtb_start); 49 49 50 50 planetcore_set_stdout_path(table); 51 51
+1 -1
arch/powerpc/boot/holly.c
··· 28 28 u32 heapsize = 0x8000000 - (u32)_end; /* 128M */ 29 29 30 30 simple_alloc_init(_end, heapsize, 32, 64); 31 - ft_init(_dtb_start, 0, 4); 31 + fdt_init(_dtb_start); 32 32 serial_console_init(); 33 33 }
+182
arch/powerpc/boot/libfdt-wrapper.c
··· 1 + /* 2 + * This file does the necessary interface mapping between the bootwrapper 3 + * device tree operations and the interface provided by shared source 4 + * files flatdevicetree.[ch]. 5 + * 6 + * Copyright 2007 David Gibson, IBM Corporation. 7 + * 8 + * This library is free software; you can redistribute it and/or 9 + * modify it under the terms of the GNU General Public License as 10 + * published by the Free Software Foundation; either version 2 of the 11 + * License, or (at your option) any later version. 12 + * 13 + * This library is distributed in the hope that it will be useful, but 14 + * WITHOUT ANY WARRANTY; without even the implied warranty of 15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 + * General Public License for more details. 17 + * 18 + * You should have received a copy of the GNU General Public License 19 + * along with this library; if not, write to the Free Software 20 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 21 + * 02110-1301 USA 22 + */ 23 + 24 + #include <stddef.h> 25 + #include <stdio.h> 26 + #include <page.h> 27 + #include <libfdt.h> 28 + #include "ops.h" 29 + 30 + #define DEBUG 0 31 + #define BAD_ERROR(err) (((err) < 0) \ 32 + && ((err) != -FDT_ERR_NOTFOUND) \ 33 + && ((err) != -FDT_ERR_EXISTS)) 34 + 35 + #define check_err(err) \ 36 + ({ \ 37 + if (BAD_ERROR(err) || ((err < 0) && DEBUG)) \ 38 + printf("%s():%d %s\n\r", __FUNCTION__, __LINE__, \ 39 + fdt_strerror(err)); \ 40 + if (BAD_ERROR(err)) \ 41 + exit(); \ 42 + (err < 0) ? -1 : 0; \ 43 + }) 44 + 45 + #define offset_devp(off) \ 46 + ({ \ 47 + int offset = (off); \ 48 + check_err(offset) ? NULL : (void *)(offset+1); \ 49 + }) 50 + 51 + #define devp_offset(devp) (((int)(devp))-1) 52 + 53 + static void *fdt; 54 + static void *buf; /* = NULL */ 55 + 56 + #define EXPAND_GRANULARITY 1024 57 + 58 + static void expand_buf(int minexpand) 59 + { 60 + int size = fdt_totalsize(fdt); 61 + int rc; 62 + 63 + size = _ALIGN(size + minexpand, EXPAND_GRANULARITY); 64 + buf = platform_ops.realloc(buf, size); 65 + if (!buf) 66 + fatal("Couldn't find %d bytes to expand device tree\n\r", size); 67 + rc = fdt_open_into(fdt, buf, size); 68 + if (rc != 0) 69 + fatal("Couldn't expand fdt into new buffer: %s\n\r", 70 + fdt_strerror(rc)); 71 + 72 + fdt = buf; 73 + } 74 + 75 + static void *fdt_wrapper_finddevice(const char *path) 76 + { 77 + return offset_devp(fdt_path_offset(fdt, path)); 78 + } 79 + 80 + static int fdt_wrapper_getprop(const void *devp, const char *name, 81 + void *buf, const int buflen) 82 + { 83 + const void *p; 84 + int len; 85 + 86 + p = fdt_getprop(fdt, devp_offset(devp), name, &len); 87 + if (!p) 88 + return check_err(len); 89 + memcpy(buf, p, min(len, buflen)); 90 + return len; 91 + } 92 + 93 + static int fdt_wrapper_setprop(const void *devp, const char *name, 94 + const void *buf, const int len) 95 + { 96 + int rc; 97 + 98 + rc = fdt_setprop(fdt, devp_offset(devp), name, buf, len); 99 + if (rc == -FDT_ERR_NOSPACE) { 100 + expand_buf(len + 16); 101 + rc = fdt_setprop(fdt, devp_offset(devp), name, buf, len); 102 + } 103 + 104 + return check_err(rc); 105 + } 106 + 107 + static void *fdt_wrapper_get_parent(const void *devp) 108 + { 109 + return offset_devp(fdt_parent_offset(fdt, devp_offset(devp))); 110 + } 111 + 112 + static void *fdt_wrapper_create_node(const void *devp, const char *name) 113 + { 114 + int offset; 115 + 116 + offset = fdt_add_subnode(fdt, devp_offset(devp), name); 117 + if (offset == -FDT_ERR_NOSPACE) { 118 + expand_buf(strlen(name) + 16); 119 + offset = fdt_add_subnode(fdt, devp_offset(devp), name); 120 + } 121 + 122 + return offset_devp(offset); 123 + } 124 + 125 + static void *fdt_wrapper_find_node_by_prop_value(const void *prev, 126 + const char *name, 127 + const char *val, 128 + int len) 129 + { 130 + return offset_devp(fdt_node_offset_by_prop_value(fdt, devp_offset(prev), 131 + name, val, len)); 132 + } 133 + 134 + static char *fdt_wrapper_get_path(const void *devp, char *buf, int len) 135 + { 136 + int rc; 137 + 138 + rc = fdt_get_path(fdt, devp_offset(devp), buf, len); 139 + if (check_err(rc)) 140 + return NULL; 141 + return buf; 142 + } 143 + 144 + static unsigned long fdt_wrapper_finalize(void) 145 + { 146 + int rc; 147 + 148 + rc = fdt_pack(fdt); 149 + if (rc != 0) 150 + fatal("Couldn't pack flat tree: %s\n\r", 151 + fdt_strerror(rc)); 152 + return (unsigned long)fdt; 153 + } 154 + 155 + void fdt_init(void *blob) 156 + { 157 + int err; 158 + 159 + dt_ops.finddevice = fdt_wrapper_finddevice; 160 + dt_ops.getprop = fdt_wrapper_getprop; 161 + dt_ops.setprop = fdt_wrapper_setprop; 162 + dt_ops.get_parent = fdt_wrapper_get_parent; 163 + dt_ops.create_node = fdt_wrapper_create_node; 164 + dt_ops.find_node_by_prop_value = fdt_wrapper_find_node_by_prop_value; 165 + dt_ops.get_path = fdt_wrapper_get_path; 166 + dt_ops.finalize = fdt_wrapper_finalize; 167 + 168 + /* Make sure the dt blob is the right version and so forth */ 169 + fdt = blob; 170 + err = fdt_open_into(fdt, fdt, fdt_totalsize(blob)); 171 + if (err == -FDT_ERR_NOSPACE) { 172 + int bufsize = fdt_totalsize(fdt) + 4; 173 + buf = malloc(bufsize); 174 + err = fdt_open_into(fdt, buf, bufsize); 175 + } 176 + 177 + if (err != 0) 178 + fatal("fdt_init(): %s\n\r", fdt_strerror(err)); 179 + 180 + if (buf) 181 + fdt = buf; 182 + }
+17
arch/powerpc/boot/libfdt_env.h
··· 1 + #ifndef _ARCH_POWERPC_BOOT_LIBFDT_ENV_H 2 + #define _ARCH_POWERPC_BOOT_LIBFDT_ENV_H 3 + 4 + #include <types.h> 5 + #include <string.h> 6 + 7 + typedef u32 uint32_t; 8 + typedef u64 uint64_t; 9 + 10 + #define fdt16_to_cpu(x) (x) 11 + #define cpu_to_fdt16(x) (x) 12 + #define fdt32_to_cpu(x) (x) 13 + #define cpu_to_fdt32(x) (x) 14 + #define fdt64_to_cpu(x) (x) 15 + #define cpu_to_fdt64(x) (x) 16 + 17 + #endif /* _ARCH_POWERPC_BOOT_LIBFDT_ENV_H */
+1
arch/powerpc/boot/ops.h
··· 80 80 81 81 void start(void); 82 82 int ft_init(void *dt_blob, unsigned int max_size, unsigned int max_find_device); 83 + void fdt_init(void *blob); 83 84 int serial_console_init(void); 84 85 int ns16550_console_init(void *devp, struct serial_console_data *scdp); 85 86 int mpsc_console_init(void *devp, struct serial_console_data *scdp);
+1 -2
arch/powerpc/boot/prpmc2800.c
··· 547 547 if (!dtb) 548 548 exit(); 549 549 memmove(dtb, _dtb_start, dt_size); 550 - if (ft_init(dtb, dt_size, 16)) 551 - exit(); 550 + fdt_init(dtb); 552 551 553 552 bridge_base = mv64x60_get_bridge_base(); 554 553
+1 -1
arch/powerpc/boot/ps3.c
··· 131 131 printf("\n-- PS3 bootwrapper --\n"); 132 132 133 133 simple_alloc_init(_end, heapsize, 32, 64); 134 - ft_init(_dtb_start, 0, 4); 134 + fdt_init(_dtb_start); 135 135 136 136 chosen = finddevice("/chosen"); 137 137
+1 -1
arch/powerpc/boot/treeboot-walnut.c
··· 128 128 simple_alloc_init(_end, avail_ram, 32, 32); 129 129 platform_ops.fixups = walnut_fixups; 130 130 platform_ops.exit = ibm40x_dbcr_reset; 131 - ft_init(_dtb_start, _dtb_end - _dtb_start, 32); 131 + fdt_init(_dtb_start); 132 132 serial_console_init(); 133 133 }