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

RISC-V: Build Infrastructure

This patch contains all the build infrastructure that actually enables
the RISC-V port. This includes Makefiles, linker scripts, and Kconfig
files. It also contains the only top-level change, which adds RISC-V to
the list of architectures that need a sed run to produce the ARCH
variable when building locally.

Signed-off-by: Palmer Dabbelt <palmer@dabbelt.com>

+581 -1
+2 -1
Makefile
··· 225 225 -e s/arm.*/arm/ -e s/sa110/arm/ \ 226 226 -e s/s390x/s390/ -e s/parisc64/parisc/ \ 227 227 -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \ 228 - -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ ) 228 + -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \ 229 + -e s/riscv.*/riscv/) 229 230 230 231 # Cross compiling and selecting different set of gcc/bin-utils 231 232 # ---------------------------------------------------------------------------
+310
arch/riscv/Kconfig
··· 1 + # 2 + # For a description of the syntax of this configuration file, 3 + # see Documentation/kbuild/kconfig-language.txt. 4 + # 5 + 6 + config RISCV 7 + def_bool y 8 + select OF 9 + select OF_EARLY_FLATTREE 10 + select OF_IRQ 11 + select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE 12 + select ARCH_WANT_FRAME_POINTERS 13 + select CLONE_BACKWARDS 14 + select COMMON_CLK 15 + select GENERIC_CLOCKEVENTS 16 + select GENERIC_CPU_DEVICES 17 + select GENERIC_IRQ_SHOW 18 + select GENERIC_PCI_IOMAP 19 + select GENERIC_STRNCPY_FROM_USER 20 + select GENERIC_STRNLEN_USER 21 + select GENERIC_SMP_IDLE_THREAD 22 + select GENERIC_ATOMIC64 if !64BIT || !RISCV_ISA_A 23 + select ARCH_WANT_OPTIONAL_GPIOLIB 24 + select HAVE_MEMBLOCK 25 + select HAVE_DMA_API_DEBUG 26 + select HAVE_DMA_CONTIGUOUS 27 + select HAVE_GENERIC_DMA_COHERENT 28 + select IRQ_DOMAIN 29 + select NO_BOOTMEM 30 + select RISCV_ISA_A if SMP 31 + select SPARSE_IRQ 32 + select SYSCTL_EXCEPTION_TRACE 33 + select HAVE_ARCH_TRACEHOOK 34 + select MODULES_USE_ELF_RELA if MODULES 35 + select THREAD_INFO_IN_TASK 36 + select RISCV_IRQ_INTC 37 + select RISCV_TIMER 38 + 39 + config MMU 40 + def_bool y 41 + 42 + # even on 32-bit, physical (and DMA) addresses are > 32-bits 43 + config ARCH_PHYS_ADDR_T_64BIT 44 + def_bool y 45 + 46 + config ARCH_DMA_ADDR_T_64BIT 47 + def_bool y 48 + 49 + config PAGE_OFFSET 50 + hex 51 + default 0xC0000000 if 32BIT && MAXPHYSMEM_2GB 52 + default 0xffffffff80000000 if 64BIT && MAXPHYSMEM_2GB 53 + default 0xffffffe000000000 if 64BIT && MAXPHYSMEM_128GB 54 + 55 + config STACKTRACE_SUPPORT 56 + def_bool y 57 + 58 + config RWSEM_GENERIC_SPINLOCK 59 + def_bool y 60 + 61 + config GENERIC_BUG 62 + def_bool y 63 + depends on BUG 64 + select GENERIC_BUG_RELATIVE_POINTERS if 64BIT 65 + 66 + config GENERIC_BUG_RELATIVE_POINTERS 67 + bool 68 + 69 + config GENERIC_CALIBRATE_DELAY 70 + def_bool y 71 + 72 + config GENERIC_CSUM 73 + def_bool y 74 + 75 + config GENERIC_HWEIGHT 76 + def_bool y 77 + 78 + config PGTABLE_LEVELS 79 + int 80 + default 3 if 64BIT 81 + default 2 82 + 83 + config HAVE_KPROBES 84 + def_bool n 85 + 86 + config DMA_NOOP_OPS 87 + def_bool y 88 + 89 + menu "Platform type" 90 + 91 + choice 92 + prompt "Base ISA" 93 + default ARCH_RV64I 94 + help 95 + This selects the base ISA that this kernel will traget and must match 96 + the target platform. 97 + 98 + config ARCH_RV32I 99 + bool "RV32I" 100 + select CPU_SUPPORTS_32BIT_KERNEL 101 + select 32BIT 102 + select GENERIC_ASHLDI3 103 + select GENERIC_ASHRDI3 104 + select GENERIC_LSHRDI3 105 + 106 + config ARCH_RV64I 107 + bool "RV64I" 108 + select CPU_SUPPORTS_64BIT_KERNEL 109 + select 64BIT 110 + 111 + endchoice 112 + 113 + # We must be able to map all physical memory into the kernel, but the compiler 114 + # is still a bit more efficient when generating code if it's setup in a manner 115 + # such that it can only map 2GiB of memory. 116 + choice 117 + prompt "Kernel Code Model" 118 + default CMODEL_MEDLOW if 32BIT 119 + default CMODEL_MEDANY if 64BIT 120 + 121 + config CMODEL_MEDLOW 122 + bool "medium low code model" 123 + config CMODEL_MEDANY 124 + bool "medium any code model" 125 + endchoice 126 + 127 + choice 128 + prompt "Maximum Physical Memory" 129 + default MAXPHYSMEM_2GB if 32BIT 130 + default MAXPHYSMEM_2GB if 64BIT && CMODEL_MEDLOW 131 + default MAXPHYSMEM_128GB if 64BIT && CMODEL_MEDANY 132 + 133 + config MAXPHYSMEM_2GB 134 + bool "2GiB" 135 + config MAXPHYSMEM_128GB 136 + depends on 64BIT && CMODEL_MEDANY 137 + bool "128GiB" 138 + endchoice 139 + 140 + 141 + config SMP 142 + bool "Symmetric Multi-Processing" 143 + help 144 + This enables support for systems with more than one CPU. If 145 + you say N here, the kernel will run on single and 146 + multiprocessor machines, but will use only one CPU of a 147 + multiprocessor machine. If you say Y here, the kernel will run 148 + on many, but not all, single processor machines. On a single 149 + processor machine, the kernel will run faster if you say N 150 + here. 151 + 152 + If you don't know what to do here, say N. 153 + 154 + config NR_CPUS 155 + int "Maximum number of CPUs (2-32)" 156 + range 2 32 157 + depends on SMP 158 + default "8" 159 + 160 + config CPU_SUPPORTS_32BIT_KERNEL 161 + bool 162 + config CPU_SUPPORTS_64BIT_KERNEL 163 + bool 164 + 165 + choice 166 + prompt "CPU Tuning" 167 + default TUNE_GENERIC 168 + 169 + config TUNE_GENERIC 170 + bool "generic" 171 + 172 + endchoice 173 + 174 + config RISCV_ISA_C 175 + bool "Emit compressed instructions when building Linux" 176 + default y 177 + help 178 + Adds "C" to the ISA subsets that the toolchain is allowed to emit 179 + when building Linux, which results in compressed instructions in the 180 + Linux binary. 181 + 182 + If you don't know what to do here, say Y. 183 + 184 + config RISCV_ISA_A 185 + def_bool y 186 + 187 + endmenu 188 + 189 + menu "Kernel type" 190 + 191 + choice 192 + prompt "Kernel code model" 193 + default 64BIT 194 + 195 + config 32BIT 196 + bool "32-bit kernel" 197 + depends on CPU_SUPPORTS_32BIT_KERNEL 198 + help 199 + Select this option to build a 32-bit kernel. 200 + 201 + config 64BIT 202 + bool "64-bit kernel" 203 + depends on CPU_SUPPORTS_64BIT_KERNEL 204 + help 205 + Select this option to build a 64-bit kernel. 206 + 207 + endchoice 208 + 209 + source "mm/Kconfig" 210 + 211 + source "kernel/Kconfig.preempt" 212 + 213 + source "kernel/Kconfig.hz" 214 + 215 + endmenu 216 + 217 + menu "Bus support" 218 + 219 + config PCI 220 + bool "PCI support" 221 + select PCI_MSI 222 + help 223 + This feature enables support for PCI bus system. If you say Y 224 + here, the kernel will include drivers and infrastructure code 225 + to support PCI bus devices. 226 + 227 + If you don't know what to do here, say Y. 228 + 229 + config PCI_DOMAINS 230 + def_bool PCI 231 + 232 + config PCI_DOMAINS_GENERIC 233 + def_bool PCI 234 + 235 + source "drivers/pci/Kconfig" 236 + 237 + endmenu 238 + 239 + source "init/Kconfig" 240 + 241 + source "kernel/Kconfig.freezer" 242 + 243 + menu "Executable file formats" 244 + 245 + source "fs/Kconfig.binfmt" 246 + 247 + endmenu 248 + 249 + menu "Power management options" 250 + 251 + source kernel/power/Kconfig 252 + 253 + endmenu 254 + 255 + source "net/Kconfig" 256 + 257 + source "drivers/Kconfig" 258 + 259 + source "fs/Kconfig" 260 + 261 + menu "Kernel hacking" 262 + 263 + config CMDLINE_BOOL 264 + bool "Built-in kernel command line" 265 + help 266 + For most platforms, it is firmware or second stage bootloader 267 + that by default specifies the kernel command line options. 268 + However, it might be necessary or advantageous to either override 269 + the default kernel command line or add a few extra options to it. 270 + For such cases, this option allows hardcoding command line options 271 + directly into the kernel. 272 + 273 + For that, choose 'Y' here and fill in the extra boot parameters 274 + in CONFIG_CMDLINE. 275 + 276 + The built-in options will be concatenated to the default command 277 + line if CMDLINE_OVERRIDE is set to 'N'. Otherwise, the default 278 + command line will be ignored and replaced by the built-in string. 279 + 280 + config CMDLINE 281 + string "Built-in kernel command string" 282 + depends on CMDLINE_BOOL 283 + default "" 284 + help 285 + Supply command-line options at build time by entering them here. 286 + 287 + config CMDLINE_OVERRIDE 288 + bool "Built-in command line overrides bootloader arguments" 289 + depends on CMDLINE_BOOL 290 + help 291 + Set this option to 'Y' to have the kernel ignore the bootloader 292 + or firmware command line. Instead, the built-in command line 293 + will be used exclusively. 294 + 295 + If you don't know what to do here, say N. 296 + 297 + config EARLY_PRINTK 298 + def_bool y 299 + 300 + source "lib/Kconfig.debug" 301 + 302 + config CMDLINE_BOOL 303 + bool 304 + endmenu 305 + 306 + source "security/Kconfig" 307 + 308 + source "crypto/Kconfig" 309 + 310 + source "lib/Kconfig"
+72
arch/riscv/Makefile
··· 1 + # This file is included by the global makefile so that you can add your own 2 + # architecture-specific flags and dependencies. Remember to do have actions 3 + # for "archclean" and "archdep" for cleaning up and making dependencies for 4 + # this architecture 5 + # 6 + # This file is subject to the terms and conditions of the GNU General Public 7 + # License. See the file "COPYING" in the main directory of this archive 8 + # for more details. 9 + # 10 + 11 + LDFLAGS := 12 + OBJCOPYFLAGS := -O binary 13 + LDFLAGS_vmlinux := 14 + KBUILD_AFLAGS_MODULE += -fPIC 15 + KBUILD_CFLAGS_MODULE += -fPIC 16 + 17 + KBUILD_DEFCONFIG = defconfig 18 + 19 + export BITS 20 + ifeq ($(CONFIG_ARCH_RV64I),y) 21 + BITS := 64 22 + UTS_MACHINE := riscv64 23 + 24 + KBUILD_CFLAGS += -mabi=lp64 25 + KBUILD_AFLAGS += -mabi=lp64 26 + KBUILD_MARCH = rv64im 27 + LDFLAGS += -melf64lriscv 28 + else 29 + BITS := 32 30 + UTS_MACHINE := riscv32 31 + 32 + KBUILD_CFLAGS += -mabi=ilp32 33 + KBUILD_AFLAGS += -mabi=ilp32 34 + KBUILD_MARCH = rv32im 35 + LDFLAGS += -melf32lriscv 36 + endif 37 + 38 + KBUILD_CFLAGS += -Wall 39 + 40 + ifeq ($(CONFIG_RISCV_ISA_A),y) 41 + KBUILD_ARCH_A = a 42 + endif 43 + ifeq ($(CONFIG_RISCV_ISA_C),y) 44 + KBUILD_ARCH_C = c 45 + endif 46 + 47 + KBUILD_AFLAGS += -march=$(KBUILD_MARCH)$(KBUILD_ARCH_A)fd$(KBUILD_ARCH_C) 48 + 49 + KBUILD_CFLAGS += -march=$(KBUILD_MARCH)$(KBUILD_ARCH_A)$(KBUILD_ARCH_C) 50 + KBUILD_CFLAGS += -mno-save-restore 51 + KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET) 52 + 53 + ifeq ($(CONFIG_CMODEL_MEDLOW),y) 54 + KBUILD_CFLAGS += -mcmodel=medlow 55 + endif 56 + ifeq ($(CONFIG_CMODEL_MEDANY),y) 57 + KBUILD_CFLAGS += -mcmodel=medany 58 + endif 59 + 60 + # GCC versions that support the "-mstrict-align" option default to allowing 61 + # unaligned accesses. While unaligned accesses are explicitly allowed in the 62 + # RISC-V ISA, they're emulated by machine mode traps on all extant 63 + # architectures. It's faster to have GCC emit only aligned accesses. 64 + KBUILD_CFLAGS += $(call cc-option,-mstrict-align) 65 + 66 + head-y := arch/riscv/kernel/head.o 67 + 68 + core-y += arch/riscv/kernel/ arch/riscv/mm/ 69 + 70 + libs-y += arch/riscv/lib/ 71 + 72 + all: vmlinux
arch/riscv/configs/defconfig
+61
arch/riscv/include/asm/Kbuild
··· 1 + generic-y += bugs.h 2 + generic-y += cacheflush.h 3 + generic-y += checksum.h 4 + generic-y += clkdev.h 5 + generic-y += cputime.h 6 + generic-y += device.h 7 + generic-y += div64.h 8 + generic-y += dma.h 9 + generic-y += dma-contiguous.h 10 + generic-y += emergency-restart.h 11 + generic-y += errno.h 12 + generic-y += exec.h 13 + generic-y += fb.h 14 + generic-y += fcntl.h 15 + generic-y += ftrace.h 16 + generic-y += futex.h 17 + generic-y += hardirq.h 18 + generic-y += hash.h 19 + generic-y += hw_irq.h 20 + generic-y += ioctl.h 21 + generic-y += ioctls.h 22 + generic-y += ipcbuf.h 23 + generic-y += irq_regs.h 24 + generic-y += irq_work.h 25 + generic-y += kdebug.h 26 + generic-y += kmap_types.h 27 + generic-y += kvm_para.h 28 + generic-y += local.h 29 + generic-y += mm-arch-hooks.h 30 + generic-y += mman.h 31 + generic-y += module.h 32 + generic-y += msgbuf.h 33 + generic-y += mutex.h 34 + generic-y += param.h 35 + generic-y += percpu.h 36 + generic-y += poll.h 37 + generic-y += posix_types.h 38 + generic-y += preempt.h 39 + generic-y += resource.h 40 + generic-y += scatterlist.h 41 + generic-y += sections.h 42 + generic-y += sembuf.h 43 + generic-y += setup.h 44 + generic-y += shmbuf.h 45 + generic-y += shmparam.h 46 + generic-y += signal.h 47 + generic-y += socket.h 48 + generic-y += sockios.h 49 + generic-y += stat.h 50 + generic-y += statfs.h 51 + generic-y += swab.h 52 + generic-y += termbits.h 53 + generic-y += termios.h 54 + generic-y += topology.h 55 + generic-y += trace_clock.h 56 + generic-y += types.h 57 + generic-y += unaligned.h 58 + generic-y += user.h 59 + generic-y += vga.h 60 + generic-y += vmlinux.lds.h 61 + generic-y += xor.h
+1
arch/riscv/kernel/.gitignore
··· 1 + /vmlinux.lds
+33
arch/riscv/kernel/Makefile
··· 1 + # 2 + # Makefile for the RISC-V Linux kernel 3 + # 4 + 5 + extra-y += head.o 6 + extra-y += vmlinux.lds 7 + 8 + obj-y += cpu.o 9 + obj-y += cpufeature.o 10 + obj-y += entry.o 11 + obj-y += irq.o 12 + obj-y += process.o 13 + obj-y += ptrace.o 14 + obj-y += reset.o 15 + obj-y += setup.o 16 + obj-y += signal.o 17 + obj-y += syscall_table.o 18 + obj-y += sys_riscv.o 19 + obj-y += time.o 20 + obj-y += traps.o 21 + obj-y += riscv_ksyms.o 22 + obj-y += stacktrace.o 23 + obj-y += vdso.o 24 + obj-y += cacheinfo.o 25 + obj-y += vdso/ 26 + 27 + CFLAGS_setup.o := -mcmodel=medany 28 + 29 + obj-$(CONFIG_SMP) += smpboot.o 30 + obj-$(CONFIG_SMP) += smp.o 31 + obj-$(CONFIG_MODULES) += module.o 32 + 33 + clean:
+92
arch/riscv/kernel/vmlinux.lds.S
··· 1 + /* 2 + * Copyright (C) 2012 Regents of the University of California 3 + * Copyright (C) 2017 SiFive 4 + * 5 + * This program is free software; you can redistribute it and/or 6 + * modify it under the terms of the GNU General Public License 7 + * as published by the Free Software Foundation, version 2. 8 + * 9 + * This program is distributed in the hope that it will be useful, 10 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 + * GNU General Public License for more details. 13 + */ 14 + 15 + #define LOAD_OFFSET PAGE_OFFSET 16 + #include <asm/vmlinux.lds.h> 17 + #include <asm/page.h> 18 + #include <asm/cache.h> 19 + #include <asm/thread_info.h> 20 + 21 + OUTPUT_ARCH(riscv) 22 + ENTRY(_start) 23 + 24 + jiffies = jiffies_64; 25 + 26 + SECTIONS 27 + { 28 + /* Beginning of code and text segment */ 29 + . = LOAD_OFFSET; 30 + _start = .; 31 + __init_begin = .; 32 + HEAD_TEXT_SECTION 33 + INIT_TEXT_SECTION(PAGE_SIZE) 34 + INIT_DATA_SECTION(16) 35 + /* we have to discard exit text and such at runtime, not link time */ 36 + .exit.text : 37 + { 38 + EXIT_TEXT 39 + } 40 + .exit.data : 41 + { 42 + EXIT_DATA 43 + } 44 + PERCPU_SECTION(L1_CACHE_BYTES) 45 + __init_end = .; 46 + 47 + .text : { 48 + _text = .; 49 + _stext = .; 50 + TEXT_TEXT 51 + SCHED_TEXT 52 + CPUIDLE_TEXT 53 + LOCK_TEXT 54 + KPROBES_TEXT 55 + ENTRY_TEXT 56 + IRQENTRY_TEXT 57 + *(.fixup) 58 + _etext = .; 59 + } 60 + 61 + /* Start of data section */ 62 + _sdata = .; 63 + RO_DATA_SECTION(L1_CACHE_BYTES) 64 + .srodata : { 65 + *(.srodata*) 66 + } 67 + 68 + RW_DATA_SECTION(L1_CACHE_BYTES, PAGE_SIZE, THREAD_SIZE) 69 + .sdata : { 70 + __global_pointer$ = . + 0x800; 71 + *(.sdata*) 72 + /* End of data section */ 73 + _edata = .; 74 + *(.sbss*) 75 + } 76 + 77 + BSS_SECTION(0, 0, 0) 78 + 79 + EXCEPTION_TABLE(0x10) 80 + NOTES 81 + 82 + .rel.dyn : { 83 + *(.rel.dyn*) 84 + } 85 + 86 + _end = .; 87 + 88 + STABS_DEBUG 89 + DWARF_DEBUG 90 + 91 + DISCARDS 92 + }
+6
arch/riscv/lib/Makefile
··· 1 + lib-y += delay.o 2 + lib-y += memcpy.o 3 + lib-y += memset.o 4 + lib-y += uaccess.o 5 + 6 + lib-$(CONFIG_32BIT) += udivdi3.o
+4
arch/riscv/mm/Makefile
··· 1 + obj-y += init.o 2 + obj-y += fault.o 3 + obj-y += extable.o 4 + obj-y += ioremap.o