diff --git a/sys/arm64/ofw/ofw_initrd.c b/sys/arm64/ofw/ofw_initrd.c new file mode 100644 --- /dev/null +++ b/sys/arm64/ofw/ofw_initrd.c @@ -0,0 +1,132 @@ +/*- + * Copyright (C) 2018 Breno Leitao + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * The pupose of this is to support U-boot managed FreeBSD bootup by using + * only binary images, without any device with a partition table. + * + * This functionality has been ported from sys/powerpc/ofw/ofw_initrd.c + * + * Please find an example U-boot usage below: + * + * setenv kernel_comp_addr_r 0x3000000 + * setenv kernel_comp_size 0x04000000 + * setenv fdt_addr_r 0x2000000 + * dhcp + * tftp $fdt_addr_r rk3328-rock64.dtb + * tftp $kernel_addr_r kernel.bin.gz + * setenv ramdisk_addr_r 0x07000000 + * tftp $ramdisk_addr_r mfsroot + * fdt addr $fdt_addr_r + * fdt chosen $ramdisk_addr_r $filesize + * booti $kernel_addr_r - $fdt_addr_r + * + * The "fdt chosen" command above embeds ramdisk setting into the actual fdt tree. + * + * The "mfsroot" image is an uncompressed UFS disk image. + * + * FreeBSD boot log should be like the following: + * + * md0: Embedded image 11534336 bytes at 0xffffa0007c42b000 + * + * mountroot> ? + * + * List of GEOM managed disk devices: + * ufsid/6416031dd9f2971da ufsid/6416031dd9f2971d md0a md0 + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include "opt_md.h" + +extern u_char *mfs_root; +extern int mfs_root_size; + +static void ofw_initrd_probe_and_attach(void *junk); + +SYSINIT(ofw_initrd_probe_and_attach, SI_SUB_KMEM, SI_ORDER_ANY, + ofw_initrd_probe_and_attach, NULL); + +static void +ofw_initrd_probe_and_attach(void *junk) +{ + phandle_t chosen; + vm_paddr_t start, end; + pcell_t cell[2]; + ssize_t size; + u_char *taste; + + chosen = OF_finddevice("/chosen"); + if (chosen <= 0) + return; + + if (!OF_hasprop(chosen, "linux,initrd-start") || + !OF_hasprop(chosen, "linux,initrd-end")) + return; + + size = OF_getencprop(chosen, "linux,initrd-start", cell, sizeof(cell)); + if (size == 4) + start = cell[0]; + else if (size == 8) + start = (uint64_t)cell[0] << 32 | cell[1]; + else { + printf("ofw_initrd: Wrong linux,initrd-start size\n"); + return; + } + + size = OF_getencprop(chosen, "linux,initrd-end", cell, sizeof(cell)); + if (size == 4) + end = cell[0]; + else if (size == 8) + end = (uint64_t)cell[0] << 32 | cell[1]; + else{ + printf("ofw_initrd: Wrong linux,initrd-end size\n"); + return; + } + + if (end - start > 0) { + taste = (u_char *) PHYS_TO_DMAP(start); + mfs_root = taste; + mfs_root_size = end - start; + printf("ofw_initrd: initrd loaded at 0x%08lx-0x%08lx\n", + start, end); + } +} diff --git a/sys/conf/files.arm64 b/sys/conf/files.arm64 --- a/sys/conf/files.arm64 +++ b/sys/conf/files.arm64 @@ -338,6 +338,7 @@ dev/ofw/ofw_cpu.c optional fdt dev/ofw/ofw_pci.c optional fdt pci dev/ofw/ofw_pcib.c optional fdt pci +arm64/ofw/ofw_initrd.c optional fdt md_root_mem dev/pci/controller/pci_n1sdp.c optional pci_n1sdp acpi dev/pci/pci_host_generic.c optional pci