at91sam9260/9g20ek: refactor init_board script
Subsystems (2)
PATCH 1/1 at91sam9260/9g20ek: refactor init_board script
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 <[email protected]>
Cc Jean-Christophe PLAGNIOL-VILLARD <[email protected]>
--- arch/arm/boards/at91sam9260ek/env/bin/init_board | 54 ++++++++++-------------- 1 file changed, 22 insertions(+), 32 deletions(-)
arch/arm/boards/at91sam9260ek/env/bin/init_board +22 -32
@@ -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
Signature · 7 lines
1.8.1.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
AppliedQuoted 7 lines · Fabio Porcedda
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 compactReduce the number of lines from 50 to 40.
Applied, thanks
Sascha
Quoted 88 lines
Tested on at91sam9260ek.
Signed-off-by Fabio Porcedda <[email protected]>Cc Jean-Christophe PLAGNIOL-VILLARD <[email protected]>--- arch/arm/boards/at91sam9260ek/env/bin/init_board | 54 ++++++++++-------------- 1 file changed, 22 insertions(+), 32 deletions(-)arch/arm/boards/at91sam9260ek/env/bin/init_board +22
-32@@ -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" +usbserialSignature · 7 lines
1.8.1.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox