arm/dt: Make __vet_atags also accept a dtb image
Subsystems (3)
PATCH v6 1/5 arm/dt: Make __vet_atags also accept a dtb image
The dtb is passed to the kernel via register r2, which is the same method that is used to pass an atags pointer. This patch modifies __vet_atags to not clear r2 when it encounters a dtb image.
v2: fixed bugs pointed out by Nicolas Pitre
--- arch/arm/kernel/head-common.S | 24 ++++++++++++++++++------ arch/arm/kernel/head.S | 8 ++++---- 2 files changed, 22 insertions(+), 10 deletions(-)
arch/arm/kernel/head-common.S +18 -6
@@ -15,6 +15,12 @@ #define ATAG_CORE_SIZE ((2*4 + 3*4) >> 2) #define ATAG_CORE_SIZE_EMPTY ((2*4) >> 2) +#ifdef CONFIG_CPU_BIG_ENDIAN +#define OF_DT_MAGIC 0xd00dfeed +#else +#define OF_DT_MAGIC 0xedfe0dd0 /* 0xd00dfeed in big-endian */ +#endif + /* * Exception handling. Something went wrong and we can't proceed. We * ought to tell the user, but since we don't have any guarantee that
@@ -28,20 +34,26 @@ /* Determine validity of the r2 atags pointer. The heuristic requires * that the pointer be aligned, in the first 16k of physical RAM and - * that the ATAG_CORE marker is first and present. Future revisions + * that the ATAG_CORE marker is first and present. If CONFIG_OF_FLATTREE + * is selected, then it will also accept a dtb pointer. Future revisions * of this function may be more lenient with the physical address and * may also be able to move the ATAGS block if necessary. * * Returns: - * r2 either valid atags pointer, or zero + * r2 either valid atags pointer, valid dtb pointer, or zero * r5, r6 corrupted */ __vet_atags: tst r2, #0x3 @ aligned? bne 1f - ldr r5, [r2, #0] @ is first tag ATAG_CORE? - cmp r5, #ATAG_CORE_SIZE + ldr r5, [r2, #0] +#ifdef CONFIG_OF_FLATTREE + ldr r6, =OF_DT_MAGIC @ is it a DTB? + cmp r5, r6 + beq 2f +#endif + cmp r5, #ATAG_CORE_SIZE @ is first tag ATAG_CORE? cmpne r5, #ATAG_CORE_SIZE_EMPTY bne 1f ldr r5, [r2, #4]
@@ -49,7 +61,7 @@ __vet_atags: cmp r5, r6 bne 1f - mov pc, lr @ atag pointer is ok +2: mov pc, lr @ atag/dtb pointer is ok 1: mov r2, #0 mov pc, lr
@@ -61,7 +73,7 @@ ENDPROC(__vet_atags) * * r0 = cp#15 control register * r1 = machine ID - * r2 = atags pointer + * r2 = atags/dtb pointer * r9 = processor ID */ __INIT
arch/arm/kernel/head.S +4 -4
@@ -59,7 +59,7 @@ * * This is normally called from the decompressor code. The requirements * are: MMU = off, D-cache = off, I-cache = dont care, r0 = 0, - * r1 = machine nr, r2 = atags pointer. + * r1 = machine nr, r2 = atags or dtb pointer. * * This code is mostly position independent, so if you link the kernel at * 0xc0008000, you call this at __pa(0xc0008000).
@@ -91,7 +91,7 @@ ENTRY(stext) #endif /* - * r1 = machine no, r2 = atags, + * r1 = machine no, r2 = atags or dtb, * r8 = phys_offset, r9 = cpuid, r10 = procinfo */ bl __vet_atags
@@ -339,7 +339,7 @@ __secondary_data: * * r0 = cp#15 control register * r1 = machine ID - * r2 = atags pointer + * r2 = atags or dtb pointer * r4 = page table pointer * r9 = processor ID * r13 = *virtual* address to jump to upon completion
@@ -376,7 +376,7 @@ ENDPROC(__enable_mmu) * * r0 = cp#15 control register * r1 = machine ID - * r2 = atags pointer + * r2 = atags or dtb pointer * r9 = processor ID * r13 = *virtual* address to jump to upon completion *
PATCH v6 2/5 arm/dt: Allow CONFIG_OF on ARM
Add some basic empty infrastructure for DT support on ARM.
v5: - Fix off-by-one error in size calculation of initrd
- Stop mucking with cmd_line, and load command line from dt into boot_command_line instead which matches the behaviour of ATAGS booting
v3: - moved cmd_line export and initrd setup to this patch to make the
series bisectable.
- switched to alloc_bootmem_align() for allocation when unflattening the device tree. memblock_alloc() was not the right interface.
--- arch/arm/Kconfig | 7 ++++++ arch/arm/include/asm/prom.h | 25 ++++++++++++++++++++++ arch/arm/include/asm/setup.h | 2 ++ arch/arm/kernel/Makefile | 1 + arch/arm/kernel/devtree.c | 47 ++++++++++++++++++++++++++++++++++++++++++ arch/arm/kernel/setup.c | 2 +- arch/arm/mm/init.c | 9 ++++++++ 7 files changed, 92 insertions(+), 1 deletions(-) create mode 100644 arch/arm/include/asm/prom.h create mode 100644 arch/arm/kernel/devtree.c
arch/arm/Kconfig +7 -0
@@ -1687,6 +1687,13 @@ endmenu menu "Boot options" +config USE_OF + bool "Flattened Device Tree support" + select OF + select OF_EARLY_FLATTREE + help + Include support for flattened device tree machine descriptions. + # Compressed boot loader in ROM. Yes, we really want to ask about # TEXT and BSS so we preserve their values in the config files. config ZBOOT_ROM_TEXT
arch/arm/include/asm/prom.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* arch/arm/include/asm/prom.h +* +* Copyright (C) 2009 Canonical Ltd. <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +*/ +#ifndef __ASMARM_PROM_H +#define __ASMARM_PROM_H + +#ifdef CONFIG_OF + +#include <asm/setup.h> +#include <asm/irq.h> + +static inline void irq_dispose_mapping (unsigned int virq) +{ +return ; +} + +#endif /* CONFIG_OF */ +#endif /* ASMARM_PROM_H */
arch/arm/include/asm/setup.h +2 -0
@@ -217,6 +217,8 @@ extern struct meminfo meminfo;#define bank_phys_end (bank) ((bank)->start + (bank)->size)#define bank_phys_size (bank) (bank)->size +extern int arm_add_memory (phys_addr_t start,unsigned long size); +#endif /* __KERNEL__ */ #endif
arch/arm/kernel/Makefile +1 -0
@@ -44,6 +44,7 @@ obj-$(CONFIG_ARM_THUMBEE) += thumbee.o obj-$(CONFIG_KGDB) += kgdb.o obj-$(CONFIG_ARM_UNWIND) += unwind.o obj-$(CONFIG_HAVE_TCM) += tcm.o +obj-$(CONFIG_OF) += devtree.o obj-$(CONFIG_CRASH_DUMP) += crash_dump.o obj-$(CONFIG_SWP_EMULATE) += swp_emulate.o CFLAGS_swp_emulate.o := -Wa,-march=armv7-a
arch/arm/kernel/devtree.c new file +47 -0
47 lines not on this page · raw message
arch/arm/kernel/setup.c +1 -1
@@ -466,7 +466,7 @@ static struct machine_desc * __init setup_machine(unsigned int nr)/* can't use cpu_relax() here as it may require MMU setup */ ; } -static int __init arm_add_memory (phys_addr_t start,unsigned long size) +int __init arm_add_memory (phys_addr_t start,unsigned long size) {struct membank *bank = &meminfo.bank[meminfo.nr_banks];
arch/arm/mm/init.c +9 -0
@@ -15,6 +15,7 @@#include <linux/mman.h> #include <linux/nodemask.h> #include <linux/initrd.h> +#include <linux/of_fdt.h> #include <linux/highmem.h> #include <linux/gfp.h> #include <linux/memblock.h>
@@ -71,6 +72,14 @@ static int __init parse_tag_initrd2(const struct tag *tag)__tagtable (ATAG_INITRD2 , parse_tag_initrd2); +#ifdef CONFIG_OF_FLATTREE +void __init early_init_dt_setup_initrd_arch (unsigned long start,unsigned long end) +{ + phys_initrd_start = start; + phys_initrd_size = end - start; +} +#endif /* CONFIG_OF_FLATTREE */ +/* * This keeps memory configuration data used by a couple memory * initialization functions, as well as show_mem() for the skipping
PATCH v6 3/5 arm/dt: consolidate atags setup into setup_machine_atags
In reply to Grant LikelyIn preparation for adding device tree support, this patch consolidates all of the atag-specific setup into a single function.
v5: - drop double printk("Machine; %s\n", ...); call.
- leave copying boot_command_line in setup_arch() since it isn't atags specific.
v4: - adapt to the removal of lookup_machine_type()
- break out dump of machine_desc table into dump_machine_table() because the device tree probe code will use it.
- Add for_each_machine_desc() macro
--- arch/arm/include/asm/mach/arch.h | 7 ++++ arch/arm/kernel/setup.c | 69 ++++++++++++++++++++++---------------- 2 files changed, 47 insertions(+), 29 deletions(-)
arch/arm/include/asm/mach/arch.h +7 -0
@@ -48,6 +48,13 @@ struct machine_desc {extern struct machine_desc *machine_desc;/* +* Machine type table - also only accessible during boot +*/ +extern struct machine_desc __arch_info_begin[], __arch_info_end[]; +#define for_each_machine_desc (p) \ + for (p = __arch_info_begin; p < __arch_info_end; p++) + +/* * Set of macros to define architecture features. This is built into * a table by the linker. */
arch/arm/kernel/setup.c +40 -29
102 lines not on this page · raw message
PATCH v6 4/5 arm/dt: probe for platforms via the device tree
In reply to Grant LikelyIf a dtb is passed to the kernel then the kernel needs to iterate through compiled-in mdescs looking for one that matches and move the dtb data to a safe location before it gets accidentally overwritten by the kernel.
This patch creates a new function, setup_machine_fdt() which is analogous to the setup_machine_atags() created in the previous patch. It does all the early setup needed to use a device tree machine description.
v5: - Print warning with neither dtb nor atags are passed to the kernel
- Fix bug in setting of __machine_arch_type to the selected machine, not just the last machine in the list.
- Copy command line directly into boot_command_line instead of cmd_line
v4: - Dump some output when a matching machine_desc cannot be found
v3: - Added processing of reserved list.
- Backed out the v2 change that copied instead of reserved the dtb. dtb is reserved again and the real problem was fixed by using alloc_bootmem_align() for early allocation of RAM for unflattening the tree.
- Moved cmd_line and initrd changes to earlier patch to make series bisectable.
v2: Changed to save the dtb by copying into an allocated buffer.
- Since the dtb will very likely be passed in the first 16k of ram where the interrupt vectors live, memblock_reserve() is insufficient to protect the dtb data.
--- arch/arm/include/asm/mach/arch.h | 2 + arch/arm/include/asm/prom.h | 12 +++++ arch/arm/include/asm/setup.h | 2 + arch/arm/kernel/devtree.c | 98 ++++++++++++++++++++++++++++++++++++++ arch/arm/kernel/setup.c | 23 +++++++-- arch/arm/mm/init.c | 2 + 6 files changed, 135 insertions(+), 4 deletions(-)
arch/arm/include/asm/mach/arch.h +2 -0
@@ -18,6 +18,8 @@ struct machine_desc {unsigned int nr;/* architecture number */ const char *name;/* architecture name */ unsigned long boot_params;/* tagged list */ +const char **dt_compat;/* array of device tree +* 'compatible' strings */ unsigned int nr_irqs;/* number of IRQs */
arch/arm/include/asm/prom.h +12 -0
@@ -21,5 +21,17 @@ static inline void irq_dispose_mapping(unsigned int virq)return ; } +extern struct machine_desc *setup_machine_fdt (unsigned int dt_phys); +extern void arm_dt_memblock_reserve (void ); + +#else /* CONFIG_OF */ + +static inline struct machine_desc *setup_machine_fdt (unsigned int dt_phys) +{ +return NULL ; +} + +static inline void arm_dt_memblock_reserve (void ) { } +#endif /* CONFIG_OF */ #endif /* ASMARM_PROM_H */
arch/arm/include/asm/setup.h +2 -0
@@ -218,6 +218,8 @@ extern struct meminfo meminfo;#define bank_phys_size (bank) (bank)->sizeextern int arm_add_memory (phys_addr_t start,unsigned long size); +extern void early_print (const char *str, ...); +extern void dump_machine_table (void );#endif /* __KERNEL__ */
arch/arm/kernel/devtree.c +98 -0
110 lines not on this page · raw message
arch/arm/kernel/setup.c +19 -4
@@ -20,6 +20,7 @@#include <linux/screen_info.h> #include <linux/init.h> #include <linux/kexec.h> +#include <linux/of_fdt.h> #include <linux/crash_dump.h> #include <linux/root_dev.h> #include <linux/cpu.h>
@@ -42,6 +43,7 @@#include <asm/cachetype.h> #include <asm/tlbflush.h> +#include <asm/prom.h> #include <asm/mach/arch.h> #include <asm/mach/irq.h> #include <asm/mach/time.h>
@@ -309,7 +311,7 @@ static void __init cacheid_init(void)*/ extern struct proc_info_list *lookup_processor_type (unsigned int ); -static void __init early_print (const char *str, ...) +void __init early_print (const char *str, ...) {extern void printascii (const char *);char buf[256 ];
@@ -439,7 +441,7 @@ void cpu_init(void) : "r14"); } -static void __init dump_machine_table (void ) +void __init dump_machine_table (void ) {struct machine_desc *p;
@@ -837,8 +839,17 @@ static struct machine_desc * __init setup_machine_tags(unsigned int nr)if (tags->hdr.tag !=ATAG_CORE )convert_to_tag_list (tags);#endif -if (tags->hdr.tag !=ATAG_CORE ) + +if (tags->hdr.tag !=ATAG_CORE ) { +#if defined(CONFIG_OF ) +/* +* If CONFIG_OF is set, then assume this is a reasonably +* modern system that should pass boot parameters +*/ +early_print ("Warning: Neither atags nor dtb found\n" ); +#endif tags = (struct tag *)&init_tags; + }if (mdesc->fixup) mdesc->fixup (mdesc, tags, &from, &meminfo);
@@ -864,7 +875,9 @@ void __init setup_arch(char **cmdline_p)unwind_init ();setup_processor (); - mdesc =setup_machine_tags (machine_arch_type); + mdesc =setup_machine_fdt (__atags_pointer); +if (!mdesc) + mdesc =setup_machine_tags (machine_arch_type); machine_desc = mdesc; machine_name = mdesc->name;
@@ -887,6 +900,8 @@ void __init setup_arch(char **cmdline_p)paging_init (mdesc);request_standard_resources (mdesc); +unflatten_device_tree (); +#ifdef CONFIG_SMP if (is_smp ())smp_init_cpus ();
arch/arm/mm/init.c +2 -0
@@ -22,6 +22,7 @@#include <linux/sort.h> #include <asm/mach-types.h> +#include <asm/prom.h> #include <asm/sections.h> #include <asm/setup.h> #include <asm/sizes.h>
@@ -322,6 +323,7 @@ void __init arm_memblock_init(struct meminfo *mi, struct machine_desc *mdesc)#endif arm_mm_memblock_reserve (); +arm_dt_memblock_reserve ();/* reserve any platform specific memblock areas */ if (mdesc->reserve)
PATCH v6 5/5 dt: add documentation of ARM dt boot interface
In reply to Grant Likelyv6: typo fixes
v5: clarified that dtb should be aligned on a 64 bit boundary in RAM.
v3: added details to Documentation/arm/Booting
--- Documentation/arm/Booting | 33 ++++++++++++++-- Documentation/devicetree/booting-without-of.txt | 48 +++++++++++++++++++++-- 2 files changed, 73 insertions(+), 8 deletions(-)
Documentation/arm/Booting +29 -4
@@ -65,13 +65,19 @@ looks at the connected hardware is beyond the scope of this document. The boot loader must ultimately be able to provide a MACH_TYPE_xxx value to the kernel. (see linux/arch/arm/tools/mach-types). - -4. Setup the kernel tagged list -------------------------------- +4. Setup boot data +------------------ Existing boot loaders: OPTIONAL, HIGHLY RECOMMENDED New boot loaders: MANDATORY +The boot loader must provide either a tagged list or a dtb image for +passing configuration data to the kernel. The physical address of the +boot data is passed to the kernel in register r2. + +4a. Setup the kernel tagged list +-------------------------------- + The boot loader must create and initialise the kernel tagged list. A valid tagged list starts with ATAG_CORE and ends with ATAG_NONE. The ATAG_CORE tag may or may not be empty. An empty ATAG_CORE tag
@@ -101,6 +107,24 @@ The tagged list must be placed in a region of memory where neither the kernel decompressor nor initrd 'bootp' program will overwrite it. The recommended placement is in the first 16KiB of RAM. +4b. Setup the device tree +------------------------- + +The boot loader must load a device tree image (dtb) into system ram +at a 64bit aligned address and initialize it with the boot data. The +dtb format is documented in Documentation/devicetree/booting-without-of.txt. +The kernel will look for the dtb magic value of 0xd00dfeed at the dtb +physical address to determine if a dtb has been passed instead of a +tagged list. + +The boot loader must pass at a minimum the size and location of the +system memory, and the root filesystem location. The dtb must be +placed in a region of memory where the kernel decompressor will not +overwrite it. The recommended placement is in the first 16KiB of RAM +with the caveat that it may not be located at physical address 0 since +the kernel interprets a value of 0 in r2 to mean neither a tagged list +nor a dtb were passed. + 5. Calling the kernel image ---------------------------
@@ -125,7 +149,8 @@ In either case, the following conditions must be met: - CPU register settings r0 = 0, r1 = machine type number discovered in (3) above. - r2 = physical address of tagged list in system RAM. + r2 = physical address of tagged list in system RAM, or + physical address of device tree block (dtb) in system RAM - CPU mode All forms of interrupts must be disabled (IRQs and FIQs)
Documentation/devicetree/booting-without-of.txt +44 -4
66 lines not on this page · raw message