mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 07/11] add a generic default environment
Date: Mon, 14 Jun 2010 11:48:37 +0200	[thread overview]
Message-ID: <1276508921-3264-8-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>

We have several nearly identical default environments in the tree.
Lets merge them to a single environment and use it on many boards.
This defaultenv is arm centric at the moment due to the use of arm
specific boot commands. This can be improved over time.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 defaultenv/bin/_update       |   39 +++++++++++++++
 defaultenv/bin/boot          |  110 ++++++++++++++++++++++++++++++++++++++++++
 defaultenv/bin/hush_hack     |    1 +
 defaultenv/bin/init          |   30 +++++++++++
 defaultenv/bin/update_kernel |   15 ++++++
 defaultenv/bin/update_rootfs |   16 ++++++
 6 files changed, 211 insertions(+), 0 deletions(-)
 create mode 100644 defaultenv/bin/_update
 create mode 100644 defaultenv/bin/boot
 create mode 100644 defaultenv/bin/hush_hack
 create mode 100644 defaultenv/bin/init
 create mode 100644 defaultenv/bin/update_kernel
 create mode 100644 defaultenv/bin/update_rootfs

diff --git a/defaultenv/bin/_update b/defaultenv/bin/_update
new file mode 100644
index 0000000..ddd6b84
--- /dev/null
+++ b/defaultenv/bin/_update
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+if [ -z "$part" -o -z "$image" ]; then
+	echo "define \$part and \$image"
+	exit 1
+fi
+
+if [ ! -e "$part" ]; then
+	echo "Partition $part does not exist"
+	exit 1
+fi
+
+if [ $# = 1 ]; then
+	image=$1
+fi
+
+if [ x$ip = xdhcp ]; then
+	dhcp
+fi
+
+ping $eth0.serverip
+if [ $? -ne 0 ] ; then
+	echo "Server did not reply! Update aborted."
+	exit 1
+fi
+
+unprotect $part
+
+echo
+echo "erasing partition $part"
+echo
+erase $part
+
+echo
+echo "flashing $image to $part"
+echo
+tftp $image $part
+
+protect $part
diff --git a/defaultenv/bin/boot b/defaultenv/bin/boot
new file mode 100644
index 0000000..8c300a3
--- /dev/null
+++ b/defaultenv/bin/boot
@@ -0,0 +1,110 @@
+#!/bin/sh
+
+. /env/config
+
+if [ x$1 = xnand ]; then
+	rootfs_loc=nand
+	kernel_loc=nand
+elif [ x$1 = xnor ]; then
+	rootfs_loc=nor
+	kernel_loc=nor
+elif [ x$1 = xnet ]; then
+	rootfs_loc=net
+	kernel_loc=net
+fi
+
+
+if [ x$ip = xdhcp ]; then
+	bootargs="$bootargs ip=dhcp"
+elif [ x$ip = xnone ]; then
+	bootargs="ip=none"
+else
+	bootargs="$bootargs ip=$eth0.ipaddr::$eth0.gateway:$eth0.netmask:::"
+fi
+
+
+if [ $rootfs_loc = net ]; then
+	bootargs="$bootargs root=/dev/nfs nfsroot=$nfsroot,v3,tcp noinitrd"
+elif [ $rootfs_loc = initrd ]; then
+	bootargs="$bootargs root=/dev/ram0 rdinit=/sbin/init"
+else
+	if [ x$rootfs_loc = xnand ]; then
+		rootfs_mtdblock=$rootfs_mtdblock_nand
+	else
+		rootfs_mtdblock=$rootfs_mtdblock_nor
+	fi
+
+	if [ $rootfs_type = ubifs ]; then
+		bootargs="$bootargs root=ubi0:root ubi.mtd=$rootfs_mtdblock"
+	else
+		bootargs="$bootargs root=/dev/mtdblock$rootfs_mtdblock"
+	fi
+
+	bootargs="$bootargs rootfstype=$rootfs_type noinitrd"
+fi
+
+if [ -n $nor_parts ]; then
+	mtdparts="${mtdparts}physmap-flash.o:${nor_parts};"
+fi
+
+if [ -n $nand_parts ]; then
+	mtdparts="${mtdparts}$nand_device:${nor_parts};"
+fi
+
+if [ -n $mtdparts ]; then
+	bootargs="${bootargs} mtdparts=\"${mtdparts}\""
+fi
+
+if [ ! -e /dev/ram0.kernelraw ]; then
+	# arm raw kernel images are usually located at sdram start + 0x8000
+	addpart dev/ram0 8M@0x8000(kernelraw)
+fi
+
+if [ ! -e /dev/ram0.kernel ]; then
+	# Here we can safely put the kernel without risking of overwriting it
+	# while extracting
+	addpart dev/ram0 8M(kernel)
+fi
+
+if [ $kernel_loc = net ]; then
+	if [ x$ip = xdhcp ]; then
+		dhcp
+	fi
+	if [ $kernelimage_type = uimage ]; then
+		netload="/dev/ram0.kernel"
+	elif [ $kernelimage_type = zimage ]; then
+		netload="/dev/ram0.kernel"
+	elif [ $kernelimage_type = raw ]; then
+		netload="/dev/ram0.kernelraw"
+	elif [ $kernelimage_type = raw_lzo ]; then
+		netload="/dev/ram0.kernel"
+	else
+		echo "error: missing kernel_image_type"
+		exit 1
+	fi
+	tftp $kernelimage $netload || exit 1
+	kdev="$netload"
+elif [ $kernel_loc = nor ]; then
+	kdev="/dev/nor0.kernel"
+elif [ $kernel_loc = nand ]; then
+	kdev="/dev/nand0.kernel.bb"
+else
+	echo "error: missing kernel_loc"
+	exit 1
+fi
+
+if [ $kernelimage_type = uimage ]; then
+	bootm $kdev
+elif [ $kernelimage_type = zimage ]; then
+	bootz $kdev
+elif [ $kernelimage_type = raw ]; then
+	if [ $kernel_loc != net ]; then
+		ec
+		cp $kdev /dev/ram0.kernelraw
+	fi
+	bootu /dev/ram0.kernelraw
+elif [ $kernelimage_type = raw_lzo ]; then
+	unlzo $kdev /dev/ram0.kernelraw
+	bootu /dev/ram0.kernelraw
+fi
+
diff --git a/defaultenv/bin/hush_hack b/defaultenv/bin/hush_hack
new file mode 100644
index 0000000..5fffa92
--- /dev/null
+++ b/defaultenv/bin/hush_hack
@@ -0,0 +1 @@
+nand -a /dev/nand0.*
diff --git a/defaultenv/bin/init b/defaultenv/bin/init
new file mode 100644
index 0000000..b17fcbc
--- /dev/null
+++ b/defaultenv/bin/init
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+PATH=/env/bin
+export PATH
+
+. /env/config
+if [ -e /dev/nor0 ]; then
+	addpart /dev/nor0 $nor_parts
+fi
+
+if [ -e /dev/nand0 ]; then
+	addpart /dev/nand0 $nand_parts
+
+	# Uh, oh, hush first expands wildcards and then starts executing
+	# commands. What a bug!
+	source /env/bin/hush_hack
+fi
+
+echo
+echo -n "Hit any key to stop autoboot: "
+timeout -a $autoboot_timeout
+if [ $? != 0 ]; then
+	echo
+	echo "type update_kernel nand|nor [<imagename>] to update kernel into flash"
+	echo "type update_rootfs nand|nor [<imagename>] to update rootfs into flash"
+	echo
+	exit
+fi
+
+boot
diff --git a/defaultenv/bin/update_kernel b/defaultenv/bin/update_kernel
new file mode 100644
index 0000000..1d35ed9
--- /dev/null
+++ b/defaultenv/bin/update_kernel
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+. /env/config
+image=$kernelimage
+
+if [ x$1 = xnand ]; then
+	part=/dev/nand0.kernel.bb
+elif [ x$1 = xnor ]; then
+	part=/dev/nor0.kernel
+else
+	echo "usage: $0 nor|nand [imagename]"
+	exit 1
+fi
+
+. /env/bin/_update $2
diff --git a/defaultenv/bin/update_rootfs b/defaultenv/bin/update_rootfs
new file mode 100644
index 0000000..6366315
--- /dev/null
+++ b/defaultenv/bin/update_rootfs
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+. /env/config
+
+image=$rootfsimage
+
+if [ x$1 = xnand ]; then
+	part=/dev/nand0.root.bb
+elif [ x$1 = xnor ]; then
+	part=/dev/nor0.root
+else
+	echo "usage: $0 nor|nand [imagename]"
+	exit 1
+fi
+
+. /env/bin/_update $2
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2010-06-14  9:48 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-14  9:48 More patches Sascha Hauer
2010-06-14  9:48 ` [PATCH 01/11] pcm037: Add MMU support Sascha Hauer
2010-06-14  9:48 ` [PATCH 02/11] bootu: Allow passing in devices as parameter Sascha Hauer
2010-06-14  9:48 ` [PATCH 03/11] Allow to merge default environment from more than one directory Sascha Hauer
2010-06-14  9:48 ` [PATCH 04/11] include support for a simple pseudo number generator Sascha Hauer
2010-06-15  9:39   ` Peter Korsgaard
2010-06-15 11:54     ` Sascha Hauer
2010-06-17 13:17   ` Sascha Hauer
2010-06-17 13:26     ` Andy Pont
2010-06-17 14:14     ` Peter Korsgaard
2010-06-14  9:48 ` [PATCH 05/11] net: implement random_ether_addr Sascha Hauer
2010-06-14  9:48 ` [PATCH 06/11] net: use a random mac address if the current device does not have one Sascha Hauer
2010-06-14  9:48 ` Sascha Hauer [this message]
2010-06-15  9:13   ` [PATCH 07/11] add a generic default environment Uwe Kleine-König
2010-06-17 13:20   ` Sascha Hauer
2010-06-19 20:14     ` Uwe Kleine-König
2010-06-14  9:48 ` [PATCH 08/11] pcm038: use generic default env Sascha Hauer
2010-06-14  9:48 ` [PATCH 09/11] pcm043: " Sascha Hauer
2010-06-14  9:48 ` [PATCH 10/11] pcm037: " Sascha Hauer
2010-06-14  9:48 ` [PATCH 11/11] pca100: " Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1276508921-3264-8-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox