Date: Wed, 2 Dec 2009 15:38:32 GMT From: Rafal Jaworowski <raj@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 171273 for review Message-ID: <200912021538.nB2FcWMJ064613@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/chv.cgi?CH=171273 Change 171273 by raj@raj_fdt on 2009/12/02 15:38:30 Initial support for FDT blob handling in loader(8). The following operations are supported: - load blob as a KLD data module - retrieve and validate blob header - list device tree - inspect node properties - run-time manipulate the blob: - modify existing props - add, delete props - add, delete nodes - prapare device tree blob as part of metadata, pass it to the kernel for booting Usage examples can be found here: http://wiki.freebsd.org/FlattenedDeviceTree/loader Affected files ... .. //depot/projects/fdt/sys/boot/fdt/Makefile#1 add .. //depot/projects/fdt/sys/boot/powerpc/uboot/Makefile#2 edit .. //depot/projects/fdt/sys/boot/uboot/common/main.c#2 edit .. //depot/projects/fdt/sys/boot/uboot/common/metadata.c#3 edit .. //depot/projects/fdt/sys/boot/uboot/lib/Makefile#2 edit .. //depot/projects/fdt/sys/boot/uboot/lib/fdt.c#1 add Differences ... ==== //depot/projects/fdt/sys/boot/powerpc/uboot/Makefile#2 (text+ko) ==== @@ -19,6 +19,8 @@ LOADER_GZIP_SUPPORT?= no LOADER_BZIP2_SUPPORT?= no +LOADER_FDT_SUPPORT?= yes + .if ${LOADER_DISK_SUPPORT} == "yes" CFLAGS+= -DLOADER_DISK_SUPPORT .endif @@ -46,6 +48,9 @@ .if ${LOADER_TFTP_SUPPORT} == "yes" CFLAGS+= -DLOADER_TFTP_SUPPORT .endif +.if ${LOADER_FDT_SUPPORT} == "yes" +CFLAGS+= -DLOADER_FDT_SUPPORT +.endif .if !defined(NO_FORTH) # Enable BootForth @@ -71,6 +76,11 @@ .include "${.CURDIR}/../../uboot/common/Makefile.inc" CFLAGS+= -I${.CURDIR}/../../uboot/common +# FDT support library +LIBFDT= ${.OBJDIR}/../../fdt/libfdt.a +CFLAGS+= -I${.CURDIR}/../../fdt +CFLAGS+= -I${.OBJDIR}/../../fdt + # U-Boot standalone support library LIBUBOOT= ${.OBJDIR}/../../uboot/lib/libuboot.a CFLAGS+= -I${.CURDIR}/../../uboot/lib @@ -79,8 +89,8 @@ # where to get libstand from CFLAGS+= -I${.CURDIR}/../../../../lib/libstand/ -DPADD= ${LIBFICL} ${LIBUBOOT} ${LIBSTAND} -LDADD= ${LIBFICL} ${LIBUBOOT} -lstand +DPADD= ${LIBFICL} ${LIBUBOOT} ${LIBFDT} ${LIBSTAND} +LDADD= ${LIBFICL} ${LIBUBOOT} ${LIBFDT} -lstand vers.c: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version ${NEWVERSWHAT} ==== //depot/projects/fdt/sys/boot/uboot/common/main.c#2 (text+ko) ==== @@ -258,3 +258,5 @@ ub_dump_si(si); return (CMD_OK); } + +COMMAND_SET(fdt, "fdt", "flattened device tree handling", command_fdt); ==== //depot/projects/fdt/sys/boot/uboot/common/metadata.c#3 (text+ko) ==== @@ -42,6 +42,8 @@ #include "bootstrap.h" #include "glue.h" +extern int fdt_fixup(void); + /* * Return a 'boothowto' value corresponding to the kernel arguments in * (kargs) and any relevant environment variables. @@ -262,15 +264,15 @@ { #define TMP_MAX_ETH 8 #define TMP_MAX_MR 8 - struct bootinfo *bi; - struct bi_mem_region tmp_mr[TMP_MAX_MR]; - struct bi_eth_addr tmp_eth[TMP_MAX_ETH]; - struct sys_info *si; - char *str, *end; - const char *env; - void *ptr; - u_int8_t tmp_addr[6]; - int i, n, mr_no, eth_no, size; + struct bootinfo *bi; + struct bi_mem_region tmp_mr[TMP_MAX_MR]; + struct bi_eth_addr tmp_eth[TMP_MAX_ETH]; + struct sys_info *si; + char *str, *end; + const char *env; + void *ptr; + uint8_t tmp_addr[6]; + int i, n, mr_no, eth_no, size; if ((si = ub_get_sys_info()) == NULL) panic("can't retrieve U-Boot sysinfo"); @@ -370,7 +372,7 @@ int md_load(char *args, vm_offset_t *modulep) { - struct preloaded_file *kfp; + struct preloaded_file *kfp, *bfp; struct preloaded_file *xp; struct file_metadata *md; struct bootinfo *bip; @@ -379,6 +381,7 @@ vm_offset_t envp; vm_offset_t size; vm_offset_t vaddr; + vm_offset_t dtbp; char *rootdevname; int howto; int bisize; @@ -389,7 +392,8 @@ * relocation. */ uint32_t mdt[] = { - MODINFOMD_SSYM, MODINFOMD_ESYM, MODINFOMD_KERNEND, MODINFOMD_ENVP + MODINFOMD_SSYM, MODINFOMD_ESYM, MODINFOMD_KERNEND, + MODINFOMD_ENVP, MODINFOMD_DTBP }; howto = md_getboothowto(args); @@ -405,23 +409,23 @@ /* Try reading the /etc/fstab file to select the root device */ getrootmount(rootdevname); - /* find the last module in the chain */ + /* Find the last module in the chain */ addr = 0; for (xp = file_findfile(NULL, NULL); xp != NULL; xp = xp->f_next) { if (addr < (xp->f_addr + xp->f_size)) addr = xp->f_addr + xp->f_size; } - /* pad to a page boundary */ + /* Pad to a page boundary */ addr = roundup(addr, PAGE_SIZE); - /* copy our environment */ + /* Copy our environment */ envp = addr; addr = md_copyenv(addr); - /* pad to a page boundary */ + /* Pad to a page boundary */ addr = roundup(addr, PAGE_SIZE); - /* prepare bootinfo */ + /* Prepare bootinfo */ bisize = md_bootinfo(&bip); kernend = 0; @@ -433,12 +437,21 @@ file_addmetadata(kfp, MODINFOMD_HOWTO, sizeof howto, &howto); file_addmetadata(kfp, MODINFOMD_BOOTINFO, bisize, bip); file_addmetadata(kfp, MODINFOMD_ENVP, sizeof envp, &envp); + + /* XXX This should be conditional: whether FDT support is enabled */ + /* Handle device tree blob */ + fdt_fixup(); + bfp = file_findfile(NULL, "dtb"); + dtbp = bfp == NULL ? 0 : bfp->f_addr; + file_addmetadata(kfp, MODINFOMD_DTBP, sizeof dtbp, &dtbp); file_addmetadata(kfp, MODINFOMD_KERNEND, sizeof kernend, &kernend); + /* Figure out the size and location of the metadata */ *modulep = addr; size = md_copymodules(0); kernend = roundup(addr + size, PAGE_SIZE); + /* Provide MODINFOMD_KERNEND */ md = file_findmetadata(kfp, MODINFOMD_KERNEND); bcopy(&kernend, md->md_data, sizeof kernend); @@ -453,7 +466,9 @@ bcopy(&vaddr, md->md_data, sizeof vaddr); } } + + /* Only now copy actual modules and metadata */ (void)md_copymodules(addr); - return(0); + return (0); } ==== //depot/projects/fdt/sys/boot/uboot/lib/Makefile#2 (text+ko) ==== @@ -7,9 +7,15 @@ SRCS= devicename.c elf_freebsd.c console.c copy.c disk.c \ module.c net.c reboot.c time.c glue.c +SRCS+= fdt.c + CFLAGS+= -ffreestanding -msoft-float CFLAGS+= -I${.CURDIR}/../../../../lib/libstand/ + +# Pick up FDT includes +CFLAGS+= -I${.CURDIR}/../../../../sys/contrib/dtc/libfdt/ + # Pick up the bootstrap header for some interface items CFLAGS+= -I${.CURDIR}/../../common -I${.CURDIR}/../../.. -I.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200912021538.nB2FcWMJ064613>