Skip to contentSkip to conversation

palm treo 680 smartphone board support

PATCH New Mike Dunn 5 participants 25 messages Apr 12, 2013 – Apr 16, 2013

Subsystems (7)
lore
Share & tools
lore

Mike Dunn

author
#0 lore raw

v3 cover palm treo 680 smartphone board support

This patchset adds support for the Palm Treo 680 smartphone. I had to make some minor tweaks to u-boot to get things working. Most of these changes are small, and most only touch the pxa arch.

Thanks for looking.

Changelog:
v3:
- changed commit message for patch that adds bitrev library to specify the HEAD commit of the linux kernel that the library was taken from, not only the commit that added it to the kernel
- in docg4 driver patch, replaced dbg macro with MTDDEBUG
- put flash_u-boot utility in a separate patch

v2:
- tabs removed in #defines in palmtreo680.h
- use '__weak' macro in pxa_lcd
- remove externs from function prototypes in bitrev.h
- remove commented-out code from docg4.c
- the CONFIG_SYS_LCD_PXA_NO_L_BIAS patch was removed; the same result is accomplished by re-configuring the L_BIAS gpio in the board-specific lcd_enable(), which runs after the driver initialization
- userland utility for programming u-boot to flash moved to tools/palmtreo680
- commit message for patches that add bitrev library and docg4 driver contain the commit and linux version for when the code was added to linux

Mike Dunn (8):
pxa_lcd: add the ACX544AKN lcd device
pxa_lcd: make lcd_enable() a weak pointer
pxa27x_udc: remove call to unimplemented set_GPIO_mode()
arm: bootm: call udc_disable() before booting linux
lib: import bitrev library from the linux kernel
mtd: nand: add driver for diskonchip g4 nand flash add support for palm treo 680 board
palmtreo680: add utility that writes u-boot to flash

 CREDITS                                  |    4 +
 MAINTAINERS                              |    3 +
 arch/arm/include/asm/arch-pxa/hardware.h |   11 -
 arch/arm/include/asm/bootm.h             |    1 +
 arch/arm/lib/bootm.c                     |    1 +
 board/palmtreo680/Makefile               |   34 +
 board/palmtreo680/palmtreo680.c          |  179 ++++++
 board/palmtreo680/palmtreo680_spl.lds    |   51 ++
 boards.cfg                               |    1 +
 doc/README.palmtreo680                   |  570 +++++++++++++++++
 drivers/mtd/nand/Makefile                |    2 +
 drivers/mtd/nand/docg4.c                 | 1028 ++++++++++++++++++++++++++++++
 drivers/mtd/nand/docg4_spl.c             |  222 +++++++
 drivers/usb/gadget/pxa27x_udc.c          |    4 +-
 drivers/video/pxa_lcd.c                  |   34 +-
 include/configs/palmtreo680.h            |  295 +++++++++
 include/linux/bitrev.h                   |   23 +
 include/linux/mtd/docg4.h                |  134 ++++
 lib/Makefile                             |    1 +
 lib/bitrev.c                             |   59 ++
 tools/palmtreo680/flash_u-boot.c         |  167 +++++
 21 files changed, 2811 insertions(+), 13 deletions(-)
 create mode 100644 board/palmtreo680/Makefile
 create mode 100644 board/palmtreo680/palmtreo680.c
 create mode 100644 board/palmtreo680/palmtreo680_spl.lds
 create mode 100644 doc/README.palmtreo680
 create mode 100644 drivers/mtd/nand/docg4.c
 create mode 100644 drivers/mtd/nand/docg4_spl.c
 create mode 100644 include/configs/palmtreo680.h
 create mode 100644 include/linux/bitrev.h
 create mode 100644 include/linux/mtd/docg4.h
 create mode 100644 lib/bitrev.c
 create mode 100644 tools/palmtreo680/flash_u-boot.c
Signature · 1 line
1.7.8.6
author
#1 lore raw

PATCH v3 1/8 pxa_lcd: add the ACX544AKN lcd device

This adds the definitions required to support the LCD device on the Palm Treo 680.

---
Changelog:
v3: no change
v2: no change

 drivers/video/pxa_lcd.c |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)
drivers/video/pxa_lcd.c +32 -0
index b40ec36..d5fbe7b 100644
@@ -248,6 +248,38 @@ vidinfo_t panel_info = {
 };
 #endif /* CONFIG_ACX517AKN */
 
+#ifdef CONFIG_ACX544AKN
+
+# define LCD_BPP	LCD_COLOR16
+
+/* you have to set lccr0 and lccr3 (including pcd) */
+# define REG_LCCR0	0x003008f9
+# define REG_LCCR3	0x04700007 /* 16bpp */
+
+vidinfo_t panel_info = {
+	.vl_col		= 320,
+	.vl_row		= 320,
+	.vl_width	= 320,
+	.vl_height	= 320,
+	.vl_clkp	= CONFIG_SYS_LOW,
+	.vl_oep		= CONFIG_SYS_LOW,
+	.vl_hsp		= CONFIG_SYS_LOW,
+	.vl_vsp		= CONFIG_SYS_LOW,
+	.vl_dp		= CONFIG_SYS_LOW,
+	.vl_bpix	= LCD_BPP,
+	.vl_lbw		= 0,
+	.vl_splt	= 0,
+	.vl_clor	= 1,
+	.vl_tft		= 1,
+	.vl_hpw		= 0x05,
+	.vl_blw		= 0x13,
+	.vl_elw		= 0x08,
+	.vl_vpw		= 0x02,
+	.vl_bfw		= 0x07,
+	.vl_efw		= 0x05,
+};
+#endif /* CONFIG_ACX544AKN */
+
 /*----------------------------------------------------------------------*/
 
 #ifdef CONFIG_LQ038J7DH53
Signature · 1 line
1.7.8.6
author
#2 lore raw

PATCH v3 2/8 pxa_lcd: make lcd_enable() a weak pointer

In reply to Mike Dunn

Make lcd_init() a weak pointer so that boards can overload it if necessary. The palmtreo680 board needs to wiggle some gpios and configure the pwm controller in order to get the lcd and its backlight working.

---
Changelog:
v3: no change

v2:
- use __weak macro instead of explicit compiler directive

 drivers/video/pxa_lcd.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/video/pxa_lcd.c +1 -1
index d5fbe7b..5e4c685 100644
@@ -410,7 +410,7 @@ void lcd_initcolregs (void)
 #endif /* LCD_MONOCHROME */
 
 /*----------------------------------------------------------------------*/
-void lcd_enable (void)
+__weak void lcd_enable(void)
 {
 }
 
Signature · 1 line
1.7.8.6
author
#3 lore raw

PATCH v3 3/8 pxa27x_udc: remove call to unimplemented set_GPIO_mode()

In reply to Mike Dunn

If CONFIG_USB_DEV_PULLUP_GPIO is defined, a link error occurs because the set_GPIO_mode() helper function is not implemented. This function doesn't do much except make the code a little more readable, so I just manually coded its equivalent and removed the prototype from the header file. It is invoked no where else in the code.

While I was at it, I noticed that two other function prototypes in the same header file are also neither implemented nor invoked anywhere, so I removed them as well.

---
Changelog:
v3: no change
v2: no change

 arch/arm/include/asm/arch-pxa/hardware.h |   11 -----------
 drivers/usb/gadget/pxa27x_udc.c          |    4 +++-
 2 files changed, 3 insertions(+), 12 deletions(-)
arch/arm/include/asm/arch-pxa/hardware.h +0 -11
index 44b800f..2397bce 100644
@@ -77,17 +77,6 @@
 #define GPIO_FALLING_EDGE	1
 #define GPIO_RISING_EDGE	2
 #define GPIO_BOTH_EDGES		3
-extern void set_GPIO_IRQ_edge( int gpio_nr, int edge_mask );
-
-/*
- * Handy routine to set GPIO alternate functions
- */
-extern void set_GPIO_mode( int gpio_mode );
-
-/*
- * return current lclk frequency in units of 10kHz
- */
-extern unsigned int get_lclk_frequency_10khz(void);
 
 #endif
 
drivers/usb/gadget/pxa27x_udc.c +3 -1
index 4c00081..71cc0f2 100644
@@ -610,7 +610,9 @@ void udc_connect(void)
 
 #ifdef CONFIG_USB_DEV_PULLUP_GPIO
 	/* Turn on the USB connection by enabling the pullup resistor */
-	set_GPIO_mode(CONFIG_USB_DEV_PULLUP_GPIO | GPIO_OUT);
+	writel(readl(GPDR(CONFIG_USB_DEV_PULLUP_GPIO))
+		     | GPIO_bit(CONFIG_USB_DEV_PULLUP_GPIO),
+	       GPDR(CONFIG_USB_DEV_PULLUP_GPIO));
 	writel(GPIO_bit(CONFIG_USB_DEV_PULLUP_GPIO), GPSR(CONFIG_USB_DEV_PULLUP_GPIO));
 #else
 	/* Host port 2 transceiver D+ pull up enable */
Signature · 1 line
1.7.8.6
author
#4 lore raw

PATCH v3 4/8 arm: bootm: call udc_disable() before booting linux

In reply to Mike Dunn

On the pxa270, if the udc device is not disabled before jumping to linux, the device fails to initialize in linux because it was left in a running state, and the linux driver assumes that it is in a disabled state.

---
Changelog:
v3: no change
v2: no change

Arguably, this is a bug in the linux driver, but it seemed pretty simple and benign to just disable it in u-boot. I'll also send a patch to upstream kernel to fix its driver.

 arch/arm/include/asm/bootm.h |    1 +
 arch/arm/lib/bootm.c         |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
arch/arm/include/asm/bootm.h +1 -0
index db2ff94..68189cc 100644
@@ -21,6 +21,7 @@
 
 #ifdef CONFIG_USB_DEVICE
 extern void udc_disconnect(void);
+extern void udc_disable(void);
 #endif
 
 #endif
arch/arm/lib/bootm.c +1 -0
index f3b30c5..6daa7bf 100644
@@ -105,6 +105,7 @@ static void announce_and_cleanup(void)
 
 #ifdef CONFIG_USB_DEVICE
 	udc_disconnect();
+	udc_disable();
 #endif
 	cleanup_before_linux();
 }
Signature · 1 line
1.7.8.6
#5 lore raw

PATCH v3 4/8 arm: bootm: call udc_disable() before booting linux

Dear Mike Dunn,

Quoted 5 lines

On the pxa270, if the udc device is not disabled before jumping to linux, the device fails to initialize in linux because it was left in a running state, and the linux driver assumes that it is in a disabled state.

Albert, can I get your ACK on this?

Best regards,
Marek Vasut

#6 lore raw

PATCH v3 4/8 arm: bootm: call udc_disable() before booting linux

In reply to Mike Dunn

Hi Mike,

Quoted 35 lines · Mike Dunn

On the pxa270, if the udc device is not disabled before jumping to linux, the device fails to initialize in linux because it was left in a running state, and the linux driver assumes that it is in a disabled state.

---
Changelog:
v3: no change
v2: no change

Arguably, this is a bug in the linux driver, but it seemed pretty simple and benign to just disable it in u-boot. I'll also send a patch to upstream kernel to fix its driver.

 arch/arm/include/asm/bootm.h |    1 +
 arch/arm/lib/bootm.c         |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
arch/arm/include/asm/bootm.h +1 -0
index db2ff94..68189cc 100644
@@ -21,6 +21,7 @@
 
 #ifdef CONFIG_USB_DEVICE
 extern void udc_disconnect(void);
+extern void udc_disable(void);
 #endif
 
 #endif
arch/arm/lib/bootm.c +0 -0
index f3b30c5..6daa7bf 100644

arch/arm/lib/bootm.c static void announce_and_cleanup(void) · line 111

Quoted 7 lines
arch/arm/lib/bootm.c +1 -0
@@ -105,6 +105,7 @@ static void announce_and_cleanup(void)
 
 #ifdef CONFIG_USB_DEVICE
 	udc_disconnect();
+	udc_disable();
 #endif
 	cleanup_before_linux();
 }

Amicalement,

Signature · 1 line
Albert.
#7 lore raw

PATCH v3 4/8 arm: bootm: call udc_disable() before booting linux

Dear Albert ARIBAUD,

Quoted 51 lines

Hi Mike,

On Fri, 12 Apr 2013 11:59:16 -0700, Mike Dunn <[email protected]>

Quoted 46 lines · wrote:

On the pxa270, if the udc device is not disabled before jumping to linux, the device fails to initialize in linux because it was left in a running state, and the linux driver assumes that it is in a disabled state.

---

Changelog:
v3: no change
v2: no change

Arguably, this is a bug in the linux driver, but it seemed pretty simple and benign to just disable it in u-boot. I'll also send a patch to upstream kernel to fix its driver.

 arch/arm/include/asm/bootm.h |    1 +
 arch/arm/lib/bootm.c         |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
arch/arm/include/asm/bootm.h +1 -0
index db2ff94..68189cc 100644
@@ -21,6 +21,7 @@
 
 #ifdef CONFIG_USB_DEVICE
 extern void udc_disconnect(void);
 
+extern void udc_disable(void);
 
 #endif

#endif

arch/arm/lib/bootm.c +1 -0
index f3b30c5..6daa7bf 100644
@@ -105,6 +105,7 @@ static void announce_and_cleanup(void)
 
 #ifdef CONFIG_USB_DEVICE
 
 	udc_disconnect();
 
+	udc_disable();
 
Quoted 7 lines
Quoted 5 lines

#endif

cleanup_before_linux();

}

Tom, will this not break any of your musb-toys?

Best regards,
Marek Vasut

#8 lore raw

PATCH v3 4/8 arm: bootm: call udc_disable() before booting linux

Quoted 55 lines · Marek Vasut

Dear Albert ARIBAUD,

Quoted 53 lines

Hi Mike,

On Fri, 12 Apr 2013 11:59:16 -0700, Mike Dunn <[email protected]>

Quoted 48 lines · wrote:

On the pxa270, if the udc device is not disabled before jumping to linux, the device fails to initialize in linux because it was left in a running state, and the linux driver assumes that it is in a disabled state.

---

Changelog:
v3: no change
v2: no change

Arguably, this is a bug in the linux driver, but it seemed pretty simple and benign to just disable it in u-boot. I'll also send a patch to upstream kernel to fix its driver.

 arch/arm/include/asm/bootm.h |    1 +
 arch/arm/lib/bootm.c         |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
arch/arm/include/asm/bootm.h +1 -0
index db2ff94..68189cc 100644
@@ -21,6 +21,7 @@
 
 #ifdef CONFIG_USB_DEVICE
 extern void udc_disconnect(void);
 
+extern void udc_disable(void);
 
 #endif

#endif

arch/arm/lib/bootm.c +1 -0
index f3b30c5..6daa7bf 100644
@@ -105,6 +105,7 @@ static void announce_and_cleanup(void)
 
 #ifdef CONFIG_USB_DEVICE
 
 	udc_disconnect();
 
+	udc_disable();
 

#endif

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

cleanup_before_linux();

}

Tom, will this not break any of your musb-toys?

Albert, did you test this on your musb using nearly released now board? :)

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130415/c5a4c823/attachment.pgp>
#9 lore raw

PATCH v3 4/8 arm: bootm: call udc_disable() before booting linux

Hi Tom,

Quoted 58 lines · Tom Rini
Quoted 57 lines · Marek Vasut

Dear Albert ARIBAUD,

Quoted 55 lines

Hi Mike,

On Fri, 12 Apr 2013 11:59:16 -0700, Mike Dunn <[email protected]>

Quoted 50 lines · wrote:

On the pxa270, if the udc device is not disabled before jumping to linux, the device fails to initialize in linux because it was left in a running state, and the linux driver assumes that it is in a disabled state.

---

Changelog:
v3: no change
v2: no change

Arguably, this is a bug in the linux driver, but it seemed pretty simple and benign to just disable it in u-boot. I'll also send a patch to upstream kernel to fix its driver.

 arch/arm/include/asm/bootm.h |    1 +
 arch/arm/lib/bootm.c         |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
arch/arm/include/asm/bootm.h +1 -0
index db2ff94..68189cc 100644
@@ -21,6 +21,7 @@
 
 #ifdef CONFIG_USB_DEVICE
 extern void udc_disconnect(void);
 
+extern void udc_disable(void);
 
 #endif

#endif

arch/arm/lib/bootm.c +1 -0
index f3b30c5..6daa7bf 100644
@@ -105,6 +105,7 @@ static void announce_and_cleanup(void)
 
 #ifdef CONFIG_USB_DEVICE
 
 	udc_disconnect();
 
+	udc_disable();
 

#endif

cleanup_before_linux();

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

}

Tom, will this not break any of your musb-toys?

Albert, did you test this on your musb using nearly released now board? :)

No, I haven't. I had assumed from Marex' request that this worked for him and he wanted my formal ack on it.

Amicalement,

Signature · 1 line
Albert.
#10 lore raw

PATCH v3 4/8 arm: bootm: call udc_disable() before booting linux

Dear Albert ARIBAUD,

Quoted 66 lines

Hi Tom,

Quoted 63 lines · Tom Rini
Quoted 62 lines · Marek Vasut

Dear Albert ARIBAUD,

Quoted 59 lines

Hi Mike,

On Fri, 12 Apr 2013 11:59:16 -0700, Mike Dunn <[email protected]>

Quoted 49 lines · wrote:

On the pxa270, if the udc device is not disabled before jumping to linux, the device fails to initialize in linux because it was left in a running state, and the linux driver assumes that it is in a disabled state.

---

Changelog:
v3: no change
v2: no change

Arguably, this is a bug in the linux driver, but it seemed pretty simple and benign to just disable it in u-boot. I'll also send a patch to upstream kernel to fix its driver.

 arch/arm/include/asm/bootm.h |    1 +
 arch/arm/lib/bootm.c         |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
(quoted diff) +0 -0

b/arch/arm/include/asm/bootm.h index db2ff94..68189cc 100644

arch/arm/include/asm/bootm.h +1 -0
@@ -21,6 +21,7 @@
 
 #ifdef CONFIG_USB_DEVICE
 extern void udc_disconnect(void);
 
+extern void udc_disable(void);
 
 #endif

#endif

arch/arm/lib/bootm.c +1 -0
index f3b30c5..6daa7bf 100644
@@ -105,6 +105,7 @@ static void announce_and_cleanup(void)
 
 #ifdef CONFIG_USB_DEVICE
 
 	udc_disconnect();
 
+	udc_disable();
 

#endif

Quoted 3 lines

cleanup_before_linux();

}

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Tom, will this not break any of your musb-toys?

Albert, did you test this on your musb using nearly released now board?

:)

No, I haven't. I had assumed from Marex' request that this worked for him and he wanted my formal ack on it.

I want ACK for a few more devices, thus I also CCed Tom to test on musb rigs.

Best regards,
Marek Vasut

author
#11 lore raw

PATCH v3 5/8 lib: import bitrev library from the linux kernel

In reply to Mike Dunn

This patch adds the bitrev library from the linux kernel. This is a simple algorithm that uses an 8 bit look-up table to reverse the bits in data types of 8, 16, or 32 bit widths. The docg4 nand flash driver uses it.

[port from linux kernel v3.9 commit 7ee32a6d30d1c8a3b7a07a6269da8f0a08662927] [originally added: v2.6.20 by commit a5cfc1ec58a07074dacb6aa8c79eff864c966d12]

---
Changelog:
v3: no change
v2: remove 'extern' from function prototypes in bitrev.h

 include/linux/bitrev.h |   23 ++++++++++++++++++
 lib/Makefile           |    1 +
 lib/bitrev.c           |   59 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 83 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/bitrev.h
 create mode 100644 lib/bitrev.c
include/linux/bitrev.h new file +23 -0
new file mode 100644
index 0000000..a61d956
@@ -0,0 +1,23 @@
+/*
+ * This file is released under the terms of GPL v2 and any later version.
+ * See the file COPYING in the root directory of the source tree for details.
+ *
+ * Based on bitrev from the Linux kernel, by Akinobu Mita
+ */
+
+#ifndef _LINUX_BITREV_H
+#define _LINUX_BITREV_H
+
+#include <linux/types.h>
+
+extern u8 const byte_rev_table[256];
+
+static inline u8 bitrev8(u8 byte)
+{
+	return byte_rev_table[byte];
+}
+
+u16 bitrev16(u16 in);
+u32 bitrev32(u32 in);
+
+#endif /* _LINUX_BITREV_H */
lib/Makefile +1 -0
index 1bfd3ee..b4aaae9 100644
@@ -55,6 +55,7 @@ COBJS-$(CONFIG_SHA1) += sha1.o
 COBJS-$(CONFIG_SHA256) += sha256.o
 COBJS-y	+= strmhz.o
 COBJS-$(CONFIG_RBTREE)	+= rbtree.o
+COBJS-$(CONFIG_BITREVERSE) += bitrev.o
 endif
 
 ifdef CONFIG_SPL_BUILD
lib/bitrev.c new file +59 -0

59 lines not on this page · raw message

Signature · 1 line
1.7.8.6
author
#12 lore raw

PATCH v3 6/8 mtd: nand: add driver for diskonchip g4 nand flash

In reply to Mike Dunn

This patch adds a driver for the diskonchip G4 nand flash device. It is based on the driver from the linux kernel.

This also includes a separate SPL driver. A separate SPL driver is used because the device operates in a different mode (reliable mode) when loading a boot image, and also because the storage format of the boot image is different from normal data (pages are stored redundantly). The SPL driver basically mimics how a typical IPL reads data from the device. The special operating mode and storage format are used to compensate for the fact that the IPL does not contain the BCH ecc decoding algorithm (due to size constraints). Although the u-boot SPL *could* use ecc, it operates like an IPL for the sake of simplicity and uniformity, since the IPL and SPL share the task of loading the u-boot image. As a side benefit, the SPL driver is very small.

[port from linux kernel 3.4 commit 570469f3bde7f71cc1ece07a18d54a05b6a8775d]

---
Changelog:
v3: replace dbg macro with MTDDEBUG
v2: remove commented-out code

 drivers/mtd/nand/Makefile    |    2 +
 drivers/mtd/nand/docg4.c     | 1028 ++++++++++++++++++++++++++++++++++++++++++
 drivers/mtd/nand/docg4_spl.c |  222 +++++++++
 include/linux/mtd/docg4.h    |  134 ++++++
 4 files changed, 1386 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mtd/nand/docg4.c
 create mode 100644 drivers/mtd/nand/docg4_spl.c
 create mode 100644 include/linux/mtd/docg4.h
drivers/mtd/nand/Makefile +2 -0
index c77c0c4..1bcf43c 100644
@@ -34,6 +34,7 @@ NORMAL_DRIVERS=y
 endif
 
 COBJS-$(CONFIG_SPL_NAND_AM33XX_BCH) += am335x_spl_bch.o
+COBJS-$(CONFIG_SPL_NAND_DOCG4) += docg4_spl.o
 COBJS-$(CONFIG_SPL_NAND_SIMPLE) += nand_spl_simple.o
 COBJS-$(CONFIG_SPL_NAND_LOAD) += nand_spl_load.o
 COBJS-$(CONFIG_SPL_NAND_ECC) += nand_ecc.o
@@ -78,6 +79,7 @@ COBJS-$(CONFIG_NAND_SPEAR) += spr_nand.o
 COBJS-$(CONFIG_TEGRA_NAND) += tegra_nand.o
 COBJS-$(CONFIG_NAND_OMAP_GPMC) += omap_gpmc.o
 COBJS-$(CONFIG_NAND_PLAT) += nand_plat.o
+COBJS-$(CONFIG_NAND_DOCG4) += docg4.o
 
 else  # minimal SPL drivers
 
drivers/mtd/nand/docg4.c new file +1028 -0

1,028 lines not on this page · raw message

drivers/mtd/nand/docg4_spl.c new file +222 -0

222 lines not on this page · raw message

include/linux/mtd/docg4.h new file +134 -0

134 lines not on this page · raw message

Signature · 1 line
1.7.8.6
#13 lore raw

PATCH v3 6/8 mtd: nand: add driver for diskonchip g4 nand flash

Quoted 33 lines · Mike Dunn

This patch adds a driver for the diskonchip G4 nand flash device. It is based
on the driver from the linux kernel.

This also includes a separate SPL driver. A separate SPL driver is used because
the device operates in a different mode (reliable mode) when loading a boot
image, and also because the storage format of the boot image is different from
normal data (pages are stored redundantly). The SPL driver basically mimics how
a typical IPL reads data from the device. The special operating mode and
storage format are used to compensate for the fact that the IPL does not contain
the BCH ecc decoding algorithm (due to size constraints). Although the u-boot
SPL *could* use ecc, it operates like an IPL for the sake of simplicity and
uniformity, since the IPL and SPL share the task of loading the u-boot image.
As a side benefit, the SPL driver is very small.

[port from linux kernel 3.4 commit
570469f3bde7f71cc1ece07a18d54a05b6a8775d]

---
Changelog:
v3: replace dbg macro with MTDDEBUG
v2: remove commented-out code

Quoted 9 lines
 drivers/mtd/nand/Makefile    |    2 +
 drivers/mtd/nand/docg4.c     | 1028  
++++++++++++++++++++++++++++++++++++++++++
 drivers/mtd/nand/docg4_spl.c |  222 +++++++++
 include/linux/mtd/docg4.h    |  134 ++++++
 4 files changed, 1386 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mtd/nand/docg4.c
 create mode 100644 drivers/mtd/nand/docg4_spl.c
 create mode 100644 include/linux/mtd/docg4.h

-Scott

#14 lore raw

PATCH v3 6/8 mtd: nand: add driver for diskonchip g4 nand flash

Dear Scott Wood,

Quoted 40 lines · Mike Dunn
Quoted 39 lines

This patch adds a driver for the diskonchip G4 nand flash device. It is based
on the driver from the linux kernel.

This also includes a separate SPL driver. A separate SPL driver is used because
the device operates in a different mode (reliable mode) when loading a boot
image, and also because the storage format of the boot image is different from
normal data (pages are stored redundantly). The SPL driver basically mimics how
a typical IPL reads data from the device. The special operating mode and
storage format are used to compensate for the fact that the IPL does not contain
the BCH ecc decoding algorithm (due to size constraints). Although the u-boot
SPL *could* use ecc, it operates like an IPL for the sake of simplicity and
uniformity, since the IPL and SPL share the task of loading the u-boot image.
As a side benefit, the SPL driver is very small.

[port from linux kernel 3.4 commit
570469f3bde7f71cc1ece07a18d54a05b6a8775d]

---

Changelog:
v3: replace dbg macro with MTDDEBUG
v2: remove commented-out code

 drivers/mtd/nand/Makefile    |    2 +
 drivers/mtd/nand/docg4.c     | 1028

++++++++++++++++++++++++++++++++++++++++++

Quoted 8 lines
Quoted 6 lines
 drivers/mtd/nand/docg4_spl.c |  222 +++++++++
 include/linux/mtd/docg4.h    |  134 ++++++
 4 files changed, 1386 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mtd/nand/docg4.c
 create mode 100644 drivers/mtd/nand/docg4_spl.c
 create mode 100644 include/linux/mtd/docg4.h

I'll pick them all if that's ok with you, Scott ?

Best regards,
Marek Vasut

#15 lore raw

PATCH v3 6/8 mtd: nand: add driver for diskonchip g4 nand flash

Quoted 56 lines · Marek Vasut

Dear Scott Wood,

Quoted 2 lines · Mike Dunn
Quoted 1 line

This patch adds a driver for the diskonchip G4 nand flash

device. It

Quoted 4 lines
Quoted 4 lines

is based
on the driver from the linux kernel.

This also includes a separate SPL driver. A separate SPL driver

is

Quoted 2 lines
Quoted 2 lines

used because
the device operates in a different mode (reliable mode) when

loading

Quoted 4 lines
Quoted 4 lines

a boot
image, and also because the storage format of the boot image is different from
normal data (pages are stored redundantly). The SPL driver

basically

Quoted 2 lines
Quoted 2 lines

mimics how
a typical IPL reads data from the device. The special operating

mode

Quoted 2 lines
Quoted 2 lines

and
storage format are used to compensate for the fact that the IPL

does

Quoted 2 lines
Quoted 2 lines

not contain
the BCH ecc decoding algorithm (due to size constraints).

Although

Quoted 29 lines
Quoted 28 lines

the u-boot
SPL *could* use ecc, it operates like an IPL for the sake of simplicity and
uniformity, since the IPL and SPL share the task of loading the u-boot image.
As a side benefit, the SPL driver is very small.

[port from linux kernel 3.4 commit
570469f3bde7f71cc1ece07a18d54a05b6a8775d]

---

Changelog:
v3: replace dbg macro with MTDDEBUG
v2: remove commented-out code

 drivers/mtd/nand/Makefile    |    2 +
 drivers/mtd/nand/docg4.c     | 1028

++++++++++++++++++++++++++++++++++++++++++

 drivers/mtd/nand/docg4_spl.c |  222 +++++++++
 include/linux/mtd/docg4.h    |  134 ++++++
 4 files changed, 1386 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mtd/nand/docg4.c
 create mode 100644 drivers/mtd/nand/docg4_spl.c
 create mode 100644 include/linux/mtd/docg4.h
Quoted 3 lines
Quoted 1 line

I'll pick them all if that's ok with you, Scott ?

Yes, that's fine.

-Scott

author
#16 lore raw

PATCH v3 7/8 add support for palm treo 680 board

In reply to Mike Dunn

A quick overview of u-boot implementation on the treo 680...

The treo 680 has a Diskonchip G4 nand flash chip. This device has a 2k region that maps to the system bus at the reset vector in a NOR-like fashion so that it can be used as the boot device. The phone is shipped with this 2k region configured as write-protected (can't be modified) and programmed with an initial program loader (IPL). At power-up, this IPL loads the contents of two flash blocks to SDRAM and jumps to it. The capacity of the two blocks is not large enough to hold all of u-boot, so a u-boot SPL is used. To conserve flash space, these two blocks and the necessary number of subsequent blocks are programmed with a concatenated spl + u-boot image. That way, the IPL will also load a portion of u-boot proper, and when the spl runs, it relocates the portion of u-boot that the IPL has already loaded, and then resumes loading the remaining part of u-boot before jumping to it.

The default_environment is used (CONFIG_ENV_IS_NOWHERE) because I didn't think that having a writable environment was worth the cost of a flash block, although adding it would be straightforward. I abuse the CONFIG_EXTRA_ENV_SETTINGS option to specify the usbtty for the console (CONFIG_SYS_CONSOLE_IS_IN_ENV).

Support for the LCD is included, but currently it is only useful for displaying the u-boot splash screen. But if u-boot is built without the usbtty console, it does display the auto-boot progress nicely.

---
Changelog:
v3: flash_u-boot utility split into separate patch
v2:
- tabs removed in #defines in palmtreo680.h
- utility for programming u-boot to flash moved to tools/palmtreo680

 CREDITS                               |    4 +
 MAINTAINERS                           |    3 +
 board/palmtreo680/Makefile            |   34 ++
 board/palmtreo680/palmtreo680.c       |  179 +++++++++++
 board/palmtreo680/palmtreo680_spl.lds |   51 +++
 boards.cfg                            |    1 +
 doc/README.palmtreo680                |  570 +++++++++++++++++++++++++++++++++
 include/configs/palmtreo680.h         |  295 +++++++++++++++++
 8 files changed, 1137 insertions(+), 0 deletions(-)
 create mode 100644 board/palmtreo680/Makefile
 create mode 100644 board/palmtreo680/palmtreo680.c
 create mode 100644 board/palmtreo680/palmtreo680_spl.lds
 create mode 100644 doc/README.palmtreo680
 create mode 100644 include/configs/palmtreo680.h
CREDITS +4 -0
index 7c1458f..3b657e9 100644
@@ -124,6 +124,10 @@ N: James F. Dougherty
 E: jfd at GigabitNetworks.COM
 D: Port to the MOUSSE board
 
+N: Mike Dunn
+E: mikedunn at newsguy.com
+D: Palmtreo680 board, docg4 nand flash driver
+
 N: Dave Ellis
 E: DGE at sixnetio.com
 D: EEPROM Speedup, SXNI855T port
MAINTAINERS +3 -0
index 1614b91..db62af1 100644
@@ -650,6 +650,9 @@ Wolfgang Denk <[email protected]>
 	imx27lite	i.MX27
 	qong		i.MX31
 
+Mike Dunn <[email protected]>
+	palmtreo680	pxa270
+
 Kristoffer Ericson <[email protected]>
 
 	jornada	SA1110
board/palmtreo680/Makefile new file +34 -0
new file mode 100644
index 0000000..34ffb99
@@ -0,0 +1,34 @@
+#
+# Palm Treo680 Support
+#
+# Copyright (C) 2013 Mike Dunn <[email protected]>
+#
+# This file is released under the terms of GPL v2 and any later version.
+# See the file COPYING in the root directory of the source tree for details.
+
+include $(TOPDIR)/config.mk
+
+LIB	= $(obj)lib$(BOARD).o
+
+COBJS	:= palmtreo680.o
+
+SRCS	:= $(COBJS:.o=.c)
+OBJS	:= $(addprefix $(obj),$(COBJS))
+
+$(LIB):	$(obj).depend $(OBJS)
+	$(call cmd_link_o_target, $(OBJS))
+
+clean:
+	rm -f $(OBJS)
+
+distclean:	clean
+	rm -f $(LIB) core *.bak $(obj).depend
+
+#########################################################################
+
+# defines $(obj).depend target
+include $(SRCTREE)/rules.mk
+
+sinclude $(obj).depend
+
+#########################################################################
board/palmtreo680/palmtreo680.c new file +179 -0

179 lines not on this page · raw message

board/palmtreo680/palmtreo680_spl.lds new file +51 -0

51 lines not on this page · raw message

boards.cfg +1 -0
index 5fc70be..72a9440 100644
@@ -331,6 +331,7 @@ h2200                        arm         pxa
 lubbock                      arm         pxa
 palmld                       arm         pxa
 palmtc                       arm         pxa
+palmtreo680                  arm         pxa
 polaris                      arm         pxa         trizepsiv           -              -           trizepsiv:POLARIS
 pxa255_idp                   arm         pxa
 trizepsiv                    arm         pxa
doc/README.palmtreo680 new file +570 -0

570 lines not on this page · raw message

include/configs/palmtreo680.h new file +295 -0

295 lines not on this page · raw message

Signature · 1 line
1.7.8.6
#17 lore raw

PATCH v3 7/8 add support for palm treo 680 board

Dear Mike Dunn,

[...]

board/palmtreo680/palmtreo680.c line 34

Quoted 7 lines
board/palmtreo680/palmtreo680.c new file +7 -0
+int board_init(void)
+{
+	/* We have RAM, disable cache */
+	dcache_disable();
+	icache_disable();
+
+	gd->bd->bi_arch_number = MACH_TYPE_TREO680;

This is not needed, just define CONFIG_MACH_TYPE in treo680.h

board/palmtreo680/palmtreo680.c line 35

Quoted 1 line
board/palmtreo680/palmtreo680.c new file +1 -0
+	gd->bd->bi_boot_params = 0xa0000100;

Is this not CONFIG_SYS_DRAM_BASE + 0x100 ? I think it is.

Quoted 27 lines
board/palmtreo680/palmtreo680.c new file +27 -0
+
+	return 0;
+}
+
+int dram_init(void)
+{
+	/* IPL initializes SDRAM (we're already running from it) */
+	gd->ram_size = PHYS_SDRAM_1_SIZE;
+	return 0;
+}
+
+#ifdef CONFIG_LCD
+void lcd_enable(void)
+{
+	/*
+	 * Undo the L_BIAS / gpio77 pin configuration performed by the pxa lcd
+	 * driver code.  We need it as an output gpio.
+	 */
+	writel((readl(GAFR2_L) & ~(0xc << 24)), GAFR2_L);
+
+	/* power-up and enable the lcd */
+	writel(0x00400000, GPSR(86)); /* enable; drive high */
+	writel(0x00002000, GPSR(77)); /* power; drive high */
+	writel(0x02000000, GPCR(25)); /* enable_n; drive low */
+
+	/* turn on LCD backlight and configure PWM for reasonable brightness */
+	writel(0x00, PWM_CTRL0);

board/palmtreo680/palmtreo680.c line 72

Quoted 10 lines
board/palmtreo680/palmtreo680.c new file +10 -0
+	writel(0x1b1, PWM_PERVAL0);
+	writel(0xfd, PWM_PWDUTY0);
+	writel(0x00000040, GPSR(38)); /*  backlight power on */
+}
+#endif
+
+#ifdef CONFIG_MMC
+int board_mmc_init(bd_t *bis)
+{
+	writel(0x00000400, GPSR(42)); /* power on */

Can you not use your bitlibrary for this stuff? Or maybe at least use (1 << n) here to make it more readable.

But seriously, do you not want to (in the longer run) implement proper GPIO driver for PXA? That'd help a lot. Also, do you not want to volunteer to fix PXA? I think it's a bit rotting all around ;-)

Quoted 7 lines
board/palmtreo680/palmtreo680.c new file +7 -0
+	return pxa_mmc_register(0);
+}
+#endif
+
+void board_nand_init(void)
+{
+	/* we have one 128M diskonchip G4  */

board/palmtreo680/palmtreo680.c line 89

Quoted 10 lines
board/palmtreo680/palmtreo680.c new file +10 -0
+
+	struct mtd_info *mtd = &nand_info[0];
+	struct nand_chip *nand = &docg4_nand_chip;
+	if (docg4_nand_init(mtd, nand, 0))
+		hang();
+}
+
+#ifdef CONFIG_SPL_BUILD
+void *memcpy(void *dest, const void *src, size_t count)
+{

CONFIG_SPL_LIBCOMMON_SUPPORT shall give you memcpy.

[...]

Review

Quoted 2 lines
(quoted diff) +2 -0
+void nand_boot(void)
+{

[...]

Will the common/spl/ NAND loading code not cut it here? I guess it won't since PXA is FUBAR when it comes to any kind of SPL loading. Do you not want to fix that? I'd be really grateful if you did ;-)

[...]

btw. you dont really need to #define CONFIG_PXA27X to value "1" in your config, just remove those useless trailing "1"s .

author
#18 lore raw

PATCH v3 7/8 add support for palm treo 680 board

Quoted 4 lines · Marek Vasut

Dear Mike Dunn,

[...]

Quoted 9 lines

board/palmtreo680/palmtreo680.c line 34

Quoted 7 lines
board/palmtreo680/palmtreo680.c new file +7 -0
+int board_init(void)
+{
+	/* We have RAM, disable cache */
+	dcache_disable();
+	icache_disable();
+
+	gd->bd->bi_arch_number = MACH_TYPE_TREO680;

This is not needed, just define CONFIG_MACH_TYPE in treo680.h

Oops, yes, I see.

Quoted 4 lines

board/palmtreo680/palmtreo680.c line 35

Quoted 2 lines
board/palmtreo680/palmtreo680.c new file +1 -0
+	gd->bd->bi_boot_params = 0xa0000100;

Is this not CONFIG_SYS_DRAM_BASE + 0x100 ? I think it is.

Correct.

[...]

Quoted 8 lines

board/palmtreo680/palmtreo680.c line 72

Quoted 5 lines
board/palmtreo680/palmtreo680.c new file +5 -0
+
+#ifdef CONFIG_MMC
+int board_mmc_init(bd_t *bis)
+{
+	writel(0x00000400, GPSR(42)); /* power on */

Can you not use your bitlibrary for this stuff? Or maybe at least use (1 << n) here to make it more readable.

Well, bitrev reverses the bits; not really applicable here. But you're right, a shift would be better for clarity.

Quoted 4 lines

But seriously, do you not want to (in the longer run) implement proper GPIO driver for PXA? That'd help a lot. Also, do you not want to volunteer to fix PXA? I think it's a bit rotting all around ;-)

Sure, I'd be open to that.

Quoted 12 lines
Quoted 12 lines
board/palmtreo680/palmtreo680.c new file +11 -0
+	return pxa_mmc_register(0);
+}
+#endif
+
+void board_nand_init(void)
+{
+	/* we have one 128M diskonchip G4  */
+
+	struct mtd_info *mtd = &nand_info[0];
+	struct nand_chip *nand = &docg4_nand_chip;
+	if (docg4_nand_init(mtd, nand, 0))
Quoted 8 lines

board/palmtreo680/palmtreo680.c line 89

Quoted 6 lines
board/palmtreo680/palmtreo680.c new file +6 -0
+		hang();
+}
+
+#ifdef CONFIG_SPL_BUILD
+void *memcpy(void *dest, const void *src, size_t count)
+{

CONFIG_SPL_LIBCOMMON_SUPPORT shall give you memcpy.

This does not appear to be the case. Unless I'm mistaken, memcpy() will be in either lib/libgeneric.o (lib/string.c) or arch/arm/lib/libarm.o (arch/arm/lib/memcpy.S) - depending on CONFIG_USE_ARCH_MEMCPY - but in neither case will it be in common/libcommon.o.

Quoted 10 lines

[...]

Review

Quoted 2 lines
(quoted diff) +2 -0
+void nand_boot(void)
+{

[...]

Will the common/spl/ NAND loading code not cut it here? I guess it won't since PXA is FUBAR when it comes to any kind of SPL loading. Do you not want to fix that? I'd be really grateful if you did ;-)

Well, palmtreo680 is a special case because its nand_boot() resumes loading u-boot where the IPL left off. IOW, the IPL has already loaded a portion of u-boot, whereas a generic nand_boot() will want to load the entire image.

I'd be willing to help with pxa spl code, but that might be difficult without hardware to test on, no?

Quoted 5 lines

[...]

btw. you dont really need to #define CONFIG_PXA27X to value "1" in your config, just remove those useless trailing "1"s .

Ah yes. And I'm finding some other clean-ups in the config file.

Thanks again Marek,
Mike

#19 lore raw

PATCH v3 7/8 add support for palm treo 680 board

Dear Mike Dunn,

[...]

Quoted 10 lines
Quoted 5 lines

board/palmtreo680/palmtreo680.c line 89

Quoted 3 lines
board/palmtreo680/palmtreo680.c new file +3 -0
+#ifdef CONFIG_SPL_BUILD
+void *memcpy(void *dest, const void *src, size_t count)
+{

CONFIG_SPL_LIBCOMMON_SUPPORT shall give you memcpy.

This does not appear to be the case. Unless I'm mistaken, memcpy() will be in either lib/libgeneric.o (lib/string.c) or arch/arm/lib/libarm.o (arch/arm/lib/memcpy.S) - depending on CONFIG_USE_ARCH_MEMCPY - but in neither case will it be in common/libcommon.o.

CONFIG_SPL_LIBGENERIC_SUPPORT then ;-)

Quoted 11 lines
Quoted 10 lines

[...]

Review

Quoted 2 lines
(quoted diff) +2 -0
+void nand_boot(void)
+{

[...]

Will the common/spl/ NAND loading code not cut it here? I guess it won't since PXA is FUBAR when it comes to any kind of SPL loading. Do you not want to fix that? I'd be really grateful if you did ;-)

Quoted 7 lines

Well, palmtreo680 is a special case because its nand_boot() resumes loading u-boot where the IPL left off. IOW, the IPL has already loaded a portion of u-boot, whereas a generic nand_boot() will want to load the entire image.

I'd be willing to help with pxa spl code, but that might be difficult without hardware to test on, no?

Yes, indeed.
[...]

author
#20 lore raw

PATCH v3 7/8 add support for palm treo 680 board

Quoted 10 lines · Marek Vasut

Dear Mike Dunn,

[...]

Quoted 6 lines
Quoted 5 lines

board/palmtreo680/palmtreo680.c line 89

Quoted 3 lines
board/palmtreo680/palmtreo680.c new file +3 -0
+#ifdef CONFIG_SPL_BUILD
+void *memcpy(void *dest, const void *src, size_t count)
+{

CONFIG_SPL_LIBCOMMON_SUPPORT shall give you memcpy.

Quoted 6 lines
Quoted 4 lines

This does not appear to be the case. Unless I'm mistaken, memcpy() will be in either lib/libgeneric.o (lib/string.c) or arch/arm/lib/libarm.o (arch/arm/lib/memcpy.S) - depending on CONFIG_USE_ARCH_MEMCPY - but in neither case will it be in common/libcommon.o.

CONFIG_SPL_LIBGENERIC_SUPPORT then ;-)

<smacks forehead>

Does preclude use of CONFIG_USE_ARCH_MEMCPY though.

Thanks,
Mike

author
#21 lore raw

PATCH v3 8/8 palmtreo680: add utility that writes u-boot to flash

In reply to Mike Dunn

This adds a userspace linux utility that writes the u-boot image to an mtd partition on the docg4 nand flash.

A special utility is required to do this because u-boot is partially loaded by an initial program loader (IPL) that is permanently programmed to the boot region of the flash. This IPL expects the image to be written in a unique format. The characteristics of this format can be summarized as follows:
- Flash blocks to be loaded must have a magic number in the oob bytes of the first page of the block.
- Each page must be written redundantly in the subsequent page.
- The integrated flash controller's "reliable mode" is used, requiring that alternate 2k regions (4 pages) are skipped when writing.
For these reasons, a u-boot image can not be written using nandwrite from mtd-utils.

---
Changelog:
v3: new patch; split off from patch 7 in v2 of patchset

 tools/palmtreo680/flash_u-boot.c |  167 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 167 insertions(+), 0 deletions(-)
 create mode 100644 tools/palmtreo680/flash_u-boot.c
tools/palmtreo680/flash_u-boot.c new file +167 -0
new file mode 100644
index 0000000..97b336f
@@ -0,0 +1,167 @@
+/*
+ * Copyright (C) 2013 Mike Dunn <[email protected]>
+ *
+ * This file is released under the terms of GPL v2 and any later version.
+ * See the file COPYING in the root directory of the source tree for details.
+ *
+ *
+ * This is a userspace Linux utility that, when run on the Treo 680, will
+ * program u-boot to flash.  The docg4 driver *must* be loaded with the
+ * reliable_mode and ignore_badblocks parameters enabled:
+ *
+ *        modprobe docg4 ignore_badblocks=1 reliable_mode=1
+ *
+ * This utility writes the concatenated spl + u-boot image to the start of the
+ * mtd device in the format expected by the IPL/SPL.  The image file and mtd
+ * device node are passed to the utility as arguments.  The blocks must have
+ * been erased beforehand.
+ *
+ * When you compile this, note that it links to libmtd from mtd-utils, so ensure
+ * that your include and lib paths include this.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <errno.h>
+#include <mtd/mtd-user.h>
+#include "libmtd.h"
+
+#define RELIABLE_BLOCKSIZE  0x10000 /* block capacity in reliable mode */
+#define STANDARD_BLOCKSIZE  0x40000 /* block capacity in normal mode */
+#define PAGESIZE 512
+#define PAGES_PER_BLOCK 512
+#define OOBSIZE 7		/* available to user (16 total) */
+
+uint8_t ff_oob[OOBSIZE] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+
+/* this is the magic number the IPL looks for (ASCII "BIPO") */
+uint8_t page0_oob[OOBSIZE] = {'B', 'I', 'P', 'O', 0xff, 0xff, 0xff};
+
+int main(int argc, char * const argv[])
+{
+	int devfd, datafd, num_blocks, block;
+	off_t file_size;
+	libmtd_t mtd_desc;
+	struct mtd_dev_info devinfo;
+	uint8_t *blockbuf;
+	char response[8];
+
+	if (argc != 3) {
+		printf("usage: %s <image file> <mtd dev node>\n", argv[0]);
+		exit(-1);
+	}
+
+	mtd_desc = libmtd_open();
+	if (mtd_desc == NULL) {
+		fprintf(stderr, "can't initialize libmtd\n");
+		exit(-1);
+	}
+
+	/* open the spl image file and mtd device */
+	datafd = open(argv[1], O_RDONLY);
+	if (datafd == -1) {
+		perror(argv[1]);
+		exit(-1);
+	}
+	devfd = open(argv[2], O_WRONLY);
+	if (devfd == -1) {
+		perror(argv[2]);
+		exit(-1);
+	}
+	if (mtd_get_dev_info(mtd_desc, argv[2], &devinfo) < 0) {
+		fprintf(stderr, "mtd_get_dev_info failed\n");
+		exit(-1);
+	}
+
+	/* determine the number of blocks needed by the image */
+	file_size = lseek(datafd, 0, SEEK_END);
+	if (file_size == (off_t)-1) {
+		perror("lseek");
+		exit(-1);
+	}
+	num_blocks = (file_size + RELIABLE_BLOCKSIZE - 1) / RELIABLE_BLOCKSIZE;
+	file_size = lseek(datafd, 0, SEEK_SET);
+	if (file_size == (off_t)-1) {
+		perror("lseek");
+		exit(-1);
+	}
+	printf("The mtd partition contains %d blocks\n", devinfo.eb_cnt);
+	printf("U-boot will occupy %d blocks\n", num_blocks);
+	if (num_blocks > devinfo.eb_cnt) {
+		fprintf(stderr, "Insufficient blocks on partition\n");
+		exit(-1);
+	}
+
+	printf("IMPORTANT: These blocks must be in an erased state!\n");
+	printf("Do you want to proceed?\n");
+	scanf("%s", response);
+	if ((response[0] != 'y') && (response[0] != 'Y')) {
+		printf("Exiting\n");
+		close(devfd);
+		close(datafd);
+		exit(-1);
+	}
+
+	blockbuf = malloc(RELIABLE_BLOCKSIZE);
+	if (blockbuf == NULL) {
+		perror("malloc");
+		exit(-1);
+	}
+
+	for (block = 0; block < num_blocks; block++) {
+		int ofs, page;
+		ssize_t read_ret;
+		uint8_t *pagebuf = blockbuf, *buf = blockbuf;
+		uint8_t *oobbuf = page0_oob; /* magic num in oob of 1st page */
+		size_t len = RELIABLE_BLOCKSIZE;
+		int ret;
+
+		/* read data for one block from file */
+		while (len != 0 && (read_ret = read(datafd, buf, len)) != 0) {
+			if (read_ret == -1) {
+				if (errno == EINTR)
+					continue;
+				perror("read");
+				exit(-1);
+			}
+			len -= read_ret;
+			buf += read_ret;
+		}
+
+		printf("Block %d: writing\r", block + 1);
+		fflush(stdout);
+
+		for (page = 0, ofs = 0;
+		     page < PAGES_PER_BLOCK;
+		     page++, ofs += PAGESIZE) {
+			if (page & 0x04)  /* Odd-numbered 2k page */
+				continue; /* skipped in reliable mode */
+
+			ret = mtd_write(mtd_desc, &devinfo, devfd, block, ofs,
+					pagebuf, PAGESIZE, oobbuf, OOBSIZE,
+					MTD_OPS_PLACE_OOB);
+			if (ret) {
+				fprintf(stderr,
+					"\nmtd_write returned %d on block %d, ofs %x\n",
+					ret, block + 1, ofs);
+				exit(-1);
+			}
+			oobbuf = ff_oob;  /* oob for subsequent pages */
+
+			if (page & 0x01)  /* odd-numbered subpage */
+				pagebuf += PAGESIZE;
+		}
+	}
+
+	printf("\nDone\n");
+
+	close(devfd);
+	close(datafd);
+	free(blockbuf);
+	return 0;
+}
Signature · 1 line
1.7.8.6
#22 lore raw

PATCH v3 8/8 palmtreo680: add utility that writes u-boot to flash

Dear Mike Dunn,

Quoted 77 lines

This adds a userspace linux utility that writes the u-boot image to an mtd partition on the docg4 nand flash.

A special utility is required to do this because u-boot is partially loaded by an initial program loader (IPL) that is permanently programmed to the boot region of the flash. This IPL expects the image to be written in a unique format. The characteristics of this format can be summarized as
follows: - Flash blocks to be loaded must have a magic number in the oob bytes of the first page of the block.
- Each page must be written redundantly in the subsequent page.
- The integrated flash controller's "reliable mode" is used, requiring
that alternate 2k regions (4 pages) are skipped when writing. For these reasons, a u-boot image can not be written using nandwrite from mtd-utils.

---
Changelog:
v3: new patch; split off from patch 7 in v2 of patchset

 tools/palmtreo680/flash_u-boot.c |  167
++++++++++++++++++++++++++++++++++++++ 1 files changed, 167 insertions(+),
0 deletions(-)
 create mode 100644 tools/palmtreo680/flash_u-boot.c
(quoted diff) +0 -0

b/tools/palmtreo680/flash_u-boot.c new file mode 100644 index 0000000..97b336f

tools/palmtreo680/flash_u-boot.c new file +5 -0
@@ -0,0 +1,167 @@
+/*
+ * Copyright (C) 2013 Mike Dunn <[email protected]>
+ *
+ * This file is released under the terms of GPL v2 and any later version.
+ * See the file COPYING in the root directory of the source tree for

details. + *
+ *
+ * This is a userspace Linux utility that, when run on the Treo 680, will
+ * program u-boot to flash. The docg4 driver *must* be loaded with the
+ * reliable_mode and ignore_badblocks parameters enabled:
+ *
+ * modprobe docg4 ignore_badblocks=1 reliable_mode=1
+ *
+ * This utility writes the concatenated spl + u-boot image to the start of the + * mtd device in the format expected by the IPL/SPL. The image file and mtd + * device node are passed to the utility as arguments. The blocks must have + * been erased beforehand.
+ *
+ * When you compile this, note that it links to libmtd from mtd-utils, so ensure + * that your include and lib paths include this.
+ */

tools/palmtreo680/flash_u-boot.c new file +25 -0
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <errno.h>
+#include <mtd/mtd-user.h>
+#include "libmtd.h"
+
+#define RELIABLE_BLOCKSIZE  0x10000 /* block capacity in reliable mode */
+#define STANDARD_BLOCKSIZE  0x40000 /* block capacity in normal mode */
+#define PAGESIZE 512
+#define PAGES_PER_BLOCK 512
+#define OOBSIZE 7		/* available to user (16 total) */
+
+uint8_t ff_oob[OOBSIZE] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+
+/* this is the magic number the IPL looks for (ASCII "BIPO") */
+uint8_t page0_oob[OOBSIZE] = {'B', 'I', 'P', 'O', 0xff, 0xff, 0xff};
+
+int main(int argc, char * const argv[])
+{

tools/palmtreo680/flash_u-boot.c line 56

Quoted 10 lines
tools/palmtreo680/flash_u-boot.c new file +10 -0
+	int devfd, datafd, num_blocks, block;
+	off_t file_size;
+	libmtd_t mtd_desc;
+	struct mtd_dev_info devinfo;
+	uint8_t *blockbuf;
+	char response[8];
+
+	if (argc != 3) {
+		printf("usage: %s <image file> <mtd dev node>\n", argv[0]);
+		exit(-1);

Use proper errno and "return" as you're returning from main() anyway.

Quoted 44 lines
tools/palmtreo680/flash_u-boot.c new file +44 -0
+	}
+
+	mtd_desc = libmtd_open();
+	if (mtd_desc == NULL) {
+		fprintf(stderr, "can't initialize libmtd\n");
+		exit(-1);
+	}
+
+	/* open the spl image file and mtd device */
+	datafd = open(argv[1], O_RDONLY);
+	if (datafd == -1) {
+		perror(argv[1]);
+		exit(-1);
+	}
+	devfd = open(argv[2], O_WRONLY);
+	if (devfd == -1) {
+		perror(argv[2]);
+		exit(-1);
+	}
+	if (mtd_get_dev_info(mtd_desc, argv[2], &devinfo) < 0) {
+		fprintf(stderr, "mtd_get_dev_info failed\n");
+		exit(-1);
+	}
+
+	/* determine the number of blocks needed by the image */
+	file_size = lseek(datafd, 0, SEEK_END);
+	if (file_size == (off_t)-1) {
+		perror("lseek");
+		exit(-1);
+	}
+	num_blocks = (file_size + RELIABLE_BLOCKSIZE - 1) / RELIABLE_BLOCKSIZE;
+	file_size = lseek(datafd, 0, SEEK_SET);
+	if (file_size == (off_t)-1) {
+		perror("lseek");
+		exit(-1);
+	}
+	printf("The mtd partition contains %d blocks\n", devinfo.eb_cnt);
+	printf("U-boot will occupy %d blocks\n", num_blocks);
+	if (num_blocks > devinfo.eb_cnt) {
+		fprintf(stderr, "Insufficient blocks on partition\n");
+		exit(-1);
+	}
+
+	printf("IMPORTANT: These blocks must be in an erased state!\n");

tools/palmtreo680/flash_u-boot.c line 110

Quoted 10 lines
tools/palmtreo680/flash_u-boot.c new file +10 -0
+	printf("Do you want to proceed?\n");
+	scanf("%s", response);
+	if ((response[0] != 'y') && (response[0] != 'Y')) {
+		printf("Exiting\n");
+		close(devfd);
+		close(datafd);
+		exit(-1);
+	}
+
+	blockbuf = malloc(RELIABLE_BLOCKSIZE);

Do you not want to use some calloc() here to make sure the "blockbuf" is zeroed?

Quoted 5 lines
tools/palmtreo680/flash_u-boot.c new file +5 -0
+	if (blockbuf == NULL) {
+		perror("malloc");
+		exit(-1);
+	}
+

tools/palmtreo680/flash_u-boot.c line 125

Quoted 10 lines
tools/palmtreo680/flash_u-boot.c new file +10 -0
+	for (block = 0; block < num_blocks; block++) {
+		int ofs, page;
+		ssize_t read_ret;
+		uint8_t *pagebuf = blockbuf, *buf = blockbuf;
+		uint8_t *oobbuf = page0_oob; /* magic num in oob of 1st page */
+		size_t len = RELIABLE_BLOCKSIZE;
+		int ret;
+
+		/* read data for one block from file */
+		while (len != 0 && (read_ret = read(datafd, buf, len)) != 0) {

Uh, this really might be a candidate for IOCCC, split this please ...

Quoted 15 lines
tools/palmtreo680/flash_u-boot.c new file +15 -0
+			if (read_ret == -1) {
+				if (errno == EINTR)
+					continue;
+				perror("read");
+				exit(-1);
+			}
+			len -= read_ret;
+			buf += read_ret;
+		}
+
+		printf("Block %d: writing\r", block + 1);
+		fflush(stdout);
+
+		for (page = 0, ofs = 0;
+		     page < PAGES_PER_BLOCK;

tools/palmtreo680/flash_u-boot.c

Quoted 10 lines
tools/palmtreo680/flash_u-boot.c new file +10 -0
+		     page++, ofs += PAGESIZE) {
+			if (page & 0x04)  /* Odd-numbered 2k page */
+				continue; /* skipped in reliable mode */
+
+			ret = mtd_write(mtd_desc, &devinfo, devfd, block, ofs,
+					pagebuf, PAGESIZE, oobbuf, OOBSIZE,
+					MTD_OPS_PLACE_OOB);
+			if (ret) {
+				fprintf(stderr,
+					"\nmtd_write returned %d on block %d, 

ofs %x\n",

Quoted 17 lines
tools/palmtreo680/flash_u-boot.c new file +17 -0
+					ret, block + 1, ofs);
+				exit(-1);
+			}
+			oobbuf = ff_oob;  /* oob for subsequent pages */
+
+			if (page & 0x01)  /* odd-numbered subpage */
+				pagebuf += PAGESIZE;
+		}
+	}
+
+	printf("\nDone\n");
+
+	close(devfd);
+	close(datafd);
+	free(blockbuf);
+	return 0;
+}
author
#23 lore raw

PATCH v3 8/8 palmtreo680: add utility that writes u-boot to flash

Thanks again Marek. A question below...

On 04/14/2013 10:38 AM, Marek Vasut wrote:

[...]

Quoted 6 lines

tools/palmtreo680/flash_u-boot.c line 56

Quoted 4 lines
tools/palmtreo680/flash_u-boot.c new file +4 -0
+
+	if (argc != 3) {
+		printf("usage: %s <image file> <mtd dev node>\n", argv[0]);
+		exit(-1);

Use proper errno and "return" as you're returning from main() anyway.

Agreed regarding 'return'. But should I be concerned with setting or preserving errno before all 'return -1' lines? Is it normal practice for a common utility to set errno? errno will have to be saved in many places, since perror() itself can change it. This will add many more lines of code.

[...]

Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	blockbuf = malloc(RELIABLE_BLOCKSIZE);

Do you not want to use some calloc() here to make sure the "blockbuf" is zeroed?

Not necessary here; the buffer is always filled or the utility exits with error.
But will change to calloc() anyway.

[...]

Quoted 5 lines

tools/palmtreo680/flash_u-boot.c line 125

Quoted 3 lines
tools/palmtreo680/flash_u-boot.c new file +3 -0
+
+		/* read data for one block from file */
+		while (len != 0 && (read_ret = read(datafd, buf, len)) != 0) {

Uh, this really might be a candidate for IOCCC, split this please ...

Well, OK, but... I normally don't embed calls in tests, but I do it here because the read is performed at the start of each loop iteration, and I thought this made it clearer and more concise. Basically it means "loop while there's still more data to write, and read() does not return EOF".

Actually, read() should never return EOF, because earlier I check the file length, so if I'm going to do the sanity check anyway, maybe it should be separate.

Thanks,
Mike

#24 lore raw

PATCH v3 8/8 palmtreo680: add utility that writes u-boot to flash

Dear Mike Dunn,

Quoted 15 lines

Thanks again Marek. A question below...

On 04/14/2013 10:38 AM, Marek Vasut wrote:

[...]

Quoted 6 lines

tools/palmtreo680/flash_u-boot.c line 56

Quoted 4 lines
tools/palmtreo680/flash_u-boot.c new file +4 -0
+
+	if (argc != 3) {
+		printf("usage: %s <image file> <mtd dev node>\n", argv[0]);
+		exit(-1);

Use proper errno and "return" as you're returning from main() anyway.

Quoted 5 lines

Agreed regarding 'return'. But should I be concerned with setting or preserving errno before all 'return -1' lines? Is it normal practice for a common utility to set errno? errno will have to be saved in many places, since perror() itself can change it. This will add many more lines of code.

Ooops! errno.h, sorry for the confusion :-(

Quoted 10 lines

[...]

Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	blockbuf = malloc(RELIABLE_BLOCKSIZE);

Do you not want to use some calloc() here to make sure the "blockbuf" is zeroed?

Not necessary here; the buffer is always filled or the utility exits with error. But will change to calloc() anyway.

If you're sure it's filled, then it's no problem.

Quoted 8 lines

[...]

Quoted 5 lines

tools/palmtreo680/flash_u-boot.c line 125

Quoted 3 lines
tools/palmtreo680/flash_u-boot.c new file +3 -0
+
+		/* read data for one block from file */
+		while (len != 0 && (read_ret = read(datafd, buf, len)) != 0) {

Uh, this really might be a candidate for IOCCC, split this please ...

Quoted 8 lines

Well, OK, but... I normally don't embed calls in tests, but I do it here because the read is performed at the start of each loop iteration, and I thought this made it clearer and more concise. Basically it means "loop while there's still more data to write, and read() does not return EOF".

Actually, read() should never return EOF, because earlier I check the file length, so if I'm going to do the sanity check anyway, maybe it should be separate.

I'd say you can loop and break; out if needed, no ?

while (cond.) {
if (x)
break;
if (y)
break;

do_useful_stuff here;
}

Best regards,
Marek Vasut