162306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ciKBUILD_DEFCONFIG := mmu_defconfig
362306a36Sopenharmony_ci
462306a36Sopenharmony_ciUTS_SYSNAME = -DUTS_SYSNAME=\"Linux\"
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci# What CPU version are we building for, and crack it open
762306a36Sopenharmony_ci# as major.minor.rev
862306a36Sopenharmony_ciCPU_VER   := $(CONFIG_XILINX_MICROBLAZE0_HW_VER)
962306a36Sopenharmony_ciCPU_MAJOR := $(word 1, $(subst ., , $(CPU_VER)))
1062306a36Sopenharmony_ciCPU_MINOR := $(word 2, $(subst ., , $(CPU_VER)))
1162306a36Sopenharmony_ciCPU_REV   := $(word 3, $(subst ., , $(CPU_VER)))
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ciexport CPU_VER CPU_MAJOR CPU_MINOR CPU_REV
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci# Use cpu-related CONFIG_ vars to set compile options.
1662306a36Sopenharmony_ci# The various CONFIG_XILINX cpu features options are integers 0/1/2...
1762306a36Sopenharmony_ci# rather than bools y/n
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci# Work out HW multipler support. This is tricky.
2062306a36Sopenharmony_ci# 1. Spartan2 has no HW multipliers.
2162306a36Sopenharmony_ci# 2. MicroBlaze v3.x always uses them, except in Spartan 2
2262306a36Sopenharmony_ci# 3. All other FPGa/CPU ver combos, we can trust the CONFIG_ settings
2362306a36Sopenharmony_ciifeq (,$(findstring spartan2,$(CONFIG_XILINX_MICROBLAZE0_FAMILY)))
2462306a36Sopenharmony_ci  ifeq ($(CPU_MAJOR),3)
2562306a36Sopenharmony_ci    CPUFLAGS-1 += -mno-xl-soft-mul
2662306a36Sopenharmony_ci  else
2762306a36Sopenharmony_ci    # USE_HW_MUL can be 0, 1, or 2, defining a hierarchy of HW Mul support.
2862306a36Sopenharmony_ci    CPUFLAGS-$(subst 1,,$(CONFIG_XILINX_MICROBLAZE0_USE_HW_MUL)) += -mxl-multiply-high
2962306a36Sopenharmony_ci    CPUFLAGS-$(CONFIG_XILINX_MICROBLAZE0_USE_HW_MUL) += -mno-xl-soft-mul
3062306a36Sopenharmony_ci  endif
3162306a36Sopenharmony_ciendif
3262306a36Sopenharmony_ciCPUFLAGS-$(CONFIG_XILINX_MICROBLAZE0_USE_DIV) += -mno-xl-soft-div
3362306a36Sopenharmony_ciCPUFLAGS-$(CONFIG_XILINX_MICROBLAZE0_USE_BARREL) += -mxl-barrel-shift
3462306a36Sopenharmony_ciCPUFLAGS-$(CONFIG_XILINX_MICROBLAZE0_USE_PCMP_INSTR) += -mxl-pattern-compare
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ciifdef CONFIG_CPU_BIG_ENDIAN
3762306a36Sopenharmony_ciKBUILD_CFLAGS += -mbig-endian
3862306a36Sopenharmony_ciKBUILD_AFLAGS += -mbig-endian
3962306a36Sopenharmony_ciKBUILD_LDFLAGS += -EB
4062306a36Sopenharmony_cielse
4162306a36Sopenharmony_ciKBUILD_CFLAGS += -mlittle-endian
4262306a36Sopenharmony_ciKBUILD_AFLAGS += -mlittle-endian
4362306a36Sopenharmony_ciKBUILD_LDFLAGS += -EL
4462306a36Sopenharmony_ciendif
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ciCPUFLAGS-1 += $(call cc-option,-mcpu=v$(CPU_VER))
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci# r31 holds current when in kernel mode
4962306a36Sopenharmony_ciKBUILD_CFLAGS += -ffixed-r31 $(CPUFLAGS-y) $(CPUFLAGS-1) $(CPUFLAGS-2)
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_cilibs-y += arch/microblaze/lib/
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ciboot := arch/microblaze/boot
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci# Are we making a simpleImage.<boardname> target? If so, crack out the boardname
5662306a36Sopenharmony_ciDTB:=$(subst simpleImage.,,$(filter simpleImage.%, $(MAKECMDGOALS)))
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ciexport DTB
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ciall: linux.bin
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ciarchheaders:
6362306a36Sopenharmony_ci	$(Q)$(MAKE) $(build)=arch/microblaze/kernel/syscalls all
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ciPHONY += linux.bin linux.bin.gz linux.bin.ub
6662306a36Sopenharmony_cilinux.bin.ub linux.bin.gz: linux.bin
6762306a36Sopenharmony_cilinux.bin: vmlinux
6862306a36Sopenharmony_cilinux.bin linux.bin.gz linux.bin.ub:
6962306a36Sopenharmony_ci	$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
7062306a36Sopenharmony_ci	@echo 'Kernel: $(boot)/$@ is ready' ' (#'$(or $(KBUILD_BUILD_VERSION),`cat .version`)')'
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ciPHONY += simpleImage.$(DTB)
7362306a36Sopenharmony_cisimpleImage.$(DTB): vmlinux
7462306a36Sopenharmony_ci	$(Q)$(MAKE) $(build)=$(boot) $(addprefix $(boot)/$@., ub unstrip strip)
7562306a36Sopenharmony_ci	@echo 'Kernel: $(boot)/$@ is ready' ' (#'$(or $(KBUILD_BUILD_VERSION),`cat .version`)')'
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_cidefine archhelp
7862306a36Sopenharmony_ci  echo '* linux.bin    - Create raw binary'
7962306a36Sopenharmony_ci  echo '  linux.bin.gz - Create compressed raw binary'
8062306a36Sopenharmony_ci  echo '  linux.bin.ub - Create U-Boot wrapped raw binary'
8162306a36Sopenharmony_ci  echo '  simpleImage.<dt> - Create the following images with <dt>.dtb linked in'
8262306a36Sopenharmony_ci  echo '                    simpleImage.<dt>        : raw image'
8362306a36Sopenharmony_ci  echo '                    simpleImage.<dt>.ub     : raw image with U-Boot header'
8462306a36Sopenharmony_ci  echo '                    simpleImage.<dt>.unstrip: ELF (identical to vmlinux)'
8562306a36Sopenharmony_ci  echo '                    simpleImage.<dt>.strip  : stripped ELF'
8662306a36Sopenharmony_ci  echo '  Targets with <dt> embed a device tree blob inside the image'
8762306a36Sopenharmony_ci  echo '  These targets support board with firmware that does not'
8862306a36Sopenharmony_ci  echo '  support passing a device tree directly. Replace <dt> with the'
8962306a36Sopenharmony_ci  echo '  name of a dts file from the arch/microblaze/boot/dts/ directory'
9062306a36Sopenharmony_ci  echo '  (minus the .dts extension).'
9162306a36Sopenharmony_ciendef
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ciMRPROPER_FILES += $(boot)/simpleImage.*
94