diff mbox

Makefile: Introduced super-simple config file

Message ID 20111209052729.2380.21525.stgit@localhost
State New
Headers show

Commit Message

Christoffer Dall Dec. 9, 2011, 5:27 a.m. UTC
Factor out all configuration details into a separate configuration file
names config.mk. This file is added to .gitignore, but a default config
file is supplied in config-default.mk.

The default config file creates kernel command boot lines for NFS boots
based on a script obtaining the host IP addres. Naturally users can
change this to a static IP or another script if they wish.

The config file lets users select a system and other config options
depend on this overall setting.

I am no expert on Makefiles, so there could be better ways to accomplish
these things, but I think this suffices for now.

This patch applies after Peter Maydell's latest patch series, which in turn
applies to the following tree:
git://linux-arm.org/boot-wrapper.git kvm-smp

Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>
---
 .gitignore        |    1 +
 Makefile          |   39 ++++--------------------
 boot.S            |   26 +---------------
 config-default.mk |   86 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 get_ip.sh         |    7 ++++
 5 files changed, 103 insertions(+), 56 deletions(-)
 create mode 100644 config-default.mk
 create mode 100755 get_ip.sh

Comments

Peter Maydell Dec. 9, 2011, 11:08 a.m. UTC | #1
On 9 December 2011 05:27, Christoffer Dall
<c.dall@virtualopensystems.com> wrote:
>  %: force
> +       $(warning ehehehehh $@)
>        $(MAKE) -C $(KERNEL_SRC) $@

Stray debug tracing?

> diff --git a/boot.S b/boot.S
> index e1c8d78..d1c766d 100644
> --- a/boot.S
> +++ b/boot.S
> @@ -142,30 +142,8 @@ atags:
>        @ ATAG_CMDLINE
>        .long   (1f - .) >> 2
>        .long   0x54410009
> -#ifdef KCMD
> -        /* User-specified command line always overrides */
> -        .asciz KCMD
> -#else
> -#ifdef MACH_MPS
> -       .asciz  "rdinit=/bin/sh console=ttyAMA3 mem=4M earlyprintk"
> -#elif defined(VEXPRESS)
> -
> -#ifdef USE_INITRD
> -       .asciz  "console=ttyAMA0 mem=512M mem=512M@0x880000000 earlyprintk ip=192.168.27.200::192.168.27.1:255.255.255.0:angstrom:eth0:off"
> -#else /* VEXPRESS && !USE_INITRD */
> -       .asciz  "console=ttyAMA0 mem=512M mem=512M@0x880000000 earlyprintk root=/dev/nfs nfsroot=192.168.27.93:/srv/nfs_root,tcp rw ip=dhcp nfsrootdebug"
> -#endif
> -
> -#else /* ! VEXPRESS && ! MACH_MPS */
> -
> -#ifdef USE_INITRD
> -       .asciz  "console=ttyAMA0 mem=256M earlyprintk"
> -#else
> -       .asciz  "root=/dev/nfs nfsroot=10.1.77.43:/work/debootstrap/arm ip=dhcp console=ttyAMA0 mem=256M earlyprintk"
> -#endif
> -
> -#endif
> -#endif
> +        /* Use the C-define for the kernel boot command */
> +       .ascii  KCMD
>        .align  2
>  1:

This is an unrelated change, really.
> +USE_INITRD ?= no
> +ifeq ($(USE_INITRD),yes)
> +CPPFLAGS       += -DUSE_INITRD
> +FILESYSTEM     = filesystem.cpio.gz

This should be a "?=", so you can set USE_INITRD and also override
FILESYSTEM.

> +# Default NFS root
> +NFS_ROOT       ?= /srv/nfsroot
> +NFS_SERVER     ?= $(shell ./get_ip.sh)

> --- /dev/null
> +++ b/get_ip.sh
> @@ -0,0 +1,7 @@
> +#/bin/bash
> +
> +ifconfig | \
> +       grep 'inet addr:'| \
> +       grep -v '127.0.0.1' | \
> +       cut -d: -f2 | \
> +       awk '{ print $1}'

This doesn't work on systems with more than one non-loopback
network interface (it prints the IP addresses for all of them).

How about this instead?

# there's no shorthand := equivalent of ?= and we don't want
# to run the shell every time we use the variable
ifeq ($(origin NFS_SERVER), undefined)
NFS_SERVER := $(shell ip addr show scope global | sed -ne '/inet/{s/
*inet \([^/]*\)\/.*/\1/p;q}')
endif

(also saves having to have an external script)

-- PMM
Christoffer Dall Dec. 9, 2011, 2:49 p.m. UTC | #2
On Fri, Dec 9, 2011 at 6:08 AM, Peter Maydell <peter.maydell@linaro.org> wrote:
> On 9 December 2011 05:27, Christoffer Dall
> <c.dall@virtualopensystems.com> wrote:
>>  %: force
>> +       $(warning ehehehehh $@)
>>        $(MAKE) -C $(KERNEL_SRC) $@
>
> Stray debug tracing?

oh yeah :)

>
>> diff --git a/boot.S b/boot.S
>> index e1c8d78..d1c766d 100644
>> --- a/boot.S
>> +++ b/boot.S
>> @@ -142,30 +142,8 @@ atags:
>>        @ ATAG_CMDLINE
>>        .long   (1f - .) >> 2
>>        .long   0x54410009
>> -#ifdef KCMD
>> -        /* User-specified command line always overrides */
>> -        .asciz KCMD
>> -#else
>> -#ifdef MACH_MPS
>> -       .asciz  "rdinit=/bin/sh console=ttyAMA3 mem=4M earlyprintk"
>> -#elif defined(VEXPRESS)
>> -
>> -#ifdef USE_INITRD
>> -       .asciz  "console=ttyAMA0 mem=512M mem=512M@0x880000000 earlyprintk ip=192.168.27.200::192.168.27.1:255.255.255.0:angstrom:eth0:off"
>> -#else /* VEXPRESS && !USE_INITRD */
>> -       .asciz  "console=ttyAMA0 mem=512M mem=512M@0x880000000 earlyprintk root=/dev/nfs nfsroot=192.168.27.93:/srv/nfs_root,tcp rw ip=dhcp nfsrootdebug"
>> -#endif
>> -
>> -#else /* ! VEXPRESS && ! MACH_MPS */
>> -
>> -#ifdef USE_INITRD
>> -       .asciz  "console=ttyAMA0 mem=256M earlyprintk"
>> -#else
>> -       .asciz  "root=/dev/nfs nfsroot=10.1.77.43:/work/debootstrap/arm ip=dhcp console=ttyAMA0 mem=256M earlyprintk"
>> -#endif
>> -
>> -#endif
>> -#endif
>> +        /* Use the C-define for the kernel boot command */
>> +       .ascii  KCMD
>>        .align  2
>>  1:
>
> This is an unrelated change, really.

Why do you think so? The fact that all the config settings depending
on the board type is now set in the config file eliminates the need to
have this check in the boot.S file. I can split it into two patches if
you want, but....

should be .asciz though I guess.


>> +USE_INITRD ?= no
>> +ifeq ($(USE_INITRD),yes)
>> +CPPFLAGS       += -DUSE_INITRD
>> +FILESYSTEM     = filesystem.cpio.gz
>
> This should be a "?=", so you can set USE_INITRD and also override
> FILESYSTEM.
>
yes, you're right, I missed that one.

>> +# Default NFS root
>> +NFS_ROOT       ?= /srv/nfsroot
>> +NFS_SERVER     ?= $(shell ./get_ip.sh)
>
>> --- /dev/null
>> +++ b/get_ip.sh
>> @@ -0,0 +1,7 @@
>> +#/bin/bash
>> +
>> +ifconfig | \
>> +       grep 'inet addr:'| \
>> +       grep -v '127.0.0.1' | \
>> +       cut -d: -f2 | \
>> +       awk '{ print $1}'
>
> This doesn't work on systems with more than one non-loopback
> network interface (it prints the IP addresses for all of them).
>
> How about this instead?
>
> # there's no shorthand := equivalent of ?= and we don't want
> # to run the shell every time we use the variable
> ifeq ($(origin NFS_SERVER), undefined)
> NFS_SERVER := $(shell ip addr show scope global | sed -ne '/inet/{s/
> *inet \([^/]*\)\/.*/\1/p;q}')
> endif
>
> (also saves having to have an external script)
>
ok, looks good.
diff mbox

Patch

diff --git a/.gitignore b/.gitignore
index 05aa345..07eefe1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,5 +2,6 @@  filesystem.cpio.gz
 linux-system.axf
 uImage
 model.lds
+config.mk
 *.o
 *.swp
diff --git a/Makefile b/Makefile
index e1635ea..ec5ccfb 100644
--- a/Makefile
+++ b/Makefile
@@ -5,47 +5,21 @@ 
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE.txt file.
 
-CPPFLAGS	+= -DSMP
-#CPPFLAGS	+= -DTHUMB2_KERNEL
-CPPFLAGS	+= -march=armv7-a
-CPPFLAGS	+= -DVEXPRESS
-
-# Turn this on to use an initrd whose contents are in filesystem.cpio.gz
-USE_INITRD = no
-ifeq ($(USE_INITRD),yes)
-CPPFLAGS	+= -DUSE_INITRD
-FILESYSTEM	= filesystem.cpio.gz
+
+# Include config file (prefer config.mk, fall back to config-default.mk)
+ifneq ($(wildcard config.mk),)
+include config.mk
 else
-FILESYSTEM =
+include config-default.mk
 endif
 
-# MPS (Cortex-M3) definitions
-#CPPFLAGS	+= -DMACH_MPS -DTHUMB2_KERNEL
-#CPPFLAGS	+= -march=armv7-m
-#CPPFLAGS	+= -mthumb -Wa,-mthumb -Wa,-mimplicit-it=always
-
-# Kernel command line
-# MPS:
-# KCMD = "rdinit=/bin/sh console=ttyAMA3 mem=4M earlyprintk"
-# not-vexpress (ie EB, RealviewPB, etc), with initrd
-# KCMD = "console=ttyAMA0 mem=256M earlyprintk"
-# not-vexpress, without initrd:
-# KCMD = "root=/dev/nfs nfsroot=10.1.77.43:/work/debootstrap/arm ip=dhcp console=ttyAMA0 mem=256M earlyprintk"
-# Vexpress, with initrd:
-# KCMD = "console=ttyAMA0 mem=512M mem=512M@0x880000000 earlyprintk ip=192.168.27.200::192.168.27.1:255.255.255.0:angstrom:eth0:off"
-# VExpress, without initrd:
-KCMD ?= "console=ttyAMA0 mem=512M mem=512M@0x880000000 earlyprintk root=/dev/nfs nfsroot=172.31.252.250:/srv/arm-oneiric-root,tcp rw ip=dhcp nfsrootdebug"
-
 MONITOR		= monitor.S
 BOOTLOADER	= boot.S
-KERNEL_SRC	= ../linux-kvm-arm
 KERNEL		= uImage
 
 IMAGE		= linux-system.axf
 LD_SCRIPT	= model.lds.S
 
-CROSS_COMPILE	?= arm-unknown-eabi-
-ARCH		?= arm
 
 CC		= $(CROSS_COMPILE)gcc
 LD		= $(CROSS_COMPILE)ld
@@ -79,10 +53,11 @@  $(KERNEL_SRC)/arch/arm/boot/uImage: force
 # Pass any target we don't know about through to the kernel makefile.
 # This is a convenience rule so we can say 'make menuconfig' etc here.
 %: force
+	$(warning ehehehehh $@)
 	$(MAKE) -C $(KERNEL_SRC) $@
 
 force: ;
 
 Makefile: ;
 
-.PHONY: all clean
+.PHONY: all clean config.mk config-default.mk
diff --git a/boot.S b/boot.S
index e1c8d78..d1c766d 100644
--- a/boot.S
+++ b/boot.S
@@ -142,30 +142,8 @@  atags:
 	@ ATAG_CMDLINE
 	.long	(1f - .) >> 2
 	.long	0x54410009
-#ifdef KCMD
-        /* User-specified command line always overrides */
-        .asciz KCMD
-#else
-#ifdef MACH_MPS
-	.asciz	"rdinit=/bin/sh console=ttyAMA3 mem=4M earlyprintk"
-#elif defined(VEXPRESS)
-
-#ifdef USE_INITRD
-	.asciz	"console=ttyAMA0 mem=512M mem=512M@0x880000000 earlyprintk ip=192.168.27.200::192.168.27.1:255.255.255.0:angstrom:eth0:off"
-#else /* VEXPRESS && !USE_INITRD */
-	.asciz	"console=ttyAMA0 mem=512M mem=512M@0x880000000 earlyprintk root=/dev/nfs nfsroot=192.168.27.93:/srv/nfs_root,tcp rw ip=dhcp nfsrootdebug"
-#endif
-
-#else /* ! VEXPRESS && ! MACH_MPS */
-
-#ifdef USE_INITRD
-	.asciz	"console=ttyAMA0 mem=256M earlyprintk"
-#else
-	.asciz	"root=/dev/nfs nfsroot=10.1.77.43:/work/debootstrap/arm ip=dhcp console=ttyAMA0 mem=256M earlyprintk"
-#endif
-
-#endif
-#endif
+        /* Use the C-define for the kernel boot command */
+	.ascii	KCMD
 	.align	2
 1:
 
diff --git a/config-default.mk b/config-default.mk
new file mode 100644
index 0000000..5160e58
--- /dev/null
+++ b/config-default.mk
@@ -0,0 +1,86 @@ 
+# Configuration file included in Makefile
+#
+# Copyright (C) 2011 Columbia University. All rights reserved.
+# 		     Christoffer Dall <cdall@cs.columbia.edu>
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE.txt file.
+#
+# This is a sample configuration file. To make changes, copy this file to
+# config.mk and modify that file.
+#
+# For all systems you can override USE_INITRD and KCMD from the command-line.
+#
+
+###########################################################################
+# Main options
+#
+CROSS_COMPILE	?= arm-unknown-eabi-
+ARCH		?= arm
+KERNEL_SRC	?= ../linux-kvm-arm
+
+# Select system:
+# mps:		MPS (Cortex-M3)
+# realview_eb:	RealViewPB, EB, etc.
+# vexpress:	Versatile Express
+SYSTEM ?= vexpress
+
+###########################################################################
+# Turn this on to use an initrd whose contents are in filesystem.cpio.gz
+USE_INITRD ?= no
+ifeq ($(USE_INITRD),yes)
+CPPFLAGS	+= -DUSE_INITRD
+FILESYSTEM	= filesystem.cpio.gz
+else
+FILESYSTEM =
+endif
+
+###########################################################################
+# Default NFS root
+NFS_ROOT	?= /srv/nfsroot
+NFS_SERVER	?= $(shell ./get_ip.sh)
+
+
+###########################################################################
+# MPS (Cortex-M3) definitions
+#
+ifeq ($(SYSTEM),mps)
+# C-flags
+CPPFLAGS	+= -DMACH_MPS -DTHUMB2_KERNEL
+CPPFLAGS	+= -march=armv7-m
+CPPFLAGS	+= -mthumb -Wa,-mthumb -Wa,-mimplicit-it=always
+
+# Kernel command line
+KCMD ?= "rdinit=/bin/sh console=ttyAMA3 mem=4M earlyprintk"
+endif
+
+
+###########################################################################
+# EB, RealviewPB, etc
+#
+ifeq ($(SYSTEM),realview_eb)
+# Default kernel command line, using initrd:
+ifeq ($(USE_INITRD),yes)
+KCMD ?= "console=ttyAMA0 mem=256M earlyprintk"
+endif
+#
+# Default kernel command line, without initrd:
+ifneq ($(USE_INITRD),yes)
+	KCMD ?= "root=/dev/nfs nfsroot=$(NFS_HOST):$(NFS_ROOT) ip=dhcp console=ttyAMA0 mem=256M earlyprintk"
+endif
+endif
+
+
+###########################################################################
+# Versatile Express
+#
+ifeq ($(SYSTEM),vexpress)
+# Default kernel command line, using initrd:
+ifeq ($(USE_INITRD),yes)
+KCMD ?= "console=ttyAMA0 mem=512M mem=512M@0x880000000 earlyprintk ip=dhcp"
+endif
+#
+# Default kernel command line, without initrd:
+ifneq ($(USE_INITRD),yes)
+	KCMD ?= "console=ttyAMA0 mem=512M mem=512M@0x880000000 earlyprintk root=/dev/nfs nfsroot=$(NFS_SERVER):$(NFS_ROOT),tcp rw ip=dhcp nfsrootdebug"
+endif
+endif
diff --git a/get_ip.sh b/get_ip.sh
new file mode 100755
index 0000000..2ef9eac
--- /dev/null
+++ b/get_ip.sh
@@ -0,0 +1,7 @@ 
+#/bin/bash
+
+ifconfig | \
+	grep 'inet addr:'| \
+	grep -v '127.0.0.1' | \
+	cut -d: -f2 | \
+	awk '{ print $1}'