From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from mail-ea0-f178.google.com ([209.85.215.178]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1U7Onc-00051O-DG for barebox@lists.infradead.org; Mon, 18 Feb 2013 11:22:21 +0000 Received: by mail-ea0-f178.google.com with SMTP id a14so2324964eaa.9 for ; Mon, 18 Feb 2013 03:22:18 -0800 (PST) From: Fabio Porcedda Date: Mon, 18 Feb 2013 12:22:15 +0100 Message-Id: <1361186535-14811-1-git-send-email-fabio.porcedda@gmail.com> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: barebox-bounces@lists.infradead.org Errors-To: barebox-bounces+u.kleine-koenig=pengutronix.de@lists.infradead.org Subject: [PATCH] at91sam9260/9g20ek: refactor init_board script To: barebox@lists.infradead.org Refactor to remove duplicated code without changing functionality. Put "then" on the same line of "if", because: - is the most used style in barebox - is like c code style - is more compact Reduce the number of lines from 50 to 40. Tested on at91sam9260ek. Signed-off-by: Fabio Porcedda Cc: Jean-Christophe PLAGNIOL-VILLARD --- arch/arm/boards/at91sam9260ek/env/bin/init_board | 54 ++++++++++-------------- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/arch/arm/boards/at91sam9260ek/env/bin/init_board b/arch/arm/boards/at91sam9260ek/env/bin/init_board index 977430d..27d767d 100644 --- a/arch/arm/boards/at91sam9260ek/env/bin/init_board +++ b/arch/arm/boards/at91sam9260ek/env/bin/init_board @@ -8,43 +8,33 @@ vendor_id=0x4321 dfu_config="/dev/nand0.barebox.bb(barebox)sr,/dev/nand0.kernel.bb(kernel)r,/dev/nand0.rootfs.bb(rootfs)r" -if [ $at91_udc0.vbus != 1 ] -then +if [ $at91_udc0.vbus != 1 ]; then echo "No USB Device cable plugged, normal boot" exit fi gpio_get_value ${dfu_button} -if [ $? != 0 ] -then - autoboot_timeout=16 - echo "enable tty over USB Device, increase the boot delay to ${autoboot_timeout}s" - usbserial - exit -fi - -echo "${button_name} pressed detected wait ${button_wait}s" -timeout -s -a ${button_wait} - -if [ $at91_udc0.vbus != 1 ] -then - echo "No USB Device cable plugged, normal boot" - exit -fi - -gpio_get_value ${dfu_button} -if [ $? != 0 ] -then +if [ $? = 0 ]; then + echo "${button_name} pressed detected wait ${button_wait}s" + timeout -s -a ${button_wait} + + if [ $at91_udc0.vbus != 1 ]; then + echo "No USB Device cable plugged, normal boot" + exit + fi + + gpio_get_value ${dfu_button} + if [ $? = 0 ]; then + echo "" + echo "Start DFU Mode" + echo "" + led ds5 1 + dfu ${dfu_config} -P ${product_id} -V ${vendor_id} + exit + fi echo "${button_name} released, normal boot" - autoboot_timeout=16 - echo "enable tty over USB Device, increase the boot delay to ${autoboot_timeout}s" - usbserial - exit fi -echo "" -echo "Start DFU Mode" -echo "" - -led ds5 1 -dfu ${dfu_config} -P ${product_id} -V ${vendor_id} +autoboot_timeout=16 +echo "enable tty over USB Device, increase the boot delay to ${autoboot_timeout}s" +usbserial -- 1.8.1.1 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox