Skip to content

Commit 2fc8483

Browse files
author
Ley Foon Tan
committed
nios2: Build infrastructure
This patch adds Makefile and Kconfig files required for building a nios2 kernel. Signed-off-by: Ley Foon Tan <[email protected]>
1 parent 9cce02e commit 2fc8483

File tree

15 files changed

+826
-0
lines changed

15 files changed

+826
-0
lines changed

arch/nios2/Kconfig

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
config NIOS2
2+
def_bool y
3+
select ARCH_WANT_OPTIONAL_GPIOLIB
4+
select CLKSRC_OF
5+
select GENERIC_ATOMIC64
6+
select GENERIC_CLOCKEVENTS
7+
select GENERIC_CPU_DEVICES
8+
select GENERIC_IRQ_PROBE
9+
select GENERIC_IRQ_SHOW
10+
select HAVE_ARCH_TRACEHOOK
11+
select IRQ_DOMAIN
12+
select MODULES_USE_ELF_RELA
13+
select OF
14+
select OF_EARLY_FLATTREE
15+
select SOC_BUS
16+
select SPARSE_IRQ
17+
select USB_ARCH_HAS_HCD if USB_SUPPORT
18+
19+
config GENERIC_CSUM
20+
def_bool y
21+
22+
config GENERIC_HWEIGHT
23+
def_bool y
24+
25+
config GENERIC_CALIBRATE_DELAY
26+
def_bool y
27+
28+
config NO_IOPORT_MAP
29+
def_bool y
30+
31+
config HAS_DMA
32+
def_bool y
33+
34+
config FPU
35+
def_bool n
36+
37+
config SWAP
38+
def_bool n
39+
40+
config RWSEM_GENERIC_SPINLOCK
41+
def_bool y
42+
43+
config TRACE_IRQFLAGS_SUPPORT
44+
def_bool n
45+
46+
source "init/Kconfig"
47+
48+
menu "Kernel features"
49+
50+
source "kernel/Kconfig.preempt"
51+
52+
source "kernel/Kconfig.freezer"
53+
54+
source "kernel/Kconfig.hz"
55+
56+
source "mm/Kconfig"
57+
58+
config FORCE_MAX_ZONEORDER
59+
int "Maximum zone order"
60+
range 9 20
61+
default "11"
62+
help
63+
The kernel memory allocator divides physically contiguous memory
64+
blocks into "zones", where each zone is a power of two number of
65+
pages. This option selects the largest power of two that the kernel
66+
keeps in the memory allocator. If you need to allocate very large
67+
blocks of physically contiguous memory, then you may need to
68+
increase this value.
69+
70+
This config option is actually maximum order plus one. For example,
71+
a value of 11 means that the largest free memory block is 2^10 pages.
72+
73+
endmenu
74+
75+
source "arch/nios2/platform/Kconfig.platform"
76+
77+
menu "Processor type and features"
78+
79+
config MMU
80+
def_bool y
81+
82+
config NIOS2_ALIGNMENT_TRAP
83+
bool "Catch alignment trap"
84+
default y
85+
help
86+
Nios II CPUs cannot fetch/store data which is not bus aligned,
87+
i.e., a 2 or 4 byte fetch must start at an address divisible by
88+
2 or 4. Any non-aligned load/store instructions will be trapped and
89+
emulated in software if you say Y here, which has a performance
90+
impact.
91+
92+
comment "Boot options"
93+
94+
config CMDLINE_BOOL
95+
bool "Default bootloader kernel arguments"
96+
default y
97+
98+
config CMDLINE
99+
string "Default kernel command string"
100+
default ""
101+
depends on CMDLINE_BOOL
102+
help
103+
On some platforms, there is currently no way for the boot loader to
104+
pass arguments to the kernel. For these platforms, you can supply
105+
some command-line options at build time by entering them here. In
106+
other cases you can specify kernel args so that you don't have
107+
to set them up in board prom initialization routines.
108+
109+
config CMDLINE_FORCE
110+
bool "Force default kernel command string"
111+
depends on CMDLINE_BOOL
112+
help
113+
Set this to have arguments from the default kernel command string
114+
override those passed by the boot loader.
115+
116+
config NIOS2_CMDLINE_IGNORE_DTB
117+
bool "Ignore kernel command string from DTB"
118+
depends on !CMDLINE_FORCE
119+
default y
120+
help
121+
Set this to ignore the bootargs property from the devicetree's
122+
chosen node and fall back to CMDLINE if nothing is passed.
123+
124+
config NIOS2_PASS_CMDLINE
125+
bool "Passed kernel command line from u-boot"
126+
default n
127+
help
128+
Use bootargs env variable from u-boot for kernel command line.
129+
will override "Default kernel command string".
130+
Say N if you are unsure.
131+
132+
endmenu
133+
134+
menu "Advanced setup"
135+
136+
config ADVANCED_OPTIONS
137+
bool "Prompt for advanced kernel configuration options"
138+
help
139+
140+
comment "Default settings for advanced configuration options are used"
141+
depends on !ADVANCED_OPTIONS
142+
143+
config NIOS2_KERNEL_MMU_REGION_BASE_BOOL
144+
bool "Set custom kernel MMU region base address"
145+
depends on ADVANCED_OPTIONS
146+
help
147+
This option allows you to set the virtual address of the kernel MMU region.
148+
149+
Say N here unless you know what you are doing.
150+
151+
config NIOS2_KERNEL_MMU_REGION_BASE
152+
hex "Virtual base address of the kernel MMU region " if NIOS2_KERNEL_MMU_REGION_BASE_BOOL
153+
default "0x80000000"
154+
help
155+
This option allows you to set the virtual base address of the kernel MMU region.
156+
157+
config NIOS2_KERNEL_REGION_BASE_BOOL
158+
bool "Set custom kernel region base address"
159+
depends on ADVANCED_OPTIONS
160+
help
161+
This option allows you to set the virtual address of the kernel region.
162+
163+
Say N here unless you know what you are doing.
164+
165+
config NIOS2_KERNEL_REGION_BASE
166+
hex "Virtual base address of the kernel region " if NIOS2_KERNEL_REGION_BASE_BOOL
167+
default "0xc0000000"
168+
169+
config NIOS2_IO_REGION_BASE_BOOL
170+
bool "Set custom I/O region base address"
171+
depends on ADVANCED_OPTIONS
172+
help
173+
This option allows you to set the virtual address of the I/O region.
174+
175+
Say N here unless you know what you are doing.
176+
177+
config NIOS2_IO_REGION_BASE
178+
hex "Virtual base address of the I/O region" if NIOS2_IO_REGION_BASE_BOOL
179+
default "0xe0000000"
180+
181+
endmenu
182+
183+
menu "Executable file formats"
184+
185+
source "fs/Kconfig.binfmt"
186+
187+
endmenu
188+
189+
source "net/Kconfig"
190+
191+
source "drivers/Kconfig"
192+
193+
source "fs/Kconfig"
194+
195+
source "arch/nios2/Kconfig.debug"
196+
197+
source "security/Kconfig"
198+
199+
source "crypto/Kconfig"
200+
201+
source "lib/Kconfig"

arch/nios2/Kconfig.debug

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
menu "Kernel hacking"
2+
3+
config TRACE_IRQFLAGS_SUPPORT
4+
def_bool y
5+
6+
source "lib/Kconfig.debug"
7+
8+
config DEBUG_STACK_USAGE
9+
bool "Enable stack utilization instrumentation"
10+
depends on DEBUG_KERNEL
11+
help
12+
Enables the display of the minimum amount of free stack which each
13+
task has ever had available in the sysrq-T and sysrq-P debug output.
14+
15+
This option will slow down process creation somewhat.
16+
17+
endmenu

arch/nios2/Makefile

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#
2+
# This file is subject to the terms and conditions of the GNU General Public
3+
# License. See the file "COPYING" in the main directory of this archive
4+
# for more details.
5+
#
6+
# Copyright (C) 2013 Altera Corporation
7+
# Copyright (C) 1994, 95, 96, 2003 by Wind River Systems
8+
# Written by Fredrik Markstrom
9+
#
10+
# This file is included by the global makefile so that you can add your own
11+
# architecture-specific flags and dependencies. Remember to do have actions
12+
# for "archclean" cleaning up for this architecture.
13+
#
14+
# Nios2 port by Wind River Systems Inc trough:
15+
16+
17+
UTS_SYSNAME = Linux
18+
19+
export MMU
20+
21+
LIBGCC := $(shell $(CC) $(KBUILD_CFLAGS) -print-libgcc-file-name)
22+
23+
KBUILD_CFLAGS += -pipe -D__linux__ -D__ELF__
24+
KBUILD_CFLAGS += $(if $(CONFIG_NIOS2_HW_MUL_SUPPORT),-mhw-mul,-mno-hw-mul)
25+
KBUILD_CFLAGS += $(if $(CONFIG_NIOS2_HW_MULX_SUPPORT),-mhw-mulx,-mno-hw-mulx)
26+
KBUILD_CFLAGS += $(if $(CONFIG_NIOS2_HW_DIV_SUPPORT),-mhw-div,-mno-hw-div)
27+
KBUILD_CFLAGS += $(if $(CONFIG_NIOS2_FPU_SUPPORT),-mcustom-fpu-cfg=60-1,)
28+
29+
KBUILD_CFLAGS += -fno-optimize-sibling-calls
30+
KBUILD_CFLAGS += -DUTS_SYSNAME=\"$(UTS_SYSNAME)\"
31+
KBUILD_CFLAGS += -fno-builtin
32+
KBUILD_CFLAGS += -G 0
33+
34+
head-y := arch/nios2/kernel/head.o
35+
libs-y += arch/nios2/lib/ $(LIBGCC)
36+
core-y += arch/nios2/kernel/ arch/nios2/mm/
37+
core-y += arch/nios2/platform/
38+
39+
INSTALL_PATH ?= /tftpboot
40+
nios2-boot := arch/$(ARCH)/boot
41+
BOOT_TARGETS = vmImage zImage
42+
PHONY += $(BOOT_TARGETS) install
43+
KBUILD_IMAGE := $(nios2-boot)/vmImage
44+
45+
ifneq ($(CONFIG_NIOS2_DTB_SOURCE),"")
46+
core-y += $(nios2-boot)/
47+
endif
48+
49+
all: vmImage
50+
51+
archclean:
52+
$(Q)$(MAKE) $(clean)=$(nios2-boot)
53+
54+
%.dtb:
55+
$(Q)$(MAKE) $(build)=$(nios2-boot) $(nios2-boot)/$@
56+
57+
dtbs:
58+
$(Q)$(MAKE) $(build)=$(nios2-boot) $(nios2-boot)/$@
59+
60+
$(BOOT_TARGETS): vmlinux
61+
$(Q)$(MAKE) $(build)=$(nios2-boot) $(nios2-boot)/$@
62+
63+
install:
64+
$(Q)$(MAKE) $(build)=$(nios2-boot) BOOTIMAGE=$(KBUILD_IMAGE) install
65+
66+
define archhelp
67+
echo '* vmImage - Kernel-only image for U-Boot ($(KBUILD_IMAGE))'
68+
echo ' install - Install kernel using'
69+
echo ' (your) ~/bin/$(INSTALLKERNEL) or'
70+
echo ' (distribution) /sbin/$(INSTALLKERNEL) or'
71+
echo ' install to $$(INSTALL_PATH)'
72+
echo ' dtbs - Build device tree blobs for enabled boards'
73+
endef

arch/nios2/boot/Makefile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#
2+
# arch/nios2/boot/Makefile
3+
#
4+
# This file is subject to the terms and conditions of the GNU General Public
5+
# License. See the file "COPYING" in the main directory of this archive
6+
# for more details.
7+
#
8+
9+
UIMAGE_LOADADDR = $(shell $(NM) vmlinux | awk '$$NF == "_stext" {print $$1}')
10+
UIMAGE_ENTRYADDR = $(shell $(NM) vmlinux | awk '$$NF == "_start" {print $$1}')
11+
UIMAGE_COMPRESSION = gzip
12+
13+
OBJCOPYFLAGS_vmlinux.bin := -O binary
14+
15+
targets += vmlinux.bin vmlinux.gz vmImage
16+
17+
$(obj)/vmlinux.bin: vmlinux FORCE
18+
$(call if_changed,objcopy)
19+
20+
$(obj)/vmlinux.gz: $(obj)/vmlinux.bin FORCE
21+
$(call if_changed,gzip)
22+
23+
$(obj)/vmImage: $(obj)/vmlinux.gz
24+
$(call if_changed,uimage)
25+
@$(kecho) 'Kernel: $@ is ready'
26+
27+
# Rule to build device tree blobs
28+
DTB_SRC := $(patsubst "%",%,$(CONFIG_NIOS2_DTB_SOURCE))
29+
30+
# Make sure the generated dtb gets removed during clean
31+
extra-$(CONFIG_NIOS2_DTB_SOURCE_BOOL) += system.dtb
32+
33+
$(obj)/system.dtb: $(DTB_SRC) FORCE
34+
$(call cmd,dtc)
35+
36+
# Ensure system.dtb exists
37+
$(obj)/linked_dtb.o: $(obj)/system.dtb
38+
39+
obj-$(CONFIG_NIOS2_DTB_SOURCE_BOOL) += linked_dtb.o
40+
41+
targets += $(dtb-y)
42+
43+
# Rule to build device tree blobs with make command
44+
$(obj)/%.dtb: $(src)/dts/%.dts FORCE
45+
$(call if_changed_dep,dtc)
46+
47+
$(obj)/dtbs: $(addprefix $(obj)/, $(dtb-y))
48+
49+
clean-files := *.dtb
50+
51+
install:
52+
sh $(srctree)/$(src)/install.sh $(KERNELRELEASE) $(BOOTIMAGE) System.map "$(INSTALL_PATH)"

arch/nios2/boot/install.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/sh
2+
#
3+
# This file is subject to the terms and conditions of the GNU General Public
4+
# License. See the file "COPYING" in the main directory of this archive
5+
# for more details.
6+
#
7+
# Copyright (C) 1995 by Linus Torvalds
8+
#
9+
# Adapted from code in arch/i386/boot/Makefile by H. Peter Anvin
10+
#
11+
# "make install" script for nios2 architecture
12+
#
13+
# Arguments:
14+
# $1 - kernel version
15+
# $2 - kernel image file
16+
# $3 - kernel map file
17+
# $4 - default install path (blank if root directory)
18+
#
19+
20+
verify () {
21+
if [ ! -f "$1" ]; then
22+
echo "" 1>&2
23+
echo " *** Missing file: $1" 1>&2
24+
echo ' *** You need to run "make" before "make install".' 1>&2
25+
echo "" 1>&2
26+
exit 1
27+
fi
28+
}
29+
30+
# Make sure the files actually exist
31+
verify "$2"
32+
verify "$3"
33+
34+
# User may have a custom install script
35+
36+
if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi
37+
if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi
38+
39+
# Default install - same as make zlilo
40+
41+
if [ -f $4/vmlinuz ]; then
42+
mv $4/vmlinuz $4/vmlinuz.old
43+
fi
44+
45+
if [ -f $4/System.map ]; then
46+
mv $4/System.map $4/System.old
47+
fi
48+
49+
cat $2 > $4/vmlinuz
50+
cp $3 $4/System.map
51+
52+
sync

0 commit comments

Comments
 (0)