[PATCH 1/3] boards: phytec-som-am335x: Get ready for EMMC boot

2015-06-26 Thread Teresa Remmet
Select correct instance when booting from a mmc interface.

Signed-off-by: Teresa Remmet 
---
 arch/arm/boards/phytec-som-am335x/board.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boards/phytec-som-am335x/board.c 
b/arch/arm/boards/phytec-som-am335x/board.c
index 74e39d7..7a87841 100644
--- a/arch/arm/boards/phytec-som-am335x/board.c
+++ b/arch/arm/boards/phytec-som-am335x/board.c
@@ -68,7 +68,10 @@ static int physom_devices_init(void)
of_device_enable_path("/chosen/environment-spi");
break;
case BOOTSOURCE_MMC:
-   omap_set_bootmmc_devname("mmc0");
+   if (bootsource_get_instance() == 0)
+   omap_set_bootmmc_devname("mmc0");
+   else
+   omap_set_bootmmc_devname("mmc1");
break;
default:
of_device_enable_path("/chosen/environment-nand");
-- 
1.9.1


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


[PATCH 2/3] ARM: dts: am33xx-strip: Keep devices we can boot from

2015-06-26 Thread Teresa Remmet
As we can boot from mmc2 don't strip it.

Signed-off-by: Teresa Remmet 
---
 arch/arm/dts/am33xx-strip.dtsi | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/arch/arm/dts/am33xx-strip.dtsi b/arch/arm/dts/am33xx-strip.dtsi
index 3dc9a57..085200e 100644
--- a/arch/arm/dts/am33xx-strip.dtsi
+++ b/arch/arm/dts/am33xx-strip.dtsi
@@ -11,8 +11,6 @@
aliases {
/delete-property/ i2c1;
/delete-property/ i2c2;
-   /delete-property/ mmc0;
-   /delete-property/ mmc1;
/delete-property/ mmc2;
/delete-property/ d_can0;
/delete-property/ d_can1;
@@ -21,7 +19,6 @@
 
 /delete-node/ &i2c1;
 /delete-node/ &i2c2;
-/delete-node/ &mmc2;
 /delete-node/ &mmc3;
 /delete-node/ &hwspinlock;
 /delete-node/ &wdt2;
-- 
1.9.1


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


[PATCH 3/3] ARM: dts: am33xx-strip: Strip more unused nodes

2015-06-26 Thread Teresa Remmet
There are still some nodes not used in barebox. Removed them.

Signed-off-by: Teresa Remmet 
---
 arch/arm/dts/am33xx-strip.dtsi | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/dts/am33xx-strip.dtsi b/arch/arm/dts/am33xx-strip.dtsi
index 085200e..04cf315 100644
--- a/arch/arm/dts/am33xx-strip.dtsi
+++ b/arch/arm/dts/am33xx-strip.dtsi
@@ -43,3 +43,5 @@
 /delete-node/ &mcasp0;
 /delete-node/ &mcasp1;
 /delete-node/ &rng;
+/delete-node/ &rtc;
+/delete-node/ &wkup_m3;
-- 
1.9.1


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


[PATCH 2/7] drivers: i2c: Only register available devices

2015-07-17 Thread Teresa Remmet
Only register i2c devices from device tree where status is enabled.

Signed-off-by: Teresa Remmet 
---
 drivers/i2c/i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index 5d0fa06..f0df666 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -278,7 +278,7 @@ static void of_i2c_register_devices(struct i2c_adapter 
*adap)
if (!IS_ENABLED(CONFIG_OFDEVICE) || !adap->dev.device_node)
return;
 
-   for_each_child_of_node(adap->dev.device_node, n) {
+   for_each_available_child_of_node(adap->dev.device_node, n) {
struct i2c_board_info info = {};
struct i2c_client *result;
const __be32 *addr;
-- 
1.9.1


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


[PATCH 4/7] ARM: dts: phyFLEX-AM335x-som: Disable eeprom on default

2015-07-17 Thread Teresa Remmet
Only enable eeprom when populated. So disable it in dtsi
file and enable if needed in board dts.

Signed-off-by: Teresa Remmet 
---
 arch/arm/dts/am335x-phytec-phyflex-som.dtsi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/dts/am335x-phytec-phyflex-som.dtsi 
b/arch/arm/dts/am335x-phytec-phyflex-som.dtsi
index b8c6886..81ecf9d 100644
--- a/arch/arm/dts/am335x-phytec-phyflex-som.dtsi
+++ b/arch/arm/dts/am335x-phytec-phyflex-som.dtsi
@@ -138,6 +138,7 @@
byte_len = <4096>;
pagesize = <32>;
reg = <0x52>;
+   status = "disabled";
};
 };
 
-- 
1.9.1


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


[PATCH 1/7] mtd: core: Check partitions for empty string

2015-07-17 Thread Teresa Remmet
Make setting partitions a litte bit more robust.

Signed-off-by: Teresa Remmet 
---
 drivers/mtd/core.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index fda9034..3bdf441 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -386,6 +386,9 @@ static int mtd_partition_set(struct device_d *dev, struct 
param_d *p, const char
struct mtd_info *mtdpart, *tmp;
int ret;
 
+   if (!val)
+   return -EINVAL;
+
list_for_each_entry_safe(mtdpart, tmp, &mtd->partitions, 
partitions_entry) {
ret = mtd_del_partition(mtdpart);
if (ret)
-- 
1.9.1


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


[PATCH 5/7] ARM: phytec-som-am335x: Add support for 1024MiB RAM on one chip

2015-07-17 Thread Teresa Remmet
Added support for IM8G16D3FBBG15EI 1024MiB RAM on one chip.

Signed-off-by: Teresa Remmet 
---
 arch/arm/boards/phytec-som-am335x/lowlevel.c|  1 +
 arch/arm/boards/phytec-som-am335x/ram-timings.h | 22 +-
 images/Makefile.am33xx  |  6 ++
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boards/phytec-som-am335x/lowlevel.c 
b/arch/arm/boards/phytec-som-am335x/lowlevel.c
index 948bfa5..0ff62a3 100644
--- a/arch/arm/boards/phytec-som-am335x/lowlevel.c
+++ b/arch/arm/boards/phytec-som-am335x/lowlevel.c
@@ -124,6 +124,7 @@ PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_128mb, 
am335x_phytec_phycore_s
 PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_256mb, 
am335x_phytec_phycore_som_mlo, PHYCORE_MT41J128M16125IT_256MB);
 PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_512mb, 
am335x_phytec_phycore_som_mlo, PHYCORE_MT41J256M16HA15EIT_512MB);
 PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_2x512mb, 
am335x_phytec_phycore_som_mlo, PHYCORE_MT41J512M8125IT_2x512MB);
+PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_1024mb, 
am335x_phytec_phycore_som_mlo, PHYCORE_IM8G16D3FBBG15EI_1024MB);
 PHYTEC_ENTRY(start_am33xx_phytec_phycore_sdram, am335x_phytec_phycore_som);
 PHYTEC_ENTRY(start_am33xx_phytec_phycore_no_spi_sdram, 
am335x_phytec_phycore_som_no_spi);
 
diff --git a/arch/arm/boards/phytec-som-am335x/ram-timings.h 
b/arch/arm/boards/phytec-som-am335x/ram-timings.h
index 3dcee20..698b073 100644
--- a/arch/arm/boards/phytec-som-am335x/ram-timings.h
+++ b/arch/arm/boards/phytec-som-am335x/ram-timings.h
@@ -29,6 +29,7 @@ enum {
PHYCORE_MT41J64M1615IT_128MB,
PHYCORE_MT41J256M16HA15EIT_512MB,
PHYCORE_MT41J512M8125IT_2x512MB,
+   PHYCORE_IM8G16D3FBBG15EI_1024MB,
 
PHYCARD_NT5CB128M16BP_256MB,
 };
@@ -133,7 +134,7 @@ struct am335x_sdram_timings physom_timings[] = {
},
},
 
-   /* 1024MB */
+   /* 2x512MB */
[PHYCORE_MT41J512M8125IT_2x512MB] = {
.regs = {
.emif_read_latency  = 0x7,
@@ -152,6 +153,25 @@ struct am335x_sdram_timings physom_timings[] = {
},
},
 
+   /* 1024MB */
+   [PHYCORE_IM8G16D3FBBG15EI_1024MB] = {
+   .regs = {
+   .emif_read_latency  = 0x7,
+   .emif_tim1  = 0x0AAAE4DB,
+   .emif_tim2  = 0x268F7FDA,
+   .emif_tim3  = 0x501F88BF,
+   .sdram_config   = 0x61C053B2,
+   .zq_config  = 0x50074BE4,
+   .sdram_ref_ctrl = 0x0C30
+   },
+   .data = {
+   .rd_slave_ratio0= 0x33,
+   .wr_dqs_slave_ratio0= 0x4a,
+   .fifo_we_slave_ratio0   = 0xa4,
+   .wr_slave_ratio0= 0x85,
+   },
+   },
+
/* 256MB */
[PHYCARD_NT5CB128M16BP_256MB] = {
.regs = {
diff --git a/images/Makefile.am33xx b/images/Makefile.am33xx
index 657aeb0..df77f19 100644
--- a/images/Makefile.am33xx
+++ b/images/Makefile.am33xx
@@ -57,6 +57,12 @@ FILE_barebox-am33xx-phytec-phycore-mlo-2x512mb.spi.img = 
start_am33xx_phytec_phy
 am33xx-mlo-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-mlo-2x512mb.img
 am33xx-mlospi-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-mlo-2x512mb.spi.img
 
+pblx-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
start_am33xx_phytec_phycore_sram_1024mb
+FILE_barebox-am33xx-phytec-phycore-mlo-1024mb.img = 
start_am33xx_phytec_phycore_sram_1024mb.pblx.mlo
+FILE_barebox-am33xx-phytec-phycore-mlo-1024mb.spi.img = 
start_am33xx_phytec_phycore_sram_1024mb.pblx.mlospi
+am33xx-mlo-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-mlo-1024mb.img
+am33xx-mlospi-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-mlo-1024mb.spi.img
+
 pblx-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += start_am33xx_phytec_phyflex_sdram
 FILE_barebox-am33xx-phytec-phyflex.img = start_am33xx_phytec_phyflex_sdram.pblx
 am33xx-barebox-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phyflex.img
-- 
1.9.1


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


[PATCH 3/7] ARM: dts: am335x-phytec boards: Fixup spi flash node name

2015-07-17 Thread Teresa Remmet
Signed-off-by: Teresa Remmet 
---
 arch/arm/dts/am335x-phytec-phycore-som.dtsi | 2 +-
 arch/arm/dts/am335x-phytec-phyflex-som.dtsi | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/dts/am335x-phytec-phycore-som.dtsi 
b/arch/arm/dts/am335x-phytec-phycore-som.dtsi
index ed8e257..59816d0 100644
--- a/arch/arm/dts/am335x-phytec-phycore-som.dtsi
+++ b/arch/arm/dts/am335x-phytec-phycore-som.dtsi
@@ -162,7 +162,7 @@
pinctrl-0 = <&spi0_pins>;
status = "disabled";
 
-   flash: m25p80 {
+   flash: m25p80@0 {
compatible = "m25p80";
spi-max-frequency = <4800>;
reg = <0>;
diff --git a/arch/arm/dts/am335x-phytec-phyflex-som.dtsi 
b/arch/arm/dts/am335x-phytec-phyflex-som.dtsi
index fc9c9ba..b8c6886 100644
--- a/arch/arm/dts/am335x-phytec-phyflex-som.dtsi
+++ b/arch/arm/dts/am335x-phytec-phyflex-som.dtsi
@@ -151,7 +151,7 @@
pinctrl-names = "default";
pinctrl-0 = <&spi0_pins>;
status = "disabled";
-   flash: m25p80 {
+   flash: m25p80@0 {
compatible = "m25p80";
spi-max-frequency = <4800>;
reg = <0>;
-- 
1.9.1


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


[PATCH 7/7] ARM: dts: Add support for all phyFLEX-AM335x options

2015-07-17 Thread Teresa Remmet
Add support for all possible combinations of phyFLEX-AM335x modules.

Signed-off-by: Teresa Remmet 
---
 arch/arm/boards/phytec-som-am335x/lowlevel.c   |  3 +++
 arch/arm/dts/Makefile  |  2 ++
 .../dts/am335x-phytec-phyflex-som-no-eeprom.dts| 22 ++
 .../am335x-phytec-phyflex-som-no-spi-no-eeprom.dts | 18 ++
 arch/arm/dts/am335x-phytec-phyflex-som-no-spi.dts  | 22 ++
 images/Makefile.am33xx | 12 
 6 files changed, 79 insertions(+)
 create mode 100644 arch/arm/dts/am335x-phytec-phyflex-som-no-eeprom.dts
 create mode 100644 arch/arm/dts/am335x-phytec-phyflex-som-no-spi-no-eeprom.dts
 create mode 100644 arch/arm/dts/am335x-phytec-phyflex-som-no-spi.dts

diff --git a/arch/arm/boards/phytec-som-am335x/lowlevel.c 
b/arch/arm/boards/phytec-som-am335x/lowlevel.c
index adc19de..64c1c53 100644
--- a/arch/arm/boards/phytec-som-am335x/lowlevel.c
+++ b/arch/arm/boards/phytec-som-am335x/lowlevel.c
@@ -134,6 +134,9 @@ 
PHYTEC_ENTRY(start_am33xx_phytec_phycore_no_spi_no_eeprom_sdram, am335x_phytec_p
 PHYTEC_ENTRY_MLO(start_am33xx_phytec_phyflex_sram_256mb, 
am335x_phytec_phyflex_som_mlo, PHYFLEX_MT41K128M16JT_256MB);
 PHYTEC_ENTRY_MLO(start_am33xx_phytec_phyflex_sram_512mb, 
am335x_phytec_phyflex_som_mlo, PHYFLEX_MT41K256M16HA_512MB);
 PHYTEC_ENTRY(start_am33xx_phytec_phyflex_sdram, am335x_phytec_phyflex_som);
+PHYTEC_ENTRY(start_am33xx_phytec_phyflex_no_spi_sdram, 
am335x_phytec_phyflex_som_no_spi);
+PHYTEC_ENTRY(start_am33xx_phytec_phyflex_no_eeprom_sdram, 
am335x_phytec_phyflex_som_no_eeprom);
+PHYTEC_ENTRY(start_am33xx_phytec_phyflex_no_spi_no_eeprom_sdram, 
am335x_phytec_phyflex_som_no_spi_no_eeprom);
 
 /* phycard-som */
 PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycard_sram_256mb, 
am335x_phytec_phycard_som_mlo, PHYCARD_NT5CB128M16BP_256MB);
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 3d5cb53..15d620a 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -32,6 +32,8 @@ pbl-dtb-$(CONFIG_MACH_PCA100) += 
imx27-phytec-phycard-s-rdk-bb.dtb.o
 pbl-dtb-$(CONFIG_MACH_PCAAXL3) += imx6q-phytec-pbaa03.dtb.o
 pbl-dtb-$(CONFIG_MACH_PCM038) += imx27-phytec-phycore-rdk.dtb.o
 pbl-dtb-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += am335x-phytec-phyflex-som.dtb.o 
am335x-phytec-phyflex-som-mlo.dtb.o \
+   am335x-phytec-phyflex-som-no-spi.dtb.o 
am335x-phytec-phyflex-som-no-eeprom.dtb.o \
+   am335x-phytec-phyflex-som-no-spi-no-eeprom.dtb.o \
am335x-phytec-phycore-som.dtb.o am335x-phytec-phycore-som-no-spi.dtb.o 
am335x-phytec-phycore-som-mlo.dtb.o \
am335x-phytec-phycore-som-no-eeprom.dtb.o 
am335x-phytec-phycore-som-no-spi-no-eeprom.dtb.o \
am335x-phytec-phycard-som.dtb.o am335x-phytec-phycard-som-mlo.dtb.o
diff --git a/arch/arm/dts/am335x-phytec-phyflex-som-no-eeprom.dts 
b/arch/arm/dts/am335x-phytec-phyflex-som-no-eeprom.dts
new file mode 100644
index 000..0022e14
--- /dev/null
+++ b/arch/arm/dts/am335x-phytec-phyflex-som-no-eeprom.dts
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2015 PHYTEC Messtechnik GmbH
+ * Author: Wadim Egorov 
+ *Teresa Remmet 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+/dts-v1/;
+
+#include "am33xx.dtsi"
+#include "am335x-phytec-phyflex-som.dtsi"
+
+/ {
+   model = "Phytec phyFLEX AM335x";
+   compatible = "phytec,phyflex-am335x-som", "phytec,am335x-som", 
"ti,am33xx";
+};
+
+&spi0 {
+   status = "okay";
+};
diff --git a/arch/arm/dts/am335x-phytec-phyflex-som-no-spi-no-eeprom.dts 
b/arch/arm/dts/am335x-phytec-phyflex-som-no-spi-no-eeprom.dts
new file mode 100644
index 000..486aac6
--- /dev/null
+++ b/arch/arm/dts/am335x-phytec-phyflex-som-no-spi-no-eeprom.dts
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) 2015 PHYTEC Messtechnik GmbH
+ * Author: Wadim Egorov 
+ *Teresa Remmet 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+/dts-v1/;
+
+#include "am33xx.dtsi"
+#include "am335x-phytec-phyflex-som.dtsi"
+
+/ {
+   model = "Phytec phyFLEX AM335x";
+   compatible = "phytec,phyflex-am335x-som", "phytec,am335x-som", 
"ti,am33xx";
+};
diff --git a/arch/arm/dts/am335x-phytec-phyflex-som-no-spi.dts 
b/arch/arm/dts/am335x-phytec-phyflex-som-no-spi.dts
new file mode 100644
index 000..5f3a1e0
--- /dev/null
+++ b/arch/arm/dts/am335x-phytec-phyflex-som-no-spi.dts
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2015 PHYTEC Messtechnik GmbH
+ * Author: Wadim Egorov 
+ *Teresa Remmet 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it und

[PATCH 6/7] ARM: dts: Add support for all phyCORE-AM335x options

2015-07-17 Thread Teresa Remmet
Add support for all possible combinations of phyCORE-AM335x
modules.

Signed-off-by: Teresa Remmet 
---
 arch/arm/boards/phytec-som-am335x/lowlevel.c|  2 ++
 arch/arm/dts/Makefile   |  1 +
 .../arm/dts/am335x-phytec-phycore-som-no-eeprom.dts | 21 +
 .../am335x-phytec-phycore-som-no-spi-no-eeprom.dts  | 17 +
 images/Makefile.am33xx  |  8 
 5 files changed, 49 insertions(+)
 create mode 100644 arch/arm/dts/am335x-phytec-phycore-som-no-eeprom.dts
 create mode 100644 arch/arm/dts/am335x-phytec-phycore-som-no-spi-no-eeprom.dts

diff --git a/arch/arm/boards/phytec-som-am335x/lowlevel.c 
b/arch/arm/boards/phytec-som-am335x/lowlevel.c
index 0ff62a3..adc19de 100644
--- a/arch/arm/boards/phytec-som-am335x/lowlevel.c
+++ b/arch/arm/boards/phytec-som-am335x/lowlevel.c
@@ -127,6 +127,8 @@ PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_2x512mb, 
am335x_phytec_phycore
 PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_1024mb, 
am335x_phytec_phycore_som_mlo, PHYCORE_IM8G16D3FBBG15EI_1024MB);
 PHYTEC_ENTRY(start_am33xx_phytec_phycore_sdram, am335x_phytec_phycore_som);
 PHYTEC_ENTRY(start_am33xx_phytec_phycore_no_spi_sdram, 
am335x_phytec_phycore_som_no_spi);
+PHYTEC_ENTRY(start_am33xx_phytec_phycore_no_eeprom_sdram, 
am335x_phytec_phycore_som_no_eeprom);
+PHYTEC_ENTRY(start_am33xx_phytec_phycore_no_spi_no_eeprom_sdram, 
am335x_phytec_phycore_som_no_spi_no_eeprom);
 
 /* phyflex-som */
 PHYTEC_ENTRY_MLO(start_am33xx_phytec_phyflex_sram_256mb, 
am335x_phytec_phyflex_som_mlo, PHYFLEX_MT41K128M16JT_256MB);
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 06c29c8..3d5cb53 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -33,6 +33,7 @@ pbl-dtb-$(CONFIG_MACH_PCAAXL3) += imx6q-phytec-pbaa03.dtb.o
 pbl-dtb-$(CONFIG_MACH_PCM038) += imx27-phytec-phycore-rdk.dtb.o
 pbl-dtb-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += am335x-phytec-phyflex-som.dtb.o 
am335x-phytec-phyflex-som-mlo.dtb.o \
am335x-phytec-phycore-som.dtb.o am335x-phytec-phycore-som-no-spi.dtb.o 
am335x-phytec-phycore-som-mlo.dtb.o \
+   am335x-phytec-phycore-som-no-eeprom.dtb.o 
am335x-phytec-phycore-som-no-spi-no-eeprom.dtb.o \
am335x-phytec-phycard-som.dtb.o am335x-phytec-phycard-som-mlo.dtb.o
 pbl-dtb-$(CONFIG_MACH_PHYTEC_PFLA02) += imx6s-phytec-pbab01.dtb.o 
imx6dl-phytec-pbab01.dtb.o imx6q-phytec-pbab01.dtb.o 
imx6q-phytec-phyboard-alcor.dtb.o imx6dl-phytec-phyboard-subra.dtb.o
 pbl-dtb-$(CONFIG_MACH_PLATHOME_OPENBLOCKS_AX3) += 
armada-xp-openblocks-ax3-4-bb.dtb.o
diff --git a/arch/arm/dts/am335x-phytec-phycore-som-no-eeprom.dts 
b/arch/arm/dts/am335x-phytec-phycore-som-no-eeprom.dts
new file mode 100644
index 000..3dd130e
--- /dev/null
+++ b/arch/arm/dts/am335x-phytec-phycore-som-no-eeprom.dts
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2015 Phytec Messtechnik GmbH
+ * Author: Teresa Remmet 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+/dts-v1/;
+
+#include "am33xx.dtsi"
+#include "am335x-phytec-phycore-som.dtsi"
+
+/ {
+   model = "Phytec phyCORE AM335x";
+   compatible = "phytec,phycore-am335x-som", "phytec,am335x-som", 
"ti,am33xx";
+};
+
+&spi0 {
+   status = "okay";
+};
diff --git a/arch/arm/dts/am335x-phytec-phycore-som-no-spi-no-eeprom.dts 
b/arch/arm/dts/am335x-phytec-phycore-som-no-spi-no-eeprom.dts
new file mode 100644
index 000..397be77
--- /dev/null
+++ b/arch/arm/dts/am335x-phytec-phycore-som-no-spi-no-eeprom.dts
@@ -0,0 +1,17 @@
+/*
+ * Copyright (C) 2015 Phytec Messtechnik GmbH
+ * Author:  Teresa Remmet 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+/dts-v1/;
+
+#include "am33xx.dtsi"
+#include "am335x-phytec-phycore-som.dtsi"
+
+/ {
+   model = "Phytec phyCORE AM335x";
+   compatible = "phytec,phycore-am335x-som", "phytec,am335x-som", 
"ti,am33xx";
+};
diff --git a/images/Makefile.am33xx b/images/Makefile.am33xx
index df77f19..45813ca 100644
--- a/images/Makefile.am33xx
+++ b/images/Makefile.am33xx
@@ -33,6 +33,14 @@ pblx-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
start_am33xx_phytec_phycore_no_spi_sdra
 FILE_barebox-am33xx-phytec-phycore-no-spi.img = 
start_am33xx_phytec_phycore_no_spi_sdram.pblx
 am33xx-barebox-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-no-spi.img
 
+pblx-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
start_am33xx_phytec_phycore_no_eeprom_sdram
+FILE_barebox-am33xx-phytec-phycore-no-eeprom.img = 
start_am33xx_phytec_phycore_no_eeprom_sdram.pblx
+am33xx-barebox-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
bareb

[PATCH] ARM: dts: beaglebone: Strip MLO device tree

2015-07-30 Thread Teresa Remmet
Reduce size of beaglebone MLO image.

Signed-off-by: Teresa Remmet 
Tested-by: Daniel Schultz 
---
 arch/arm/dts/am335x-bone-common.dts | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/dts/am335x-bone-common.dts 
b/arch/arm/dts/am335x-bone-common.dts
index 5d3d2ed..91745d3 100644
--- a/arch/arm/dts/am335x-bone-common.dts
+++ b/arch/arm/dts/am335x-bone-common.dts
@@ -8,6 +8,7 @@
  */
 
 #include "am33xx.dtsi"
+#include "am33xx-strip.dtsi"
 #include "am335x-bone-common.dtsi"
 
 / {
-- 
1.9.1


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


Re: boards: phytec-som-am335x: ethernet broken after reset

2015-09-23 Thread Teresa Remmet
Hello Michael,

can you give me a little bit more information about the hardware you
are using? As the phytec-som-am335x, includes 3 different modules.
Names of the images in use and hardware revision of the som whould be
great.

I have made a quick test it with a phycore som on master. It worked for
me.

Regards,
Teresa

Am Mittwoch, den 23.09.2015, 17:28 +0200 schrieb Michael Grzeschik:
> Hi Teresa,
> 
> With the current code for the phytec-som-am335x, the ethernet works only
> after the first powerup. If you soft reset the module the network won't
> work anymore.
> 
> ...
> cpsw 4a10.ethernet: detected phy mask 0x6
> mdio_bus: miibus0: probed
> cpsw 4a10.ethernet: Failed to setup slave 0: I/O error
> ...
> 
> That happens in the second boot. The phy is probably in a wrong state and
> won't communicate over MDIO.
> 
> Do you have any ideas?
> 
> Thanks,
> Michael
> 



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


Re: boards: phytec-som-am335x: ethernet broken after reset

2015-09-30 Thread Teresa Remmet
Hello Michael,

Am Dienstag, den 29.09.2015, 16:12 +0200 schrieb Michael Grzeschik:
> On Thu, Sep 24, 2015 at 08:37:31AM +0200, Teresa Remmet wrote:
> > can you give me a little bit more information about the hardware you
> > are using? As the phytec-som-am335x, includes 3 different modules.
> > Names of the images in use and hardware revision of the som whould be
> > great.
> 
> It is an 1358.3 som which uses the MT41K128M16JT memory instead of the
> MT41J128M16125IT. I created an extra image, as it is used with an custom
> baseboard.

The MT41K128M16JT is a newer RAM. We tested that this also runs with the
timings of MT41J128M16125IT. Maybe I should add a comment into the code
as this leads to confusion.

> 
> > I have made a quick test it with a phycore som on master. It worked for
> > me.
> 
> Ok, Than there must be some differences. Possibly another used phy on
> the 1358.3 module.

I have checked this now also on a 1358.3 with MT41K128M16JT and a SMSC
LAN 8710A phy. It works with barebox master.

Regards,
Teresa

> 
> Thanks,
> Michael
> 



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


[PATCH 2/2] ARM: am335x_defconfig: Enable SMSC phy driver

2015-11-02 Thread Teresa Remmet
The phyCORE-AM335x has a SMSC phy mounted. Enabled the driver for it.

Signed-off-by: Teresa Remmet 
---
 arch/arm/configs/am335x_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/configs/am335x_defconfig 
b/arch/arm/configs/am335x_defconfig
index 234042f..9563865 100644
--- a/arch/arm/configs/am335x_defconfig
+++ b/arch/arm/configs/am335x_defconfig
@@ -88,12 +88,12 @@ CONFIG_NET=y
 CONFIG_NET_NFS=y
 CONFIG_NET_NETCONSOLE=y
 CONFIG_NET_RESOLV=y
-CONFIG_OFDEVICE=y
 CONFIG_OF_BAREBOX_DRIVERS=y
 CONFIG_DRIVER_SERIAL_NS16550=y
 CONFIG_DRIVER_SERIAL_NS16550_OMAP_EXTENSIONS=y
 CONFIG_DRIVER_NET_CPSW=y
 CONFIG_MICREL_PHY=y
+CONFIG_SMSC_PHY=y
 CONFIG_NET_USB=y
 CONFIG_NET_USB_ASIX=y
 CONFIG_NET_USB_SMSC95XX=y
-- 
1.9.1


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


[PATCH 1/2] dts: phyFLEX-AM335x: Disable second ethernet interface

2015-11-03 Thread Teresa Remmet
There are phyFLEX modules with only the first eth phy mounted.
As barebox only supports the first interface anyway, disable
the second interface for now.

Signed-off-by: Teresa Remmet 
---
 arch/arm/dts/am335x-phytec-phyflex-som.dtsi | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/arm/dts/am335x-phytec-phyflex-som.dtsi 
b/arch/arm/dts/am335x-phytec-phyflex-som.dtsi
index 6d488fa..c60943c 100644
--- a/arch/arm/dts/am335x-phytec-phyflex-som.dtsi
+++ b/arch/arm/dts/am335x-phytec-phyflex-som.dtsi
@@ -224,12 +224,13 @@
phy_id = <&davinci_mdio>, <2>;
phy-mode = "rmii";
dual_emac_res_vlan = <2>;
+   status = "disabled";
 };
 
 &mac {
pinctrl-names = "default";
-   pinctrl-0 = <&emac_rgmii1_pins &emac_rmii2_pins>;
-   dual_emac;
+   slaves = <1>;
+   pinctrl-0 = <&emac_rgmii1_pins>;
status = "okay";
 };
 
-- 
1.9.1


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


[PATCH] driver: watchdog: Add support for omap_wdt

2015-11-10 Thread Teresa Remmet
Add support for OMAP Watchdog driver.

Based on omap_wdt Linux driver (v4.3-rc1).

Signed-off-by: Teresa Remmet 
---
 drivers/watchdog/Kconfig|   6 ++
 drivers/watchdog/Makefile   |   1 +
 drivers/watchdog/omap_wdt.c | 199 
 3 files changed, 206 insertions(+)
 create mode 100644 drivers/watchdog/omap_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 582c615..60a56bf 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -34,4 +34,10 @@ config WATCHDOG_JZ4740
help
  Hardware driver for the built-in watchdog timer on Ingenic jz4740 
SoCs.
 
+config WATCHDOG_OMAP
+   bool "TI OMAP"
+   depends on ARCH_OMAP
+   help
+ Add support for watchdog on the TI OMAP SoC.
+
 endif
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 1e63c49..e3afe1c 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -1,5 +1,6 @@
 obj-$(CONFIG_WATCHDOG) += wd_core.o
 obj-$(CONFIG_WATCHDOG_DAVINCI) += davinci_wdt.o
+obj-$(CONFIG_WATCHDOG_OMAP) += omap_wdt.o
 obj-$(CONFIG_WATCHDOG_MXS28) += im28wd.o
 obj-$(CONFIG_WATCHDOG_JZ4740) += jz4740.o
 obj-$(CONFIG_WATCHDOG_IMX_RESET_SOURCE) += imxwd.o
diff --git a/drivers/watchdog/omap_wdt.c b/drivers/watchdog/omap_wdt.c
new file mode 100644
index 000..aa71a68
--- /dev/null
+++ b/drivers/watchdog/omap_wdt.c
@@ -0,0 +1,199 @@
+/*
+ * omap_wdt.c
+ *
+ * Watchdog driver for the TI OMAP 16xx & 24xx/34xx 32KHz (non-secure) watchdog
+ *
+ * Copyright (c) 2015 Phytec Messtechnik GmbH
+ * Author: Teresa Remmet 
+ *
+ * Based on Linux Kernel OMAP WTD driver:
+ *
+ * Author: MontaVista Software, Inc.
+ *   or 
+ *
+ * 2003 (c) MontaVista Software, Inc. This file is licensed under the
+ * terms of the GNU General Public License version 2. This program is
+ * licensed "as is" without any warranty of any kind, whether express
+ * or implied.
+ *
+ * History:
+ *
+ * 20030527: George G. Davis 
+ * Initially based on linux-2.4.19-rmk7-pxa1/drivers/char/sa1100_wdt.c
+ * (c) Copyright 2000 Oleg Drokin 
+ * Based on SoftDog driver by Alan Cox 
+ *
+ * Copyright (c) 2004 Texas Instruments.
+ * 1. Modified to support OMAP1610 32-KHz watchdog timer
+ * 2. Ported to 2.6 kernel
+ *
+ * Copyright (c) 2005 David Brownell
+ * Use the driver model and standard identifiers; handle bigger timeouts.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define OMAP_WATCHDOG_REV  (0x00)
+#define OMAP_WATCHDOG_SYS_CONFIG   (0x10)
+#define OMAP_WATCHDOG_STATUS   (0x14)
+#define OMAP_WATCHDOG_CNTRL(0x24)
+#define OMAP_WATCHDOG_CRR  (0x28)
+#define OMAP_WATCHDOG_LDR  (0x2c)
+#define OMAP_WATCHDOG_TGR  (0x30)
+#define OMAP_WATCHDOG_WPS  (0x34)
+#define OMAP_WATCHDOG_SPR  (0x48)
+
+#define TIMER_MARGIN_DEFAULT   60  /* 60 secs */
+
+#define PTV0   /* prescale */
+#define GET_WLDR_VAL(secs)  (0x - ((secs) * (32768/(1<base;
+
+   /* wait for posted write to complete */
+   while ((readl(base + OMAP_WATCHDOG_WPS)) & 0x08);
+
+   wdev->wdt_trgr_pattern = ~wdev->wdt_trgr_pattern;
+   writel(wdev->wdt_trgr_pattern, (base + OMAP_WATCHDOG_TGR));
+
+   /* wait for posted write to complete */
+   while ((readl(base + OMAP_WATCHDOG_WPS)) & 0x08);
+   /* reloaded WCRR from WLDR */
+}
+
+static void omap_wdt_enable(struct omap_wdt_dev *wdev)
+{
+   void __iomem *base = wdev->base;
+
+   /* Sequence to enable the watchdog */
+   writel(0x, base + OMAP_WATCHDOG_SPR);
+   while ((readl(base + OMAP_WATCHDOG_WPS)) & 0x10);
+
+   writel(0x, base + OMAP_WATCHDOG_SPR);
+   while ((readl(base + OMAP_WATCHDOG_WPS)) & 0x10);
+}
+
+static void omap_wdt_disable(struct omap_wdt_dev *wdev)
+{
+   void __iomem *base = wdev->base;
+
+   /* sequence required to disable watchdog */
+   writel(0x, base + OMAP_WATCHDOG_SPR);   /* TIMER_MODE */
+   while (readl(base + OMAP_WATCHDOG_WPS) & 0x10);
+
+   writel(0x, base + OMAP_WATCHDOG_SPR);   /* TIMER_MODE */
+   while (readl(base + OMAP_WATCHDOG_WPS) & 0x10);
+}
+
+static void omap_wdt_set_timer(struct omap_wdt_dev *wdev,
+  unsigned int timeout)
+{
+   u32 pre_margin = GET_WLDR_VAL(timeout);
+   void __iomem *base = wdev->base;
+
+   /* just count up at 32 KHz */
+   while (readl(base + OMAP_WATCHDOG_WPS) & 0x04);
+
+   writel(pre_margin, base + OMAP_WATCHDOG_LDR);
+   while (readl(base + OMAP_WATCHDOG_WPS) & 0x04);
+
+}
+
+static void omap_wdt_init(struct omap_wdt_dev *wdev)
+{
+   void __iomem *base = wdev->base;
+
+   /*
+* Make sure the watchdog is disabled. This is unfortunately required

Re: am335x: MLO and Barebox

2015-12-07 Thread Teresa Remmet
Hello Yegor,

yes you do understand this correct. There is a am335x_mlo_defconfig for
MLO and a am335x_defconfig for a full barebox image. Both configs will
drop out all available am335x images. Not only Phytec ones.

Regards,
Teresa

Am Montag, den 07.12.2015, 11:38 +0100 schrieb Yegor Yefremov:
> I've looked at Phytec defconfigs. Do I understand it correctly, that I
> need two defconfigs: one for MLO and one for Barebox itself?
> 
> Regards,
> Yegor
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox



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


[PATCH] mtd: nand: nand_omap_gpmc: Fix ecc steps

2018-05-18 Thread Teresa Remmet
The eccsteps where set wrong for OMAP_ECC_BCH8_CODE_HW_ROMCODE.
So the ECC was only corrected for the first 512 bytes chunk of a 2k page.

Moved out the ecc step iteration out of the correcting loop to make
it more alike the generic nand functions. And made sure that
the ECC is caclulated for all chunks.

This patch is based on work of Sascha Hauer.

Fixes commit dec7b4d2bf9c ("mtd: nand_omap_gpmc: fix BCH error correction").

Signed-off-by: Teresa Remmet 
---
Hello,

this patch hopefully finally fixes the nand issue in the nand_omap_gpmc driver.
Sascha and Daniel worked on this before but thier final solution was not 
correct.
The problem was that we can not get rid of the 14 byte ECC
size used in OMAP_ECC_BCH8_CODE_HW_ROMCODE. The generic nand write function
needs to consider the offset, too. Or we read wrong ECC after writing.

Maybe there is someone out there to test if this is also working with
OMAP_ECC_BCH8_CODE_HW.

Teresa

 drivers/mtd/nand/nand_omap_gpmc.c | 115 +++---
 1 file changed, 56 insertions(+), 59 deletions(-)

diff --git a/drivers/mtd/nand/nand_omap_gpmc.c 
b/drivers/mtd/nand/nand_omap_gpmc.c
index e18ce6358a73..97bdb8f19753 100644
--- a/drivers/mtd/nand/nand_omap_gpmc.c
+++ b/drivers/mtd/nand/nand_omap_gpmc.c
@@ -297,19 +297,18 @@ static int omap_correct_bch(struct mtd_info *mtd, uint8_t 
*dat,
 {
struct nand_chip *nand = (struct nand_chip *)(mtd->priv);
struct gpmc_nand_info *oinfo = (struct gpmc_nand_info *)(nand->priv);
-   int i, j, eccflag, totalcount, actual_eccsize;
+   int j, actual_eccsize;
const uint8_t *erased_ecc_vec;
unsigned int err_loc[8];
-   int bitflip_count;
int bch_max_err;
+   int bitflip_count = 0;
+   int eccflag = 0;
+   bool is_error_reported = false;
 
-   int eccsteps = (nand->ecc.mode == NAND_ECC_HW) &&
-   (nand->ecc.size == 2048) ? 4 : 1;
int eccsize = oinfo->nand.ecc.bytes;
 
switch (oinfo->ecc_mode) {
case OMAP_ECC_BCH8_CODE_HW:
-   eccsize /= eccsteps;
actual_eccsize = eccsize;
erased_ecc_vec = bch8_vector;
bch_max_err = BCH8_MAX_ERROR;
@@ -324,58 +323,45 @@ static int omap_correct_bch(struct mtd_info *mtd, uint8_t 
*dat,
return -EINVAL;
}
 
-   totalcount = 0;
-
-   for (i = 0; i < eccsteps; i++) {
-   bool is_error_reported = false;
-   bitflip_count = 0;
-   eccflag = 0;
-
-   /* check for any ecc error */
-   for (j = 0; (j < actual_eccsize) && (eccflag == 0); j++) {
-   if (calc_ecc[j] != 0) {
-   eccflag = 1;
-   break;
-   }
-   }
-
-   if (eccflag == 1) {
-   if (memcmp(calc_ecc, erased_ecc_vec, actual_eccsize) == 
0) {
-   /*
-* calc_ecc[] matches pattern for ECC
-* (all 0xff) so this is definitely
-* an erased-page
-*/
-   } else {
-   bitflip_count = nand_check_erased_ecc_chunk(
-   dat, oinfo->nand.ecc.size, 
read_ecc,
-   eccsize, NULL, 0, bch_max_err);
-   if (bitflip_count < 0)
-   is_error_reported = true;
-   }
+   /* check for any ecc error */
+   for (j = 0; (j < actual_eccsize) && (eccflag == 0); j++) {
+   if (calc_ecc[j] != 0) {
+   eccflag = 1;
+   break;
}
+   }
 
-   if (is_error_reported) {
-   bitflip_count = omap_gpmc_decode_bch(1,
-   calc_ecc, err_loc);
+   if (eccflag == 1) {
+   if (memcmp(calc_ecc, erased_ecc_vec, actual_eccsize) == 0) {
+   /*
+* calc_ecc[] matches pattern for ECC
+* (all 0xff) so this is definitely
+* an erased-page
+*/
+   } else {
+   bitflip_count = nand_check_erased_ecc_chunk(
+   dat, oinfo->nand.ecc.size, read_ecc,
+   eccsize, NULL, 0, bch_max_err);
if (bitflip_count < 0)
-   return bitflip_count;
-
-   for (j = 0; j < bitflip_count; j++) {
-   if (err_loc[j] < 4096)
-   dat[err_loc[j

[PATCH v2] mtd: nand: nand_omap_gpmc: Fix ecc steps

2018-05-23 Thread Teresa Remmet
The eccsteps where set wrong for OMAP_ECC_BCH8_CODE_HW_ROMCODE.
So the ECC was only corrected for the first 512 bytes chunk of a 2k page.

Moved out the ecc step iteration out of the correcting loop to make
it more alike the generic nand functions. And made sure that
the ECC is caclulated for all chunks.

This patch is based on work of Sascha Hauer.

Fixes commit dec7b4d2bf9c ("mtd: nand_omap_gpmc: fix BCH error correction").

Signed-off-by: Teresa Remmet 
---
Changes in v2:
- removed unnecessary check of eccflag
- return funtion early when no error came up

 drivers/mtd/nand/nand_omap_gpmc.c | 118 +++---
 1 file changed, 59 insertions(+), 59 deletions(-)

diff --git a/drivers/mtd/nand/nand_omap_gpmc.c 
b/drivers/mtd/nand/nand_omap_gpmc.c
index e18ce6358a73..9c9519156dcf 100644
--- a/drivers/mtd/nand/nand_omap_gpmc.c
+++ b/drivers/mtd/nand/nand_omap_gpmc.c
@@ -297,19 +297,18 @@ static int omap_correct_bch(struct mtd_info *mtd, uint8_t 
*dat,
 {
struct nand_chip *nand = (struct nand_chip *)(mtd->priv);
struct gpmc_nand_info *oinfo = (struct gpmc_nand_info *)(nand->priv);
-   int i, j, eccflag, totalcount, actual_eccsize;
+   int j, actual_eccsize;
const uint8_t *erased_ecc_vec;
unsigned int err_loc[8];
-   int bitflip_count;
int bch_max_err;
+   int bitflip_count = 0;
+   bool eccflag = 0;
+   bool is_error_reported = false;
 
-   int eccsteps = (nand->ecc.mode == NAND_ECC_HW) &&
-   (nand->ecc.size == 2048) ? 4 : 1;
int eccsize = oinfo->nand.ecc.bytes;
 
switch (oinfo->ecc_mode) {
case OMAP_ECC_BCH8_CODE_HW:
-   eccsize /= eccsteps;
actual_eccsize = eccsize;
erased_ecc_vec = bch8_vector;
bch_max_err = BCH8_MAX_ERROR;
@@ -324,58 +323,48 @@ static int omap_correct_bch(struct mtd_info *mtd, uint8_t 
*dat,
return -EINVAL;
}
 
-   totalcount = 0;
-
-   for (i = 0; i < eccsteps; i++) {
-   bool is_error_reported = false;
-   bitflip_count = 0;
-   eccflag = 0;
-
-   /* check for any ecc error */
-   for (j = 0; (j < actual_eccsize) && (eccflag == 0); j++) {
-   if (calc_ecc[j] != 0) {
-   eccflag = 1;
-   break;
-   }
-   }
-
-   if (eccflag == 1) {
-   if (memcmp(calc_ecc, erased_ecc_vec, actual_eccsize) == 
0) {
-   /*
-* calc_ecc[] matches pattern for ECC
-* (all 0xff) so this is definitely
-* an erased-page
-*/
-   } else {
-   bitflip_count = nand_check_erased_ecc_chunk(
-   dat, oinfo->nand.ecc.size, 
read_ecc,
-   eccsize, NULL, 0, bch_max_err);
-   if (bitflip_count < 0)
-   is_error_reported = true;
-   }
+   /* check for any ecc error */
+   for (j = 0; j < actual_eccsize; j++) {
+   if (calc_ecc[j] != 0) {
+   eccflag = 1;
+   break;
}
+   }
 
-   if (is_error_reported) {
-   bitflip_count = omap_gpmc_decode_bch(1,
-   calc_ecc, err_loc);
+   if (eccflag == 1) {
+   if (memcmp(calc_ecc, erased_ecc_vec, actual_eccsize) == 0) {
+   /*
+* calc_ecc[] matches pattern for ECC
+* (all 0xff) so this is definitely
+* an erased-page
+*/
+   return 0;
+   } else {
+   bitflip_count = nand_check_erased_ecc_chunk(
+   dat, oinfo->nand.ecc.size, read_ecc,
+   eccsize, NULL, 0, bch_max_err);
if (bitflip_count < 0)
-   return bitflip_count;
-
-   for (j = 0; j < bitflip_count; j++) {
-   if (err_loc[j] < 4096)
-   dat[err_loc[j] >> 3] ^=
-   1 << (err_loc[j] & 7);
-   /* else, not interested to correct ecc */
-   }
+   is_error_reported = true;
}
+   } else {
+   return 0;
+   }
 
-   totalcount += bitflip_count;
-   

[PATCH 1/2] arm: am33xx: Move function to read from Master OSC

2016-01-19 Thread Teresa Remmet
From: Daniel Schultz 

Move the function to read the Master OSC speed from
the SYSBOOT Configuration Pin for reuse.

Signed-off-by: Daniel Schultz 
Signed-off-by: Teresa Remmet 
---
 arch/arm/mach-omap/am33xx_clock.c  | 24 
 arch/arm/mach-omap/dmtimer.c   | 19 ++-
 arch/arm/mach-omap/include/mach/am33xx-clock.h |  1 +
 3 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/arch/arm/mach-omap/am33xx_clock.c 
b/arch/arm/mach-omap/am33xx_clock.c
index 6d8adde..19aeb59 100644
--- a/arch/arm/mach-omap/am33xx_clock.c
+++ b/arch/arm/mach-omap/am33xx_clock.c
@@ -318,3 +318,27 @@ void am33xx_pll_init(int mpupll_M, int osc, int ddrpll_M)
/* Enable the required peripherals */
am33xx_enable_per_clocks();
 }
+
+u64 am33xx_get_osc_clock(void)
+{
+   u64 osc;
+   u32 sysboot;
+
+   sysboot = (readl(AM33XX_CTRL_STATUS) >> 22) & 3;
+   switch (sysboot) {
+   case 0:
+   osc = 1920;
+   break;
+   case 1:
+   osc = 2400;
+   break;
+   case 2:
+   osc = 2500;
+   break;
+   case 3:
+   osc = 2600;
+   break;
+   }
+
+   return osc;
+}
diff --git a/arch/arm/mach-omap/dmtimer.c b/arch/arm/mach-omap/dmtimer.c
index 56adda0..7fd4f4d 100644
--- a/arch/arm/mach-omap/dmtimer.c
+++ b/arch/arm/mach-omap/dmtimer.c
@@ -31,6 +31,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -82,24 +83,8 @@ static struct clocksource dmtimer_cs = {
 static int dmtimer_init(void)
 {
u64 clk_speed;
-   int sysboot;
-
-   sysboot = (readl(AM33XX_CTRL_STATUS) >> 22) & 3;
-   switch (sysboot) {
-   case 0:
-   clk_speed = 1920;
-   break;
-   case 1:
-   clk_speed = 2400;
-   break;
-   case 2:
-   clk_speed = 2500;
-   break;
-   case 3:
-   clk_speed = 2600;
-   break;
-   }
 
+   clk_speed = am33xx_get_osc_clock();
dmtimer_cs.mult = clocksource_hz2mult(clk_speed, dmtimer_cs.shift);
 
/* Enable counter */
diff --git a/arch/arm/mach-omap/include/mach/am33xx-clock.h 
b/arch/arm/mach-omap/include/mach/am33xx-clock.h
index 2d6a727..a458ccd 100644
--- a/arch/arm/mach-omap/include/mach/am33xx-clock.h
+++ b/arch/arm/mach-omap/include/mach/am33xx-clock.h
@@ -185,5 +185,6 @@
 
 void am33xx_pll_init(int mpupll_M, int osc, int ddrpll_M);
 void am33xx_enable_ddr_clocks(void);
+u64 am33xx_get_osc_clock(void);
 
 #endif  /* endif _AM33XX_CLOCKS_H_ */
-- 
1.9.1


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


[PATCH 2/2] arm: am33xx: Master Osc clock speed handling

2016-01-19 Thread Teresa Remmet
From: Daniel Schultz 

Setup the plls with Master Osc. clock speed from the SYSBOOT
Configuration Pin.

Signed-off-by: Daniel Schultz 
---
 arch/arm/boards/afi-gf/lowlevel.c  |  2 +-
 arch/arm/boards/beaglebone/lowlevel.c  |  4 ++--
 arch/arm/boards/phytec-som-am335x/lowlevel.c   |  4 +---
 arch/arm/mach-omap/am33xx_clock.c  | 10 +-
 arch/arm/mach-omap/include/mach/am33xx-clock.h |  2 +-
 5 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/arch/arm/boards/afi-gf/lowlevel.c 
b/arch/arm/boards/afi-gf/lowlevel.c
index 4aaecb9..efe15ec 100644
--- a/arch/arm/boards/afi-gf/lowlevel.c
+++ b/arch/arm/boards/afi-gf/lowlevel.c
@@ -222,7 +222,7 @@ static noinline int gf_sram_init(void)
while(__raw_readl(AM33XX_WDT_REG(WWPS)) != 0x0);
 
/* Setup the PLLs and the clocks for the peripherals */
-   am33xx_pll_init(MPUPLL_M_500, 24, DDRPLL_M_200);
+   am33xx_pll_init(MPUPLL_M_500, DDRPLL_M_200);
 
board_config_ddr();
 
diff --git a/arch/arm/boards/beaglebone/lowlevel.c 
b/arch/arm/boards/beaglebone/lowlevel.c
index 05b3e5f..79d5985 100644
--- a/arch/arm/boards/beaglebone/lowlevel.c
+++ b/arch/arm/boards/beaglebone/lowlevel.c
@@ -138,11 +138,11 @@ static noinline int beaglebone_sram_init(void)
 
/* Setup the PLLs and the clocks for the peripherals */
if (is_beaglebone_black()) {
-   am33xx_pll_init(MPUPLL_M_500, 24, DDRPLL_M_400);
+   am33xx_pll_init(MPUPLL_M_500, DDRPLL_M_400);
am335x_sdram_init(0x18B, &ddr3_cmd_ctrl, &ddr3_regs,
&ddr3_data);
} else {
-   am33xx_pll_init(MPUPLL_M_500, 24, DDRPLL_M_266);
+   am33xx_pll_init(MPUPLL_M_500, DDRPLL_M_266);
am335x_sdram_init(0x18B, &ddr2_cmd_ctrl, &ddr2_regs,
&ddr2_data);
}
diff --git a/arch/arm/boards/phytec-som-am335x/lowlevel.c 
b/arch/arm/boards/phytec-som-am335x/lowlevel.c
index 64c1c53..d7afbb6 100644
--- a/arch/arm/boards/phytec-som-am335x/lowlevel.c
+++ b/arch/arm/boards/phytec-som-am335x/lowlevel.c
@@ -32,7 +32,6 @@
 
 #include "ram-timings.h"
 
-#define CLK_M_OSC_MHZ  25
 #define DDR_IOCTRL 0x18B
 
 static const struct am33xx_cmd_control physom_cmd = {
@@ -67,11 +66,10 @@ static noinline void physom_board_init(int sdram, void *fdt)
writel(WDT_DISABLE_CODE1, AM33XX_WDT_REG(WSPR));
while (readl(AM33XX_WDT_REG(WWPS)) != 0x0);
 
-
writel(WDT_DISABLE_CODE2, AM33XX_WDT_REG(WSPR));
while (readl(AM33XX_WDT_REG(WWPS)) != 0x0);
 
-   am33xx_pll_init(MPUPLL_M_600, CLK_M_OSC_MHZ, DDRPLL_M_400);
+   am33xx_pll_init(MPUPLL_M_600, DDRPLL_M_400);
 
am335x_sdram_init(DDR_IOCTRL, &physom_cmd,
&timing->regs,
diff --git a/arch/arm/mach-omap/am33xx_clock.c 
b/arch/arm/mach-omap/am33xx_clock.c
index 19aeb59..23666f2 100644
--- a/arch/arm/mach-omap/am33xx_clock.c
+++ b/arch/arm/mach-omap/am33xx_clock.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define PRCM_MOD_EN0x2
 #definePRCM_FORCE_WAKEUP   0x2
@@ -304,8 +305,15 @@ void am33xx_enable_ddr_clocks(void)
 /*
  * Configure the PLL/PRCM for necessary peripherals
  */
-void am33xx_pll_init(int mpupll_M, int osc, int ddrpll_M)
+void am33xx_pll_init(int mpupll_M, int ddrpll_M)
 {
+   int osc;
+   u64 tmp;
+
+   tmp = am33xx_get_osc_clock();
+   do_div(tmp, 100);
+   osc = tmp;
+
mpu_pll_config(mpupll_M, osc);
core_pll_config(osc);
per_pll_config(osc);
diff --git a/arch/arm/mach-omap/include/mach/am33xx-clock.h 
b/arch/arm/mach-omap/include/mach/am33xx-clock.h
index a458ccd..95a147f 100644
--- a/arch/arm/mach-omap/include/mach/am33xx-clock.h
+++ b/arch/arm/mach-omap/include/mach/am33xx-clock.h
@@ -183,7 +183,7 @@
 
 #define CM_ALWON_GPMC_CLKCTRL   CM_PER_GPMC_CLKCTRL
 
-void am33xx_pll_init(int mpupll_M, int osc, int ddrpll_M);
+void am33xx_pll_init(int mpupll_M, int ddrpll_M);
 void am33xx_enable_ddr_clocks(void);
 u64 am33xx_get_osc_clock(void);
 
-- 
1.9.1


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


[PATCH v2 1/2] arm: am33xx: Move function to read from Master OSC

2016-01-24 Thread Teresa Remmet
From: Daniel Schultz 

Move the function to read the Master OSC speed from
the SYSBOOT Configuration Pin for reuse.

Signed-off-by: Daniel Schultz 
Signed-off-by: Teresa Remmet 
---
Changes in v2:
- Return kHz instead of Hz to be able to use a 32bit type

 arch/arm/mach-omap/am33xx_clock.c  | 27 ++
 arch/arm/mach-omap/dmtimer.c   | 20 +++
 arch/arm/mach-omap/include/mach/am33xx-clock.h |  1 +
 3 files changed, 31 insertions(+), 17 deletions(-)

diff --git a/arch/arm/mach-omap/am33xx_clock.c 
b/arch/arm/mach-omap/am33xx_clock.c
index 6d8adde..3ed1d52 100644
--- a/arch/arm/mach-omap/am33xx_clock.c
+++ b/arch/arm/mach-omap/am33xx_clock.c
@@ -318,3 +318,30 @@ void am33xx_pll_init(int mpupll_M, int osc, int ddrpll_M)
/* Enable the required peripherals */
am33xx_enable_per_clocks();
 }
+
+/*
+ * Return the OSC clock value from SYSBOOT pins in kHz.
+ */
+int am33xx_get_osc_clock(void)
+{
+   int osc;
+   u32 sysboot;
+
+   sysboot = (readl(AM33XX_CTRL_STATUS) >> 22) & 3;
+   switch (sysboot) {
+   case 0:
+   osc = 19200;
+   break;
+   case 1:
+   osc = 24000;
+   break;
+   case 2:
+   osc = 25000;
+   break;
+   case 3:
+   osc = 26000;
+   break;
+   }
+
+   return osc;
+}
diff --git a/arch/arm/mach-omap/dmtimer.c b/arch/arm/mach-omap/dmtimer.c
index 56adda0..e223b8c 100644
--- a/arch/arm/mach-omap/dmtimer.c
+++ b/arch/arm/mach-omap/dmtimer.c
@@ -31,6 +31,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -82,24 +83,9 @@ static struct clocksource dmtimer_cs = {
 static int dmtimer_init(void)
 {
u64 clk_speed;
-   int sysboot;
-
-   sysboot = (readl(AM33XX_CTRL_STATUS) >> 22) & 3;
-   switch (sysboot) {
-   case 0:
-   clk_speed = 1920;
-   break;
-   case 1:
-   clk_speed = 2400;
-   break;
-   case 2:
-   clk_speed = 2500;
-   break;
-   case 3:
-   clk_speed = 2600;
-   break;
-   }
 
+   clk_speed = am33xx_get_osc_clock();
+   clk_speed *= 1000;
dmtimer_cs.mult = clocksource_hz2mult(clk_speed, dmtimer_cs.shift);
 
/* Enable counter */
diff --git a/arch/arm/mach-omap/include/mach/am33xx-clock.h 
b/arch/arm/mach-omap/include/mach/am33xx-clock.h
index 2d6a727..b9dcebd 100644
--- a/arch/arm/mach-omap/include/mach/am33xx-clock.h
+++ b/arch/arm/mach-omap/include/mach/am33xx-clock.h
@@ -185,5 +185,6 @@
 
 void am33xx_pll_init(int mpupll_M, int osc, int ddrpll_M);
 void am33xx_enable_ddr_clocks(void);
+int am33xx_get_osc_clock(void);
 
 #endif  /* endif _AM33XX_CLOCKS_H_ */
-- 
1.9.1


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


[PATCH v2 2/2] arm: am33xx: Master Osc clock speed handling

2016-01-24 Thread Teresa Remmet
From: Daniel Schultz 

Setup the plls with Master Osc. clock speed from the SYSBOOT
Configuration Pin.

Signed-off-by: Daniel Schultz 
Signed-off-by: Teresa Remmet 
---
Changes in v2:
- Updated patch as am33xx_get_osc_clock() returns now kHz

 arch/arm/boards/afi-gf/lowlevel.c  | 2 +-
 arch/arm/boards/beaglebone/lowlevel.c  | 4 ++--
 arch/arm/boards/phytec-som-am335x/lowlevel.c   | 4 +---
 arch/arm/mach-omap/am33xx_clock.c  | 8 +++-
 arch/arm/mach-omap/include/mach/am33xx-clock.h | 2 +-
 5 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/arch/arm/boards/afi-gf/lowlevel.c 
b/arch/arm/boards/afi-gf/lowlevel.c
index 4aaecb9..efe15ec 100644
--- a/arch/arm/boards/afi-gf/lowlevel.c
+++ b/arch/arm/boards/afi-gf/lowlevel.c
@@ -222,7 +222,7 @@ static noinline int gf_sram_init(void)
while(__raw_readl(AM33XX_WDT_REG(WWPS)) != 0x0);
 
/* Setup the PLLs and the clocks for the peripherals */
-   am33xx_pll_init(MPUPLL_M_500, 24, DDRPLL_M_200);
+   am33xx_pll_init(MPUPLL_M_500, DDRPLL_M_200);
 
board_config_ddr();
 
diff --git a/arch/arm/boards/beaglebone/lowlevel.c 
b/arch/arm/boards/beaglebone/lowlevel.c
index 05b3e5f..79d5985 100644
--- a/arch/arm/boards/beaglebone/lowlevel.c
+++ b/arch/arm/boards/beaglebone/lowlevel.c
@@ -138,11 +138,11 @@ static noinline int beaglebone_sram_init(void)
 
/* Setup the PLLs and the clocks for the peripherals */
if (is_beaglebone_black()) {
-   am33xx_pll_init(MPUPLL_M_500, 24, DDRPLL_M_400);
+   am33xx_pll_init(MPUPLL_M_500, DDRPLL_M_400);
am335x_sdram_init(0x18B, &ddr3_cmd_ctrl, &ddr3_regs,
&ddr3_data);
} else {
-   am33xx_pll_init(MPUPLL_M_500, 24, DDRPLL_M_266);
+   am33xx_pll_init(MPUPLL_M_500, DDRPLL_M_266);
am335x_sdram_init(0x18B, &ddr2_cmd_ctrl, &ddr2_regs,
&ddr2_data);
}
diff --git a/arch/arm/boards/phytec-som-am335x/lowlevel.c 
b/arch/arm/boards/phytec-som-am335x/lowlevel.c
index 64c1c53..d7afbb6 100644
--- a/arch/arm/boards/phytec-som-am335x/lowlevel.c
+++ b/arch/arm/boards/phytec-som-am335x/lowlevel.c
@@ -32,7 +32,6 @@
 
 #include "ram-timings.h"
 
-#define CLK_M_OSC_MHZ  25
 #define DDR_IOCTRL 0x18B
 
 static const struct am33xx_cmd_control physom_cmd = {
@@ -67,11 +66,10 @@ static noinline void physom_board_init(int sdram, void *fdt)
writel(WDT_DISABLE_CODE1, AM33XX_WDT_REG(WSPR));
while (readl(AM33XX_WDT_REG(WWPS)) != 0x0);
 
-
writel(WDT_DISABLE_CODE2, AM33XX_WDT_REG(WSPR));
while (readl(AM33XX_WDT_REG(WWPS)) != 0x0);
 
-   am33xx_pll_init(MPUPLL_M_600, CLK_M_OSC_MHZ, DDRPLL_M_400);
+   am33xx_pll_init(MPUPLL_M_600, DDRPLL_M_400);
 
am335x_sdram_init(DDR_IOCTRL, &physom_cmd,
&timing->regs,
diff --git a/arch/arm/mach-omap/am33xx_clock.c 
b/arch/arm/mach-omap/am33xx_clock.c
index 3ed1d52..ad735cb 100644
--- a/arch/arm/mach-omap/am33xx_clock.c
+++ b/arch/arm/mach-omap/am33xx_clock.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define PRCM_MOD_EN0x2
 #definePRCM_FORCE_WAKEUP   0x2
@@ -304,8 +305,13 @@ void am33xx_enable_ddr_clocks(void)
 /*
  * Configure the PLL/PRCM for necessary peripherals
  */
-void am33xx_pll_init(int mpupll_M, int osc, int ddrpll_M)
+void am33xx_pll_init(int mpupll_M, int ddrpll_M)
 {
+   int osc;
+
+   osc = am33xx_get_osc_clock();
+   osc /= 1000;
+
mpu_pll_config(mpupll_M, osc);
core_pll_config(osc);
per_pll_config(osc);
diff --git a/arch/arm/mach-omap/include/mach/am33xx-clock.h 
b/arch/arm/mach-omap/include/mach/am33xx-clock.h
index b9dcebd..284d5f8 100644
--- a/arch/arm/mach-omap/include/mach/am33xx-clock.h
+++ b/arch/arm/mach-omap/include/mach/am33xx-clock.h
@@ -183,7 +183,7 @@
 
 #define CM_ALWON_GPMC_CLKCTRL   CM_PER_GPMC_CLKCTRL
 
-void am33xx_pll_init(int mpupll_M, int osc, int ddrpll_M);
+void am33xx_pll_init(int mpupll_M, int ddrpll_M);
 void am33xx_enable_ddr_clocks(void);
 int am33xx_get_osc_clock(void);
 
-- 
1.9.1


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


[PATCH 4/7] ARM: board: phytec-som-am335x: RAM timings for phyCORE-AM335x-R2

2016-02-16 Thread Teresa Remmet
From: Arnd Beuscher 

Add RAM Timings for new phyCORE-AM335x-R2 SoM with
512MB (MT41K256M16TW107IT).

Signed-off-by: Arnd Beuscher 
Sigend-off-by: Teresa Remmet 
---
 arch/arm/boards/phytec-som-am335x/lowlevel.c|  1 +
 arch/arm/boards/phytec-som-am335x/ram-timings.h | 20 
 images/Makefile.am33xx  |  6 ++
 3 files changed, 27 insertions(+)

diff --git a/arch/arm/boards/phytec-som-am335x/lowlevel.c 
b/arch/arm/boards/phytec-som-am335x/lowlevel.c
index d7afbb6..8af450e 100644
--- a/arch/arm/boards/phytec-som-am335x/lowlevel.c
+++ b/arch/arm/boards/phytec-som-am335x/lowlevel.c
@@ -123,6 +123,7 @@ PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_256mb, 
am335x_phytec_phycore_s
 PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_512mb, 
am335x_phytec_phycore_som_mlo, PHYCORE_MT41J256M16HA15EIT_512MB);
 PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_2x512mb, 
am335x_phytec_phycore_som_mlo, PHYCORE_MT41J512M8125IT_2x512MB);
 PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_1024mb, 
am335x_phytec_phycore_som_mlo, PHYCORE_IM8G16D3FBBG15EI_1024MB);
+PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_r2_sram_512mb, 
am335x_phytec_phycore_som_mlo, PHYCORE_R2_MT41K256M16TW107IT_512MB);
 PHYTEC_ENTRY(start_am33xx_phytec_phycore_sdram, am335x_phytec_phycore_som);
 PHYTEC_ENTRY(start_am33xx_phytec_phycore_no_spi_sdram, 
am335x_phytec_phycore_som_no_spi);
 PHYTEC_ENTRY(start_am33xx_phytec_phycore_no_eeprom_sdram, 
am335x_phytec_phycore_som_no_eeprom);
diff --git a/arch/arm/boards/phytec-som-am335x/ram-timings.h 
b/arch/arm/boards/phytec-som-am335x/ram-timings.h
index 698b073..b89d561 100644
--- a/arch/arm/boards/phytec-som-am335x/ram-timings.h
+++ b/arch/arm/boards/phytec-som-am335x/ram-timings.h
@@ -30,6 +30,7 @@ enum {
PHYCORE_MT41J256M16HA15EIT_512MB,
PHYCORE_MT41J512M8125IT_2x512MB,
PHYCORE_IM8G16D3FBBG15EI_1024MB,
+   PHYCORE_R2_MT41K256M16TW107IT_512MB,
 
PHYCARD_NT5CB128M16BP_256MB,
 };
@@ -192,6 +193,25 @@ struct am335x_sdram_timings physom_timings[] = {
.dll_lock_diff0 = 0x0,
},
},
+
+   /* 512MB R2 */
+   [PHYCORE_R2_MT41K256M16TW107IT_512MB] = {
+   .regs = {
+   .emif_read_latency  = 0x7,
+   .emif_tim1  = 0x0AAAD4DB,
+   .emif_tim2  = 0x266B7FDA,
+   .emif_tim3  = 0x501F867F,
+   .sdram_config   = 0x61C05332,
+   .zq_config  = 0x50074BE4,
+   .sdram_ref_ctrl = 0x0C30,
+   },
+   .data = {
+   .rd_slave_ratio0= 0x37,
+   .wr_dqs_slave_ratio0= 0x38,
+   .fifo_we_slave_ratio0   = 0x92,
+   .wr_slave_ratio0= 0x72,
+   },
+   },
 };
 
 #endif
diff --git a/images/Makefile.am33xx b/images/Makefile.am33xx
index 375ff90..eec6fc5 100644
--- a/images/Makefile.am33xx
+++ b/images/Makefile.am33xx
@@ -59,6 +59,12 @@ FILE_barebox-am33xx-phytec-phycore-mlo-512mb.spi.img = 
start_am33xx_phytec_phyco
 am33xx-mlo-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-mlo-512mb.img
 am33xx-mlospi-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-mlo-512mb.spi.img
 
+pblx-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
start_am33xx_phytec_phycore_r2_sram_512mb
+FILE_barebox-am33xx-phytec-phycore-r2-mlo-512mb.img = 
start_am33xx_phytec_phycore_r2_sram_512mb.pblx.mlo
+FILE_barebox-am33xx-phytec-phycore-r2-mlo-512mb.spi.img = 
start_am33xx_phytec_phycore_r2_sram_512mb.pblx.mlospi
+am33xx-mlo-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-r2-mlo-512mb.img
+am33xx-mlospi-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-r2-mlo-512mb.spi.img
+
 pblx-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
start_am33xx_phytec_phycore_sram_2x512mb
 FILE_barebox-am33xx-phytec-phycore-mlo-2x512mb.img = 
start_am33xx_phytec_phycore_sram_2x512mb.pblx.mlo
 FILE_barebox-am33xx-phytec-phycore-mlo-2x512mb.spi.img = 
start_am33xx_phytec_phycore_sram_2x512mb.pblx.mlospi
-- 
1.9.1


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


[PATCH 2/7] ARM: am335x_defconfig: Enable watchdog support

2016-02-16 Thread Teresa Remmet
Enable wdt driver and command.

Signed-off-by: Teresa Remmet 
---
 arch/arm/configs/am335x_defconfig | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/arm/configs/am335x_defconfig 
b/arch/arm/configs/am335x_defconfig
index 180e016..7cf48b8 100644
--- a/arch/arm/configs/am335x_defconfig
+++ b/arch/arm/configs/am335x_defconfig
@@ -79,6 +79,7 @@ CONFIG_CMD_NANDTEST=y
 CONFIG_CMD_SPI=y
 CONFIG_CMD_LED_TRIGGER=y
 CONFIG_CMD_USBGADGET=y
+CONFIG_CMD_WD=y
 CONFIG_CMD_BAREBOX_UPDATE=y
 CONFIG_CMD_OF_NODE=y
 CONFIG_CMD_OF_PROPERTY=y
@@ -124,6 +125,8 @@ CONFIG_LED_GPIO=y
 CONFIG_LED_GPIO_OF=y
 CONFIG_LED_TRIGGERS=y
 CONFIG_EEPROM_AT24=y
+CONFIG_WATCHDOG=y
+CONFIG_WATCHDOG_OMAP=y
 CONFIG_GPIO_GENERIC_PLATFORM=y
 CONFIG_PINCTRL_SINGLE=y
 CONFIG_BUS_OMAP_GPMC=y
-- 
1.9.1


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


[PATCH 0/7] AM335x related patches

2016-02-16 Thread Teresa Remmet
Different AM335x changes containing new RAM timings and
reducing image size of all am335x boards.

Patches have been tested on PHYTEC boards and beaglebone black.

Regards
Teresa

Arnd Beuscher (1):
  ARM: board: phytec-som-am335x: RAM timings for phyCORE-AM335x-R2

Jan Remmet (1):
  ARM: dts: am335x-phytec: eeprom name

Teresa Remmet (4):
  ARM: am335x_defconfig: Enable watchdog support
  ARM: boards: phytec-som-am335x: New RAM Timings for phyCORE-AM335x-R2
  ARM: dts: beaglebone: Strip clocks in MLO device tree
  ARM: AM335x: Make use of ARM_USE_COMPRESSED_DTB

Wadim Egorov (1):
  ARM: am335x_defconfig: Enable NANDTEST command

 arch/arm/boards/afi-gf/lowlevel.c   |  6 ++--
 arch/arm/boards/beaglebone/lowlevel.c   | 12 
 arch/arm/boards/phytec-som-am335x/lowlevel.c| 10 ---
 arch/arm/boards/phytec-som-am335x/ram-timings.h | 40 +
 arch/arm/configs/am335x_defconfig   |  4 +++
 arch/arm/dts/am335x-bone-common.dts |  1 +
 arch/arm/dts/am335x-phytec-phycard-som.dtsi |  2 +-
 arch/arm/dts/am335x-phytec-phycore-som.dtsi |  2 +-
 arch/arm/mach-omap/Kconfig  |  1 +
 images/Makefile.am33xx  | 12 
 10 files changed, 75 insertions(+), 15 deletions(-)

-- 
1.9.1


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


[PATCH 7/7] ARM: AM335x: Make use of ARM_USE_COMPRESSED_DTB

2016-02-16 Thread Teresa Remmet
Use ARM_USE_COMPRESSED_DTB for all AM335x based board,
to reduce the image size even more.

Saves about 9kB in MLO image and 20kB in barebox image.

Signed-off-by: Teresa Remmet 
---
 arch/arm/boards/afi-gf/lowlevel.c|  6 +++---
 arch/arm/boards/beaglebone/lowlevel.c| 12 ++--
 arch/arm/boards/phytec-som-am335x/lowlevel.c |  8 
 arch/arm/mach-omap/Kconfig   |  1 +
 4 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/arch/arm/boards/afi-gf/lowlevel.c 
b/arch/arm/boards/afi-gf/lowlevel.c
index efe15ec..91b4b68 100644
--- a/arch/arm/boards/afi-gf/lowlevel.c
+++ b/arch/arm/boards/afi-gf/lowlevel.c
@@ -196,7 +196,7 @@ static const struct module_pin_mux board_can_pin_mux[] = {
{-1},
 };
 
-extern char __dtb_am335x_afi_gf_start[];
+extern char __dtb_z_am335x_afi_gf_start[];
 
 /**
  * @brief The basic entry point for board initialization.
@@ -211,7 +211,7 @@ static noinline int gf_sram_init(void)
 {
void *fdt;
 
-   fdt = __dtb_am335x_afi_gf_start;
+   fdt = __dtb_z_am335x_afi_gf_start;
 
/* WDT1 is already running when the bootloader gets control
 * Disable it to avoid "random" resets
@@ -258,7 +258,7 @@ ENTRY_FUNCTION(start_am33xx_afi_gf_sdram, r0, r1, r2)
 {
void *fdt;
 
-   fdt = __dtb_am335x_afi_gf_start - get_runtime_offset();
+   fdt = __dtb_z_am335x_afi_gf_start - get_runtime_offset();
 
putc_ll('>');
 
diff --git a/arch/arm/boards/beaglebone/lowlevel.c 
b/arch/arm/boards/beaglebone/lowlevel.c
index 79d5985..100f64f 100644
--- a/arch/arm/boards/beaglebone/lowlevel.c
+++ b/arch/arm/boards/beaglebone/lowlevel.c
@@ -103,9 +103,9 @@ static const struct am33xx_emif_regs ddr3_regs = {
.sdram_ref_ctrl = 0xC30,
 };
 
-extern char __dtb_am335x_boneblack_start[];
-extern char __dtb_am335x_bone_common_start[];
-extern char __dtb_am335x_bone_start[];
+extern char __dtb_z_am335x_boneblack_start[];
+extern char __dtb_z_am335x_bone_common_start[];
+extern char __dtb_z_am335x_bone_start[];
 
 /**
  * @brief The basic entry point for board initialization.
@@ -121,7 +121,7 @@ static noinline int beaglebone_sram_init(void)
uint32_t sdram_size;
void *fdt;
 
-   fdt = __dtb_am335x_bone_common_start;
+   fdt = __dtb_z_am335x_bone_common_start;
 
if (is_beaglebone_black())
sdram_size = SZ_512M;
@@ -176,10 +176,10 @@ ENTRY_FUNCTION(start_am33xx_beaglebone_sdram, r0, r1, r2)
 
if (is_beaglebone_black()) {
sdram_size = SZ_512M;
-   fdt = __dtb_am335x_boneblack_start;
+   fdt = __dtb_z_am335x_boneblack_start;
} else {
sdram_size = SZ_256M;
-   fdt = __dtb_am335x_bone_start;
+   fdt = __dtb_z_am335x_bone_start;
}
 
fdt -= get_runtime_offset();
diff --git a/arch/arm/boards/phytec-som-am335x/lowlevel.c 
b/arch/arm/boards/phytec-som-am335x/lowlevel.c
index 4240f40..73e75eb 100644
--- a/arch/arm/boards/phytec-som-am335x/lowlevel.c
+++ b/arch/arm/boards/phytec-som-am335x/lowlevel.c
@@ -102,8 +102,8 @@ static noinline void physom_board_entry(unsigned long 
bootinfo, int sdram, void
 #define PHYTEC_ENTRY_MLO(name, fdt_name, sdram)\
ENTRY_FUNCTION(name, bootinfo, r1, r2)  \
{   \
-   extern char __dtb_##fdt_name##_start[]; \
-   void *fdt =__dtb_##fdt_name##_start -   \
+   extern char __dtb_z_##fdt_name##_start[];   \
+   void *fdt = __dtb_z_##fdt_name##_start -\
get_runtime_offset();   \
physom_board_entry(bootinfo, sdram, fdt);   \
}
@@ -111,8 +111,8 @@ static noinline void physom_board_entry(unsigned long 
bootinfo, int sdram, void
 #define PHYTEC_ENTRY(name, fdt_name)   \
ENTRY_FUNCTION(name, r0, r1, r2)\
{   \
-   extern char __dtb_##fdt_name##_start[]; \
-   void *fdt =__dtb_##fdt_name##_start -   \
+   extern char __dtb_z_##fdt_name##_start[];   \
+   void *fdt = __dtb_z_##fdt_name##_start -\
get_runtime_offset();   \
am335x_barebox_entry(fdt);  \
}
diff --git a/arch/arm/mach-omap/Kconfig b/arch/arm/mach-omap/Kconfig
index 5c68062..d7c863c 100644
--- a/arch/arm/mach-omap/Kconfig
+++ b/arch/arm/mach-omap/Kconfig
@@ -44,6 +44,7 @@ config ARCH_AM33XX
select GENERIC_GPIO
select OFTREE
select OMAP_CLOCK_SOURCE_DMTIMER
+   select ARM_USE_COMPRESSED_DTB
help
  Say Y here if you are using Texas Instrument's AM33x

[PATCH 6/7] ARM: dts: beaglebone: Strip clocks in MLO device tree

2016-02-16 Thread Teresa Remmet
Reduce even more size of beaglebone MLO device tree with stripping
the clocks.

Signed-off-by: Teresa Remmet 
---
 arch/arm/dts/am335x-bone-common.dts | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/dts/am335x-bone-common.dts 
b/arch/arm/dts/am335x-bone-common.dts
index 91745d3..0488cbe 100644
--- a/arch/arm/dts/am335x-bone-common.dts
+++ b/arch/arm/dts/am335x-bone-common.dts
@@ -9,6 +9,7 @@
 
 #include "am33xx.dtsi"
 #include "am33xx-strip.dtsi"
+#include "am33xx-clocks-strip.dtsi"
 #include "am335x-bone-common.dtsi"
 
 / {
-- 
1.9.1


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


[PATCH 3/7] ARM: dts: am335x-phytec: eeprom name

2016-02-16 Thread Teresa Remmet
From: Jan Remmet 

use eeprom as name like in the kernel. This is needed if you use the
state framework.
phycard: also fix index, it has address 0x54

Signed-off-by: Jan Remmet 
---
 arch/arm/dts/am335x-phytec-phycard-som.dtsi | 2 +-
 arch/arm/dts/am335x-phytec-phycore-som.dtsi | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/dts/am335x-phytec-phycard-som.dtsi 
b/arch/arm/dts/am335x-phytec-phycard-som.dtsi
index c0b2456..d1dfa86 100644
--- a/arch/arm/dts/am335x-phytec-phycard-som.dtsi
+++ b/arch/arm/dts/am335x-phytec-phycard-som.dtsi
@@ -92,7 +92,7 @@
status = "okay";
clock-frequency = <40>;
 
-   eeprom: 24c32@52 {
+   eeprom: eeprom@54 {
status = "disabled";
compatible = "atmel,24c32";
pagesize = <32>;
diff --git a/arch/arm/dts/am335x-phytec-phycore-som.dtsi 
b/arch/arm/dts/am335x-phytec-phycore-som.dtsi
index ba0589c..f3a1d4d 100644
--- a/arch/arm/dts/am335x-phytec-phycore-som.dtsi
+++ b/arch/arm/dts/am335x-phytec-phycore-som.dtsi
@@ -143,7 +143,7 @@
status = "okay";
clock-frequency = <40>;
 
-   eeprom: 24c32@52 {
+   eeprom: eeprom@52 {
status = "disabled";
compatible = "atmel,24c32";
pagesize = <32>;
-- 
1.9.1


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


[PATCH 1/7] ARM: am335x_defconfig: Enable NANDTEST command

2016-02-16 Thread Teresa Remmet
From: Wadim Egorov 

Signed-off-by: Wadim Egorov 
---
 arch/arm/configs/am335x_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/configs/am335x_defconfig 
b/arch/arm/configs/am335x_defconfig
index 9563865..180e016 100644
--- a/arch/arm/configs/am335x_defconfig
+++ b/arch/arm/configs/am335x_defconfig
@@ -75,6 +75,7 @@ CONFIG_CMD_FLASH=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_I2C=y
 CONFIG_CMD_LED=y
+CONFIG_CMD_NANDTEST=y
 CONFIG_CMD_SPI=y
 CONFIG_CMD_LED_TRIGGER=y
 CONFIG_CMD_USBGADGET=y
-- 
1.9.1


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


[PATCH 5/7] ARM: boards: phytec-som-am335x: New RAM Timings for phyCORE-AM335x-R2

2016-02-16 Thread Teresa Remmet
Add RAM timings for phyCORE-AM335x-R2 256MB RAM.

Signed-off-by: Teresa Remmet 
---
 arch/arm/boards/phytec-som-am335x/lowlevel.c|  1 +
 arch/arm/boards/phytec-som-am335x/ram-timings.h | 20 
 images/Makefile.am33xx  |  6 ++
 3 files changed, 27 insertions(+)

diff --git a/arch/arm/boards/phytec-som-am335x/lowlevel.c 
b/arch/arm/boards/phytec-som-am335x/lowlevel.c
index 8af450e..4240f40 100644
--- a/arch/arm/boards/phytec-som-am335x/lowlevel.c
+++ b/arch/arm/boards/phytec-som-am335x/lowlevel.c
@@ -124,6 +124,7 @@ PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_512mb, 
am335x_phytec_phycore_s
 PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_2x512mb, 
am335x_phytec_phycore_som_mlo, PHYCORE_MT41J512M8125IT_2x512MB);
 PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_1024mb, 
am335x_phytec_phycore_som_mlo, PHYCORE_IM8G16D3FBBG15EI_1024MB);
 PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_r2_sram_512mb, 
am335x_phytec_phycore_som_mlo, PHYCORE_R2_MT41K256M16TW107IT_512MB);
+PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_r2_sram_256mb, 
am335x_phytec_phycore_som_mlo, PHYCORE_R2_MT41K128M16JT_256MB);
 PHYTEC_ENTRY(start_am33xx_phytec_phycore_sdram, am335x_phytec_phycore_som);
 PHYTEC_ENTRY(start_am33xx_phytec_phycore_no_spi_sdram, 
am335x_phytec_phycore_som_no_spi);
 PHYTEC_ENTRY(start_am33xx_phytec_phycore_no_eeprom_sdram, 
am335x_phytec_phycore_som_no_eeprom);
diff --git a/arch/arm/boards/phytec-som-am335x/ram-timings.h 
b/arch/arm/boards/phytec-som-am335x/ram-timings.h
index b89d561..884874c 100644
--- a/arch/arm/boards/phytec-som-am335x/ram-timings.h
+++ b/arch/arm/boards/phytec-som-am335x/ram-timings.h
@@ -31,6 +31,7 @@ enum {
PHYCORE_MT41J512M8125IT_2x512MB,
PHYCORE_IM8G16D3FBBG15EI_1024MB,
PHYCORE_R2_MT41K256M16TW107IT_512MB,
+   PHYCORE_R2_MT41K128M16JT_256MB,
 
PHYCARD_NT5CB128M16BP_256MB,
 };
@@ -212,6 +213,25 @@ struct am335x_sdram_timings physom_timings[] = {
.wr_slave_ratio0= 0x72,
},
},
+
+   /* 256MB R2 */
+   [PHYCORE_R2_MT41K128M16JT_256MB] = {
+   .regs = {
+   .emif_read_latency  = 0x7,
+   .emif_tim1  = 0x0AAAD4DB,
+   .emif_tim2  = 0x26437FDA,
+   .emif_tim3  = 0x501F83FF,
+   .sdram_config   = 0x61C052B2,
+   .zq_config  = 0x50074BE4,
+   .sdram_ref_ctrl = 0x0C30,
+   },
+   .data = {
+   .rd_slave_ratio0= 0x36,
+   .wr_dqs_slave_ratio0= 0x38,
+   .fifo_we_slave_ratio0   = 0x99,
+   .wr_slave_ratio0= 0x73,
+   },
+   },
 };
 
 #endif
diff --git a/images/Makefile.am33xx b/images/Makefile.am33xx
index eec6fc5..6c7e81a 100644
--- a/images/Makefile.am33xx
+++ b/images/Makefile.am33xx
@@ -47,6 +47,12 @@ FILE_barebox-am33xx-phytec-phycore-mlo-256mb.spi.img = 
start_am33xx_phytec_phyco
 am33xx-mlo-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-mlo-256mb.img
 am33xx-mlospi-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-mlo-256mb.spi.img
 
+pblx-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
start_am33xx_phytec_phycore_r2_sram_256mb
+FILE_barebox-am33xx-phytec-phycore-r2-mlo-256mb.img = 
start_am33xx_phytec_phycore_r2_sram_256mb.pblx.mlo
+FILE_barebox-am33xx-phytec-phycore-r2-mlo-256mb.spi.img = 
start_am33xx_phytec_phycore_r2_sram_256mb.pblx.mlospi
+am33xx-mlo-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-r2-mlo-256mb.img
+am33xx-mlospi-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-r2-mlo-256mb.spi.img
+
 pblx-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += start_am33xx_phytec_phycore_sram_128mb
 FILE_barebox-am33xx-phytec-phycore-mlo-128mb.img = 
start_am33xx_phytec_phycore_sram_128mb.pblx.mlo
 FILE_barebox-am33xx-phytec-phycore-mlo-128mb.spi.img = 
start_am33xx_phytec_phycore_sram_128mb.pblx.mlospi
-- 
1.9.1


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


[PATCH 2/2] ARM: am335x_defconfig: Enable the of_fixup_status command

2016-02-16 Thread Teresa Remmet
Signed-off-by: Teresa Remmet 
---
 arch/arm/configs/am335x_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/configs/am335x_defconfig 
b/arch/arm/configs/am335x_defconfig
index 7cf48b8..9196fb8 100644
--- a/arch/arm/configs/am335x_defconfig
+++ b/arch/arm/configs/am335x_defconfig
@@ -84,6 +84,7 @@ CONFIG_CMD_BAREBOX_UPDATE=y
 CONFIG_CMD_OF_NODE=y
 CONFIG_CMD_OF_PROPERTY=y
 CONFIG_CMD_OF_DISPLAY_TIMINGS=y
+CONFIG_CMD_OF_FIXUP_STATUS=y
 CONFIG_CMD_OFTREE=y
 CONFIG_CMD_TIME=y
 CONFIG_NET=y
-- 
1.9.1


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


[PATCH 1/2] commands: Add of_fixup_status

2016-02-16 Thread Teresa Remmet
of_fixup_status enables or disables the status property of a
given node with a device tree fixup.

Signed-off-by: Teresa Remmet 
---
 commands/Kconfig   |  16 +++
 commands/Makefile  |   1 +
 commands/of_fixup_status.c | 101 +
 3 files changed, 118 insertions(+)
 create mode 100644 commands/of_fixup_status.c

diff --git a/commands/Kconfig b/commands/Kconfig
index b4fdc86..9519a44 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -2114,6 +2114,22 @@ config CMD_OF_DISPLAY_TIMINGS
  -s path   select display-timings and register oftree fixup
  -f dtbwork on dtb. Has no effect on -s option
 
+config CMD_OF_FIXUP_STATUS
+   tristate
+   select OFTREE
+   prompt "of_fixup_status"
+   help
+ Register a fixup to enable or disable node
+
+ Usage: of_fixup_node [-d] path
+
+ Options:
+ -ddisable node
+ path  Node path or alias
+
+ Register a fixup to enable or disable a device tree node.
+ Nodes are enabled on default. Disabled with -d.
+
 config CMD_OFTREE
tristate
select OFTREE
diff --git a/commands/Makefile b/commands/Makefile
index d985341..8975d4b 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -78,6 +78,7 @@ obj-$(CONFIG_CMD_OF_PROPERTY) += of_property.o
 obj-$(CONFIG_CMD_OF_NODE)  += of_node.o
 obj-$(CONFIG_CMD_OF_DUMP)  += of_dump.o
 obj-$(CONFIG_CMD_OF_DISPLAY_TIMINGS)   += of_display_timings.o
+obj-$(CONFIG_CMD_OF_FIXUP_STATUS)  += of_fixup_status.o
 obj-$(CONFIG_CMD_MAGICVAR) += magicvar.o
 obj-$(CONFIG_CMD_IOMEM)+= iomemport.o
 obj-$(CONFIG_CMD_LINUX_EXEC)   += linux_exec.o
diff --git a/commands/of_fixup_status.c b/commands/of_fixup_status.c
new file mode 100644
index 000..03494cc
--- /dev/null
+++ b/commands/of_fixup_status.c
@@ -0,0 +1,101 @@
+/*
+ * of_fixup_status.c - Register a fixup to enable or disable nodes in the
+ * device tree
+ *
+ * Copyright (c) 2014-2016 PHYTEC Messtechnik GmbH
+ * Author:
+ *     Teresa Remmet
+ * Wadim Egorov
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct fixup_status_data {
+   char *node;
+   bool status;
+};
+
+static int of_fixup_status(struct device_node *root, void *context)
+{
+   struct fixup_status_data *data = context;
+   struct device_node *node;
+
+   node = of_find_node_by_path_from(root, data->node);
+   if (!node) {
+   pr_err("Could not find node in tree: %s\n", data->node);
+   return -EINVAL;
+   }
+
+   if (data->status)
+   return of_device_enable(node);
+   else
+   return of_device_disable(node);
+}
+
+static int do_of_fixup_status(int argc, char *argv[])
+{
+   int opt;
+   bool status = 1;
+   char *node = NULL;
+   struct fixup_status_data *data;
+
+   while ((opt = getopt(argc, argv, "d")) > 0) {
+   switch (opt) {
+   case 'd':
+   status = 0;
+   break;
+   default:
+   return COMMAND_ERROR_USAGE;
+   }
+   }
+
+   if (optind == argc)
+   return COMMAND_ERROR_USAGE;
+
+   node = xstrdup(argv[optind]);
+
+   data = xzalloc(sizeof(*data));
+   data->node = node;
+   data->status = status;
+
+   of_register_fixup(of_fixup_status, (void *)data);
+
+   return 0;
+}
+
+BAREBOX_CMD_HELP_START(of_fixup_status)
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT("-d",  "disable node")
+BAREBOX_CMD_HELP_OPT("path",  "Node path\n")
+BAREBOX_CMD_HELP_TEXT("Register a fixup to enable or disable a device tree 
node.")
+BAREBOX_CMD_HELP_TEXT("Nodes are enabled on default. Disabled with -d.")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(of_fixup_status)
+   .cmd= do_of_fixup_status,
+   BAREBOX_CMD_DESC("register a fixup to enable or disable node")
+   BAREBOX_CMD_OPTS("[-d] path")
+   BAREBOX_CMD_GROUP(CMD_GRP_MISC)
+   BAREBOX_CMD_COMPLETE(devicetree_file_complete)
+   BAREBOX_CMD_HELP(cmd_of_fixup_status_help)
+BAREBOX_CMD_END
-- 
1.9.1


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


[PATCH v2 3/3] ARM: am335x_defconfig: Enable the of_fixup_status command

2016-02-24 Thread Teresa Remmet
Signed-off-by: Teresa Remmet 
---
 arch/arm/configs/am335x_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/configs/am335x_defconfig 
b/arch/arm/configs/am335x_defconfig
index 7cf48b8..9196fb8 100644
--- a/arch/arm/configs/am335x_defconfig
+++ b/arch/arm/configs/am335x_defconfig
@@ -84,6 +84,7 @@ CONFIG_CMD_BAREBOX_UPDATE=y
 CONFIG_CMD_OF_NODE=y
 CONFIG_CMD_OF_PROPERTY=y
 CONFIG_CMD_OF_DISPLAY_TIMINGS=y
+CONFIG_CMD_OF_FIXUP_STATUS=y
 CONFIG_CMD_OFTREE=y
 CONFIG_CMD_TIME=y
 CONFIG_NET=y
-- 
1.9.1


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


[PATCH v2 1/3] common: oftree: Add fuction to register set status fixup

2016-02-24 Thread Teresa Remmet
Added a function to register a fixup to enable or disable
device tree nodes.

Signed-off-by: Teresa Remmet 
---
 common/oftree.c | 36 
 include/of.h|  1 +
 2 files changed, 37 insertions(+)

diff --git a/common/oftree.c b/common/oftree.c
index d408f14..3103bb1 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -139,6 +139,42 @@ static int of_register_bootargs_fixup(void)
 }
 late_initcall(of_register_bootargs_fixup);
 
+struct of_fixup_status_data {
+   char *node;
+   bool status;
+};
+
+static int of_fixup_status(struct device_node *root, void *context)
+{
+   struct of_fixup_status_data *data = context;
+   struct device_node *node;
+
+   node = of_find_node_by_path_or_alias(root, data->node);
+   if (!node)
+   return -ENODEV;
+
+   if (data->status)
+   return of_device_enable(node);
+   else
+   return of_device_disable(node);
+}
+
+/**
+ * of_register_set_status_fixup - register fix up to set status of nodes
+ * Register a fixup to enable or disable a node in the devicet tree by
+ * passing the path or alias.
+ */
+int of_register_set_status_fixup(char *node, bool status)
+{
+   struct of_fixup_status_data *data;
+
+   data = xzalloc(sizeof(*data));
+   data->node = node;
+   data->status = status;
+
+   return of_register_fixup(of_fixup_status, (void *)data);
+}
+
 struct of_fixup {
int (*fixup)(struct device_node *, void *);
void *context;
diff --git a/include/of.h b/include/of.h
index 75cc3c1..ae65409 100644
--- a/include/of.h
+++ b/include/of.h
@@ -249,6 +249,7 @@ int of_find_path(struct device_node *node, const char 
*propname, char **outpath,
 int of_find_path_by_node(struct device_node *node, char **outpath, unsigned 
flags);
 int of_register_fixup(int (*fixup)(struct device_node *, void *), void 
*context);
 int of_unregister_fixup(int (*fixup)(struct device_node *, void *), void 
*context);
+int of_register_set_status_fixup(char *node, bool status);
 struct device_node *of_find_node_by_alias(struct device_node *root,
const char *alias);
 struct device_node *of_find_node_by_path_or_alias(struct device_node *root,
-- 
1.9.1


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


[PATCH v2 2/3] commands: Add of_fixup_status

2016-02-24 Thread Teresa Remmet
of_fixup_status enables or disables the status property of a
given node with a device tree fixup.

Signed-off-by: Teresa Remmet 
---
 commands/Kconfig   | 16 ++
 commands/Makefile  |  1 +
 commands/of_fixup_status.c | 74 ++
 3 files changed, 91 insertions(+)
 create mode 100644 commands/of_fixup_status.c

diff --git a/commands/Kconfig b/commands/Kconfig
index b4fdc86..9519a44 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -2114,6 +2114,22 @@ config CMD_OF_DISPLAY_TIMINGS
  -s path   select display-timings and register oftree fixup
  -f dtbwork on dtb. Has no effect on -s option
 
+config CMD_OF_FIXUP_STATUS
+   tristate
+   select OFTREE
+   prompt "of_fixup_status"
+   help
+ Register a fixup to enable or disable node
+
+ Usage: of_fixup_node [-d] path
+
+ Options:
+ -ddisable node
+ path  Node path or alias
+
+ Register a fixup to enable or disable a device tree node.
+ Nodes are enabled on default. Disabled with -d.
+
 config CMD_OFTREE
tristate
select OFTREE
diff --git a/commands/Makefile b/commands/Makefile
index d985341..8975d4b 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -78,6 +78,7 @@ obj-$(CONFIG_CMD_OF_PROPERTY) += of_property.o
 obj-$(CONFIG_CMD_OF_NODE)  += of_node.o
 obj-$(CONFIG_CMD_OF_DUMP)  += of_dump.o
 obj-$(CONFIG_CMD_OF_DISPLAY_TIMINGS)   += of_display_timings.o
+obj-$(CONFIG_CMD_OF_FIXUP_STATUS)  += of_fixup_status.o
 obj-$(CONFIG_CMD_MAGICVAR) += magicvar.o
 obj-$(CONFIG_CMD_IOMEM)+= iomemport.o
 obj-$(CONFIG_CMD_LINUX_EXEC)   += linux_exec.o
diff --git a/commands/of_fixup_status.c b/commands/of_fixup_status.c
new file mode 100644
index 000..9a4a619
--- /dev/null
+++ b/commands/of_fixup_status.c
@@ -0,0 +1,74 @@
+/*
+ * of_fixup_status.c - Register a fixup to enable or disable nodes in the
+ * device tree
+ *
+ * Copyright (c) 2014-2016 PHYTEC Messtechnik GmbH
+ * Author:
+ *     Teresa Remmet
+ * Wadim Egorov
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int do_of_fixup_status(int argc, char *argv[])
+{
+   int opt;
+   bool status = 1;
+   char *node = NULL;
+
+   while ((opt = getopt(argc, argv, "d")) > 0) {
+   switch (opt) {
+   case 'd':
+   status = 0;
+   break;
+   default:
+   return COMMAND_ERROR_USAGE;
+   }
+   }
+
+   if (optind == argc)
+   return COMMAND_ERROR_USAGE;
+
+   node = xstrdup(argv[optind]);
+
+   of_register_set_status_fixup(node, status);
+
+   return 0;
+}
+
+BAREBOX_CMD_HELP_START(of_fixup_status)
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT("-d",  "disable node")
+BAREBOX_CMD_HELP_OPT("path",  "Node path\n")
+BAREBOX_CMD_HELP_TEXT("Register a fixup to enable or disable a device tree 
node.")
+BAREBOX_CMD_HELP_TEXT("Nodes are enabled on default. Disabled with -d.")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(of_fixup_status)
+   .cmd= do_of_fixup_status,
+   BAREBOX_CMD_DESC("register a fixup to enable or disable node")
+   BAREBOX_CMD_OPTS("[-d] path")
+   BAREBOX_CMD_GROUP(CMD_GRP_MISC)
+   BAREBOX_CMD_COMPLETE(devicetree_file_complete)
+   BAREBOX_CMD_HELP(cmd_of_fixup_status_help)
+BAREBOX_CMD_END
-- 
1.9.1


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


Re: [PATCH v2 1/3] common: oftree: Add fuction to register set status fixup

2016-02-25 Thread Teresa Remmet
Hello Trent,

Am Donnerstag, den 25.02.2016, 18:18 + schrieb Trent Piepho:
> On Thu, 2016-02-25 at 08:36 +0100, Teresa Remmet wrote:
> 
> >  
> > +struct of_fixup_status_data {
> > +   char *node;
> 
> const char *node.
> 
> I think path would be a better name, as node usually is a device_node
> pointer, not a path.

I named it node as it could also be an alias and not only a path.
But I don't might to rename it.

I'll send a fixup, also for the rest.

Regards,
Teresa

> 
> > +   bool status;
> > +};
> > +
> > +static int of_fixup_status(struct device_node *root, void *context)
> > +{
> > +   struct of_fixup_status_data *data = context;
> 
> const struct of_fixup_status_data *data
> 
> > +   struct device_node *node;
> > +
> > +   node = of_find_node_by_path_or_alias(root, data->node);
> > +   if (!node)
> > +   return -ENODEV;
> > +
> > +   if (data->status)
> > +   return of_device_enable(node);
> > +   else
> > +   return of_device_disable(node);
> > +}
> > +
> > +/**
> > + * of_register_set_status_fixup - register fix up to set status of nodes
> > + * Register a fixup to enable or disable a node in the devicet tree by
> > + * passing the path or alias.
> > + */
> > +int of_register_set_status_fixup(char *node, bool status)
> 
> (const char *path, bool status)
> 
> > +{
> > +   struct of_fixup_status_data *data;
> > +
> > +   data = xzalloc(sizeof(*data));
> > +   data->node = node;
> > +   data->status = status;
> > +
> > +   return of_register_fixup(of_fixup_status, (void *)data);
> > +}



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


[PATCH for next] fixup! common: oftree: Add fuction to register set status fixup

2016-02-26 Thread Teresa Remmet
Signed-off-by: Teresa Remmet 
---
 common/oftree.c | 10 +-
 include/of.h|  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/common/oftree.c b/common/oftree.c
index 3103bb1..e98b908 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -140,16 +140,16 @@ static int of_register_bootargs_fixup(void)
 late_initcall(of_register_bootargs_fixup);
 
 struct of_fixup_status_data {
-   char *node;
+   const char *path;
bool status;
 };
 
 static int of_fixup_status(struct device_node *root, void *context)
 {
-   struct of_fixup_status_data *data = context;
+   const struct of_fixup_status_data *data = context;
struct device_node *node;
 
-   node = of_find_node_by_path_or_alias(root, data->node);
+   node = of_find_node_by_path_or_alias(root, data->path);
if (!node)
return -ENODEV;
 
@@ -164,12 +164,12 @@ static int of_fixup_status(struct device_node *root, void 
*context)
  * Register a fixup to enable or disable a node in the devicet tree by
  * passing the path or alias.
  */
-int of_register_set_status_fixup(char *node, bool status)
+int of_register_set_status_fixup(const char *path, bool status)
 {
struct of_fixup_status_data *data;
 
data = xzalloc(sizeof(*data));
-   data->node = node;
+   data->path = path;
data->status = status;
 
return of_register_fixup(of_fixup_status, (void *)data);
diff --git a/include/of.h b/include/of.h
index ae65409..8c8f57a 100644
--- a/include/of.h
+++ b/include/of.h
@@ -249,7 +249,7 @@ int of_find_path(struct device_node *node, const char 
*propname, char **outpath,
 int of_find_path_by_node(struct device_node *node, char **outpath, unsigned 
flags);
 int of_register_fixup(int (*fixup)(struct device_node *, void *), void 
*context);
 int of_unregister_fixup(int (*fixup)(struct device_node *, void *), void 
*context);
-int of_register_set_status_fixup(char *node, bool status);
+int of_register_set_status_fixup(const char *node, bool status);
 struct device_node *of_find_node_by_alias(struct device_node *root,
const char *alias);
 struct device_node *of_find_node_by_path_or_alias(struct device_node *root,
-- 
1.9.1


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


[PATCH 2/2] mtd: nand: omap_gpmc: Fix bitflips in empty page

2016-04-11 Thread Teresa Remmet
When using BCH8 decoding, bitflips in an empty page are
not checked. This can cause issues if UBI/UBIFS are used.
Extend the omap_correct_bch() function to check for them.

Code is based on linux mainline mtd/nand/omap2.c driver.

Signed-off-by: Teresa Remmet 
---
 drivers/mtd/nand/nand_omap_gpmc.c | 62 ++-
 1 file changed, 42 insertions(+), 20 deletions(-)

diff --git a/drivers/mtd/nand/nand_omap_gpmc.c 
b/drivers/mtd/nand/nand_omap_gpmc.c
index 1d1de5b..a4e6452 100644
--- a/drivers/mtd/nand/nand_omap_gpmc.c
+++ b/drivers/mtd/nand/nand_omap_gpmc.c
@@ -87,6 +87,9 @@
 
 #define BCH8_MAX_ERROR 8   /* upto 8 bit correctable */
 
+static const uint8_t bch8_vector[] = {0xf3, 0xdb, 0x14, 0x16, 0x8b, 0xd2,
+   0xbe, 0xcc, 0xac, 0x6b, 0xff, 0x99, 0x7b};
+
 int omap_gpmc_decode_bch(int select_4_8, unsigned char *ecc, unsigned int 
*err_loc);
 
 static const char *ecc_mode_strings[] = {
@@ -294,8 +297,11 @@ static int omap_correct_bch(struct mtd_info *mtd, uint8_t 
*dat,
 {
struct nand_chip *nand = (struct nand_chip *)(mtd->priv);
struct gpmc_nand_info *oinfo = (struct gpmc_nand_info *)(nand->priv);
-   int i, j, eccflag, count, totalcount, actual_eccsize;
+   int i, j, eccflag, totalcount, actual_eccsize;
+   const uint8_t *erased_ecc_vec;
unsigned int err_loc[8];
+   int bitflip_count;
+   int bch_max_err;
 
int eccsteps = oinfo->nand.ecc.steps;
int eccsize = oinfo->nand.ecc.bytes;
@@ -304,9 +310,13 @@ static int omap_correct_bch(struct mtd_info *mtd, uint8_t 
*dat,
case OMAP_ECC_BCH8_CODE_HW:
eccsize /= eccsteps;
actual_eccsize = eccsize;
+   erased_ecc_vec = bch8_vector;
+   bch_max_err = BCH8_MAX_ERROR;
break;
case OMAP_ECC_BCH8_CODE_HW_ROMCODE:
actual_eccsize = eccsize - 1;
+   erased_ecc_vec = bch8_vector;
+   bch_max_err = BCH8_MAX_ERROR;
break;
default:
dev_err(oinfo->pdev, "invalid driver configuration\n");
@@ -316,37 +326,49 @@ static int omap_correct_bch(struct mtd_info *mtd, uint8_t 
*dat,
totalcount = 0;
 
for (i = 0; i < eccsteps; i++) {
-   /* check if any ecc error */
+   bool is_error_reported = false;
+   bitflip_count = 0;
eccflag = 0;
+
+   /* check for any ecc error */
for (j = 0; (j < actual_eccsize) && (eccflag == 0); j++) {
-   if (calc_ecc[j] != 0)
+   if (calc_ecc[j] != 0) {
eccflag = 1;
+   break;
+   }
}
 
if (eccflag == 1) {
-   eccflag = 0;
-   for (j = 0; (j < actual_eccsize) &&
-   (eccflag == 0); j++)
-   if (read_ecc[j] != 0xFF)
-   eccflag = 1;
+   if (memcmp(calc_ecc, erased_ecc_vec, actual_eccsize) == 
0) {
+   /*
+* calc_ecc[] matches pattern for ECC
+* (all 0xff) so this is definitely
+* an erased-page
+*/
+   } else {
+   bitflip_count = nand_check_erased_ecc_chunk(
+   dat, oinfo->nand.ecc.size, 
read_ecc,
+   eccsize, NULL, 0, bch_max_err);
+   if (bitflip_count < 0)
+   is_error_reported = true;
+   }
}
 
-   count = 0;
-   if (eccflag == 1) {
-   count = omap_gpmc_decode_bch(1, calc_ecc, err_loc);
-   if (count < 0)
-   return count;
-   else
-   totalcount += count;
-   }
+   if (is_error_reported) {
+   bitflip_count = omap_gpmc_decode_bch(1,
+   calc_ecc, err_loc);
+   if (bitflip_count < 0)
+   return bitflip_count;
 
-   for (j = 0; j < count; j++) {
-   if (err_loc[j] < 4096)
-   dat[err_loc[j] >> 3] ^=
+   for (j = 0; j < bitflip_count; j++) {
+   if (err_loc[j] < 4096)
+   dat[err_loc[j] >> 3] ^=
1 << (err_loc[j] & 7);
-   /* else, not int

[PATCH 1/2] mtd: nand: omap_gpmc: Remove BCH4 support

2016-04-11 Thread Teresa Remmet
This has no users and seems to be untested. Removed it.

Signed-off-by: Teresa Remmet 
---
 arch/arm/mach-omap/include/mach/gpmc_nand.h |  1 -
 drivers/bus/omap-gpmc.c |  3 ---
 drivers/mtd/nand/nand_omap_gpmc.c   | 36 +
 3 files changed, 1 insertion(+), 39 deletions(-)

diff --git a/arch/arm/mach-omap/include/mach/gpmc_nand.h 
b/arch/arm/mach-omap/include/mach/gpmc_nand.h
index 8839486..c9730a9 100644
--- a/arch/arm/mach-omap/include/mach/gpmc_nand.h
+++ b/arch/arm/mach-omap/include/mach/gpmc_nand.h
@@ -32,7 +32,6 @@
 enum gpmc_ecc_mode {
OMAP_ECC_SOFT,
OMAP_ECC_HAMMING_CODE_HW_ROMCODE,
-   OMAP_ECC_BCH4_CODE_HW,
OMAP_ECC_BCH8_CODE_HW,
OMAP_ECC_BCH8_CODE_HW_ROMCODE,
 };
diff --git a/drivers/bus/omap-gpmc.c b/drivers/bus/omap-gpmc.c
index 8ae909a..be9ef92 100644
--- a/drivers/bus/omap-gpmc.c
+++ b/drivers/bus/omap-gpmc.c
@@ -446,9 +446,6 @@ static struct dt_eccmode modes[] = {
.name = "hw-romcode",
.mode = OMAP_ECC_HAMMING_CODE_HW_ROMCODE,
}, {
-   .name = "bch4",
-   .mode = OMAP_ECC_BCH4_CODE_HW,
-   }, {
.name = "bch8",
.mode = OMAP_ECC_BCH8_CODE_HW_ROMCODE,
},
diff --git a/drivers/mtd/nand/nand_omap_gpmc.c 
b/drivers/mtd/nand/nand_omap_gpmc.c
index a920522..1d1de5b 100644
--- a/drivers/mtd/nand/nand_omap_gpmc.c
+++ b/drivers/mtd/nand/nand_omap_gpmc.c
@@ -86,7 +86,6 @@
 #define GPMC_ECC_SIZE_CONFIG_ECCSIZE1(x)   ((x) << 22)
 
 #define BCH8_MAX_ERROR 8   /* upto 8 bit correctable */
-#define BCH4_MAX_ERROR 4   /* upto 4 bit correctable */
 
 int omap_gpmc_decode_bch(int select_4_8, unsigned char *ecc, unsigned int 
*err_loc);
 
@@ -239,9 +238,6 @@ static int __omap_calculate_ecc(struct mtd_info *mtd, const 
uint8_t *dat,
int ecc_size = 8;
 
switch (oinfo->ecc_mode) {
-   case OMAP_ECC_BCH4_CODE_HW:
-   ecc_size = 4;
-   /* fall through */
case OMAP_ECC_BCH8_CODE_HW:
case OMAP_ECC_BCH8_CODE_HW_ROMCODE:
for (i = 0; i < 4; i++) {
@@ -300,24 +296,17 @@ static int omap_correct_bch(struct mtd_info *mtd, uint8_t 
*dat,
struct gpmc_nand_info *oinfo = (struct gpmc_nand_info *)(nand->priv);
int i, j, eccflag, count, totalcount, actual_eccsize;
unsigned int err_loc[8];
-   int select_4_8;
 
int eccsteps = oinfo->nand.ecc.steps;
int eccsize = oinfo->nand.ecc.bytes;
 
switch (oinfo->ecc_mode) {
-   case OMAP_ECC_BCH4_CODE_HW:
-   actual_eccsize = eccsize;
-   select_4_8 = 0;
-   break;
case OMAP_ECC_BCH8_CODE_HW:
eccsize /= eccsteps;
actual_eccsize = eccsize;
-   select_4_8 = 1;
break;
case OMAP_ECC_BCH8_CODE_HW_ROMCODE:
actual_eccsize = eccsize - 1;
-   select_4_8 = 1;
break;
default:
dev_err(oinfo->pdev, "invalid driver configuration\n");
@@ -344,7 +333,7 @@ static int omap_correct_bch(struct mtd_info *mtd, uint8_t 
*dat,
 
count = 0;
if (eccflag == 1) {
-   count = omap_gpmc_decode_bch(select_4_8, calc_ecc, 
err_loc);
+   count = omap_gpmc_decode_bch(1, calc_ecc, err_loc);
if (count < 0)
return count;
else
@@ -435,7 +424,6 @@ static int omap_correct_data(struct mtd_info *mtd, uint8_t 
*dat,
switch (oinfo->ecc_mode) {
case OMAP_ECC_HAMMING_CODE_HW_ROMCODE:
return omap_correct_hamming(mtd, dat, read_ecc, calc_ecc);
-   case OMAP_ECC_BCH4_CODE_HW:
case OMAP_ECC_BCH8_CODE_HW:
case OMAP_ECC_BCH8_CODE_HW_ROMCODE:
/*
@@ -463,17 +451,6 @@ static void omap_enable_hwecc(struct mtd_info *mtd, int 
mode)
int cs = 0;
 
switch (oinfo->ecc_mode) {
-   case OMAP_ECC_BCH4_CODE_HW:
-   if (mode == NAND_ECC_READ) {
-   eccsize1 = 0xD; eccsize0 = 0x48;
-   bch_mod = 0;
-   bch_wrapmode = 0x09;
-   } else {
-   eccsize1 = 0x20; eccsize0 = 0x00;
-   bch_mod = 0;
-   bch_wrapmode = 0x06;
-   }
-   break;
case OMAP_ECC_BCH8_CODE_HW:
case OMAP_ECC_BCH8_CODE_HW_ROMCODE:
if (mode == NAND_ECC_READ) {
@@ -764,17 +741,6 @@ static int omap_gpmc_eccmode(struct gpmc_nand_info *oinfo,
omap_oobinfo.oobfree->length = minfo->oobsize -
offset - omap_oobinfo.eccbytes;
break;
-   case OMAP_ECC_BCH4_CODE_HW:
-   oinfo->nand.ec

[PATCH] ARM: board: phytec-som-am335x: RAM timings for phycore-r2 1GB

2016-04-18 Thread Teresa Remmet
Add new RAM Timings for phyCORE R2 with MT41K512M16HA-125IT
1024MB mounted.

Signed-off-by: Teresa Remmet 
---
 arch/arm/boards/phytec-som-am335x/lowlevel.c|  1 +
 arch/arm/boards/phytec-som-am335x/ram-timings.h | 20 
 images/Makefile.am33xx  |  6 ++
 3 files changed, 27 insertions(+)

diff --git a/arch/arm/boards/phytec-som-am335x/lowlevel.c 
b/arch/arm/boards/phytec-som-am335x/lowlevel.c
index 73e75eb..33e83c5 100644
--- a/arch/arm/boards/phytec-som-am335x/lowlevel.c
+++ b/arch/arm/boards/phytec-som-am335x/lowlevel.c
@@ -125,6 +125,7 @@ PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_2x512mb, 
am335x_phytec_phycore
 PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_1024mb, 
am335x_phytec_phycore_som_mlo, PHYCORE_IM8G16D3FBBG15EI_1024MB);
 PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_r2_sram_512mb, 
am335x_phytec_phycore_som_mlo, PHYCORE_R2_MT41K256M16TW107IT_512MB);
 PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_r2_sram_256mb, 
am335x_phytec_phycore_som_mlo, PHYCORE_R2_MT41K128M16JT_256MB);
+PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_r2_sram_1024mb,  
am335x_phytec_phycore_som_mlo, PHYCORE_R2_MT41K512M16HA125IT_1024MB);
 PHYTEC_ENTRY(start_am33xx_phytec_phycore_sdram, am335x_phytec_phycore_som);
 PHYTEC_ENTRY(start_am33xx_phytec_phycore_no_spi_sdram, 
am335x_phytec_phycore_som_no_spi);
 PHYTEC_ENTRY(start_am33xx_phytec_phycore_no_eeprom_sdram, 
am335x_phytec_phycore_som_no_eeprom);
diff --git a/arch/arm/boards/phytec-som-am335x/ram-timings.h 
b/arch/arm/boards/phytec-som-am335x/ram-timings.h
index 884874c..9576d26 100644
--- a/arch/arm/boards/phytec-som-am335x/ram-timings.h
+++ b/arch/arm/boards/phytec-som-am335x/ram-timings.h
@@ -32,6 +32,7 @@ enum {
PHYCORE_IM8G16D3FBBG15EI_1024MB,
PHYCORE_R2_MT41K256M16TW107IT_512MB,
PHYCORE_R2_MT41K128M16JT_256MB,
+   PHYCORE_R2_MT41K512M16HA125IT_1024MB,
 
PHYCARD_NT5CB128M16BP_256MB,
 };
@@ -232,6 +233,25 @@ struct am335x_sdram_timings physom_timings[] = {
.wr_slave_ratio0= 0x73,
},
},
+
+   /* 1024MB R2 */
+   [PHYCORE_R2_MT41K512M16HA125IT_1024MB] = {
+   .regs = {
+   .emif_read_latency  = 0x7,
+   .emif_tim1  = 0x0AAAD4DB,
+   .emif_tim2  = 0x268F7FDA,
+   .emif_tim3  = 0x501F88BF,
+   .sdram_config   = 0x61C053B2,
+   .zq_config  = 0x50074BE4,
+   .sdram_ref_ctrl = 0x0C30,
+   },
+   .data = {
+   .rd_slave_ratio0= 0x38,
+   .wr_dqs_slave_ratio0= 0x4d,
+   .fifo_we_slave_ratio0   = 0x9d,
+   .wr_slave_ratio0= 0x82,
+   },
+   },
 };
 
 #endif
diff --git a/images/Makefile.am33xx b/images/Makefile.am33xx
index 6c7e81a..8be78ef 100644
--- a/images/Makefile.am33xx
+++ b/images/Makefile.am33xx
@@ -83,6 +83,12 @@ FILE_barebox-am33xx-phytec-phycore-mlo-1024mb.spi.img = 
start_am33xx_phytec_phyc
 am33xx-mlo-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-mlo-1024mb.img
 am33xx-mlospi-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-mlo-1024mb.spi.img
 
+pblx-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
start_am33xx_phytec_phycore_r2_sram_1024mb
+FILE_barebox-am33xx-phytec-phycore-r2-mlo-1024mb.img = 
start_am33xx_phytec_phycore_r2_sram_1024mb.pblx.mlo
+FILE_barebox-am33xx-phytec-phycore-r2-mlo-1024mb.spi.img = 
start_am33xx_phytec_phycore_r2_sram_1024mb.pblx.mlospi
+am33xx-mlo-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-r2-mlo-1024mb.img
+am33xx-mlospi-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-r2-mlo-1024mb.spi.img
+
 pblx-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += start_am33xx_phytec_phyflex_sdram
 FILE_barebox-am33xx-phytec-phyflex.img = start_am33xx_phytec_phyflex_sdram.pblx
 am33xx-barebox-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phyflex.img
-- 
1.9.1


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


Re: [PATCH] ARM: board: phytec-som-am335x: RAM timings for phycore-r2 1GB

2016-04-21 Thread Teresa Remmet
Hello Sascha,

Am Dienstag, den 19.04.2016, 08:24 +0200 schrieb Sascha Hauer:
> Hi Teresa,
> 
> On Mon, Apr 18, 2016 at 08:56:51AM +0200, Teresa Remmet wrote:
> > Add new RAM Timings for phyCORE R2 with MT41K512M16HA-125IT
> > 1024MB mounted.
> > 
> > Signed-off-by: Teresa Remmet 
> > ---
> >  arch/arm/boards/phytec-som-am335x/lowlevel.c|  1 +
> >  arch/arm/boards/phytec-som-am335x/ram-timings.h | 20 
> >  images/Makefile.am33xx  |  6 ++
> >  3 files changed, 27 insertions(+)
> 
> Applied, thanks. The usual question: Can't the new version be
> autodetected using bootstrap pins or similar? ;)


the phyCORE-AM335x R2 is a pin compatible replacement of the
phyCORE-AM335x. So we do not have any new pins left for this. But we
will think of ways to improve this anyway. 

Regards,
Teresa



> 
> Sascha
> 



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


[PATCH] net: phy: micrel: KSZ9081/KSZ8091: Disable broadcast mode

2016-04-27 Thread Teresa Remmet
KSZ9081 only supports two phy ids 0x0 and 0x3. 0x0 is also
used as broadcast address. Disable broadcast, so that id 0x0
can be used as unique address on a shared bus.

Signed-off-by: Teresa Remmet 
---
 drivers/net/phy/micrel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index e8a566d..9a30cb7 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -357,7 +357,7 @@ static struct phy_driver ksphy_driver[] = {
.phy_id_mask= MICREL_PHY_ID_MASK,
.drv.name   = "Micrel KSZ8081/91",
.features   = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
-   .config_init= kszphy_config_init,
+   .config_init= ksz8021_config_init,
.config_aneg= genphy_config_aneg,
.read_status= genphy_read_status,
 }, {
-- 
1.9.1


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


[PATCH 04/62] UBI: wl: Rename cancel flag to shutdown

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

It confused me more than once that the cancel flag of the
work function does not indicate the cancellation of a single work.
In fact it indicates the WL sub-system shutdown and therefore
worker functions have to free their wl_entries too.
That's why you cannot cancel a single work, you can only shutdown
all works.

Signed-off-by: Richard Weinberger 
Signed-off-by: Artem Bityutskiy 
---
 drivers/mtd/ubi/ubi.h |  9 +
 drivers/mtd/ubi/wl.c  | 24 +---
 2 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 51a0112..df104db 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -691,14 +691,15 @@ struct ubi_attach_info {
  * @torture: if the physical eraseblock has to be tortured
  * @anchor: produce a anchor PEB to by used by fastmap
  *
- * The @func pointer points to the worker function. If the @cancel argument is
- * not zero, the worker has to free the resources and exit immediately. The
- * worker has to return zero in case of success and a negative error code in
+ * The @func pointer points to the worker function. If the @shutdown argument 
is
+ * not zero, the worker has to free the resources and exit immediately as the
+ * WL sub-system is shutting down.
+ * The worker has to return zero in case of success and a negative error code 
in
  * case of failure.
  */
 struct ubi_work {
struct list_head list;
-   int (*func)(struct ubi_device *ubi, struct ubi_work *wrk, int cancel);
+   int (*func)(struct ubi_device *ubi, struct ubi_work *wrk, int shutdown);
/* The below fields are only relevant to erasure works */
struct ubi_wl_entry *e;
int vol_id;
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index cb2f9d7..cdfc41c0 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -816,7 +816,7 @@ static void schedule_ubi_work(struct ubi_device *ubi, 
struct ubi_work *wrk)
 }
 
 static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
-   int cancel);
+   int shutdown);
 
 #ifdef CONFIG_MTD_UBI_FASTMAP
 /**
@@ -939,14 +939,15 @@ int ubi_wl_put_fm_peb(struct ubi_device *ubi, struct 
ubi_wl_entry *fm_e,
  * wear_leveling_worker - wear-leveling worker function.
  * @ubi: UBI device description object
  * @wrk: the work object
- * @cancel: non-zero if the worker has to free memory and exit
+ * @shutdown: non-zero if the worker has to free memory and exit
+ * because the WL-subsystem is shutting down
  *
  * This function copies a more worn out physical eraseblock to a less worn out
  * one. Returns zero in case of success and a negative error code in case of
  * failure.
  */
 static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
-   int cancel)
+   int shutdown)
 {
int err, scrubbing = 0, torture = 0, protect = 0, erroneous = 0;
int vol_id = -1, uninitialized_var(lnum);
@@ -957,7 +958,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, 
struct ubi_work *wrk,
struct ubi_vid_hdr *vid_hdr;
 
kfree(wrk);
-   if (cancel)
+   if (shutdown)
return 0;
 
vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS);
@@ -1333,7 +1334,8 @@ int ubi_ensure_anchor_pebs(struct ubi_device *ubi)
  * erase_worker - physical eraseblock erase worker function.
  * @ubi: UBI device description object
  * @wl_wrk: the work object
- * @cancel: non-zero if the worker has to free memory and exit
+ * @shutdown: non-zero if the worker has to free memory and exit
+ * because the WL sub-system is shutting down
  *
  * This function erases a physical eraseblock and perform torture testing if
  * needed. It also takes care about marking the physical eraseblock bad if
@@ -1341,7 +1343,7 @@ int ubi_ensure_anchor_pebs(struct ubi_device *ubi)
  * failure.
  */
 static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
-   int cancel)
+   int shutdown)
 {
struct ubi_wl_entry *e = wl_wrk->e;
int pnum = e->pnum;
@@ -1349,7 +1351,7 @@ static int erase_worker(struct ubi_device *ubi, struct 
ubi_work *wl_wrk,
int lnum = wl_wrk->lnum;
int err, available_consumed = 0;
 
-   if (cancel) {
+   if (shutdown) {
dbg_wl("cancel erasure of PEB %d EC %d", pnum, e->ec);
kfree(wl_wrk);
kfree(e);
@@ -1667,10 +1669,10 @@ static void tree_destroy(struct rb_root *root)
 }
 
 /**
- * cancel_pending - cancel all pending works.
+ * shutdown_work - shutdown all pending works.
  * @ubi: UBI device description object
  */
-static void cancel_pending(struct ubi_device *ubi)
+static void shutdown_work(struct ubi_device *ubi)
 {
while (!list_empty(&ubi->works)) {
struct ubi_work *wrk;
@@ -1807,7 +1809,7 @@ int ubi_wl_init(struct ubi_device *ubi, stru

[PATCH 01/62] UBI: add missing kmem_cache_free() in process_pool_aeb error path

2016-05-23 Thread Teresa Remmet
From: Richard Genoud 

I ran into this error after a ubiupdatevol, because I forgot to backport
e9110361a9a4 UBI: fix the volumes tree sorting criteria.

UBI error: process_pool_aeb: orphaned volume in fastmap pool
UBI error: ubi_scan_fastmap: Attach by fastmap failed, doing a full scan!
kmem_cache_destroy ubi_ainf_peb_slab: Slab cache still has objects
CPU: 0 PID: 1 Comm: swapper Not tainted 3.14.18-00053-gf05cac8dbf85 #1
[] (unwind_backtrace) from [] (show_stack+0x10/0x14)
[] (show_stack) from [] (destroy_ai+0x230/0x244)
[] (destroy_ai) from [] (ubi_attach+0x98/0x1ec)
[] (ubi_attach) from [] (ubi_attach_mtd_dev+0x2b8/0x868)
[] (ubi_attach_mtd_dev) from [] (ubi_init+0x1dc/0x2ac)
[] (ubi_init) from [] (do_one_initcall+0x94/0x140)
[] (do_one_initcall) from [] 
(kernel_init_freeable+0xe8/0x1b0)
[] (kernel_init_freeable) from [] (kernel_init+0x8/0xe4)
[] (kernel_init) from [] (ret_from_fork+0x14/0x24)
UBI: scanning is finished

Freeing the cache in the error path fixes the Slab error.

Tested on at91sam9g35 (3.14.18+fastmap backports)

Signed-off-by: Richard Genoud 
Cc: stable  # 3.10+

Use kfree instead of kmem_cache_free() for barebox.

Signed-off-by: Teresa Remmet 
---
 drivers/mtd/ubi/fastmap.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 8f29430..a3e9069 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -329,6 +329,7 @@ static int process_pool_aeb(struct ubi_device *ubi, struct 
ubi_attach_info *ai,
av = tmp_av;
else {
ubi_err("orphaned volume in fastmap pool!");
+   kfree(new_aeb);
return UBI_BAD_FASTMAP;
}
 
-- 
1.9.1


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


[PATCH 00/62] Update UBI

2016-05-23 Thread Teresa Remmet
Hello,

this series is more or less just a cherry-pick of the UBI patches
from kernel to version v4.6. Rework was need for some patches to make
them apply and work for barebox.

After applying this series UBI is much more noisy while attaching.
I am not sure if this is wanted. But could be solved in a seperate patch.

Regards,
Teresa

Artem Bityutskiy (2):
  UBI: clean-up printing helpers
  UBI: do propagate positive error codes up

Brian Norris (6):
  UBI: fix missing brace control flow
  UBI: account for bitflips in both the VID header and data
  UBI: fix out of bounds write
  UBI: initialize LEB number variable
  UBI: align comment for readability
  UBI: fix use of "VID" vs. "EC" in header self-check

Ezequiel García (1):
  UBI: Fastmap: Fix PEB array type

Richard Genoud (1):
  UBI: add missing kmem_cache_free() in process_pool_aeb error path

Richard Weinberger (38):
  UBI: Improve comment on work_sem
  UBI: ubi_eba_read_leb: Remove in vain variable assignment
  UBI: wl: Rename cancel flag to shutdown
  UBI: Fix trivial typo in __schedule_ubi_work
  UBI: Fastmap: Calc fastmap size correctly
  UBI: vtbl: Use ubi_eba_atomic_leb_change()
  UBI: Fix double free after do_sync_erase()
  UBI: Fix invalid vfree()
  UBI: Fastmap: Care about the protection queue
  UBI: Split __wl_get_peb()
  UBI: Fastmap: Make ubi_refill_pools() fair
  UBI: Fastmap: Don't allocate new ubi_wl_entry objects
  UBI: Fastmap: Fix memory leaks while closing the WL sub-system
  UBI: Fastmap: Notify user in case of an ubi_update_fastmap() failure
  UBI: Fastmap: Wrap fastmap specific function in a ifdef
  UBI: Fastmap: Fix fastmap usage in ubi_volume_notify()
  UBI: Fastmap: Fix race in ubi_eba_atomic_leb_change()
  UBI: Fastmap: Remove bogus ubi_assert()
  UBI: Fastmap: Remove eba_orphans logic
  UBI: Fastmap: Switch to ro mode if invalidate_fastmap() fails
  UBI: Fastmap: Make WL pool size 50% of user pool size
  UBI: Fastmap: Fix leb_count unbalance
  UBI: Fastmap: Set used_ebs only for static volumes
  UBI: Fastmap: Prepare for variable sized fastmaps
  UBI: Fastmap: Rework fastmap error paths
  UBI: Fix stale pointers in ubi->lookuptbl
  UBI: Move fastmap specific functions out of wl.c
  UBI: Add accessor functions for WL data structures
  UBI: Fastmap: Wire up WL accessor functions
  UBI: Fastmap: Introduce ubi_fastmap_init()
  UBI: Fastmap: Introduce may_reserve_for_fm()
  UBI: Fastmap: Remove is_fm_block()
  UBI: Fastmap: Fall back to scanning mode after ECC error
  UBI: Validate data_size
  UBI: Fastmap: Simplify expression
  UBI: Fix typo in comment
  UBI: Fix debug message
  ubi: Fix out of bounds write in volume update code

Sebastian Siewior (3):
  mtd: ubi: fixup error correction in do_sync_erase()
  mtd: ubi: don't leak e if schedule_erase() fails
  mtd: ubi: wl: avoid erasing a PEB which is empty

Tanya Brokhman (2):
  UBI: Extend UBI layer debug/messaging capabilities
  UBI: extend UBI layer debug/messaging capabilities - cosmetics

Teresa Remmet (1):
  mtd: UBI: Remove ubi_free_fastmap

shengyong (8):
  UBI: Fastmap: Use max() to get the larger value
  UBI: Fastmap: Remove unnecessary `\'
  UBI: Fastmap: Rename variables to make them meaningful
  UBI: Init vol->reserved_pebs by assignment
  UBI: Fastmap: Do not add vol if it already exists
  UBI: add a helper function for updatting on-flash layout volumes
  UBI: Remove unnecessary `\'
  UBI: return ENOSPC if no enough space available

 drivers/mtd/ubi/attach.c | 130 
 drivers/mtd/ubi/barebox.c|  18 +-
 drivers/mtd/ubi/build.c  |  82 ++---
 drivers/mtd/ubi/debug.c  |   4 +-
 drivers/mtd/ubi/eba.c|  78 ++---
 drivers/mtd/ubi/fastmap-wl.c | 314 
 drivers/mtd/ubi/fastmap.c| 496 +++
 drivers/mtd/ubi/io.c |  98 +++---
 drivers/mtd/ubi/kapi.c   |   6 +-
 drivers/mtd/ubi/misc.c   |   4 +-
 drivers/mtd/ubi/ubi-media.h  |   4 +-
 drivers/mtd/ubi/ubi.h|  70 -
 drivers/mtd/ubi/upd.c|  12 +-
 drivers/mtd/ubi/vmt.c|  72 ++---
 drivers/mtd/ubi/vtbl.c   | 104 +++
 drivers/mtd/ubi/wl.c | 689 ++-
 drivers/mtd/ubi/wl.h |  26 ++
 17 files changed, 1175 insertions(+), 1032 deletions(-)
 create mode 100644 drivers/mtd/ubi/fastmap-wl.c
 create mode 100644 drivers/mtd/ubi/wl.h

-- 
1.9.1


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


[PATCH 03/62] UBI: ubi_eba_read_leb: Remove in vain variable assignment

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

There is no need to set err, it will be overwritten in any case
later at:
if (scrub)
err = ubi_wl_scrub_peb(ubi, pnum);

Signed-off-by: Richard Weinberger 
Signed-off-by: Artem Bityutskiy 
---
 drivers/mtd/ubi/eba.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index 7eb76ce..bf96b14 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -416,10 +416,9 @@ retry:
 
err = ubi_io_read_data(ubi, buf, pnum, offset, len);
if (err) {
-   if (err == UBI_IO_BITFLIPS) {
+   if (err == UBI_IO_BITFLIPS)
scrub = 1;
-   err = 0;
-   } else if (mtd_is_eccerr(err)) {
+   else if (mtd_is_eccerr(err)) {
if (vol->vol_type == UBI_DYNAMIC_VOLUME)
goto out_unlock;
scrub = 1;
-- 
1.9.1


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


[PATCH 02/62] UBI: Improve comment on work_sem

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

Make clear what work_sem really does.

Suggested-by: Artem Bityutskiy 
Signed-off-by: Richard Weinberger 
Signed-off-by: Artem Bityutskiy 
---
 drivers/mtd/ubi/ubi.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 471d784..51a0112 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -428,7 +428,8 @@ struct ubi_debug_info {
  *  @move_to, @move_to_put @erase_pending, @wl_scheduled, @works,
  *  @erroneous, and @erroneous_peb_count fields
  * @move_mutex: serializes eraseblock moves
- * @work_sem: synchronizes the WL worker with use tasks
+ * @work_sem: used to wait for all the scheduled works to finish and prevent
+ * new works from being submitted
  * @wl_scheduled: non-zero if the wear-leveling was scheduled
  * @lookuptbl: a table to quickly find a &struct ubi_wl_entry object for any
  * physical eraseblock
-- 
1.9.1


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


[PATCH 06/62] UBI: Fastmap: Calc fastmap size correctly

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

We need to add fm_sb too.

Signed-off-by: Richard Weinberger 
Reviewed-by: Tanya Brokhman 
Signed-off-by: Artem Bityutskiy 
---
 drivers/mtd/ubi/fastmap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index a3e9069..52b8c47 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -24,7 +24,8 @@ size_t ubi_calc_fm_size(struct ubi_device *ubi)
 {
size_t size;
 
-   size = sizeof(struct ubi_fm_hdr) + \
+   size = sizeof(struct ubi_fm_sb) + \
+   sizeof(struct ubi_fm_hdr) + \
sizeof(struct ubi_fm_scan_pool) + \
sizeof(struct ubi_fm_scan_pool) + \
(ubi->peb_count * sizeof(struct ubi_fm_ec)) + \
-- 
1.9.1


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


[PATCH 29/62] UBI: Fastmap: Remove eba_orphans logic

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

This logic is in vain as we treat protected PEBs also as used, so this
case must not happen.
If a PEB is found which is in the EBA table but not known as used
has to be issued as fatal error.

Signed-off-by: Richard Weinberger 

Conflicts:
drivers/mtd/ubi/fastmap.c

Fixed conflicts.

Signed-off-by: Teresa Remmet 
---
 drivers/mtd/ubi/fastmap.c | 90 +--
 1 file changed, 8 insertions(+), 82 deletions(-)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 4331d3c..f683d42 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -375,7 +375,6 @@ static void unmap_peb(struct ubi_attach_info *ai, int pnum)
  * @pebs: an array of all PEB numbers in the to be scanned pool
  * @pool_size: size of the pool (number of entries in @pebs)
  * @max_sqnum: pointer to the maximal sequence number
- * @eba_orphans: list of PEBs which need to be scanned
  * @free: list of PEBs which are most likely free (and go into @ai->free)
  *
  * Returns 0 on success, if the pool is unusable UBI_BAD_FASTMAP is returned.
@@ -383,12 +382,12 @@ static void unmap_peb(struct ubi_attach_info *ai, int 
pnum)
  */
 static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
 int *pebs, int pool_size, unsigned long long *max_sqnum,
-struct list_head *eba_orphans, struct list_head *lfree)
+struct list_head *lfree)
 {
struct ubi_vid_hdr *vh;
struct ubi_ec_hdr *ech;
-   struct ubi_ainf_peb *new_aeb, *tmp_aeb;
-   int i, pnum, err, found_orphan, ret = 0;
+   struct ubi_ainf_peb *new_aeb;
+   int i, pnum, err, ret = 0;
 
ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
if (!ech)
@@ -456,18 +455,6 @@ static int scan_pool(struct ubi_device *ubi, struct 
ubi_attach_info *ai,
if (err == UBI_IO_BITFLIPS)
scrub = 1;
 
-   found_orphan = 0;
-   list_for_each_entry(tmp_aeb, eba_orphans, u.list) {
-   if (tmp_aeb->pnum == pnum) {
-   found_orphan = 1;
-   break;
-   }
-   }
-   if (found_orphan) {
-   list_del(&tmp_aeb->u.list);
-   kfree(tmp_aeb);
-   }
-
new_aeb = kzalloc(sizeof(*new_aeb), GFP_KERNEL);
if (!new_aeb) {
ret = -ENOMEM;
@@ -541,10 +528,9 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
  struct ubi_attach_info *ai,
  struct ubi_fastmap_layout *fm)
 {
-   struct list_head used, eba_orphans, lfree;
+   struct list_head used, lfree;
struct ubi_ainf_volume *av;
struct ubi_ainf_peb *aeb, *tmp_aeb, *_tmp_aeb;
-   struct ubi_ec_hdr *ech;
struct ubi_fm_sb *fmsb;
struct ubi_fm_hdr *fmhdr;
struct ubi_fm_scan_pool *fmpl1, *fmpl2;
@@ -558,7 +544,6 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
 
INIT_LIST_HEAD(&used);
INIT_LIST_HEAD(&lfree);
-   INIT_LIST_HEAD(&eba_orphans);
INIT_LIST_HEAD(&ai->corr);
INIT_LIST_HEAD(&ai->free);
INIT_LIST_HEAD(&ai->erase);
@@ -731,27 +716,9 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
}
}
 
-   /* This can happen if a PEB is already in an EBA known
-* by this fastmap but the PEB itself is not in the used
-* list.
-* In this case the PEB can be within the fastmap pool
-* or while writing the fastmap it was in the protection
-* queue.
-*/
if (!aeb) {
-   aeb = kzalloc(sizeof(*aeb), GFP_KERNEL);
-   if (!aeb) {
-   ret = -ENOMEM;
-
-   goto fail;
-   }
-
-   aeb->lnum = j;
-   aeb->pnum = be32_to_cpu(fm_eba->pnum[j]);
-   aeb->ec = -1;
-   aeb->scrub = aeb->copy_flag = aeb->sqnum = 0;
-   list_add_tail(&aeb->u.list, &eba_orphans);
-   continue;
+   ubi_err(ubi, "PEB %i is in EBA but not in used 
list", pnum);
+   goto fail_bad;
}
 
  

[PATCH 49/62] UBI: add a helper function for updatting on-flash layout volumes

2016-05-23 Thread Teresa Remmet
From: shengyong 

Signed-off-by: Sheng Yong 
Signed-off-by: Richard Weinberger 
---
 drivers/mtd/ubi/vtbl.c | 45 -
 1 file changed, 24 insertions(+), 21 deletions(-)

diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c
index 0bc824e..6bae84c 100644
--- a/drivers/mtd/ubi/vtbl.c
+++ b/drivers/mtd/ubi/vtbl.c
@@ -63,6 +63,26 @@ static void self_vtbl_check(const struct ubi_device *ubi);
 static struct ubi_vtbl_record empty_vtbl_record;
 
 /**
+ * ubi_update_layout_vol - helper for updatting layout volumes on flash
+ * @ubi: UBI device description object
+ */
+static int ubi_update_layout_vol(struct ubi_device *ubi)
+{
+   struct ubi_volume *layout_vol;
+   int i, err;
+
+   layout_vol = ubi->volumes[vol_id2idx(ubi, UBI_LAYOUT_VOLUME_ID)];
+   for (i = 0; i < UBI_LAYOUT_VOLUME_EBS; i++) {
+   err = ubi_eba_atomic_leb_change(ubi, layout_vol, i, ubi->vtbl,
+   ubi->vtbl_size);
+   if (err)
+   return err;
+   }
+
+   return 0;
+}
+
+/**
  * ubi_change_vtbl_record - change volume table record.
  * @ubi: UBI device description object
  * @idx: table index to change
@@ -76,12 +96,10 @@ static struct ubi_vtbl_record empty_vtbl_record;
 int ubi_change_vtbl_record(struct ubi_device *ubi, int idx,
   struct ubi_vtbl_record *vtbl_rec)
 {
-   int i, err;
+   int err;
uint32_t crc;
-   struct ubi_volume *layout_vol;
 
ubi_assert(idx >= 0 && idx < ubi->vtbl_slots);
-   layout_vol = ubi->volumes[vol_id2idx(ubi, UBI_LAYOUT_VOLUME_ID)];
 
if (!vtbl_rec)
vtbl_rec = &empty_vtbl_record;
@@ -91,15 +109,10 @@ int ubi_change_vtbl_record(struct ubi_device *ubi, int idx,
}
 
memcpy(&ubi->vtbl[idx], vtbl_rec, sizeof(struct ubi_vtbl_record));
-   for (i = 0; i < UBI_LAYOUT_VOLUME_EBS; i++) {
-   err = ubi_eba_atomic_leb_change(ubi, layout_vol, i, ubi->vtbl,
-   ubi->vtbl_size);
-   if (err)
-   return err;
-   }
+   err = ubi_update_layout_vol(ubi);
 
self_vtbl_check(ubi);
-   return 0;
+   return err ? err : 0;
 }
 
 /**
@@ -114,9 +127,7 @@ int ubi_change_vtbl_record(struct ubi_device *ubi, int idx,
 int ubi_vtbl_rename_volumes(struct ubi_device *ubi,
struct list_head *rename_list)
 {
-   int i, err;
struct ubi_rename_entry *re;
-   struct ubi_volume *layout_vol;
 
list_for_each_entry(re, rename_list, list) {
uint32_t crc;
@@ -138,15 +149,7 @@ int ubi_vtbl_rename_volumes(struct ubi_device *ubi,
vtbl_rec->crc = cpu_to_be32(crc);
}
 
-   layout_vol = ubi->volumes[vol_id2idx(ubi, UBI_LAYOUT_VOLUME_ID)];
-   for (i = 0; i < UBI_LAYOUT_VOLUME_EBS; i++) {
-   err = ubi_eba_atomic_leb_change(ubi, layout_vol, i, ubi->vtbl,
-   ubi->vtbl_size);
-   if (err)
-   return err;
-   }
-
-   return 0;
+   return ubi_update_layout_vol(ubi);
 }
 
 /**
-- 
1.9.1


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


[PATCH 36/62] UBI: Fix stale pointers in ubi->lookuptbl

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

In some error paths the WL sub-system gives up on a PEB
and frees it's ubi_wl_entry struct but does not set
the entry in ubi->lookuptbl to NULL.
Fastmap can stumble over such a stale pointer as it uses
ubi->lookuptbl to find all PEBs.

Fix this by introducing a new helper function which free()s
a WL entry and removes the reference from the lookup table.

Signed-off-by: Richard Weinberger 

Conflicts:
drivers/mtd/ubi/wl.c

Fixed minor conflict.

Signed-off-by: Teresa Remmet 
---
 drivers/mtd/ubi/wl.c | 47 +++
 1 file changed, 31 insertions(+), 16 deletions(-)

diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index d168abc..a7ca153 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -194,6 +194,20 @@ static void wl_tree_add(struct ubi_wl_entry *e, struct 
rb_root *root)
rb_insert_color(&e->u.rb, root);
 }
 
+/**
+ * wl_tree_destroy - destroy a wear-leveling entry.
+ * @ubi: UBI device description object
+ * @e: the wear-leveling entry to add
+ *
+ * This function destroys a wear leveling entry and removes
+ * the reference from the lookup table.
+ */
+static void wl_entry_destroy(struct ubi_device *ubi, struct ubi_wl_entry *e)
+{
+   ubi->lookuptbl[e->pnum] = NULL;
+   kfree(e);
+}
+
 #ifndef CONFIG_MTD_UBI_FASTMAP
 /**
  * do_work - do one pending work.
@@ -1182,7 +1196,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, 
struct ubi_work *wrk,
err = do_sync_erase(ubi, e1, vol_id, lnum, 0);
if (err) {
if (e2)
-   kfree(e2);
+   wl_entry_destroy(ubi, e2);
goto out_ro;
}
 
@@ -1244,8 +1258,8 @@ out_error:
ubi->move_to_put = ubi->wl_scheduled = 0;
 
ubi_free_vid_hdr(ubi, vid_hdr);
-   kfree(e1);
-   kfree(e2);
+   wl_entry_destroy(ubi, e1);
+   wl_entry_destroy(ubi, e2);
 
 out_ro:
ubi_ro_mode(ubi);
@@ -1375,7 +1389,7 @@ static int erase_worker(struct ubi_device *ubi, struct 
ubi_work *wl_wrk,
if (shutdown) {
dbg_wl("cancel erasure of PEB %d EC %d", pnum, e->ec);
kfree(wl_wrk);
-   kfree(e);
+   wl_entry_destroy(ubi, e);
return 0;
}
 
@@ -1419,7 +1433,7 @@ static int erase_worker(struct ubi_device *ubi, struct 
ubi_work *wl_wrk,
return err;
}
 
-   kfree(e);
+   wl_entry_destroy(ubi, e);
if (err != -EIO)
/*
 * If this is not %-EIO, we have no idea what to do. Scheduling
@@ -1662,9 +1676,10 @@ int ubi_wl_flush(struct ubi_device *ubi, int vol_id, int 
lnum)
 
 /**
  * tree_destroy - destroy an RB-tree.
+ * @ubi: UBI device description object
  * @root: the root of the tree to destroy
  */
-static void tree_destroy(struct rb_root *root)
+static void tree_destroy(struct ubi_device *ubi, struct rb_root *root)
 {
struct rb_node *rb;
struct ubi_wl_entry *e;
@@ -1686,7 +1701,7 @@ static void tree_destroy(struct rb_root *root)
rb->rb_right = NULL;
}
 
-   kfree(e);
+   wl_entry_destroy(ubi, e);
}
}
 }
@@ -1749,7 +1764,7 @@ int ubi_wl_init(struct ubi_device *ubi, struct 
ubi_attach_info *ai)
ubi_assert(!ubi_is_fm_block(ubi, e->pnum));
ubi->lookuptbl[e->pnum] = e;
if (schedule_erase(ubi, e, aeb->vol_id, aeb->lnum, 0)) {
-   kfree(e);
+   wl_entry_destroy(ubi, e);
goto out_free;
}
 
@@ -1839,9 +1854,9 @@ int ubi_wl_init(struct ubi_device *ubi, struct 
ubi_attach_info *ai)
 
 out_free:
shutdown_work(ubi);
-   tree_destroy(&ubi->used);
-   tree_destroy(&ubi->free);
-   tree_destroy(&ubi->scrub);
+   tree_destroy(ubi, &ubi->used);
+   tree_destroy(ubi, &ubi->free);
+   tree_destroy(ubi, &ubi->scrub);
kfree(ubi->lookuptbl);
return err;
 }
@@ -1858,7 +1873,7 @@ static void protection_queue_destroy(struct ubi_device 
*ubi)
for (i = 0; i < UBI_PROT_QUEUE_LEN; ++i) {
list_for_each_entry_safe(e, tmp, &ubi->pq[i], u.list) {
list_del(&e->u.list);
-   kfree(e);
+   wl_entry_destroy(ubi, e);
}
}
 }
@@ -1889,10 +1904,10 @@ void ubi_wl_close(struct ubi_device *ubi)
ubi_fastmap_close(ubi);
shutdown_work(ubi);
protection_queue_destroy(ubi);
-   tree_destroy(&ubi->used);
-   tree_destroy(&ubi->erroneous);
-   tree_destroy(&ubi->free);
-   tree_destroy(&ubi->scrub);
+   tree_destroy(ubi, &ubi->

[PATCH 43/62] UBI: Fastmap: Fall back to scanning mode after ECC error

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

If we encounter an uncorrectable ECC error while scanning for the fastmap
UBI must not fail hard. Instead fall back to scanning mode.

Reported-by: Alexander Block 
Signed-off-by: Richard Weinberger 

Conflicts:
drivers/mtd/ubi/attach.c

Fixed minor conflict.

Signed-off-by: Teresa Remmet 
---
 drivers/mtd/ubi/attach.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
index dc14a2b..b49842b 100644
--- a/drivers/mtd/ubi/attach.c
+++ b/drivers/mtd/ubi/attach.c
@@ -1390,7 +1390,7 @@ int ubi_attach(struct ubi_device *ubi, int force_scan)
err = scan_all(ubi, ai, 0);
else {
err = scan_fast(ubi, ai);
-   if (err > 0) {
+   if (err > 0 || mtd_is_eccerr(err)) {
if (err != UBI_NO_FASTMAP) {
destroy_ai(ai);
ai = alloc_ai("ubi_aeb_slab_cache2");
-- 
1.9.1


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


[PATCH 52/62] UBI: return ENOSPC if no enough space available

2016-05-23 Thread Teresa Remmet
From: shengyong 

UBI: attaching mtd1 to ubi0
UBI: scanning is finished
UBI error: init_volumes: not enough PEBs, required 706, available 686
UBI error: ubi_wl_init: no enough physical eraseblocks (-20, need 1)
UBI error: ubi_attach_mtd_dev: failed to attach mtd1, error -12 <= NOT ENOMEM
UBI error: ubi_init: cannot attach mtd1

If available PEBs are not enough when initializing volumes, return -ENOSPC
directly. If available PEBs are not enough when initializing WL, return
-ENOSPC instead of -ENOMEM.

Cc: sta...@vger.kernel.org
Signed-off-by: Sheng Yong 
Signed-off-by: Richard Weinberger 
Reviewed-by: David Gstir 
---
 drivers/mtd/ubi/vtbl.c | 1 +
 drivers/mtd/ubi/wl.c   | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c
index 6bae84c..b5eb454 100644
--- a/drivers/mtd/ubi/vtbl.c
+++ b/drivers/mtd/ubi/vtbl.c
@@ -638,6 +638,7 @@ static int init_volumes(struct ubi_device *ubi,
if (ubi->corr_peb_count)
ubi_err(ubi, "%d PEBs are corrupted and not used",
ubi->corr_peb_count);
+   return -ENOSPC;
}
ubi->rsvd_pebs += reserved_pebs;
ubi->avail_pebs -= reserved_pebs;
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 986a2dc..2d6c6ae 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -1438,6 +1438,7 @@ int ubi_wl_init(struct ubi_device *ubi, struct 
ubi_attach_info *ai)
if (ubi->corr_peb_count)
ubi_err(ubi, "%d PEBs are corrupted and not used",
ubi->corr_peb_count);
+   err = -ENOSPC;
goto out_free;
}
ubi->avail_pebs -= reserved_pebs;
-- 
1.9.1


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


[PATCH 38/62] UBI: Add accessor functions for WL data structures

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

Fastmap need access to various WL data structures as
fastmap tightly depends on WL.
To make the access less invasive add accessor functions.

Signed-off-by: Richard Weinberger 

Conflicts:
drivers/mtd/ubi/ubi.h

Fixed minor conflict.

Signed-off-by: Teresa Remmet 
---
 drivers/mtd/ubi/ubi.h | 37 +
 1 file changed, 37 insertions(+)

diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 2ed28f7..8b5416c 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -848,6 +848,43 @@ static inline int ubi_update_fastmap(struct ubi_device 
*ubi) { return 0; }
 #endif
 
 /*
+ * ubi_for_each_free_peb - walk the UBI free RB tree.
+ * @ubi: UBI device description object
+ * @e: a pointer to a ubi_wl_entry to use as cursor
+ * @pos: a pointer to RB-tree entry type to use as a loop counter
+ */
+#define ubi_for_each_free_peb(ubi, e, tmp_rb)  \
+   ubi_rb_for_each_entry((tmp_rb), (e), &(ubi)->free, u.rb)
+
+/*
+ * ubi_for_each_used_peb - walk the UBI used RB tree.
+ * @ubi: UBI device description object
+ * @e: a pointer to a ubi_wl_entry to use as cursor
+ * @pos: a pointer to RB-tree entry type to use as a loop counter
+ */
+#define ubi_for_each_used_peb(ubi, e, tmp_rb)  \
+   ubi_rb_for_each_entry((tmp_rb), (e), &(ubi)->used, u.rb)
+
+/*
+ * ubi_for_each_scub_peb - walk the UBI scub RB tree.
+ * @ubi: UBI device description object
+ * @e: a pointer to a ubi_wl_entry to use as cursor
+ * @pos: a pointer to RB-tree entry type to use as a loop counter
+ */
+#define ubi_for_each_scrub_peb(ubi, e, tmp_rb) \
+   ubi_rb_for_each_entry((tmp_rb), (e), &(ubi)->scrub, u.rb)
+
+/*
+ * ubi_for_each_protected_peb - walk the UBI protection queue.
+ * @ubi: UBI device description object
+ * @i: a integer used as counter
+ * @e: a pointer to a ubi_wl_entry to use as cursor
+ */
+#define ubi_for_each_protected_peb(ubi, i, e)  \
+   for ((i) = 0; (i) < UBI_PROT_QUEUE_LEN; (i)++)  \
+   list_for_each_entry((e), &(ubi->pq[(i)]), u.list)
+
+/*
  * ubi_rb_for_each_entry - walk an RB-tree.
  * @rb: a pointer to type 'struct rb_node' to use as a loop counter
  * @pos: a pointer to RB-tree entry type to use as a loop counter
-- 
1.9.1


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


[PATCH 50/62] UBI: Remove unnecessary `\'

2016-05-23 Thread Teresa Remmet
From: shengyong 

Signed-off-by: Sheng Yong 
Signed-off-by: Richard Weinberger 
---
 drivers/mtd/ubi/fastmap.c | 2 +-
 drivers/mtd/ubi/wl.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index f33c2db..1504911 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -251,7 +251,7 @@ static int update_vol(struct ubi_device *ubi, struct 
ubi_attach_info *ai,
list_add_tail(&victim->u.list, &ai->erase);
 
if (av->highest_lnum == be32_to_cpu(new_vh->lnum))
-   av->last_data_size = \
+   av->last_data_size =
be32_to_cpu(new_vh->data_size);
 
dbg_bld("vol %i: AEB %i's PEB %i is the newer",
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 3c51feb..986a2dc 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -1418,7 +1418,7 @@ int ubi_wl_init(struct ubi_device *ubi, struct 
ubi_attach_info *ai)
dbg_wl("found %i PEBs", found_pebs);
 
if (ubi->fm) {
-   ubi_assert(ubi->good_peb_count == \
+   ubi_assert(ubi->good_peb_count ==
   found_pebs + ubi->fm->used_blocks);
 
for (i = 0; i < ubi->fm->used_blocks; i++) {
-- 
1.9.1


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


[PATCH 31/62] UBI: Fastmap: Make WL pool size 50% of user pool size

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

Don't use a fixed size for the WL pool.
Make it instead 50% of the user pool.
We don't make it 100% as it is not as heavily used as the user pool.

Signed-off-by: Richard Weinberger 
---
 drivers/mtd/ubi/build.c | 2 +-
 drivers/mtd/ubi/ubi-media.h | 2 --
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index b505252..8b135c3 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -585,7 +585,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
if (ubi->fm_pool.max_size < UBI_FM_MIN_POOL_SIZE)
ubi->fm_pool.max_size = UBI_FM_MIN_POOL_SIZE;
 
-   ubi->fm_wl_pool.max_size = UBI_FM_WL_POOL_SIZE;
+   ubi->fm_wl_pool.max_size = ubi->fm_pool.max_size / 2;
ubi->fm_disabled = !fm_autoconvert;
 
if (!ubi->fm_disabled && (int)mtd_div_by_eb(ubi->mtd->size, ubi->mtd)
diff --git a/drivers/mtd/ubi/ubi-media.h b/drivers/mtd/ubi/ubi-media.h
index b83ade8..34d6747 100644
--- a/drivers/mtd/ubi/ubi-media.h
+++ b/drivers/mtd/ubi/ubi-media.h
@@ -399,8 +399,6 @@ struct ubi_vtbl_record {
 #define UBI_FM_MIN_POOL_SIZE   8
 #define UBI_FM_MAX_POOL_SIZE   256
 
-#define UBI_FM_WL_POOL_SIZE25
-
 /**
  * struct ubi_fm_sb - UBI fastmap super block
  * @magic: fastmap super block magic number (%UBI_FM_SB_MAGIC)
-- 
1.9.1


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


[PATCH 44/62] UBI: Fastmap: Use max() to get the larger value

2016-05-23 Thread Teresa Remmet
From: shengyong 

Signed-off-by: Sheng Yong 
Signed-off-by: Richard Weinberger 
---
 drivers/mtd/ubi/build.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 8b135c3..0e8dccc 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -582,8 +582,8 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
 */
ubi->fm_pool.max_size = min(((int)mtd_div_by_eb(ubi->mtd->size,
ubi->mtd) / 100) * 5, UBI_FM_MAX_POOL_SIZE);
-   if (ubi->fm_pool.max_size < UBI_FM_MIN_POOL_SIZE)
-   ubi->fm_pool.max_size = UBI_FM_MIN_POOL_SIZE;
+   ubi->fm_pool.max_size = max(ubi->fm_pool.max_size,
+   UBI_FM_MIN_POOL_SIZE);
 
ubi->fm_wl_pool.max_size = ubi->fm_pool.max_size / 2;
ubi->fm_disabled = !fm_autoconvert;
-- 
1.9.1


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


[PATCH 42/62] UBI: Fastmap: Remove is_fm_block()

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

This function was added to fastmap in a very early stage
to have paranoid assertions.
With the current fastmap implementation this assert will never
trigger as fastmap PEBs are not seen by the WL sub-system.
Remove it to save us some CPU cycles.

Signed-off-by: Richard Weinberger 

Conflicts:
drivers/mtd/ubi/fastmap-wl.c

Fixed minor conflict.

Signed-off-by: Teresa Remmet 
---
 drivers/mtd/ubi/fastmap-wl.c | 19 ---
 drivers/mtd/ubi/wl.c |  5 -
 drivers/mtd/ubi/wl.h |  5 -
 3 files changed, 29 deletions(-)

diff --git a/drivers/mtd/ubi/fastmap-wl.c b/drivers/mtd/ubi/fastmap-wl.c
index 920fd54..1885b15 100644
--- a/drivers/mtd/ubi/fastmap-wl.c
+++ b/drivers/mtd/ubi/fastmap-wl.c
@@ -15,25 +15,6 @@
  */
 
 /**
- *  is_fm_block - returns 1 if a PEB is currently used in a fastmap.
- *  @ubi: UBI device description object
- *  @pnum: the to be checked PEB
- */
-static int is_fm_block(struct ubi_device *ubi, int pnum)
-{
-   int i;
-
-   if (!ubi->fm)
-   return 0;
-
-   for (i = 0; i < ubi->fm->used_blocks; i++)
-   if (ubi->fm->e[i]->pnum == pnum)
-   return 1;
-
-   return 0;
-}
-
-/**
  * find_anchor_wl_entry - find wear-leveling entry to used as anchor PEB.
  * @root: the RB-tree where to look for
  */
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index ae9def6..3c51feb 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -560,7 +560,6 @@ static int schedule_erase(struct ubi_device *ubi, struct 
ubi_wl_entry *e,
struct ubi_work *wl_wrk;
 
ubi_assert(e);
-   ubi_assert(!is_fm_block(ubi, e->pnum));
 
dbg_wl("schedule erasure of PEB %d, EC %d, torture %d",
   e->pnum, e->ec, torture);
@@ -1002,8 +1001,6 @@ static int erase_worker(struct ubi_device *ubi, struct 
ubi_work *wl_wrk,
dbg_wl("erase PEB %d EC %d LEB %d:%d",
   pnum, e->ec, wl_wrk->vol_id, wl_wrk->lnum);
 
-   ubi_assert(!is_fm_block(ubi, e->pnum));
-
err = sync_erase(ubi, e, wl_wrk->torture);
if (!err) {
/* Fine, we've erased it successfully */
@@ -1367,7 +1364,6 @@ int ubi_wl_init(struct ubi_device *ubi, struct 
ubi_attach_info *ai)
 
e->pnum = aeb->pnum;
e->ec = aeb->ec;
-   ubi_assert(!is_fm_block(ubi, e->pnum));
ubi->lookuptbl[e->pnum] = e;
if (schedule_erase(ubi, e, aeb->vol_id, aeb->lnum, 0)) {
wl_entry_destroy(ubi, e);
@@ -1386,7 +1382,6 @@ int ubi_wl_init(struct ubi_device *ubi, struct 
ubi_attach_info *ai)
e->pnum = aeb->pnum;
e->ec = aeb->ec;
ubi_assert(e->ec >= 0);
-   ubi_assert(!is_fm_block(ubi, e->pnum));
 
wl_tree_add(e, &ubi->free);
ubi->free_count++;
diff --git a/drivers/mtd/ubi/wl.h b/drivers/mtd/ubi/wl.h
index 0df78be..2a1899e9 100644
--- a/drivers/mtd/ubi/wl.h
+++ b/drivers/mtd/ubi/wl.h
@@ -1,7 +1,6 @@
 #ifndef UBI_WL_H
 #define UBI_WL_H
 #ifdef CONFIG_MTD_UBI_FASTMAP
-static int is_fm_block(struct ubi_device *ubi, int pnum);
 static int anchor_pebs_avalible(struct rb_root *root);
 static struct ubi_wl_entry *find_anchor_wl_entry(struct rb_root *root);
 static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi);
@@ -16,10 +15,6 @@ static struct ubi_wl_entry *may_reserve_for_fm(struct 
ubi_device *ubi,
   struct rb_root *root);
 #else /* !CONFIG_MTD_UBI_FASTMAP */
 static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi);
-static inline int is_fm_block(struct ubi_device *ubi, int pnum)
-{
-   return 0;
-}
 static inline void ubi_fastmap_close(struct ubi_device *ubi) { }
 static inline void ubi_fastmap_init(struct ubi_device *ubi, int *count) { }
 static struct ubi_wl_entry *may_reserve_for_fm(struct ubi_device *ubi,
-- 
1.9.1


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


[PATCH 39/62] UBI: Fastmap: Wire up WL accessor functions

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

Use the new WL accessor functions in fastmap.

Signed-off-by: Richard Weinberger 
---
 drivers/mtd/ubi/fastmap.c | 27 +++
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 7808744..e60bc7f 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -1024,11 +1024,11 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
struct ubi_fm_ec *fec;
struct ubi_fm_volhdr *fvh;
struct ubi_fm_eba *feba;
-   struct rb_node *node;
struct ubi_wl_entry *wl_e;
struct ubi_volume *vol;
struct ubi_vid_hdr *avhdr, *dvhdr;
struct ubi_work *ubi_wrk;
+   struct rb_node *tmp_rb;
int ret, i, j, free_peb_count, used_peb_count, vol_count;
int scrub_peb_count, erase_peb_count;
 
@@ -1086,8 +1086,7 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
for (i = 0; i < ubi->fm_wl_pool.size; i++)
fmpl2->pebs[i] = cpu_to_be32(ubi->fm_wl_pool.pebs[i]);
 
-   for (node = rb_first(&ubi->free); node; node = rb_next(node)) {
-   wl_e = rb_entry(node, struct ubi_wl_entry, u.rb);
+   ubi_for_each_free_peb(ubi, wl_e, tmp_rb) {
fec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
 
fec->pnum = cpu_to_be32(wl_e->pnum);
@@ -1099,8 +1098,7 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
}
fmh->free_peb_count = cpu_to_be32(free_peb_count);
 
-   for (node = rb_first(&ubi->used); node; node = rb_next(node)) {
-   wl_e = rb_entry(node, struct ubi_wl_entry, u.rb);
+   ubi_for_each_used_peb(ubi, wl_e, tmp_rb) {
fec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
 
fec->pnum = cpu_to_be32(wl_e->pnum);
@@ -,22 +1109,19 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
ubi_assert(fm_pos <= ubi->fm_size);
}
 
-   for (i = 0; i < UBI_PROT_QUEUE_LEN; i++) {
-   list_for_each_entry(wl_e, &ubi->pq[i], u.list) {
-   fec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
+   ubi_for_each_protected_peb(ubi, i, wl_e) {
+   fec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
 
-   fec->pnum = cpu_to_be32(wl_e->pnum);
-   fec->ec = cpu_to_be32(wl_e->ec);
+   fec->pnum = cpu_to_be32(wl_e->pnum);
+   fec->ec = cpu_to_be32(wl_e->ec);
 
-   used_peb_count++;
-   fm_pos += sizeof(*fec);
-   ubi_assert(fm_pos <= ubi->fm_size);
-   }
+   used_peb_count++;
+   fm_pos += sizeof(*fec);
+   ubi_assert(fm_pos <= ubi->fm_size);
}
fmh->used_peb_count = cpu_to_be32(used_peb_count);
 
-   for (node = rb_first(&ubi->scrub); node; node = rb_next(node)) {
-   wl_e = rb_entry(node, struct ubi_wl_entry, u.rb);
+   ubi_for_each_scrub_peb(ubi, wl_e, tmp_rb) {
fec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
 
fec->pnum = cpu_to_be32(wl_e->pnum);
-- 
1.9.1


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


[PATCH 37/62] UBI: Move fastmap specific functions out of wl.c

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

Fastmap is tightly connected to the WL sub-system, many fastmap-specific
functionslive in wl.c.
To get rid of most #ifdefs in wl.c move this functions into a new file
and include it into wl.c

Signed-off-by: Richard Weinberger 

Conflicts:
drivers/mtd/ubi/wl.c

Reworked this for barebox.

Signed-off-by: Teresa Remmet 
---
 drivers/mtd/ubi/fastmap-wl.c | 314 +++
 drivers/mtd/ubi/wl.c | 498 ---
 drivers/mtd/ubi/wl.h |  17 ++
 3 files changed, 418 insertions(+), 411 deletions(-)
 create mode 100644 drivers/mtd/ubi/fastmap-wl.c
 create mode 100644 drivers/mtd/ubi/wl.h

diff --git a/drivers/mtd/ubi/fastmap-wl.c b/drivers/mtd/ubi/fastmap-wl.c
new file mode 100644
index 000..64c2a05
--- /dev/null
+++ b/drivers/mtd/ubi/fastmap-wl.c
@@ -0,0 +1,314 @@
+/*
+ * Copyright (c) 2012 Linutronix GmbH
+ * Copyright (c) 2014 sigma star gmbh
+ * Author: Richard Weinberger 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ *
+ */
+
+/**
+ *  is_fm_block - returns 1 if a PEB is currently used in a fastmap.
+ *  @ubi: UBI device description object
+ *  @pnum: the to be checked PEB
+ */
+static int is_fm_block(struct ubi_device *ubi, int pnum)
+{
+   int i;
+
+   if (!ubi->fm)
+   return 0;
+
+   for (i = 0; i < ubi->fm->used_blocks; i++)
+   if (ubi->fm->e[i]->pnum == pnum)
+   return 1;
+
+   return 0;
+}
+
+/**
+ * find_anchor_wl_entry - find wear-leveling entry to used as anchor PEB.
+ * @root: the RB-tree where to look for
+ */
+static struct ubi_wl_entry *find_anchor_wl_entry(struct rb_root *root)
+{
+   struct rb_node *p;
+   struct ubi_wl_entry *e, *victim = NULL;
+   int max_ec = UBI_MAX_ERASECOUNTER;
+
+   ubi_rb_for_each_entry(p, e, root, u.rb) {
+   if (e->pnum < UBI_FM_MAX_START && e->ec < max_ec) {
+   victim = e;
+   max_ec = e->ec;
+   }
+   }
+
+   return victim;
+}
+
+/**
+ * return_unused_pool_pebs - returns unused PEB to the free tree.
+ * @ubi: UBI device description object
+ * @pool: fastmap pool description object
+ */
+static void return_unused_pool_pebs(struct ubi_device *ubi,
+   struct ubi_fm_pool *pool)
+{
+   int i;
+   struct ubi_wl_entry *e;
+
+   for (i = pool->used; i < pool->size; i++) {
+   e = ubi->lookuptbl[pool->pebs[i]];
+   wl_tree_add(e, &ubi->free);
+   ubi->free_count++;
+   }
+}
+
+static int anchor_pebs_avalible(struct rb_root *root)
+{
+   struct rb_node *p;
+   struct ubi_wl_entry *e;
+
+   ubi_rb_for_each_entry(p, e, root, u.rb)
+   if (e->pnum < UBI_FM_MAX_START)
+   return 1;
+
+   return 0;
+}
+
+/**
+ * ubi_wl_get_fm_peb - find a physical erase block with a given maximal number.
+ * @ubi: UBI device description object
+ * @anchor: This PEB will be used as anchor PEB by fastmap
+ *
+ * The function returns a physical erase block with a given maximal number
+ * and removes it from the wl subsystem.
+ * Must be called with wl_lock held!
+ */
+struct ubi_wl_entry *ubi_wl_get_fm_peb(struct ubi_device *ubi, int anchor)
+{
+   struct ubi_wl_entry *e = NULL;
+
+   if (!ubi->free.rb_node || (ubi->free_count - ubi->beb_rsvd_pebs < 1))
+   goto out;
+
+   if (anchor)
+   e = find_anchor_wl_entry(&ubi->free);
+   else
+   e = find_mean_wl_entry(ubi, &ubi->free);
+
+   if (!e)
+   goto out;
+
+   self_check_in_wl_tree(ubi, e, &ubi->free);
+
+   /* remove it from the free list,
+* the wl subsystem does no longer know this erase block */
+   rb_erase(&e->u.rb, &ubi->free);
+   ubi->free_count--;
+out:
+   return e;
+}
+
+/**
+ * ubi_refill_pools - refills all fastmap PEB pools.
+ * @ubi: UBI device description object
+ */
+void ubi_refill_pools(struct ubi_device *ubi)
+{
+   struct ubi_fm_pool *wl_pool = &ubi->fm_wl_pool;
+   struct ubi_fm_pool *pool = &ubi->fm_pool;
+   struct ubi_wl_entry *e;
+   int enough;
+
+   return_unused_pool_pebs(ubi, wl_pool);
+   return_unused_pool_pebs(ubi, pool);
+
+   wl_pool->size = 0;
+   pool->size = 0;
+
+   for (;;) {
+   enough = 0;
+   if (pool->size <

[PATCH 40/62] UBI: Fastmap: Introduce ubi_fastmap_init()

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

...and kill another #ifdef in wl.c. :-)

Signed-off-by: Richard Weinberger 
---
 drivers/mtd/ubi/wl.c | 5 +
 drivers/mtd/ubi/wl.h | 6 ++
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index aeb7f68..f9a1680 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -1440,10 +1440,7 @@ int ubi_wl_init(struct ubi_device *ubi, struct 
ubi_attach_info *ai)
ubi_assert(ubi->good_peb_count == found_pebs);
 
reserved_pebs = WL_RESERVED_PEBS;
-#ifdef CONFIG_MTD_UBI_FASTMAP
-   /* Reserve enough LEBs to store two fastmaps. */
-   reserved_pebs += (ubi->fm_size / ubi->leb_size) * 2;
-#endif
+   ubi_fastmap_init(ubi, &reserved_pebs);
 
if (ubi->avail_pebs < reserved_pebs) {
ubi_err(ubi, "no enough physical eraseblocks (%d, need %d)",
diff --git a/drivers/mtd/ubi/wl.h b/drivers/mtd/ubi/wl.h
index 797d25b..0a832b0 100644
--- a/drivers/mtd/ubi/wl.h
+++ b/drivers/mtd/ubi/wl.h
@@ -6,6 +6,11 @@ static int anchor_pebs_avalible(struct rb_root *root);
 static struct ubi_wl_entry *find_anchor_wl_entry(struct rb_root *root);
 static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi);
 static void ubi_fastmap_close(struct ubi_device *ubi);
+static inline void ubi_fastmap_init(struct ubi_device *ubi, int *count)
+{
+   /* Reserve enough LEBs to store two fastmaps. */
+   *count += (ubi->fm_size / ubi->leb_size) * 2;
+}
 #else /* !CONFIG_MTD_UBI_FASTMAP */
 static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi);
 static inline int is_fm_block(struct ubi_device *ubi, int pnum)
@@ -13,5 +18,6 @@ static inline int is_fm_block(struct ubi_device *ubi, int 
pnum)
return 0;
 }
 static inline void ubi_fastmap_close(struct ubi_device *ubi) { }
+static inline void ubi_fastmap_init(struct ubi_device *ubi, int *count) { }
 #endif /* CONFIG_MTD_UBI_FASTMAP */
 #endif /* UBI_WL_H */
-- 
1.9.1


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


[PATCH 33/62] UBI: Fastmap: Set used_ebs only for static volumes

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

If we set it for dynamic ones we might confuse various self checks.

Signed-off-by: Richard Weinberger 
---
 drivers/mtd/ubi/fastmap.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index a9efc9c..ae6c044 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -136,14 +136,15 @@ static struct ubi_ainf_volume *add_vol(struct 
ubi_attach_info *ai, int vol_id,
if (!av)
goto out;
 
-   av->highest_lnum = av->leb_count = 0;
+   av->highest_lnum = av->leb_count = av->used_ebs = 0;
av->vol_id = vol_id;
-   av->used_ebs = used_ebs;
av->data_pad = data_pad;
av->last_data_size = last_eb_bytes;
av->compat = 0;
av->vol_type = vol_type;
av->root = RB_ROOT;
+   if (av->vol_type == UBI_STATIC_VOLUME)
+   av->used_ebs = used_ebs;
 
dbg_bld("found volume (ID %i)", vol_id);
 
-- 
1.9.1


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


[PATCH 27/62] UBI: Fastmap: Fix race in ubi_eba_atomic_leb_change()

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

This function a) requests a new PEB, b) writes data to it,
c) returns the old PEB and d) registers the new PEB in the EBA table.

For the non-fastmap case this works perfectly fine and is powercut safe.
Is fastmap enabled this can lead to issues.
If a new fastmap is written between a) and c) the freshly requested PEB
is no longer in a pool and will not be scanned upon attaching.
If now a powercut happens between c) and d) the freshly requested PEB
will not be scanned and the old one got already scheduled for erase.
After attaching the EBA table will point to a erased PEB.

Fix this issue by swapping steps c) and d).

Signed-off-by: Richard Weinberger 

Conflicts:
drivers/mtd/ubi/eba.c

Fixed minor conflict.

Signed-off-by: Teresa Remmet 
---
 drivers/mtd/ubi/eba.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index bb89d10..8747213 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -809,7 +809,7 @@ write_error:
 int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol,
  int lnum, const void *buf, int len)
 {
-   int err, pnum, tries = 0, vol_id = vol->vol_id;
+   int err, pnum, old_pnum, tries = 0, vol_id = vol->vol_id;
struct ubi_vid_hdr *vid_hdr;
uint32_t crc;
 
@@ -871,14 +871,15 @@ retry:
goto write_error;
}
 
-   if (vol->eba_tbl[lnum] >= 0) {
-   err = ubi_wl_put_peb(ubi, vol_id, lnum, vol->eba_tbl[lnum], 0);
+   old_pnum = vol->eba_tbl[lnum];
+   vol->eba_tbl[lnum] = pnum;
+
+   if (old_pnum >= 0) {
+   err = ubi_wl_put_peb(ubi, vol_id, lnum, old_pnum, 0);
if (err)
goto out_leb_unlock;
}
 
-   vol->eba_tbl[lnum] = pnum;
-
 out_leb_unlock:
leb_write_unlock(ubi, vol_id, lnum);
 out_mutex:
-- 
1.9.1


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


[PATCH 58/62] mtd: ubi: fixup error correction in do_sync_erase()

2016-05-23 Thread Teresa Remmet
From: Sebastian Siewior 

Since fastmap we gained do_sync_erase(). This function can return an error
and its error handling isn't obvious. First the memory allocation for
struct ubi_work can fail and as such struct ubi_wl_entry is leaked.
However if the memory allocation succeeds then the tail function takes
care of the struct ubi_wl_entry. A free here could result in a double
free.
To make the error handling simpler, I split the tail function into one
piece which does the work and another which frees the struct ubi_work
which is passed as argument. As result do_sync_erase() can keep the
struct on stack and we get rid of one error source.

Cc: 
Fixes: 8199b901a ("UBI: Add fastmap support to the WL sub-system")
Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Richard Weinberger 

Conflicts:
drivers/mtd/ubi/wl.c

Fixed conflicts.

Signed-off-by: Teresa Remmet 
---
 drivers/mtd/ubi/wl.c | 52 
 1 file changed, 28 insertions(+), 24 deletions(-)

diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 2d6c6ae..1feef3f 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -578,6 +578,7 @@ static int schedule_erase(struct ubi_device *ubi, struct 
ubi_wl_entry *e,
return 0;
 }
 
+static int __erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk);
 /**
  * do_sync_erase - run the erase worker synchronously.
  * @ubi: UBI device description object
@@ -590,20 +591,16 @@ static int schedule_erase(struct ubi_device *ubi, struct 
ubi_wl_entry *e,
 static int do_sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e,
 int vol_id, int lnum, int torture)
 {
-   struct ubi_work *wl_wrk;
+   struct ubi_work wl_wrk;
 
dbg_wl("sync erase of PEB %i", e->pnum);
 
-   wl_wrk = kmalloc(sizeof(struct ubi_work), GFP_NOFS);
-   if (!wl_wrk)
-   return -ENOMEM;
-
-   wl_wrk->e = e;
-   wl_wrk->vol_id = vol_id;
-   wl_wrk->lnum = lnum;
-   wl_wrk->torture = torture;
+   wl_wrk.e = e;
+   wl_wrk.vol_id = vol_id;
+   wl_wrk.lnum = lnum;
+   wl_wrk.torture = torture;
 
-   return erase_worker(ubi, wl_wrk, 0);
+   return __erase_worker(ubi, &wl_wrk);
 }
 
 /**
@@ -971,7 +968,7 @@ out_unlock:
 }
 
 /**
- * erase_worker - physical eraseblock erase worker function.
+ * __erase_worker - physical eraseblock erase worker function.
  * @ubi: UBI device description object
  * @wl_wrk: the work object
  * @shutdown: non-zero if the worker has to free memory and exit
@@ -982,8 +979,7 @@ out_unlock:
  * needed. Returns zero in case of success and a negative error code in case of
  * failure.
  */
-static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
-   int shutdown)
+static int __erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk)
 {
struct ubi_wl_entry *e = wl_wrk->e;
int pnum = e->pnum;
@@ -991,21 +987,11 @@ static int erase_worker(struct ubi_device *ubi, struct 
ubi_work *wl_wrk,
int lnum = wl_wrk->lnum;
int err, available_consumed = 0;
 
-   if (shutdown) {
-   dbg_wl("cancel erasure of PEB %d EC %d", pnum, e->ec);
-   kfree(wl_wrk);
-   wl_entry_destroy(ubi, e);
-   return 0;
-   }
-
dbg_wl("erase PEB %d EC %d LEB %d:%d",
   pnum, e->ec, wl_wrk->vol_id, wl_wrk->lnum);
 
err = sync_erase(ubi, e, wl_wrk->torture);
if (!err) {
-   /* Fine, we've erased it successfully */
-   kfree(wl_wrk);
-
wl_tree_add(e, &ubi->free);
ubi->free_count++;
 
@@ -1021,7 +1007,6 @@ static int erase_worker(struct ubi_device *ubi, struct 
ubi_work *wl_wrk,
}
 
ubi_err(ubi, "failed to erase PEB %d, error %d", pnum, err);
-   kfree(wl_wrk);
 
if (err == -EINTR || err == -ENOMEM || err == -EAGAIN ||
err == -EBUSY) {
@@ -1093,6 +1078,25 @@ out_ro:
return err;
 }
 
+static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
+ int shutdown)
+{
+   int ret;
+
+   if (shutdown) {
+   struct ubi_wl_entry *e = wl_wrk->e;
+
+   dbg_wl("cancel erasure of PEB %d EC %d", e->pnum, e->ec);
+   kfree(wl_wrk);
+   wl_entry_destroy(ubi, e);
+   return 0;
+   }
+
+   ret = __erase_worker(ubi, wl_wrk);
+   kfree(wl_wrk);
+   return ret;
+}
+
 /**
  * ubi_wl_put_peb - return a PEB to the wear-leveling sub-system.
  * @ubi: UBI device description object
-- 
1.9.1


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


[PATCH 41/62] UBI: Fastmap: Introduce may_reserve_for_fm()

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

...and kill another #ifdef.

Signed-off-by: Richard Weinberger 
---
 drivers/mtd/ubi/fastmap-wl.c | 19 +++
 drivers/mtd/ubi/wl.c |  7 +--
 drivers/mtd/ubi/wl.h |  8 
 3 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/ubi/fastmap-wl.c b/drivers/mtd/ubi/fastmap-wl.c
index 64c2a05..920fd54 100644
--- a/drivers/mtd/ubi/fastmap-wl.c
+++ b/drivers/mtd/ubi/fastmap-wl.c
@@ -312,3 +312,22 @@ static void ubi_fastmap_close(struct ubi_device *ubi)
}
kfree(ubi->fm);
 }
+
+/**
+ * may_reserve_for_fm - tests whether a PEB shall be reserved for fastmap.
+ * See find_mean_wl_entry()
+ *
+ * @ubi: UBI device description object
+ * @e: physical eraseblock to return
+ * @root: RB tree to test against.
+ */
+static struct ubi_wl_entry *may_reserve_for_fm(struct ubi_device *ubi,
+  struct ubi_wl_entry *e,
+  struct rb_root *root) {
+   if (e && !ubi->fm_disabled && !ubi->fm &&
+   e->pnum < UBI_FM_MAX_START)
+   e = rb_entry(rb_next(root->rb_node),
+struct ubi_wl_entry, u.rb);
+
+   return e;
+}
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index f9a1680..ae9def6 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -346,15 +346,10 @@ static struct ubi_wl_entry *find_mean_wl_entry(struct 
ubi_device *ubi,
if (last->ec - first->ec < WL_FREE_MAX_DIFF) {
e = rb_entry(root->rb_node, struct ubi_wl_entry, u.rb);
 
-#ifdef CONFIG_MTD_UBI_FASTMAP
/* If no fastmap has been written and this WL entry can be used
 * as anchor PEB, hold it back and return the second best
 * WL entry such that fastmap can use the anchor PEB later. */
-   if (e && !ubi->fm_disabled && !ubi->fm &&
-   e->pnum < UBI_FM_MAX_START)
-   e = rb_entry(rb_next(root->rb_node),
-struct ubi_wl_entry, u.rb);
-#endif
+   e = may_reserve_for_fm(ubi, e, root);
} else
e = find_wl_entry(ubi, root, WL_FREE_MAX_DIFF/2);
 
diff --git a/drivers/mtd/ubi/wl.h b/drivers/mtd/ubi/wl.h
index 0a832b0..0df78be 100644
--- a/drivers/mtd/ubi/wl.h
+++ b/drivers/mtd/ubi/wl.h
@@ -11,6 +11,9 @@ static inline void ubi_fastmap_init(struct ubi_device *ubi, 
int *count)
/* Reserve enough LEBs to store two fastmaps. */
*count += (ubi->fm_size / ubi->leb_size) * 2;
 }
+static struct ubi_wl_entry *may_reserve_for_fm(struct ubi_device *ubi,
+  struct ubi_wl_entry *e,
+  struct rb_root *root);
 #else /* !CONFIG_MTD_UBI_FASTMAP */
 static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi);
 static inline int is_fm_block(struct ubi_device *ubi, int pnum)
@@ -19,5 +22,10 @@ static inline int is_fm_block(struct ubi_device *ubi, int 
pnum)
 }
 static inline void ubi_fastmap_close(struct ubi_device *ubi) { }
 static inline void ubi_fastmap_init(struct ubi_device *ubi, int *count) { }
+static struct ubi_wl_entry *may_reserve_for_fm(struct ubi_device *ubi,
+  struct ubi_wl_entry *e,
+  struct rb_root *root) {
+   return e;
+}
 #endif /* CONFIG_MTD_UBI_FASTMAP */
 #endif /* UBI_WL_H */
-- 
1.9.1


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


[PATCH 35/62] UBI: Fastmap: Rework fastmap error paths

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

If UBI is unable to write the fastmap to the device
we have make sure that upon next attach UBI will fall
back to scanning mode.
In case we cannot ensure that they only thing we can do
is falling back to read-only mode.

The current error handling code is not powercut proof.
It could happen that a powercut while invalidating would
lead to a state where an too old fastmap could be used upon
attach.
This patch addresses the issue by writing a fake fastmap
super block to a fresh PEB instead of reerasing the existing one.
The fake fastmap super block will UBI case to do a full scan.

Signed-off-by: Richard Weinberger 
---
 drivers/mtd/ubi/fastmap.c | 162 --
 1 file changed, 114 insertions(+), 48 deletions(-)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index de395d5..7808744 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -1309,31 +1309,87 @@ out:
 /**
  * invalidate_fastmap - destroys a fastmap.
  * @ubi: UBI device object
- * @fm: the fastmap to be destroyed
  *
+ * This function ensures that upon next UBI attach a full scan
+ * is issued. We need this if UBI is about to write a new fastmap
+ * but is unable to do so. In this case we have two options:
+ * a) Make sure that the current fastmap will not be usued upon
+ * attach time and contine or b) fall back to RO mode to have the
+ * current fastmap in a valid state.
  * Returns 0 on success, < 0 indicates an internal error.
  */
-static int invalidate_fastmap(struct ubi_device *ubi,
- struct ubi_fastmap_layout *fm)
+static int invalidate_fastmap(struct ubi_device *ubi)
 {
int ret;
-   struct ubi_vid_hdr *vh;
+   struct ubi_fastmap_layout *fm;
+   struct ubi_wl_entry *e;
+   struct ubi_vid_hdr *vh = NULL;
 
-   ret = erase_block(ubi, fm->e[0]->pnum);
-   if (ret < 0)
-   return ret;
+   if (!ubi->fm)
+   return 0;
+
+   ubi->fm = NULL;
+
+   ret = -ENOMEM;
+   fm = kzalloc(sizeof(*fm), GFP_KERNEL);
+   if (!fm)
+   goto out;
 
vh = new_fm_vhdr(ubi, UBI_FM_SB_VOLUME_ID);
if (!vh)
-   return -ENOMEM;
+   goto out_free_fm;
+
+   ret = -ENOSPC;
+   e = ubi_wl_get_fm_peb(ubi, 1);
+   if (!e)
+   goto out_free_fm;
 
-   /* deleting the current fastmap SB is not enough, an old SB may exist,
-* so create a (corrupted) SB such that fastmap will find it and fall
-* back to scanning mode in any case */
+   /*
+* Create fake fastmap such that UBI will fall back
+* to scanning mode.
+*/
vh->sqnum = cpu_to_be64(ubi_next_sqnum(ubi));
-   ret = ubi_io_write_vid_hdr(ubi, fm->e[0]->pnum, vh);
+   ret = ubi_io_write_vid_hdr(ubi, e->pnum, vh);
+   if (ret < 0) {
+   ubi_wl_put_fm_peb(ubi, e, 0, 0);
+   goto out_free_fm;
+   }
 
+   fm->used_blocks = 1;
+   fm->e[0] = e;
+
+   ubi->fm = fm;
+
+out:
+   ubi_free_vid_hdr(ubi, vh);
return ret;
+
+out_free_fm:
+   kfree(fm);
+   goto out;
+}
+
+/**
+ * return_fm_pebs - returns all PEBs used by a fastmap back to the
+ * WL sub-system.
+ * @ubi: UBI device object
+ * @fm: fastmap layout object
+ */
+static void return_fm_pebs(struct ubi_device *ubi,
+  struct ubi_fastmap_layout *fm)
+{
+   int i;
+
+   if (!fm)
+   return;
+
+   for (i = 0; i < fm->used_blocks; i++) {
+   if (fm->e[i]) {
+   ubi_wl_put_fm_peb(ubi, fm->e[i], i,
+ fm->to_be_tortured[i]);
+   fm->e[i] = NULL;
+   }
+   }
 }
 
 /**
@@ -1345,7 +1401,7 @@ static int invalidate_fastmap(struct ubi_device *ubi,
  */
 int ubi_update_fastmap(struct ubi_device *ubi)
 {
-   int ret, i;
+   int ret, i, j;
struct ubi_fastmap_layout *new_fm, *old_fm;
struct ubi_wl_entry *tmp_e;
 
@@ -1375,34 +1431,40 @@ int ubi_update_fastmap(struct ubi_device *ubi)
for (i = 1; i < new_fm->used_blocks; i++) {
tmp_e = ubi_wl_get_fm_peb(ubi, 0);
 
-   if (!tmp_e && !old_fm) {
-   int j;
-   ubi_err(ubi, "could not get any free erase block");
-
-   for (j = 1; j < i; j++)
-   ubi_wl_put_fm_peb(ubi, new_fm->e[j], j, 0);
-
-   ret = -ENOSPC;
-   goto err;
-   } else if (!tmp_e && old_fm && old_fm->e[i]) {
-   ret = erase_block(ubi, old_fm->e[i]->pnum);
-   if (ret < 0) {
-   int j;
-
-   for (j = 1; j < i; j++)
-   ubi_wl_put_fm_peb(ubi, new_fm->e[j],
-  

[PATCH 56/62] UBI: Fastmap: Fix PEB array type

2016-05-23 Thread Teresa Remmet
From: Ezequiel García 

The PEB array is an array of __be32, so let's fix the
scan_pool() prototype accordingly.

Signed-off-by: Ezequiel Garcia 
Signed-off-by: Richard Weinberger 

Conflicts:
drivers/mtd/ubi/fastmap.c

Fixed minor conflict.

Signed-off-by: Teresa Remmet 
---
 drivers/mtd/ubi/fastmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 173da9c..ffa2859 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -385,7 +385,7 @@ static void unmap_peb(struct ubi_attach_info *ai, int pnum)
  * < 0 indicates an internal error.
  */
 static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
-int *pebs, int pool_size, unsigned long long *max_sqnum,
+__be32 *pebs, int pool_size, unsigned long long *max_sqnum,
 struct list_head *lfree)
 {
struct ubi_vid_hdr *vh;
-- 
1.9.1


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


[PATCH 54/62] UBI: Fix typo in comment

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

While we are here fix a s/beween/between typo.

Signed-off-by: Richard Weinberger 
Acked-by: Brian Norris 
---
 drivers/mtd/ubi/ubi-media.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/ubi-media.h b/drivers/mtd/ubi/ubi-media.h
index 34d6747..27c49be 100644
--- a/drivers/mtd/ubi/ubi-media.h
+++ b/drivers/mtd/ubi/ubi-media.h
@@ -496,7 +496,7 @@ struct ubi_fm_volhdr {
 /* struct ubi_fm_volhdr is followed by one struct ubi_fm_eba records */
 
 /**
- * struct ubi_fm_eba - denotes an association beween a PEB and LEB
+ * struct ubi_fm_eba - denotes an association between a PEB and LEB
  * @magic: EBA table magic number
  * @reserved_pebs: number of table entries
  * @pnum: PEB number of LEB (LEB is the index)
-- 
1.9.1


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


[PATCH 51/62] UBI: Validate data_size

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

Make sure that data_size is less than LEB size.
Otherwise a handcrafted UBI image is able to trigger
an out of bounds memory access in ubi_compare_lebs().

Cc: sta...@vger.kernel.org
Signed-off-by: Richard Weinberger 
Reviewed-by: David Gstir 
---
 drivers/mtd/ubi/io.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index bb38b79..655ab50 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -618,6 +618,11 @@ static int validate_vid_hdr(const struct ubi_device *ubi,
goto bad;
}
 
+   if (data_size > ubi->leb_size) {
+   ubi_err(ubi, "bad data_size");
+   goto bad;
+   }
+
if (vol_type == UBI_VID_STATIC) {
/*
 * Although from high-level point of view static volumes may
-- 
1.9.1


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


[PATCH 47/62] UBI: Init vol->reserved_pebs by assignment

2016-05-23 Thread Teresa Remmet
From: shengyong 

`vol' is a newly allocated value by kzalloc. Initialize it by assignment
instead of `+='.

Signed-off-by: Sheng Yong 
Signed-off-by: Richard Weinberger 
---
 drivers/mtd/ubi/vmt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index fbe8876..41b814c 100644
--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -89,8 +89,8 @@ int ubi_create_volume(struct ubi_device *ubi, struct 
ubi_mkvol_req *req)
 
/* Calculate how many eraseblocks are requested */
vol->usable_leb_size = ubi->leb_size - ubi->leb_size % req->alignment;
-   vol->reserved_pebs += div_u64(req->bytes + vol->usable_leb_size - 1,
- vol->usable_leb_size);
+   vol->reserved_pebs = div_u64(req->bytes + vol->usable_leb_size - 1,
+vol->usable_leb_size);
 
/* Reserve physical eraseblocks */
if (vol->reserved_pebs > ubi->avail_pebs) {
-- 
1.9.1


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


[PATCH 46/62] UBI: Fastmap: Rename variables to make them meaningful

2016-05-23 Thread Teresa Remmet
From: shengyong 

s/fmpl1/fmpl
s/fmpl2/fmpl_wl

Add "WL" to the error message when wrong WL pool magic number is detected.

Signed-off-by: Sheng Yong 
Signed-off-by: Richard Weinberger 

Conflicts:
drivers/mtd/ubi/fastmap.c

Fixed minor conflict.

Signed-off-by: Teresa Remmet 
---
 drivers/mtd/ubi/fastmap.c | 58 +++
 1 file changed, 29 insertions(+), 29 deletions(-)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 80a6224..5483bb9 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -535,7 +535,7 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
struct ubi_ainf_peb *aeb, *tmp_aeb, *_tmp_aeb;
struct ubi_fm_sb *fmsb;
struct ubi_fm_hdr *fmhdr;
-   struct ubi_fm_scan_pool *fmpl1, *fmpl2;
+   struct ubi_fm_scan_pool *fmpl, *fmpl_wl;
struct ubi_fm_ec *fmec;
struct ubi_fm_volhdr *fmvhdr;
struct ubi_fm_eba *fm_eba;
@@ -570,30 +570,30 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
goto fail_bad;
}
 
-   fmpl1 = (struct ubi_fm_scan_pool *)(fm_raw + fm_pos);
-   fm_pos += sizeof(*fmpl1);
+   fmpl = (struct ubi_fm_scan_pool *)(fm_raw + fm_pos);
+   fm_pos += sizeof(*fmpl);
if (fm_pos >= fm_size)
goto fail_bad;
-   if (be32_to_cpu(fmpl1->magic) != UBI_FM_POOL_MAGIC) {
+   if (be32_to_cpu(fmpl->magic) != UBI_FM_POOL_MAGIC) {
ubi_err(ubi, "bad fastmap pool magic: 0x%x, expected: 0x%x",
-   be32_to_cpu(fmpl1->magic), UBI_FM_POOL_MAGIC);
+   be32_to_cpu(fmpl->magic), UBI_FM_POOL_MAGIC);
goto fail_bad;
}
 
-   fmpl2 = (struct ubi_fm_scan_pool *)(fm_raw + fm_pos);
-   fm_pos += sizeof(*fmpl2);
+   fmpl_wl = (struct ubi_fm_scan_pool *)(fm_raw + fm_pos);
+   fm_pos += sizeof(*fmpl_wl);
if (fm_pos >= fm_size)
goto fail_bad;
-   if (be32_to_cpu(fmpl2->magic) != UBI_FM_POOL_MAGIC) {
-   ubi_err(ubi, "bad fastmap pool magic: 0x%x, expected: 0x%x",
-   be32_to_cpu(fmpl2->magic), UBI_FM_POOL_MAGIC);
+   if (be32_to_cpu(fmpl_wl->magic) != UBI_FM_POOL_MAGIC) {
+   ubi_err(ubi, "bad fastmap WL pool magic: 0x%x, expected: 0x%x",
+   be32_to_cpu(fmpl_wl->magic), UBI_FM_POOL_MAGIC);
goto fail_bad;
}
 
-   pool_size = be16_to_cpu(fmpl1->size);
-   wl_pool_size = be16_to_cpu(fmpl2->size);
-   fm->max_pool_size = be16_to_cpu(fmpl1->max_size);
-   fm->max_wl_pool_size = be16_to_cpu(fmpl2->max_size);
+   pool_size = be16_to_cpu(fmpl->size);
+   wl_pool_size = be16_to_cpu(fmpl_wl->size);
+   fm->max_pool_size = be16_to_cpu(fmpl->max_size);
+   fm->max_wl_pool_size = be16_to_cpu(fmpl_wl->max_size);
 
if (pool_size > UBI_FM_MAX_POOL_SIZE || pool_size < 0) {
ubi_err(ubi, "bad pool size: %i", pool_size);
@@ -735,11 +735,11 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
}
}
 
-   ret = scan_pool(ubi, ai, fmpl1->pebs, pool_size, &max_sqnum, &lfree);
+   ret = scan_pool(ubi, ai, fmpl->pebs, pool_size, &max_sqnum, &lfree);
if (ret)
goto fail;
 
-   ret = scan_pool(ubi, ai, fmpl2->pebs, wl_pool_size, &max_sqnum, &lfree);
+   ret = scan_pool(ubi, ai, fmpl_wl->pebs, wl_pool_size, &max_sqnum, 
&lfree);
if (ret)
goto fail;
 
@@ -1020,7 +1020,7 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
void *fm_raw;
struct ubi_fm_sb *fmsb;
struct ubi_fm_hdr *fmh;
-   struct ubi_fm_scan_pool *fmpl1, *fmpl2;
+   struct ubi_fm_scan_pool *fmpl, *fmpl_wl;
struct ubi_fm_ec *fec;
struct ubi_fm_volhdr *fvh;
struct ubi_fm_eba *feba;
@@ -1068,23 +1068,23 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
erase_peb_count = 0;
vol_count = 0;
 
-   fmpl1 = (struct ubi_fm_scan_pool *)(fm_raw + fm_pos);
-   fm_pos += sizeof(*fmpl1);
-   fmpl1->magic = cpu_to_be32(UBI_FM_POOL_MAGIC);
-   fmpl1->size = cpu_to_be16(ubi->fm_pool.size);
-   fmpl1->max_size = cpu_to_be16(ubi->fm_pool.max_size);
+   fmpl = (struct ubi_fm_scan_pool *)(fm_raw + fm_pos);
+   fm_pos += sizeof(*fmpl);
+   fmpl->magic = cpu_to_be32(UBI_FM_POOL_MAGIC);
+   fmpl->size = cpu_to_be16(ubi->fm_pool.size);
+   fmpl->max_size = cpu_to_be16(ubi->fm_pool.max_size);
 
for (i = 0; i < ubi->fm_pool.size; i++)
-   fmpl1->pebs[i] = cpu_to_be32(ubi->fm_pool.pebs[i]);
+   fmpl->pebs[i] = cpu_to_be32(ubi->fm_pool.pebs[i]);
 
-   fmpl2 = (struct ubi_fm_scan

[PATCH 48/62] UBI: Fastmap: Do not add vol if it already exists

2016-05-23 Thread Teresa Remmet
From: shengyong 

During fastmap attaching, check if a volume already exists when adding
the volume to volume tree. NOTE that the issue cannot happen, only if
the on-flash fastmap data is modified.

Signed-off-by: Sheng Yong 
Signed-off-by: Richard Weinberger 
---
 drivers/mtd/ubi/fastmap.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 5483bb9..f33c2db 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -128,8 +128,10 @@ static struct ubi_ainf_volume *add_vol(struct 
ubi_attach_info *ai, int vol_id,
 
if (vol_id > av->vol_id)
p = &(*p)->rb_left;
-   else
+   else if (vol_id < av->vol_id)
p = &(*p)->rb_right;
+   else
+   return ERR_PTR(-EINVAL);
}
 
av = kmalloc(sizeof(struct ubi_ainf_volume), GFP_KERNEL);
@@ -687,6 +689,11 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
 
if (!av)
goto fail_bad;
+   if (PTR_ERR(av) == -EINVAL) {
+   ubi_err(ubi, "volume (ID %i) already exists",
+   fmvhdr->vol_id);
+   goto fail_bad;
+   }
 
ai->vols_found++;
if (ai->highest_vol_id < be32_to_cpu(fmvhdr->vol_id))
-- 
1.9.1


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


[PATCH 45/62] UBI: Fastmap: Remove unnecessary `\'

2016-05-23 Thread Teresa Remmet
From: shengyong 

Signed-off-by: Sheng Yong 
Signed-off-by: Richard Weinberger 
---
 drivers/mtd/ubi/fastmap.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index e60bc7f..80a6224 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -24,13 +24,13 @@ size_t ubi_calc_fm_size(struct ubi_device *ubi)
 {
size_t size;
 
-   size = sizeof(struct ubi_fm_sb) + \
-   sizeof(struct ubi_fm_hdr) + \
-   sizeof(struct ubi_fm_scan_pool) + \
-   sizeof(struct ubi_fm_scan_pool) + \
-   (ubi->peb_count * sizeof(struct ubi_fm_ec)) + \
-   (sizeof(struct ubi_fm_eba) + \
-   (ubi->peb_count * sizeof(__be32))) + \
+   size = sizeof(struct ubi_fm_sb) +
+   sizeof(struct ubi_fm_hdr) +
+   sizeof(struct ubi_fm_scan_pool) +
+   sizeof(struct ubi_fm_scan_pool) +
+   (ubi->peb_count * sizeof(struct ubi_fm_ec)) +
+   (sizeof(struct ubi_fm_eba) +
+   (ubi->peb_count * sizeof(__be32))) +
sizeof(struct ubi_fm_volhdr) * UBI_MAX_VOLUMES;
return roundup(size, ubi->leb_size);
 }
-- 
1.9.1


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


[PATCH 07/62] UBI: Extend UBI layer debug/messaging capabilities

2016-05-23 Thread Teresa Remmet
From: Tanya Brokhman 

If there is more then one UBI device mounted, there is no way to
distinguish between messages from different UBI devices.
Add device number to all ubi layer message types.

The R/O block driver messages were replaced by pr_* since
ubi_device structure is not used by it.

Amended a bit by Artem.

Signed-off-by: Tanya Brokhman 
Signed-off-by: Artem Bityutskiy 

Conflicts:
drivers/mtd/ubi/block.c
drivers/mtd/ubi/build.c
drivers/mtd/ubi/cdev.c
drivers/mtd/ubi/debug.c
drivers/mtd/ubi/fastmap.c
drivers/mtd/ubi/io.c
drivers/mtd/ubi/ubi.h
drivers/mtd/ubi/vmt.c
drivers/mtd/ubi/wl.c

Reworked it for barebox.

Signed-off-by: Teresa Remmet 
---
 drivers/mtd/ubi/attach.c  | 126 --
 drivers/mtd/ubi/barebox.c |  18 +++
 drivers/mtd/ubi/build.c   |  65 
 drivers/mtd/ubi/debug.c   |   4 +-
 drivers/mtd/ubi/eba.c |  53 +--
 drivers/mtd/ubi/fastmap.c |  96 +--
 drivers/mtd/ubi/io.c  |  91 -
 drivers/mtd/ubi/kapi.c|   6 +--
 drivers/mtd/ubi/misc.c|   4 +-
 drivers/mtd/ubi/ubi.h |  13 ++---
 drivers/mtd/ubi/vmt.c |  68 +
 drivers/mtd/ubi/vtbl.c|  48 +-
 drivers/mtd/ubi/wl.c  |  58 +++--
 13 files changed, 337 insertions(+), 313 deletions(-)

diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
index 88370f4..b23fa68 100644
--- a/drivers/mtd/ubi/attach.c
+++ b/drivers/mtd/ubi/attach.c
@@ -170,6 +170,7 @@ static int add_corrupted(struct ubi_attach_info *ai, int 
pnum, int ec)
 
 /**
  * validate_vid_hdr - check volume identifier header.
+ * @ubi: UBI device description object
  * @vid_hdr: the volume identifier header to check
  * @av: information about the volume this logical eraseblock belongs to
  * @pnum: physical eraseblock number the VID header came from
@@ -182,7 +183,8 @@ static int add_corrupted(struct ubi_attach_info *ai, int 
pnum, int ec)
  * information in the VID header is consistent to the information in other VID
  * headers of the same volume.
  */
-static int validate_vid_hdr(const struct ubi_vid_hdr *vid_hdr,
+static int validate_vid_hdr(const struct ubi_device *ubi,
+   const struct ubi_vid_hdr *vid_hdr,
const struct ubi_ainf_volume *av, int pnum)
 {
int vol_type = vid_hdr->vol_type;
@@ -200,7 +202,7 @@ static int validate_vid_hdr(const struct ubi_vid_hdr 
*vid_hdr,
 */
 
if (vol_id != av->vol_id) {
-   ubi_err("inconsistent vol_id");
+   ubi_err(ubi, "inconsistent vol_id");
goto bad;
}
 
@@ -210,17 +212,17 @@ static int validate_vid_hdr(const struct ubi_vid_hdr 
*vid_hdr,
av_vol_type = UBI_VID_DYNAMIC;
 
if (vol_type != av_vol_type) {
-   ubi_err("inconsistent vol_type");
+   ubi_err(ubi, "inconsistent vol_type");
goto bad;
}
 
if (used_ebs != av->used_ebs) {
-   ubi_err("inconsistent used_ebs");
+   ubi_err(ubi, "inconsistent used_ebs");
goto bad;
}
 
if (data_pad != av->data_pad) {
-   ubi_err("inconsistent data_pad");
+   ubi_err(ubi, "inconsistent data_pad");
goto bad;
}
}
@@ -228,7 +230,7 @@ static int validate_vid_hdr(const struct ubi_vid_hdr 
*vid_hdr,
return 0;
 
 bad:
-   ubi_err("inconsistent VID header at PEB %d", pnum);
+   ubi_err(ubi, "inconsistent VID header at PEB %d", pnum);
ubi_dump_vid_hdr(vid_hdr);
ubi_dump_av(av);
return -EINVAL;
@@ -330,7 +332,7 @@ int ubi_compare_lebs(struct ubi_device *ubi, const struct 
ubi_ainf_peb *aeb,
 * support these images anymore. Well, those images still work,
 * but only if no unclean reboots happened.
 */
-   ubi_err("unsupported on-flash UBI format");
+   ubi_err(ubi, "unsupported on-flash UBI format");
return -EINVAL;
}
 
@@ -371,7 +373,7 @@ int ubi_compare_lebs(struct ubi_device *ubi, const struct 
ubi_ainf_peb *aeb,
if (err == UBI_IO_BITFLIPS)
bitflips = 1;
else {
-   ubi_err("VID of PEB %d header is bad, but it 
was OK earlier, err %d",
+   ubi_err(ubi, "VID of PEB %d header is bad, but 
it was OK earlier, err %d&qu

[PATCH 55/62] UBI: Fix debug message

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

We have to use j instead of i. i is the volume id
and not the block.

Reported-by: alexander.bl...@continental-corporation.com
Signed-off-by: Richard Weinberger 
Acked-by: Brian Norris 
---
 drivers/mtd/ubi/eba.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index 8747213..a7af247 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -1237,7 +1237,7 @@ int self_check_eba(struct ubi_device *ubi, struct 
ubi_attach_info *ai_fastmap,
continue;
 
ubi_err(ubi, "LEB:%i:%i is PEB:%i instead of 
%i!",
-   vol->vol_id, i, fm_eba[i][j],
+   vol->vol_id, j, fm_eba[i][j],
scan_eba[i][j]);
ubi_assert(0);
}
-- 
1.9.1


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


[PATCH 53/62] UBI: Fastmap: Simplify expression

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

There is no need to compute pnum again.

Signed-off-by: Richard Weinberger 
Acked-by: Brian Norris 
---
 drivers/mtd/ubi/fastmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 1504911..173da9c 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -714,7 +714,7 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
for (j = 0; j < be32_to_cpu(fm_eba->reserved_pebs); j++) {
int pnum = be32_to_cpu(fm_eba->pnum[j]);
 
-   if ((int)be32_to_cpu(fm_eba->pnum[j]) < 0)
+   if (pnum < 0)
continue;
 
aeb = NULL;
-- 
1.9.1


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


[PATCH 57/62] UBI: fix use of "VID" vs. "EC" in header self-check

2016-05-23 Thread Teresa Remmet
From: Brian Norris 

Looks like a typo, using UBI_EC_HDR_SIZE_CRC (note the "EC") to compute
the CRC for the VID header.

This shouldn't cause any functional change, as both structures are 64
bytes. Verified with:

BUILD_BUG_ON(UBI_VID_HDR_SIZE_CRC != UBI_EC_HDR_SIZE_CRC);

Reported here:
http://lists.infradead.org/pipermail/linux-mtd/2013-September/048570.html

Reported by: Bill Pringlemeir 
Signed-off-by: Brian Norris 
Signed-off-by: Richard Weinberger 
---
 drivers/mtd/ubi/io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index 655ab50..43af4a5 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -988,7 +988,7 @@ static int self_check_peb_vid_hdr(const struct ubi_device 
*ubi, int pnum)
if (err && err != UBI_IO_BITFLIPS && !mtd_is_eccerr(err))
goto exit;
 
-   crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_EC_HDR_SIZE_CRC);
+   crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_VID_HDR_SIZE_CRC);
hdr_crc = be32_to_cpu(vid_hdr->hdr_crc);
if (hdr_crc != crc) {
ubi_err(ubi, "bad VID header CRC at PEB %d, calculated %#08x, 
read %#08x",
-- 
1.9.1


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


[PATCH 62/62] mtd: UBI: Remove ubi_free_fastmap

2016-05-23 Thread Teresa Remmet
Freeing the fastmap is now done by ubi_fastmap_close() from kernel.
No need to keep the barebox own fastmap free function.

Signed-off-by: Teresa Remmet 
---
 drivers/mtd/ubi/build.c   |  1 -
 drivers/mtd/ubi/fastmap.c | 14 --
 drivers/mtd/ubi/ubi.h |  1 -
 3 files changed, 16 deletions(-)

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 0e8dccc..5953e36 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -723,7 +723,6 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
/* If we don't write a new fastmap at detach time we lose all
 * EC updates that have been made since the last written fastmap. */
ubi_update_fastmap(ubi);
-   ubi_free_fastmap(ubi);
 #endif
 
uif_close(ubi);
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index ffa2859..9975722 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -1247,20 +1247,6 @@ out:
return ret;
 }
 
-void ubi_free_fastmap(struct ubi_device *ubi)
-{
-   struct ubi_fastmap_layout *fm = ubi->fm;
-   int i;
-
-   if (!fm)
-   return;
-
-   for (i = 0; i < fm->used_blocks; i++)
-   kfree(fm->e[i]);
-
-   kfree(ubi->fm);
-}
-
 /**
  * erase_block - Manually erase a PEB.
  * @ubi: UBI device object
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 8b5416c..89e3347 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -842,7 +842,6 @@ size_t ubi_calc_fm_size(struct ubi_device *ubi);
 int ubi_update_fastmap(struct ubi_device *ubi);
 int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
 int fm_anchor);
-void ubi_free_fastmap(struct ubi_device *ubi);
 #else
 static inline int ubi_update_fastmap(struct ubi_device *ubi) { return 0; }
 #endif
-- 
1.9.1


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


[PATCH 61/62] ubi: Fix out of bounds write in volume update code

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

ubi_start_leb_change() allocates too few bytes.
ubi_more_leb_change_data() will write up to req->upd_bytes +
ubi->min_io_size bytes.

Cc: sta...@vger.kernel.org
Signed-off-by: Richard Weinberger 
Reviewed-by: Boris Brezillon 
---
 drivers/mtd/ubi/upd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/upd.c b/drivers/mtd/ubi/upd.c
index 5e06753..33d4dbf 100644
--- a/drivers/mtd/ubi/upd.c
+++ b/drivers/mtd/ubi/upd.c
@@ -201,7 +201,7 @@ int ubi_start_leb_change(struct ubi_device *ubi, struct 
ubi_volume *vol,
vol->changing_leb = 1;
vol->ch_lnum = req->lnum;
 
-   vol->upd_buf = vmalloc(req->bytes);
+   vol->upd_buf = vmalloc(ALIGN((int)req->bytes, ubi->min_io_size));
if (!vol->upd_buf)
return -ENOMEM;
 
-- 
1.9.1


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


[PATCH 60/62] mtd: ubi: wl: avoid erasing a PEB which is empty

2016-05-23 Thread Teresa Remmet
From: Sebastian Siewior 

wear_leveling_worker() currently unconditionally puts a PEB on erase in
the error case even it just been taken from the free_list and never
used.
In case the PEB was never used it can be put back on the free list
saving a precious erase cycle.

v1…v2:
- to_leb_clean -> dst_leb_clean
- use the nested option for ensure_wear_leveling()
- do_sync_erase() can't go -ENOMEM so we can just go into
  RO-mode now.

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Richard Weinberger 
---
 drivers/mtd/ubi/wl.c | 21 ++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index e81f796..4535f2d 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -603,6 +603,7 @@ static int do_sync_erase(struct ubi_device *ubi, struct 
ubi_wl_entry *e,
return __erase_worker(ubi, &wl_wrk);
 }
 
+static int ensure_wear_leveling(struct ubi_device *ubi, int nested);
 /**
  * wear_leveling_worker - wear-leveling worker function.
  * @ubi: UBI device description object
@@ -624,6 +625,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, 
struct ubi_work *wrk,
 #endif
struct ubi_wl_entry *e1, *e2;
struct ubi_vid_hdr *vid_hdr;
+   int dst_leb_clean = 0;
 
kfree(wrk);
if (shutdown)
@@ -725,6 +727,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, 
struct ubi_work *wrk,
 
err = ubi_io_read_vid_hdr(ubi, e1->pnum, vid_hdr, 0);
if (err && err != UBI_IO_BITFLIPS) {
+   dst_leb_clean = 1;
if (err == UBI_IO_FF) {
/*
 * We are trying to move PEB without a VID header. UBI
@@ -770,10 +773,12 @@ static int wear_leveling_worker(struct ubi_device *ubi, 
struct ubi_work *wrk,
 * protection queue.
 */
protect = 1;
+   dst_leb_clean = 1;
goto out_not_moved;
}
if (err == MOVE_RETRY) {
scrubbing = 1;
+   dst_leb_clean = 1;
goto out_not_moved;
}
if (err == MOVE_TARGET_BITFLIPS || err == MOVE_TARGET_WR_ERR ||
@@ -799,6 +804,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, 
struct ubi_work *wrk,
ubi->erroneous_peb_count);
goto out_error;
}
+   dst_leb_clean = 1;
erroneous = 1;
goto out_not_moved;
}
@@ -865,14 +871,23 @@ out_not_moved:
wl_tree_add(e1, &ubi->scrub);
else
wl_tree_add(e1, &ubi->used);
+   if (dst_leb_clean) {
+   wl_tree_add(e2, &ubi->free);
+   ubi->free_count++;
+   }
+
ubi_assert(!ubi->move_to_put);
ubi->move_from = ubi->move_to = NULL;
ubi->wl_scheduled = 0;
 
ubi_free_vid_hdr(ubi, vid_hdr);
-   err = do_sync_erase(ubi, e2, vol_id, lnum, torture);
-   if (err)
-   goto out_ro;
+   if (dst_leb_clean) {
+   ensure_wear_leveling(ubi, 1);
+   } else {
+   err = do_sync_erase(ubi, e2, vol_id, lnum, torture);
+   if (err)
+   goto out_ro;
+   }
 
return 0;
 
-- 
1.9.1


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


[PATCH 59/62] mtd: ubi: don't leak e if schedule_erase() fails

2016-05-23 Thread Teresa Remmet
From: Sebastian Siewior 

If __erase_worker() fails to erase the EB and schedule_erase() fails as
well to do anything about it then we go RO. But that is not a reason to
leak the e argument here. Therefore clean up e.

Cc: 
Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Richard Weinberger 
---
 drivers/mtd/ubi/wl.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 1feef3f..e81f796 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -1015,6 +1015,7 @@ static int __erase_worker(struct ubi_device *ubi, struct 
ubi_work *wl_wrk)
/* Re-schedule the LEB for erasure */
err1 = schedule_erase(ubi, e, vol_id, lnum, 0);
if (err1) {
+   wl_entry_destroy(ubi, e);
err = err1;
goto out_ro;
}
-- 
1.9.1


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


[PATCH 14/62] UBI: Fastmap: Care about the protection queue

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

Fastmap can miss a PEB if it is in the protection queue
and not jet in the used tree.
Treat every protected PEB as used.

Signed-off-by: Richard Weinberger 
Signed-off-by: Artem Bityutskiy 
---
 drivers/mtd/ubi/fastmap.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 98f69a3..bd3a307 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -1180,6 +1180,19 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
fm_pos += sizeof(*fec);
ubi_assert(fm_pos <= ubi->fm_size);
}
+
+   for (i = 0; i < UBI_PROT_QUEUE_LEN; i++) {
+   list_for_each_entry(wl_e, &ubi->pq[i], u.list) {
+   fec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
+
+   fec->pnum = cpu_to_be32(wl_e->pnum);
+   fec->ec = cpu_to_be32(wl_e->ec);
+
+   used_peb_count++;
+   fm_pos += sizeof(*fec);
+   ubi_assert(fm_pos <= ubi->fm_size);
+   }
+   }
fmh->used_peb_count = cpu_to_be32(used_peb_count);
 
for (node = rb_first(&ubi->scrub); node; node = rb_next(node)) {
-- 
1.9.1


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


[PATCH 19/62] UBI: align comment for readability

2016-05-23 Thread Teresa Remmet
From: Brian Norris 

The kerneldoc for @vid_hdr_aloffset continues onto a second line, but
this is not obvious, because the second line isn't indented, and it
begins with '@'.

Signed-off-by: Brian Norris 
Signed-off-by: Richard Weinberger 
---
 drivers/mtd/ubi/ubi.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index aa0b9df..5bceb53 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -464,7 +464,7 @@ struct ubi_debug_info {
  * @vid_hdr_offset: starting offset of the volume identifier header (might be
  *  unaligned)
  * @vid_hdr_aloffset: starting offset of the VID header aligned to
- * @hdrs_min_io_size
+ *@hdrs_min_io_size
  * @vid_hdr_shift: contains @vid_hdr_offset - @vid_hdr_aloffset
  * @bad_allowed: whether the MTD device admits of bad physical eraseblocks or
  *   not
-- 
1.9.1


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


[PATCH 13/62] UBI: do propagate positive error codes up

2016-05-23 Thread Teresa Remmet
From: Artem Bityutskiy 

UBI uses positive function return codes internally, and should not propagate
them up, except in the place this path fixes. Here is the original bug report
from Dan Carpenter:

The problem is really in ubi_eba_read_leb().

drivers/mtd/ubi/eba.c
   412  err = ubi_io_read_vid_hdr(ubi, pnum, vid_hdr, 1);
   413  if (err && err != UBI_IO_BITFLIPS) {
   414  if (err > 0) {
   415  /*
   416   * The header is either absent or 
corrupted.
   417   * The former case means there is a bug 
-
   418   * switch to read-only mode just in 
case.
   419   * The latter case means a real 
corruption - we
   420   * may try to recover data. FIXME: but 
this is
   421   * not implemented.
   422   */
   423  if (err == UBI_IO_BAD_HDR_EBADMSG ||
   424  err == UBI_IO_BAD_HDR) {
   425  ubi_warn("corrupted VID header 
at PEB %d, LEB %d:%d",
   426   pnum, vol_id, lnum);
   427  err = -EBADMSG;
   428  } else
   429  ubi_ro_mode(ubi);

On this path we return UBI_IO_FF and UBI_IO_FF_BITFLIPS and it
eventually gets passed to ERR_PTR().  We probably dereference the bad
pointer and oops.  At that point we've gone read only so it was already
a bad situation...

   430  }
   431  goto out_free;
   432  } else if (err == UBI_IO_BITFLIPS)
   433  scrub = 1;
   434

Reported-by: Dan Carpenter 
Signed-off-by: Artem Bityutskiy 
---
 drivers/mtd/ubi/eba.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index 1b0b6e6..b8f5091 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -401,6 +401,7 @@ retry:
 pnum, vol_id, lnum);
err = -EBADMSG;
} else
+   err = -EINVAL;
ubi_ro_mode(ubi);
}
goto out_free;
-- 
1.9.1


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


[PATCH 18/62] UBI: initialize LEB number variable

2016-05-23 Thread Teresa Remmet
From: Brian Norris 

In some of the 'out_not_moved' error paths, lnum may be used
uninitialized. Don't ignore the warning; let's fix it.

This uninitialized variable doesn't have much visible effect in the end,
since we just schedule the PEB for erasure, and its LEB number doesn't
really matter (it just gets printed in debug messages). But let's get it
straight anyway.

Coverity CID #113449

Cc: stable 
Signed-off-by: Brian Norris 
Signed-off-by: Richard Weinberger 
---
 drivers/mtd/ubi/wl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index aaa882e..adbb29b 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -951,7 +951,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, 
struct ubi_work *wrk,
int shutdown)
 {
int err, scrubbing = 0, torture = 0, protect = 0, erroneous = 0;
-   int vol_id = -1, uninitialized_var(lnum);
+   int vol_id = -1, lnum = -1;
 #ifdef CONFIG_MTD_UBI_FASTMAP
int anchor = wrk->anchor;
 #endif
-- 
1.9.1


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


[PATCH 10/62] UBI: Fix invalid vfree()

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

The logic of vfree()'ing vol->upd_buf is tied to vol->updating.
In ubi_start_update() vol->updating is set long before vmalloc()'ing
vol->upd_buf. If we encounter a write failure in ubi_start_update()
before vmalloc() the UBI device release function will try to vfree()
vol->upd_buf because vol->updating is set.
Fix this by allocating vol->upd_buf directly after setting vol->updating.

Fixes:
[   31.559338] UBI warning: vol_cdev_release: update of volume 2 not finished, 
volume is damaged
[   31.559340] [ cut here ]
[   31.559343] WARNING: CPU: 1 PID: 2747 at mm/vmalloc.c:1446 
__vunmap+0xe3/0x110()
[   31.559344] Trying to vfree() nonexistent vm area (c90001f2b000)
[   31.559345] Modules linked in:
[   31.565620]  0bba 88002a0cbdb0 818f0497 
88003b9ba148
[   31.566347]  88002a0cbde0 8156f515 88003b9ba148 
0bba
[   31.567073]    88002a0cbe88 
8156c10a
[   31.567793] Call Trace:
[   31.568034]  [] dump_stack+0x4e/0x7a
[   31.568510]  [] ubi_io_write_vid_hdr+0x155/0x160
[   31.569084]  [] ubi_eba_write_leb+0x23a/0x870
[   31.569628]  [] vol_cdev_write+0x226/0x380
[   31.570155]  [] vfs_write+0xb5/0x1f0
[   31.570627]  [] SyS_pwrite64+0x6a/0xa0
[   31.571123]  [] system_call_fastpath+0x16/0x1b

Cc: 
Signed-off-by: Richard Weinberger 
Signed-off-by: Artem Bityutskiy 
---
 drivers/mtd/ubi/upd.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/ubi/upd.c b/drivers/mtd/ubi/upd.c
index c61c277..5e06753 100644
--- a/drivers/mtd/ubi/upd.c
+++ b/drivers/mtd/ubi/upd.c
@@ -124,6 +124,10 @@ int ubi_start_update(struct ubi_device *ubi, struct 
ubi_volume *vol,
ubi_assert(!vol->updating && !vol->changing_leb);
vol->updating = 1;
 
+   vol->upd_buf = vmalloc(ubi->leb_size);
+   if (!vol->upd_buf)
+   return -ENOMEM;
+
err = set_update_marker(ubi, vol);
if (err)
return err;
@@ -143,14 +147,12 @@ int ubi_start_update(struct ubi_device *ubi, struct 
ubi_volume *vol,
err = clear_update_marker(ubi, vol, 0);
if (err)
return err;
+
+   vfree(vol->upd_buf);
vol->updating = 0;
return 0;
}
 
-   vol->upd_buf = vmalloc(ubi->leb_size);
-   if (!vol->upd_buf)
-   return -ENOMEM;
-
vol->upd_ebs = div_u64(bytes + vol->usable_leb_size - 1,
   vol->usable_leb_size);
vol->upd_bytes = bytes;
-- 
1.9.1


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


[PATCH 32/62] UBI: Fastmap: Fix leb_count unbalance

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

If a LEB is unmapped we have to decrement leb_count as well.

Signed-off-by: Richard Weinberger 

Conflicts:
drivers/mtd/ubi/fastmap.c

Fixed minor conflict.

Signed-off-by: Teresa Remmet 
---
 drivers/mtd/ubi/fastmap.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index d94e1d9..a9efc9c 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -361,6 +361,7 @@ static void unmap_peb(struct ubi_attach_info *ai, int pnum)
aeb = rb_entry(node2, struct ubi_ainf_peb, u.rb);
if (aeb->pnum == pnum) {
rb_erase(&aeb->u.rb, &av->root);
+   av->leb_count--;
kfree(aeb);
return;
}
-- 
1.9.1


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


[PATCH 17/62] UBI: fix out of bounds write

2016-05-23 Thread Teresa Remmet
From: Brian Norris 

If aeb->len >= vol->reserved_pebs, we should not be writing aeb into the
PEB->LEB mapping.

Caught by Coverity, CID #711212.

Cc: stable 
Signed-off-by: Brian Norris 
Signed-off-by: Richard Weinberger 
---
 drivers/mtd/ubi/eba.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index 1dbf126..bb89d10 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -1306,7 +1306,8 @@ int ubi_eba_init(struct ubi_device *ubi, struct 
ubi_attach_info *ai)
 * during re-size.
 */
ubi_move_aeb_to_list(av, aeb, &ai->erase);
-   vol->eba_tbl[aeb->lnum] = aeb->pnum;
+   else
+   vol->eba_tbl[aeb->lnum] = aeb->pnum;
}
}
 
-- 
1.9.1


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


[PATCH 15/62] UBI: fix missing brace control flow

2016-05-23 Thread Teresa Remmet
From: Brian Norris 

commit 0e707ae79ba3 ("UBI: do propagate positive error codes up") seems
to have produced an unintended change in the control flow here.

Completely untested, but it looks obvious.

Caught by Coverity, which didn't like the indentation. CID 1271184.

Signed-off-by: Brian Norris 
Cc: Dan Carpenter 
Signed-off-by: Richard Weinberger 
---
 drivers/mtd/ubi/eba.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index b8f5091..1dbf126 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -400,9 +400,10 @@ retry:
ubi_warn(ubi, "corrupted VID header at 
PEB %d, LEB %d:%d",
 pnum, vol_id, lnum);
err = -EBADMSG;
-   } else
+   } else {
err = -EINVAL;
ubi_ro_mode(ubi);
+   }
}
goto out_free;
} else if (err == UBI_IO_BITFLIPS)
-- 
1.9.1


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


[PATCH 05/62] UBI: Fix trivial typo in __schedule_ubi_work

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

s/of/if/

Signed-off-by: Richard Weinberger 
Signed-off-by: Artem Bityutskiy 
---
 drivers/mtd/ubi/wl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index cdfc41c0..9c5b9b8 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -791,7 +791,7 @@ repeat:
  * @wrk: the work to schedule
  *
  * This function adds a work defined by @wrk to the tail of the pending works
- * list. Can only be used of ubi->work_sem is already held in read mode!
+ * list. Can only be used if ubi->work_sem is already held in read mode!
  */
 static void __schedule_ubi_work(struct ubi_device *ubi, struct ubi_work *wrk)
 {
-- 
1.9.1


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


[PATCH 21/62] UBI: Fastmap: Make ubi_refill_pools() fair

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

Currently ubi_refill_pools() first fills the first and then
the second one.
If only very few free PEBs are available the second pool can get
zero PEBs.
Change ubi_refill_pools() to distribute free PEBs fair between
all pools.

Signed-off-by: Richard Weinberger 
Reviewed-by: Guido Martínez 

Conflicts:
drivers/mtd/ubi/wl.c

Fixed minor conflict.

Signed-off-by: Teresa Remmet 
---
 drivers/mtd/ubi/wl.c | 86 ++--
 1 file changed, 49 insertions(+), 37 deletions(-)

diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 21838f6..5d89323 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -194,6 +194,7 @@ static void wl_tree_add(struct ubi_wl_entry *e, struct 
rb_root *root)
rb_insert_color(&e->u.rb, root);
 }
 
+#ifndef CONFIG_MTD_UBI_FASTMAP
 /**
  * do_work - do one pending work.
  * @ubi: UBI device description object
@@ -254,6 +255,7 @@ static int produce_free_peb(struct ubi_device *ubi)
 
return 0;
 }
+#endif
 
 /**
  * in_wl_tree - check if wear-leveling entry is present in a WL RB-tree.
@@ -492,6 +494,7 @@ static struct ubi_wl_entry *wl_get_wle(struct ubi_device 
*ubi)
return e;
 }
 
+#ifndef CONFIG_MTD_UBI_FASTMAP
 /**
  * wl_get_peb - get a physical eraseblock.
  * @ubi: UBI device description object
@@ -525,6 +528,7 @@ retry:
 
return e->pnum;
 }
+#endif
 
 #ifdef CONFIG_MTD_UBI_FASTMAP
 /**
@@ -546,58 +550,60 @@ static void return_unused_pool_pebs(struct ubi_device 
*ubi,
 }
 
 /**
- * refill_wl_pool - refills all the fastmap pool used by the
- * WL sub-system.
+ * ubi_refill_pools - refills all fastmap PEB pools.
  * @ubi: UBI device description object
  */
-static void refill_wl_pool(struct ubi_device *ubi)
+void ubi_refill_pools(struct ubi_device *ubi)
 {
+   struct ubi_fm_pool *wl_pool = &ubi->fm_wl_pool;
+   struct ubi_fm_pool *pool = &ubi->fm_pool;
struct ubi_wl_entry *e;
-   struct ubi_fm_pool *pool = &ubi->fm_wl_pool;
+   int enough;
 
+   return_unused_pool_pebs(ubi, wl_pool);
return_unused_pool_pebs(ubi, pool);
 
-   for (pool->size = 0; pool->size < pool->max_size; pool->size++) {
-   if (!ubi->free.rb_node ||
-  (ubi->free_count - ubi->beb_rsvd_pebs < 5))
-   break;
+   wl_pool->size = 0;
+   pool->size = 0;
 
-   e = find_wl_entry(ubi, &ubi->free, WL_FREE_MAX_DIFF);
-   self_check_in_wl_tree(ubi, e, &ubi->free);
-   rb_erase(&e->u.rb, &ubi->free);
-   ubi->free_count--;
+   for (;;) {
+   enough = 0;
+   if (pool->size < pool->max_size) {
+   if (!ubi->free.rb_node ||
+  (ubi->free_count - ubi->beb_rsvd_pebs < 5))
+   break;
 
-   pool->pebs[pool->size] = e->pnum;
-   }
-   pool->used = 0;
-}
+   e = wl_get_wle(ubi);
+   if (!e)
+   break;
 
-/**
- * refill_wl_user_pool - refills all the fastmap pool used by ubi_wl_get_peb.
- * @ubi: UBI device description object
- */
-static void refill_wl_user_pool(struct ubi_device *ubi)
-{
-   struct ubi_fm_pool *pool = &ubi->fm_pool;
+   pool->pebs[pool->size] = e->pnum;
+   pool->size++;
+   } else
+   enough++;
 
-   return_unused_pool_pebs(ubi, pool);
+   if (wl_pool->size < wl_pool->max_size) {
+   if (!ubi->free.rb_node ||
+  (ubi->free_count - ubi->beb_rsvd_pebs < 5))
+   break;
+
+   e = find_wl_entry(ubi, &ubi->free, WL_FREE_MAX_DIFF);
+   self_check_in_wl_tree(ubi, e, &ubi->free);
+   rb_erase(&e->u.rb, &ubi->free);
+   ubi->free_count--;
+
+   wl_pool->pebs[wl_pool->size] = e->pnum;
+   wl_pool->size++;
+   } else
+   enough++;
 
-   for (pool->size = 0; pool->size < pool->max_size; pool->size++) {
-   pool->pebs[pool->size] = wl_get_peb(ubi);
-   if (pool->pebs[pool->size] < 0)
+   if (enough == 2)
break;
}
+
+   wl_pool->used = 0;
pool->used = 0;
-}
 
-/**
- * ubi_refill_pools - refills all fastmap PEB pools.
- * @ubi: UBI device description object
- */
-void ubi_refill_pools(struct ubi_device *ubi)
-{
-   refill_wl_pool(ubi);
-   refill_wl_user_pool(ubi);
 }
 
 /* ubi_wl_get_peb - works exaclty like __wl_get_peb but

[PATCH 12/62] UBI: clean-up printing helpers

2016-05-23 Thread Teresa Remmet
From: Artem Bityutskiy 

Let's prefix UBI messages with 'ubiX' instead of 'UBI-X' - this is more
consistent with the way we name UBI devices.

Also, commit "32608703 UBI: Extend UBI layer debug/messaging capabilities"
added the function name print to 'ubi_msg()' - lets revert this change, since
these messages are supposed to be just informative messages, and not debugging
messages.

Signed-off-by: Artem Bityutskiy 

Conflicts:
drivers/mtd/ubi/ubi.h

Fixed minor conflict.

Signed-off-by: Teresa Remmet 
---
 drivers/mtd/ubi/ubi.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 6f93575..aa0b9df 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -38,13 +38,13 @@
 
 #define ubi_debug(fmt, ...) pr_debug("UBI: " fmt "\n", ##__VA_ARGS__)
 /* Normal UBI messages */
-#define ubi_msg(ubi, fmt, ...) pr_info("UBI-%d: %s: " fmt "\n", \
-   ubi->ubi_num, __func__, ##__VA_ARGS__)
+#define ubi_msg(ubi, fmt, ...) pr_notice(UBI_NAME_STR "%d: " fmt "\n", \
+ubi->ubi_num, ##__VA_ARGS__)
 /* UBI warning messages */
-#define ubi_warn(ubi, fmt, ...) pr_warn("UBI-%d warning: %s: " fmt "\n", \
+#define ubi_warn(ubi, fmt, ...) pr_warn(UBI_NAME_STR "%d warning: %s: " fmt 
"\n", \
ubi->ubi_num, __func__, ##__VA_ARGS__)
 /* UBI error messages */
-#define ubi_err(ubi, fmt, ...) pr_err("UBI-%d error: %s: " fmt "\n", \
+#define ubi_err(ubi, fmt, ...) pr_err(UBI_NAME_STR "%d error: %s: " fmt "\n", \
  ubi->ubi_num, __func__, ##__VA_ARGS__)
 
 /* Background thread name pattern */
-- 
1.9.1


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


[PATCH 08/62] UBI: vtbl: Use ubi_eba_atomic_leb_change()

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

This is more a cosmetic change than a fix.
By using ubi_eba_atomic_leb_change()
we can guarantee that the first VTBL record is always
correct and we don't really need the second one anymore.
But we have to keep the second one to not break anything.

Artem: add a comment

Signed-off-by: Richard Weinberger 
Signed-off-by: Artem Bityutskiy 
---
 drivers/mtd/ubi/vtbl.c | 23 +--
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c
index 6772612..bc443fb 100644
--- a/drivers/mtd/ubi/vtbl.c
+++ b/drivers/mtd/ubi/vtbl.c
@@ -26,9 +26,12 @@
  * eraseblock stores one volume table copy, i.e. LEB 0 and LEB 1 duplicate each
  * other. This redundancy guarantees robustness to unclean reboots. The volume
  * table is basically an array of volume table records. Each record contains
- * full information about the volume and protected by a CRC checksum.
+ * full information about the volume and protected by a CRC checksum. Note,
+ * nowadays we use the atomic LEB change operation when updating the volume
+ * table, so we do not really need 2 LEBs anymore, but we preserve the older
+ * design for the backward compatibility reasons.
  *
- * The volume table is changed, it is first changed in RAM. Then LEB 0 is
+ * When the volume table is changed, it is first changed in RAM. Then LEB 0 is
  * erased, and the updated volume table is written back to LEB 0. Then same for
  * LEB 1. This scheme guarantees recoverability from unclean reboots.
  *
@@ -89,12 +92,8 @@ int ubi_change_vtbl_record(struct ubi_device *ubi, int idx,
 
memcpy(&ubi->vtbl[idx], vtbl_rec, sizeof(struct ubi_vtbl_record));
for (i = 0; i < UBI_LAYOUT_VOLUME_EBS; i++) {
-   err = ubi_eba_unmap_leb(ubi, layout_vol, i);
-   if (err)
-   return err;
-
-   err = ubi_eba_write_leb(ubi, layout_vol, i, ubi->vtbl, 0,
-   ubi->vtbl_size);
+   err = ubi_eba_atomic_leb_change(ubi, layout_vol, i, ubi->vtbl,
+   ubi->vtbl_size);
if (err)
return err;
}
@@ -141,12 +140,8 @@ int ubi_vtbl_rename_volumes(struct ubi_device *ubi,
 
layout_vol = ubi->volumes[vol_id2idx(ubi, UBI_LAYOUT_VOLUME_ID)];
for (i = 0; i < UBI_LAYOUT_VOLUME_EBS; i++) {
-   err = ubi_eba_unmap_leb(ubi, layout_vol, i);
-   if (err)
-   return err;
-
-   err = ubi_eba_write_leb(ubi, layout_vol, i, ubi->vtbl, 0,
-   ubi->vtbl_size);
+   err = ubi_eba_atomic_leb_change(ubi, layout_vol, i, ubi->vtbl,
+   ubi->vtbl_size);
if (err)
return err;
}
-- 
1.9.1


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


[PATCH 23/62] UBI: Fastmap: Fix memory leaks while closing the WL sub-system

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

Add a ubi_fastmap_close() to free all resources used by fastmap
at WL shutdown.

Signed-off-by: Richard Weinberger 
Tested-by: Guido Martínez 
Reviewed-by: Guido Martínez 
---
 drivers/mtd/ubi/wl.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index fd384c6..8875ec7 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -1857,6 +1857,22 @@ static void protection_queue_destroy(struct ubi_device 
*ubi)
}
 }
 
+static void ubi_fastmap_close(struct ubi_device *ubi)
+{
+#ifdef CONFIG_MTD_UBI_FASTMAP
+   int i;
+
+   return_unused_pool_pebs(ubi, &ubi->fm_pool);
+   return_unused_pool_pebs(ubi, &ubi->fm_wl_pool);
+
+   if (ubi->fm) {
+   for (i = 0; i < ubi->fm->used_blocks; i++)
+   kfree(ubi->fm->e[i]);
+   }
+   kfree(ubi->fm);
+#endif
+}
+
 /**
  * ubi_wl_close - close the wear-leveling sub-system.
  * @ubi: UBI device description object
@@ -1864,6 +1880,7 @@ static void protection_queue_destroy(struct ubi_device 
*ubi)
 void ubi_wl_close(struct ubi_device *ubi)
 {
dbg_wl("close the WL sub-system");
+   ubi_fastmap_close(ubi);
shutdown_work(ubi);
protection_queue_destroy(ubi);
tree_destroy(&ubi->used);
-- 
1.9.1


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


[PATCH 25/62] UBI: Fastmap: Wrap fastmap specific function in a ifdef

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

...such that we can implement NOP variants of some functions.
This will help to reduce fastmap specific ifdefs in other c files.

Signed-off-by: Richard Weinberger 
Reviewed-by: Tanya Brokhman 

Conflicts:
drivers/mtd/ubi/ubi.h

Fixed minor conflict.

Signed-off-by: Teresa Remmet 
---
 drivers/mtd/ubi/ubi.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 5bceb53..2ed28f7 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -837,11 +837,16 @@ int ubi_compare_lebs(struct ubi_device *ubi, const struct 
ubi_ainf_peb *aeb,
  int pnum, const struct ubi_vid_hdr *vid_hdr);
 
 /* fastmap.c */
+#ifdef CONFIG_MTD_UBI_FASTMAP
 size_t ubi_calc_fm_size(struct ubi_device *ubi);
 int ubi_update_fastmap(struct ubi_device *ubi);
 int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
 int fm_anchor);
 void ubi_free_fastmap(struct ubi_device *ubi);
+#else
+static inline int ubi_update_fastmap(struct ubi_device *ubi) { return 0; }
+#endif
+
 /*
  * ubi_rb_for_each_entry - walk an RB-tree.
  * @rb: a pointer to type 'struct rb_node' to use as a loop counter
-- 
1.9.1


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


[PATCH 30/62] UBI: Fastmap: Switch to ro mode if invalidate_fastmap() fails

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

We have to switch to ro mode to guarantee that upon next UBI attach
all data is consistent.

Signed-off-by: Richard Weinberger 
---
 drivers/mtd/ubi/fastmap.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index f683d42..d94e1d9 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -1458,8 +1458,10 @@ err:
ret = 0;
if (old_fm) {
ret = invalidate_fastmap(ubi, old_fm);
-   if (ret < 0)
+   if (ret < 0) {
ubi_err(ubi, "Unable to invalidiate current fastmap!");
+   ubi_ro_mode(ubi);
+   }
else if (ret)
ret = 0;
}
-- 
1.9.1


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


[PATCH 22/62] UBI: Fastmap: Don't allocate new ubi_wl_entry objects

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

There is no need to allocate new ones every time, we can reuse
the existing ones.
This makes the code cleaner and more easy to follow.

Signed-off-by: Richard Weinberger 
Reviewed-by: Tanya Brokhman 
Reviewed-by: Guido Martínez 

Conflicts:
drivers/mtd/ubi/fastmap.c

Fixed minor conflict.

Sigend-off-by: Teresa Remmet 
---
 drivers/mtd/ubi/fastmap.c | 30 +-
 drivers/mtd/ubi/wl.c  |  3 ---
 2 files changed, 5 insertions(+), 28 deletions(-)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index bd3a307..2acd3dd 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -1433,18 +1433,6 @@ int ubi_update_fastmap(struct ubi_device *ubi)
return -ENOMEM;
 
new_fm->used_blocks = ubi->fm_size / ubi->leb_size;
-
-   for (i = 0; i < new_fm->used_blocks; i++) {
-   new_fm->e[i] = kzalloc(sizeof(struct ubi_ainf_peb), GFP_KERNEL);
-   if (!new_fm->e[i]) {
-   while (i--)
-   kfree(new_fm->e[i]);
-
-   kfree(new_fm);
-   return -ENOMEM;
-   }
-   }
-
old_fm = ubi->fm;
ubi->fm = NULL;
 
@@ -1478,12 +1466,9 @@ int ubi_update_fastmap(struct ubi_device *ubi)
ubi_err(ubi, "could not erase old fastmap PEB");
goto err;
}
-
-   new_fm->e[i]->pnum = old_fm->e[i]->pnum;
-   new_fm->e[i]->ec = old_fm->e[i]->ec;
+   new_fm->e[i] = old_fm->e[i];
} else {
-   new_fm->e[i]->pnum = tmp_e->pnum;
-   new_fm->e[i]->ec = tmp_e->ec;
+   new_fm->e[i] = tmp_e;
 
if (old_fm)
ubi_wl_put_fm_peb(ubi, old_fm->e[i], i,
@@ -1506,16 +1491,13 @@ int ubi_update_fastmap(struct ubi_device *ubi)
  i, 0);
goto err;
}
-
-   new_fm->e[0]->pnum = old_fm->e[0]->pnum;
+   new_fm->e[0] = old_fm->e[0];
new_fm->e[0]->ec = ret;
} else {
/* we've got a new anchor PEB, return the old one */
ubi_wl_put_fm_peb(ubi, old_fm->e[0], 0,
  old_fm->to_be_tortured[0]);
-
-   new_fm->e[0]->pnum = tmp_e->pnum;
-   new_fm->e[0]->ec = tmp_e->ec;
+   new_fm->e[0] = tmp_e;
}
} else {
if (!tmp_e) {
@@ -1528,9 +1510,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
ret = -ENOSPC;
goto err;
}
-
-   new_fm->e[0]->pnum = tmp_e->pnum;
-   new_fm->e[0]->ec = tmp_e->ec;
+   new_fm->e[0] = tmp_e;
}
 
ret = ubi_write_fastmap(ubi, new_fm);
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 5d89323..fd384c6 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -947,9 +947,6 @@ int ubi_wl_put_fm_peb(struct ubi_device *ubi, struct 
ubi_wl_entry *fm_e,
e = fm_e;
ubi_assert(e->ec >= 0);
ubi->lookuptbl[pnum] = e;
-   } else {
-   e->ec = fm_e->ec;
-   kfree(fm_e);
}
 
vol_id = lnum ? UBI_FM_DATA_VOLUME_ID : UBI_FM_SB_VOLUME_ID;
-- 
1.9.1


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


[PATCH 11/62] UBI: extend UBI layer debug/messaging capabilities - cosmetics

2016-05-23 Thread Teresa Remmet
From: Tanya Brokhman 

Some cosmetic fixes to the patch "UBI: Extend UBI layer debug/messaging
capabilities".

Signed-off-by: Tanya Brokhman 
Signed-off-by: Artem Bityutskiy 

Conflicts:
drivers/mtd/ubi/build.c
drivers/mtd/ubi/cdev.c
drivers/mtd/ubi/io.c
drivers/mtd/ubi/wl.c

Reworked it for barebox.

Signed-off-by: Teresa Remmet 
---
 drivers/mtd/ubi/build.c | 2 +-
 drivers/mtd/ubi/vtbl.c  | 7 +++
 drivers/mtd/ubi/wl.c| 5 +
 3 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index ae9afa7..2295c67 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -556,7 +556,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
 
/* Make sure ubi_num is not busy */
if (ubi_devices[ubi_num]) {
-   ubi_err(ubi, "ubi%d already exists", ubi_num);
+   ubi_err(ubi, "already exists");
return -EEXIST;
}
}
diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c
index bc443fb..0bc824e 100644
--- a/drivers/mtd/ubi/vtbl.c
+++ b/drivers/mtd/ubi/vtbl.c
@@ -644,14 +644,13 @@ static int init_volumes(struct ubi_device *ubi,
 
 /**
  * check_av - check volume attaching information.
- * @ubi: UBI device description object
  * @vol: UBI volume description object
  * @av: volume attaching information
  *
  * This function returns zero if the volume attaching information is consistent
  * to the data read from the volume tabla, and %-EINVAL if not.
  */
-static int check_av(const struct ubi_device *ubi, const struct ubi_volume *vol,
+static int check_av(const struct ubi_volume *vol,
const struct ubi_ainf_volume *av)
 {
int err;
@@ -679,7 +678,7 @@ static int check_av(const struct ubi_device *ubi, const 
struct ubi_volume *vol,
return 0;
 
 bad:
-   ubi_err(ubi, "bad attaching information, error %d", err);
+   ubi_err(vol->ubi, "bad attaching information, error %d", err);
ubi_dump_av(av);
ubi_dump_vol_info(vol);
return -EINVAL;
@@ -740,7 +739,7 @@ static int check_attaching_info(const struct ubi_device 
*ubi,
ubi_msg(ubi, "finish volume %d removal", av->vol_id);
ubi_remove_av(ai, av);
} else if (av) {
-   err = check_av(ubi, vol, av);
+   err = check_av(vol, av);
if (err)
return err;
}
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index dcc012c..aaa882e 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -439,11 +439,8 @@ struct ubi_wl_entry *ubi_wl_get_fm_peb(struct ubi_device 
*ubi, int anchor)
 {
struct ubi_wl_entry *e = NULL;
 
-   if (!ubi->free.rb_node || (ubi->free_count - ubi->beb_rsvd_pebs < 1)) {
-   ubi_warn(ubi, "Can't get peb for fastmap:anchor=%d, 
free_cnt=%d, reserved=%d",
-anchor, ubi->free_count, ubi->beb_rsvd_pebs);
+   if (!ubi->free.rb_node || (ubi->free_count - ubi->beb_rsvd_pebs < 1))
goto out;
-   }
 
if (anchor)
e = find_anchor_wl_entry(&ubi->free);
-- 
1.9.1


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


[PATCH 20/62] UBI: Split __wl_get_peb()

2016-05-23 Thread Teresa Remmet
From: Richard Weinberger 

Make it two functions, wl_get_wle() and wl_get_peb().
wl_get_peb() works exactly like __wl_get_peb() but wl_get_wle()
does not call produce_free_peb().
While refilling the fastmap user pool we cannot release ubi->wl_lock
as produce_free_peb() does.
Hence the fastmap logic uses now wl_get_wle().

Signed-off-by: Richard Weinberger 

Conflicts:
drivers/mtd/ubi/wl.c

Fixed minor conflict.

Signed-off-by: Teresa Remmet 
---
 drivers/mtd/ubi/wl.c | 63 
 1 file changed, 39 insertions(+), 24 deletions(-)

diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index adbb29b..21838f6 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -462,13 +462,46 @@ out:
 #endif
 
 /**
- * __wl_get_peb - get a physical eraseblock.
+ * wl_get_wle - get a mean wl entry to be used by wl_get_peb() or
+ * refill_wl_user_pool().
+ * @ubi: UBI device description object
+ *
+ * This function returns a a wear leveling entry in case of success and
+ * NULL in case of failure.
+ */
+static struct ubi_wl_entry *wl_get_wle(struct ubi_device *ubi)
+{
+   struct ubi_wl_entry *e;
+
+   e = find_mean_wl_entry(ubi, &ubi->free);
+   if (!e) {
+   ubi_err(ubi, "no free eraseblocks");
+   return NULL;
+   }
+
+   self_check_in_wl_tree(ubi, e, &ubi->free);
+
+   /*
+* Move the physical eraseblock to the protection queue where it will
+* be protected from being moved for some time.
+*/
+   rb_erase(&e->u.rb, &ubi->free);
+   ubi->free_count--;
+   dbg_wl("PEB %d EC %d", e->pnum, e->ec);
+
+   return e;
+}
+
+/**
+ * wl_get_peb - get a physical eraseblock.
  * @ubi: UBI device description object
  *
  * This function returns a physical eraseblock in case of success and a
  * negative error code in case of failure.
+ * It is the low level component of ubi_wl_get_peb() in the non-fastmap
+ * case.
  */
-static int __wl_get_peb(struct ubi_device *ubi)
+static int wl_get_peb(struct ubi_device *ubi)
 {
int err;
struct ubi_wl_entry *e;
@@ -487,27 +520,9 @@ retry:
goto retry;
}
 
-   e = find_mean_wl_entry(ubi, &ubi->free);
-   if (!e) {
-   ubi_err(ubi, "no free eraseblocks");
-   return -ENOSPC;
-   }
-
-   self_check_in_wl_tree(ubi, e, &ubi->free);
-
-   /*
-* Move the physical eraseblock to the protection queue where it will
-* be protected from being moved for some time.
-*/
-   rb_erase(&e->u.rb, &ubi->free);
-   ubi->free_count--;
-   dbg_wl("PEB %d EC %d", e->pnum, e->ec);
-#ifndef CONFIG_MTD_UBI_FASTMAP
-   /* We have to enqueue e only if fastmap is disabled,
-* is fastmap enabled prot_queue_add() will be called by
-* ubi_wl_get_peb() after removing e from the pool. */
+   e = wl_get_wle(ubi);
prot_queue_add(ubi, e);
-#endif
+
return e->pnum;
 }
 
@@ -568,7 +583,7 @@ static void refill_wl_user_pool(struct ubi_device *ubi)
return_unused_pool_pebs(ubi, pool);
 
for (pool->size = 0; pool->size < pool->max_size; pool->size++) {
-   pool->pebs[pool->size] = __wl_get_peb(ubi);
+   pool->pebs[pool->size] = wl_get_peb(ubi);
if (pool->pebs[pool->size] < 0)
break;
}
@@ -646,7 +661,7 @@ int ubi_wl_get_peb(struct ubi_device *ubi)
 {
int peb, err;
 
-   peb = __wl_get_peb(ubi);
+   peb = wl_get_peb(ubi);
 
if (peb < 0)
return peb;
-- 
1.9.1


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


  1   2   3   4   >