Commit e484c3eb authored by Benoit Rat's avatar Benoit Rat Committed by Alessandro Rubini

barebox: correct NAND bug in v2012.05 and new features i.e, boot menu, dhcp limit, gpio check, ...

parent ec2ef78c
From 62f41545be940803c0f7639963183181ca04e721 Mon Sep 17 00:00:00 2001
From: Benoit Rat <benoit@sevensols.com>
Date: Tue, 15 May 2012 17:08:41 +0200
Subject: [PATCH 4/9] add DHCP retries by tom
---
net/dhcp.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/net/dhcp.c b/net/dhcp.c
index ad32b53..88febea 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -607,6 +607,7 @@ static void dhcp_reset_env(void)
static int do_dhcp(int argc, char *argv[])
{
int ret, opt;
+ int retries=-1;
dhcp_reset_env();
@@ -627,6 +628,7 @@ static int do_dhcp(int argc, char *argv[])
}
}
+
dhcp_con = net_udp_new(0xffffffff, PORT_BOOTPS, dhcp_handler, NULL);
if (IS_ERR(dhcp_con)) {
ret = PTR_ERR(dhcp_con);
@@ -643,14 +645,25 @@ static int do_dhcp(int argc, char *argv[])
if (ret)
goto out1;
+ if(argc >= 2)
+ retries = simple_strtoul(argv[1], NULL, 10);
+
while (dhcp_state != BOUND) {
if (ctrlc())
break;
+ if (!retries)
+ {
+ ret = ETIMEDOUT;
+ goto out1;
+ }
+
net_poll();
if (is_timeout(dhcp_start, 3 * SECOND)) {
dhcp_start = get_time_ns();
printf("T ");
ret = bootp_request();
+ if(retries > 0)
+ retries--;
if (ret)
goto out1;
}
--
1.7.9.5
From faf08754590a65054cef411286ccc14f3a60642c Mon Sep 17 00:00:00 2001
From: Benoit Rat <benoit@sevensols.com>
Date: Mon, 28 May 2012 12:22:48 +0200
Subject: [PATCH 5/9] build: Add a script to compile with WRS env variables, &
ignore barebox_default_env
---
.gitignore | 2 +-
build.sh | 13 +++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
create mode 100755 build.sh
diff --git a/.gitignore b/.gitignore
index cc1f2e2..82963f3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -36,7 +36,7 @@ barebox.netx
barebox.map
System.map
Module.symvers
-barebox_default_env
+barebox_default_env*
#
# Generated include files
diff --git a/build.sh b/build.sh
new file mode 100755
index 0000000..d913edb
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+# To use this script you need to setup the `WRS_OUTPUT_DIR` variable by doing:
+#
+# export WRS_OUTPUT_DIR=/path/to/wrs/output/dir
+#
+# You should call the script like this:
+#
+# ./build.sh wrs3_defconfig
+# ./build.sh all
+
+
+make LINUX=${WRS_OUTPUT_DIR}/build/linux-2.6.39/ CROSS_COMPILE=${WRS_OUTPUT_DIR}/build/buildroot-2011.11/output/host/usr/bin/arm-linux- ARCH=arm $1
--
1.7.9.5
From c813f205325e95fac8e31ee616e43cacdc3dbd04 Mon Sep 17 00:00:00 2001
From: Benoit Rat <benoit@sevensols.com>
Date: Mon, 28 May 2012 12:23:13 +0200
Subject: [PATCH 6/9] gpio: add function to check them
---
arch/arm/boards/pm9g45/init.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/arch/arm/boards/pm9g45/init.c b/arch/arm/boards/pm9g45/init.c
index 9ecd628..a84e431 100644
--- a/arch/arm/boards/pm9g45/init.c
+++ b/arch/arm/boards/pm9g45/init.c
@@ -40,6 +40,25 @@
#include <mach/at91sam9_smc.h>
#include <mach/sam9_smc.h>
+/*
+ * board revision encoding
+ * V3.1 => by default: PA4 is 1 & PC7 is 0.
+ * V3.2 => by default: PA4 is 0 & PC7 is 1
+ */
+static void wrs3_check_gpios(void)
+{
+ if (!gpio_request(AT91_PIN_PA4, "") &&
+ !gpio_request(AT91_PIN_PC7, ""))
+ {
+ printf("GPIOs: PA4=%d (%d), PC7=%d (%d)\n",
+ gpio_get_value(AT91_PIN_PA4),AT91_PIN_PA4,gpio_get_value(AT91_PIN_PC7),AT91_PIN_PC7);
+ }
+ else
+ {
+ printf("Error: unable to acquire board GPIOs\n");
+ }
+}
+
static struct atmel_nand_data nand_pdata = {
.ale = 21,
.cle = 22,
@@ -148,6 +167,8 @@ static int pm9g45_devices_init(void)
armlinux_set_bootparams((void *)(AT91_CHIPSELECT_6 + 0x100));
armlinux_set_architecture(MACH_TYPE_PM9G45);
+
+ wrs3_check_gpios();
return 0;
}
--
1.7.9.5
From 868b709e683fd848afb0cdd8c17218e76d1cdcd6 Mon Sep 17 00:00:00 2001
From: Benoit Rat <benoit@sevensols.com>
Date: Mon, 2 Jul 2012 12:59:15 +0200
Subject: [PATCH 7/9] startup: load default environment when loading env
failed
---
common/startup.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/common/startup.c b/common/startup.c
index abd1b77..2992c43 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -147,6 +147,13 @@ void start_barebox (void)
run_command("source /env/bin/init", 0);
} else {
printf("not found\n");
+ if (stat("/env/", &s)) {
+ printf("Error loading %s. "
+ "Using default environment\n",
+ default_environment_path);
+ envfs_load("/dev/defaultenv", "/env");
+ run_command("source /env/bin/init", 0);
+ }
}
#endif
/* main_loop() can return to retry autoboot, if so just run it again. */
--
1.7.9.5
From 5b2b91f674f727fc1b40878e3f4a9ee721008eb2 Mon Sep 17 00:00:00 2001
From: Benoit Rat <benoit@sevensols.com>
Date: Mon, 2 Jul 2012 13:00:43 +0200
Subject: [PATCH 8/9] nand: Fix wrongly removed line for 16bits NAND
---
drivers/mtd/nand/atmel_nand.c | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 96624a1..bad75a9 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -141,6 +141,13 @@ static void atmel_read_buf(struct mtd_info *mtd, u8 *buf, int len)
memcpy_fromio(buf, chip->IO_ADDR_R, len);
}
+static void atmel_read_buf16(struct mtd_info *mtd, u8 *buf, int len)
+{
+ struct nand_chip *nand_chip = mtd->priv;
+
+ readsw(nand_chip->IO_ADDR_R, buf, len / 2);
+}
+
static void atmel_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
{
struct nand_chip *chip = mtd->priv;
@@ -148,6 +155,14 @@ static void atmel_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
memcpy_toio(chip->IO_ADDR_W, buf, len);
}
+static void atmel_write_buf16(struct mtd_info *mtd, const u8 *buf, int len)
+{
+ struct nand_chip *nand_chip = mtd->priv;
+
+ writesw(nand_chip->IO_ADDR_W, buf, len / 2);
+}
+
+
/*
* Calculate HW ECC
*
@@ -391,11 +406,14 @@ static int __init atmel_nand_probe(struct device_d *dev)
nand_chip->chip_delay = 20; /* 20us command delay time */
- if (host->board->bus_width_16) /* 16-bit bus width */
+ if (host->board->bus_width_16) { /* 16-bit bus width */
nand_chip->options |= NAND_BUSWIDTH_16;
-
- nand_chip->read_buf = atmel_read_buf;
- nand_chip->write_buf = atmel_write_buf;
+ nand_chip->read_buf = atmel_read_buf16;
+ nand_chip->write_buf = atmel_write_buf16;
+ } else {
+ nand_chip->read_buf = atmel_read_buf;
+ nand_chip->write_buf = atmel_write_buf;
+ }
atmel_nand_enable(host);
--
1.7.9.5
From ac5a6dcee581286e1bd5cc9b6da136dc601f93cd Mon Sep 17 00:00:00 2001
From: Alessandro Rubini <rubini@gnudd.com>
Date: Mon, 9 Jul 2012 13:40:30 +0200
Subject: [PATCH 9/9] wrs: init & config script with menu (support v3.2)
Author: Benoit Rat <benoit@sevensols.com>
---
arch/arm/boards/pm9g45/env/bin/init | 230 ++++++++++++++++++++++++
arch/arm/boards/pm9g45/env/config | 39 ++--
arch/arm/boards/pm9g45/env/this_is_compiled_in | 3 +
arch/arm/boards/pm9g45/init.c | 4 +-
4 files changed, 244 insertions(+), 32 deletions(-)
create mode 100644 arch/arm/boards/pm9g45/env/bin/init
create mode 100644 arch/arm/boards/pm9g45/env/this_is_compiled_in
diff --git a/arch/arm/boards/pm9g45/env/bin/init b/arch/arm/boards/pm9g45/env/bin/init
new file mode 100644
index 0000000..8a95f5c
--- /dev/null
+++ b/arch/arm/boards/pm9g45/env/bin/init
@@ -0,0 +1,230 @@
+#!/bin/sh
+#
+# Init script for WRS barebox
+# ========================
+# Syntax: Hush shell script
+# Authors: Benoit Rat, Tomasz Wlostowski
+# Environment variables:
+# - autoboot_timeout: number of seconds
+# - autoboot_altforced: "1" or "0"
+# - default_altmode: i.e "the menu number"
+# - ip: dhcp or none (in this case setup by eth0)
+#######################################
+
+echo ""
+echo "=============================================="
+
+### Default value ": ${VISUAL:=vi}"
+autoboot_timeout="10";
+autoboot_altforced="0";
+autoboot_altmode="2";
+error_timeout="60";
+
+bootargs="console=ttyS0,115200"
+
+### Override default value using /env/config
+. /env/config
+echo "Starting up barebox [wrs3] (MAC=$eth0.ethaddr)"
+
+
+### Generic setup
+PATH=/env/bin
+export PATH
+
+if [ x$autoboot_timeout != x ]; then menu_timeout="-A $autoboot_timeout"; fi
+
+gpio_set_value 33 0 #Set 2nd LED ON (PA2)
+PS1="wrs-$eth0.ethaddr# "
+mode=""
+ok="0"
+run="1"
+
+### Creating the partitions:
+if [ -e /dev/mem.kernel ]; then; else addpart /dev/mem 8M@0x71000000(kernel); fi
+if [ -e /dev/nand0.kernel ]; then; else addpart /dev/nand0 256k@0x4000(bareboxenv),8M@0x100000(kernel),-@0x4000000(rootfs); fi
+if [ -e /dev/nand0.kernel.bb ]; then; else nand -a /dev/nand0.*; fi
+
+### Create the menu for various boot in case we don't run the autoboot
+menu -r -m boot
+menu -a -m boot -d "Welcome on WRSv3 Boot Sequence"
+menu -e -a -m boot -c 'init -m nand' -d "boot from nand (default)"
+menu -e -a -m boot -c 'init -m df' -d "boot from dataflash (failsafe)"
+menu -e -a -m boot -c 'init -m script -i dhcp' -d "boot from script"
+menu -e -a -m boot -c 'init -m ram -r tftp -i dhcp' -d "boot from ram"
+menu -e -a -m boot -c 'init -m tftp -r nfs -i dhcp' -d "boot from nfs"
+menu -e -a -m boot -c 'init -m tftp -r nfs -i dhcp -x test' -d "boot from nfs (test)"
+menu -e -a -m boot -c 'init -m config' -d "edit & save config"
+menu -e -a -m boot -c 'exit 0' -d "shell (prompt terminal)"
+menu -e -a -m boot -c reset -d "reset barebox"
+
+### Check init arguments
+while getopt "m:r:i:x:
+" Option
+do
+if [ ${Option} = m ]; then
+ mode=${OPTARG}
+elif [ ${Option} = r ]; then
+ rootfs_loc=${OPTARG}
+elif [ ${Option} = i ]; then
+ ip=${OPTARG}
+elif [ ${Option} = x ]; then
+ xtra="-${OPTARG}"
+else
+fi
+done
+
+
+### In case mode is not set
+if [ x$run = x1 -a x$mode = x ]; then ### Check if an alternative mode is on or off
+ run="0"
+
+ gpio_get_value 103 #Obtain value of alternative boot jumper (only for v3.2+)
+ if [ "$?" -eq "0" ]; then
+ autoboot_altforced="1" #Force alternative boot if FGPA button is pushed
+ fi
+
+ ## Check if there is an alternative boot
+ if [ "$autoboot_altforced" -eq "1" ]; then
+ menu -m boot -S -n $autoboot_altmode
+ ok="1"
+ else
+ ## Otherwise boot from NAND
+ menu -m boot -S -n 1
+ ok="1"
+ fi
+fi
+
+################################# Boot modes
+
+
+
+
+
+### Try booting from NAND (default mode)
+if [ x$run = x1 -a x$mode = xnand ]; then
+ echo "booting from NAND"
+ run="0"
+
+ ### If barebox is not already set in NAND (first boot or NAND formatted)
+ if [ -f /env/this_is_compiled_in ]; then
+ echo "You might save & edit the config to run from NAND"
+ menu -m boot -S -n 6 #Select automatic NFS (test) option for next boot
+ ok="1"
+ else
+ cp /dev/nand0.kernel /dev/mem.kernel
+ bootargs="$bootargs root=1f01 rootfstype=jffs2 mem=32m init=/init"
+ bootz /dev/mem.kernel
+ menu -m boot -S -n $autoboot_altmode #Select the alternative boot
+ fi
+
+fi
+
+### Edit and save config mode
+if [ x$run = x1 -a x$mode = xconfig ]; then
+ echo "Editing config..."
+ run="0"
+
+ edit /env/config
+ . /env/config
+ if [ -f /env/this_is_compiled_in ]; then
+ echo "No NAND environment..."
+ rm /env/this_is_compiled_in
+ fi
+ saveenv
+ ok="1"
+fi
+
+
+### Try failsafe boot from DF
+if [ x$run = x1 -a x$mode = xdf ]; then
+ run="0"
+
+ echo "not implemented"
+fi
+
+
+### Try booting from RAM
+if [ x$run = x1 -a x$mode = xram ]; then
+ echo "booting from RAM"
+ run="0"
+
+ echo "Kernel+FS must have been set using usb-loader"
+ addpart /dev/mem 8M@0x72000000(fs)
+ bootargs="$bootargs initrd=0x72000000,8388608"
+ bootz /dev/mem.kernel
+
+ ## Otherwise try to load from TFTP
+ run="1"
+ ip=dhcp
+ mode=tftp
+ rootfs_loc=tftp
+fi
+
+
+### Obtain DHCP
+if [ x$run = x1 -a x$ip = xdhcp ]; then
+ dhcp 5
+ if [ "$?" -eq "1" ]; then
+ echo "Enable to obtain IP from DHCP"
+ echo -n "hit any key to go to menu..."; timeout -sa $error_timeout
+ menu -m boot -s
+ exit 0;
+ fi
+fi
+
+### Try autoboot from loading script
+if [ x$run = x1 -a x$mode = xscript ]; then
+ echo "booting from Script"
+ run="0"
+
+ ### Search customboot based on MAC address
+ tftp $eth0.ethaddr/wrboot /customboot
+ if [ "$?" -eq "0" ]; then
+ echo "We have got a custom boot file for this particular switch."
+ ./customboot
+
+ ### Load generic script
+ else
+ tftp wrboot
+ if [ "$?" -eq "0" ]; then
+ ./wrboot
+ fi
+ fi
+fi
+
+### Try booting from TFTP
+if [ x$run = x1 -a x$mode = xtftp ]; then
+ echo "booting from TFTP"
+ run="0"
+
+ #loading the kernel
+ tftp zImage /dev/mem.kernel
+ if [ x$rootfs_loc = xnfs ]; then
+ bootargs="$bootargs ip=${eth0.ipaddr}:${eth0.gateway}:${eth0.netmask}:${eth0.gateway}"
+ bootargs="$bootargs root=/dev/nfs nfsroot=/tftpboot/rootfs${xtra},tcp mem=32m"
+ bootz /dev/mem.kernel
+ elif [ x$rootfs_loc = xtftp ]; then
+ addpart /dev/mem 8M@0x72000000(fs)
+ tftp wrs-image.cpio.gz /dev/mem.fs
+ bootargs="$bootargs initrd=0x72000000,8388608"
+ bootz /dev/mem.kernel
+ else
+ echo "not implemented"
+ fi
+fi
+
+
+
+### Error message and go back to the menu
+if [ "$ok" -eq "0" ]; then
+ echo "Error: Loading kernel+FS from $mode!"
+ echo -n "hit any key to go to menu..."; timeout -a $error_timeout
+ menu_timeout=""
+fi
+menu -s boot $menu_timeout
+exit 0
+
+
+
+
+
diff --git a/arch/arm/boards/pm9g45/env/config b/arch/arm/boards/pm9g45/env/config
index 5f05e6f..b71cbdc 100644
--- a/arch/arm/boards/pm9g45/env/config
+++ b/arch/arm/boards/pm9g45/env/config
@@ -1,37 +1,18 @@
#!/bin/sh
+## You must use Ctrl+D to Save & Ctrl+C to Exit
-# use 'dhcp' to do dhcp in barebox and in kernel
-# use 'none' if you want to skip kernel ip autoconfiguration
-ip=dhcp
-# or set your networking parameters here
-#eth0.ipaddr=a.b.c.d
-#eth0.netmask=a.b.c.d
-#eth0.gateway=a.b.c.d
-#eth0.serverip=a.b.c.d
+##eth0.ethaddr corresponds to the MAC address of the switch, it can also be changes using flasher
+eth0.ethaddr=02:0B:AD:C0:FF:EE
-# can be either 'nfs', 'tftp' or 'nand'
-kernel_loc=nand
-# can be either 'net', 'nand' or 'initrd'
-rootfs_loc=nand
+## Timeout to autoboot in the pre-selected menu
+autoboot_timeout="10";
-# can be either 'jffs2' or 'ubifs'
-rootfs_type=ubifs
-rootfsimage=root.$rootfs_type
+## In case the default boot doesn't work we can use a specified alternative boot
+#autoboot_altforced="0";
+#autoboot_altmode="2";
-#kernelimage=zImage
-kernelimage=uImage
-#kernelimage=Image
-#kernelimage=Image.lzo
+## Timeout to show the error Message
+#error_timeout="10";
-nand_device=atmel_nand
-nand_parts="128k(bootstrap)ro,256k(barebox)ro,1664k(bareboxenv),3M(kernel),-(root)"
-rootfs_mtdblock_nand=4
-
-autoboot_timeout=3
-
-bootargs="console=ttyS0,115200"
-
-# set a fancy prompt (if support is compiled in)
-PS1="\e[1;32mbarebox@\e[1;31m\h:\w\e[0m "
diff --git a/arch/arm/boards/pm9g45/env/this_is_compiled_in b/arch/arm/boards/pm9g45/env/this_is_compiled_in
new file mode 100644
index 0000000..6acf206
--- /dev/null
+++ b/arch/arm/boards/pm9g45/env/this_is_compiled_in
@@ -0,0 +1,3 @@
+# File to check if we are using environment on NAND or not
+#
+# It is supposed to be automatically deleted when environment is installed in NAND
diff --git a/arch/arm/boards/pm9g45/init.c b/arch/arm/boards/pm9g45/init.c
index a84e431..bbdf297 100644
--- a/arch/arm/boards/pm9g45/init.c
+++ b/arch/arm/boards/pm9g45/init.c
@@ -19,7 +19,6 @@
* MA 02111-1307 USA
*
*/
-
#include <common.h>
#include <net.h>
#include <init.h>
@@ -160,8 +159,7 @@ static int pm9g45_devices_init(void)
at91_add_device_eth(0, &macb_pdata);
pm9g45_add_device_usbh();
- devfs_add_partition("nand0", 0x00000, 0x80000, PARTITION_FIXED, "self_raw");
- dev_add_bb_dev("self_raw", "self0");
+ //device, offset, size, flag, name
devfs_add_partition("nand0", 0x40000, 0x40000, PARTITION_FIXED, "env_raw");
dev_add_bb_dev("env_raw", "env0");
--
1.7.9.5
Generation
============
These patches are generated using the following git:
<https://github.com/neub/wrs-sw-barebox/tree/patcheable-wrs>
and by executing:
git format-patch v2012.05.0
However you can see the history of the development without any rebase by following:
<https://github.com/neub/wrs-sw-barebox/tree/wrs>
Application
=============
1. You first need to download the binary file: barebox-2012.05.0.tar.bz2
* Then you need to extract it to a folder, and go into it
* Initialize a git repo: `git init .`
* And finally you can apply the patches: git am 00*.patch
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment