Re: svn commit: r355487 - in head/sys: arm64/arm64 arm64/include conf
On 2019-Dec-09 08:38:01 -0600, Kyle Evans wrote: ... >> +static vm_offset_t >> +freebsd_parse_boot_param(struct arm64_bootparams *abp) >> +{ >> + vm_offset_t lastaddr = 0; >> + void *kmdp; >> +#ifdef DDB >> + vm_offset_t ksym_start; >> + vm_offset_t ksym_end; >> +#endif >> + >> + if (abp->modulep == 0) >> + return (0); >> + >> + preload_metadata = (caddr_t)(uintptr_t)(abp->modulep); >> + kmdp = preload_search_by_type("elf kernel"); >> + if (kmdp == NULL) >> + return (0); >> + >> + boothowto = MD_FETCH(kmdp, MODINFOMD_HOWTO, int); >> + loader_envp = MD_FETCH(kmdp, MODINFOMD_ENVP, char *); >> + init_static_kenv(static_kenv, 0); > >This should read "loader_envp" instead of "static_kenv" -- as written, >it stomps over the kenv provided by loader. Which breaks diskless booting and NFS root. Changing static_kenv to loader_envp unbreaks the kernel. -- Peter Jeremy signature.asc Description: PGP signature
Re: svn commit: r355487 - in head/sys: arm64/arm64 arm64/include conf
On Sat, Dec 7, 2019 at 10:14 AM Michal Meloun wrote: > > Author: mmel > Date: Sat Dec 7 16:14:23 2019 > New Revision: 355487 > URL: https://svnweb.freebsd.org/changeset/base/355487 > > Log: > Add support for booting kernel directly from U-Boot using booti command. > > In some cases, like is locked bootstrap or device's inability to boot from > removable media, we cannot use standard boot sequence and is necessary to > boot kernel directly from U-Boot. > > Discussed with: jhibbits > MFC after:1 month > Differential Revision:https://reviews.freebsd.org/D13861 > > Added: > head/sys/arm64/arm64/machdep_boot.c (contents, props changed) > Modified: > head/sys/arm64/arm64/locore.S > head/sys/arm64/arm64/machdep.c > head/sys/arm64/include/machdep.h > head/sys/conf/Makefile.arm64 > head/sys/conf/files.arm64 > head/sys/conf/options.arm64 > > [... snip ...] > Added: head/sys/arm64/arm64/machdep_boot.c > == > --- /dev/null 00:00:00 1970 (empty, because file is newly added) > +++ head/sys/arm64/arm64/machdep_boot.c Sat Dec 7 16:14:23 2019 > (r355487) > @@ -0,0 +1,254 @@ > +/*- > + * Copyright (c) 2004 Olivier Houchard > + * Copyright (c) 1994-1998 Mark Brinicombe. > + * Copyright (c) 1994 Brini. > + * All rights reserved. > + * > + * 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 AND CONTRIBUTORS ``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 THE AUTHOR OR CONTRIBUTORS 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. > + */ > + > +#include "opt_platform.h" > + > +#include > +__FBSDID("$FreeBSD$"); > + > +#include > +#include > +#include > +#include > +#include > +#include > +#ifdef FDT > +#include > +#endif > + > +#include > +#include > +#include > +#include > + > +#ifdef FDT > +#include > +#include > +#endif > + > +extern int *end; > +static char *loader_envp; > +static char static_kenv[4096]; > + > + > +#ifdef FDT > +#defineCMDLINE_GUARD "FreeBSD:" > +#defineLBABI_MAX_COMMAND_LINE 512 > +static char linux_command_line[LBABI_MAX_COMMAND_LINE + 1]; > +#endif > + > +/* > + * Fake up a boot descriptor table > + */ > + #define PRELOAD_PUSH_VALUE(type, value) do { \ > + *(type *)(preload_ptr + size) = (value);\ > + size += sizeof(type); \ > +} while (0) > + > + #define PRELOAD_PUSH_STRING(str) do { \ > + uint32_t ssize; \ > + ssize = strlen(str) + 1;\ > + PRELOAD_PUSH_VALUE(uint32_t, ssize);\ > + strcpy((char*)(preload_ptr + size), str); \ > + size += ssize; \ > + size = roundup(size, sizeof(u_long)); \ > +} while (0) > + > + > +/* Build minimal set of metatda. */ > +static vm_offset_t > +fake_preload_metadata(void *dtb_ptr, size_t dtb_size) > +{ > +#ifdef DDB > + vm_offset_t zstart = 0, zend = 0; > +#endif > + vm_offset_t lastaddr; > + static char fake_preload[256]; > + caddr_t preload_ptr; > + size_t size; > + > + preload_ptr = (caddr_t)_preload[0]; > + size = 0; > + > + PRELOAD_PUSH_VALUE(uint32_t, MODINFO_NAME); > + PRELOAD_PUSH_STRING("kernel"); > + > + PRELOAD_PUSH_VALUE(uint32_t, MODINFO_TYPE); > + PRELOAD_PUSH_STRING("elf kernel"); > + > + PRELOAD_PUSH_VALUE(uint32_t, MODINFO_ADDR); > + PRELOAD_PUSH_VALUE(uint32_t, sizeof(vm_offset_t)); > + PRELOAD_PUSH_VALUE(uint64_t, VM_MIN_KERNEL_ADDRESS); > + > + PRELOAD_PUSH_VALUE(uint32_t, MODINFO_SIZE); > + PRELOAD_PUSH_VALUE(uint32_t, sizeof(size_t)); > + PRELOAD_PUSH_VALUE(uint64_t, (size_t)( - VM_MIN_KERNEL_ADDRESS)); > +#ifdef DDB > + if (*(uint64_t
svn commit: r355487 - in head/sys: arm64/arm64 arm64/include conf
Author: mmel Date: Sat Dec 7 16:14:23 2019 New Revision: 355487 URL: https://svnweb.freebsd.org/changeset/base/355487 Log: Add support for booting kernel directly from U-Boot using booti command. In some cases, like is locked bootstrap or device's inability to boot from removable media, we cannot use standard boot sequence and is necessary to boot kernel directly from U-Boot. Discussed with: jhibbits MFC after:1 month Differential Revision:https://reviews.freebsd.org/D13861 Added: head/sys/arm64/arm64/machdep_boot.c (contents, props changed) Modified: head/sys/arm64/arm64/locore.S head/sys/arm64/arm64/machdep.c head/sys/arm64/include/machdep.h head/sys/conf/Makefile.arm64 head/sys/conf/files.arm64 head/sys/conf/options.arm64 Modified: head/sys/arm64/arm64/locore.S == --- head/sys/arm64/arm64/locore.S Sat Dec 7 15:17:00 2019 (r355486) +++ head/sys/arm64/arm64/locore.S Sat Dec 7 16:14:23 2019 (r355487) @@ -43,6 +43,24 @@ .globl kernbase .setkernbase, KERNBASE + +/* U-Boot booti related constants. */ +#if defined(LINUX_BOOT_ABI) +#define FDT_MAGIC 0xEDFE0DD0 /* FDT blob Magic */ + +#ifndef UBOOT_IMAGE_OFFSET +#defineUBOOT_IMAGE_OFFSET 0 /* Image offset from start of */ +#endif /* 2 MiB page */ + +#ifndef UBOOT_IMAGE_SIZE /* Total size of image */ +#defineUBOOT_IMAGE_SIZE _end - _start +#endif + +#ifndef UBOOT_IMAGE_FLAGS +#defineUBOOT_IMAGE_FLAGS 0 /* LE kernel, unspecified */ +#endif /* page size */ +#endif /* defined(LINUX_BOOT_ABI) */ + /* * We assume: * MMU on with an identity map, or off @@ -54,6 +72,21 @@ .text .globl _start _start: +#if defined(LINUX_BOOT_ABI) + /* U-boot image header */ + b 1f /* code 0 */ + .long 0 /* code 1 */ + .quad UBOOT_IMAGE_OFFSET /* Image offset in 2 MiB page, LE */ + .quad UBOOT_IMAGE_SIZE/* Image size, LE */ + .quad UBOOT_IMAGE_FLAGS /* Flags for kernel. LE */ + .quad 0 /* Reserved */ + .quad 0 /* Reserved */ + .quad 0 /* Reserved */ + .long 0x644d5241 /* Magic "ARM\x64", LE */ + .long 0 /* Reserved for PE COFF offset*/ +1: +#endif /* defined(LINUX_BOOT_ABI) */ + /* Drop to EL1 */ bl drop_to_el1 @@ -350,11 +383,50 @@ create_pagetables: /* Find the size of the kernel */ mov x6, #(KERNBASE) + +#if defined(LINUX_BOOT_ABI) + /* X19 is used as 'map FDT data' flag */ + mov x19, xzr + + /* No modules or FDT pointer ? */ + cbz x0, booti_no_fdt + + /* Test if modulep points to modules descriptor or to FDT */ + ldr w8, [x0] + ldr w7, =FDT_MAGIC + cmp w7, w8 + b.eqbooti_fdt +#endif + + /* Booted with modules pointer */ /* Find modulep - begin */ sub x8, x0, x6 /* Add two 2MiB pages for the module data and round up */ ldr x7, =(3 * L2_SIZE - 1) add x8, x8, x7 + b common + +#if defined(LINUX_BOOT_ABI) +booti_fdt: + /* Booted by U-Boot booti with FDT data */ + /* Set 'map FDT data' flag */ + mov x19, #1 + +booti_no_fdt: + /* Booted by U-Boot booti without FTD data */ + /* Find the end - begin */ + ldr x7, .Lend + sub x8, x7, x6 + + /* +* Add one 2MiB page for copy of FDT data (maximum FDT size), +* one for metadata and round up +*/ + ldr x7, =(3 * L2_SIZE - 1) + add x8, x8, x7 +#endif + +common: /* Get the number of l2 pages to allocate, rounded down */ lsr x10, x8, #(L2_SHIFT) @@ -404,9 +476,21 @@ create_pagetables: bl build_l1_block_pagetable #endif - /* -* Create the VA = PA map -*/ +#if defined(LINUX_BOOT_ABI) + /* Map FDT data ? */ + cbz x19, 1f + + /* Create the identity mapping for FDT data (2 MiB max) */ + mov x7, #(ATTR_nG | ATTR_IDX(VM_MEMATTR_UNCACHEABLE)) + mov x9, x0 + mov x8, x0 /* VA start (== PA start) */ + mov x10, #1 + bl build_l1_block_pagetable + +1: +#endif + + /* Create the VA = PA map */ mov x7, #(ATTR_nG | ATTR_IDX(VM_MEMATTR_UNCACHEABLE)) mov x9, x27 mov x8, x9 /* VA start (== PA start) */ Modified: head/sys/arm64/arm64/machdep.c == ---