[PATCH v2 1/2] common: state: Add property to protect existing data

2018-04-12 Thread Daniel Schultz
After an update to a newer barebox version with an enabled state
framework, existing data in storage memories could be overwritten.

Add a new property to check in front of every write task, if the meta
magic field only contains the magic number, zeros or ones.

Signed-off-by: Daniel Schultz 
---
Changes:
v2: Added check for circular backend
Improved error message if content was found

 .../devicetree/bindings/barebox/barebox,state.rst |  3 +++
 common/state/backend_bucket_circular.c|  8 +---
 common/state/backend_bucket_direct.c  |  2 ++
 common/state/state.c  | 19 ++-
 common/state/state.h  |  2 ++
 5 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/barebox/barebox,state.rst 
b/Documentation/devicetree/bindings/barebox/barebox,state.rst
index 872bac0..2893937 100644
--- a/Documentation/devicetree/bindings/barebox/barebox,state.rst
+++ b/Documentation/devicetree/bindings/barebox/barebox,state.rst
@@ -55,6 +55,9 @@ Optional Properties
 * ``algo``: A HMAC algorithm used to detect manipulation of the data
   or header, sensible values follow this pattern ``hmac()``,
   e.g. ``hmac(sha256)``. Only available for the ``backend-type`` ``raw``.
+* ``keep-previous-content``: Check if a the bucket meta magic field contains
+  other data than the magic value. If so, the backend will not write the state
+  to prevent unconditionally overwrites of existing data.
 
 .. note:: For the ``backend-storage-type`` the keyword ``noncircular`` is still
supported as a fall back to an old storage format. Recommendation is to not
diff --git a/common/state/backend_bucket_circular.c 
b/common/state/backend_bucket_circular.c
index 2324903..933493e 100644
--- a/common/state/backend_bucket_circular.c
+++ b/common/state/backend_bucket_circular.c
@@ -396,11 +396,13 @@ static int state_backend_bucket_circular_init(
meta = (struct 
state_backend_storage_bucket_circular_meta *)
(buf + sub_offset + circ->writesize - 
sizeof(*meta));
 
-   if (meta->magic != circular_magic)
+   if (meta->magic != circular_magic) {
written_length = 0;
-   else
+   if (meta->magic != ~0 && !!meta->magic)
+   bucket->wrong_magic = 1;
+   } else {
written_length = meta->written_length;
-
+   }
break;
}
}
diff --git a/common/state/backend_bucket_direct.c 
b/common/state/backend_bucket_direct.c
index 958696e..9d6a337 100644
--- a/common/state/backend_bucket_direct.c
+++ b/common/state/backend_bucket_direct.c
@@ -69,6 +69,8 @@ static int state_backend_bucket_direct_read(struct 
state_backend_storage_bucket
if (meta.magic == direct_magic) {
read_len = meta.written_length;
} else {
+   if (meta.magic != ~0 && !!meta.magic)
+   bucket->wrong_magic = 1;
if (!IS_ENABLED(CONFIG_STATE_BACKWARD_COMPATIBLE)) {
dev_err(direct->dev, "No meta data header found\n");
dev_dbg(direct->dev, "Enable backward compatibility or 
increase stride size\n");
diff --git a/common/state/state.c b/common/state/state.c
index 73dfb58..25d9502 100644
--- a/common/state/state.c
+++ b/common/state/state.c
@@ -44,6 +44,8 @@ int state_save(struct state *state)
void *buf;
ssize_t len;
int ret;
+   struct state_backend_storage_bucket *bucket;
+   struct state_backend_storage *storage;
 
if (!state->dirty)
return 0;
@@ -55,7 +57,19 @@ int state_save(struct state *state)
return ret;
}
 
-   ret = state_storage_write(&state->storage, buf, len);
+   storage = &state->storage;
+   if (state->keep_prev_content) {
+   bool has_content = 0;
+   list_for_each_entry(bucket, &storage->buckets, bucket_list)
+   has_content |= bucket->wrong_magic;
+   if (has_content) {
+   dev_err(&state->dev, "Found foreign content on backend, 
won't overwrite.\n");
+   ret = -EPERM;
+   goto out;
+   }
+   }
+
+   ret = state_storage_write(storage, buf, len);
if (ret) {
dev_err(&state->dev, "Failed to write packed state, %d\n", ret);
goto out;
@@ -623,6 +637,9 @@ struct state *state_new_from_node(struct device_node *node, 
bool readonly)
 
  

[PATCH v2 2/2] ARM: dts: AM335x: Add keep-previous-content property

2018-04-12 Thread Daniel Schultz
Some of our customers may have data in the EEPROM region, which we newly
have assigned as state partition. This property should prevent them of
data loses.

Signed-off-by: Daniel Schultz 
---
 arch/arm/dts/am335x-phytec-state.dtsi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/dts/am335x-phytec-state.dtsi 
b/arch/arm/dts/am335x-phytec-state.dtsi
index fbc35b9..6bca597 100644
--- a/arch/arm/dts/am335x-phytec-state.dtsi
+++ b/arch/arm/dts/am335x-phytec-state.dtsi
@@ -23,6 +23,7 @@
backend-type = "raw";
backend = <&backend_state_eeprom>;
backend-stridesize = <40>;
+   keep-previous-content;
 
#address-cells = <1>;
#size-cells = <1>;
-- 
2.7.4


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


Re: [PATCH 3/3] drivers: mtd: nand: omap: Return stat value

2018-02-23 Thread Daniel Schultz


On 02/16/2018 08:56 AM, Sascha Hauer wrote:

On Thu, Feb 15, 2018 at 01:51:26PM +0100, Daniel Schultz wrote:

Hi Sascha,


On 01/30/2018 08:11 AM, Sascha Hauer wrote:

On Mon, Jan 29, 2018 at 02:04:11PM +0100, Daniel Schultz wrote:

The read page function should return the total count of flipped bits,
otherwise the caller always thinks no bitflip occured.

Signed-off-by: Daniel Schultz 
---
   drivers/mtd/nand/nand_omap_gpmc.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/nand_omap_gpmc.c 
b/drivers/mtd/nand/nand_omap_gpmc.c
index e18ce63..38f4960 100644
--- a/drivers/mtd/nand/nand_omap_gpmc.c
+++ b/drivers/mtd/nand/nand_omap_gpmc.c
@@ -712,7 +712,7 @@ static int omap_gpmc_read_page_bch_rom_mode(struct mtd_info 
*mtd,
else
mtd->ecc_stats.corrected += stat;
-   return 0;
+   return stat;
   }

I'm afraid this is not enough. read_page should return the maximum
number of bitflips in any ECC step. You first have to change
omap_correct_bch() so that it returns this number.

ahh, we worked on this problem a half year ago and it seems like three
patches are missing upstream:

http://lists.infradead.org/pipermail/barebox/2017-June/030385.html
http://lists.infradead.org/pipermail/barebox/2017-June/030384.html
http://lists.infradead.org/pipermail/barebox/2017-June/030355.html

Oh, I see. It seems I have either forgotten to merge them or I have
waited for feedback. Could you create a series for all missing patches
including your new patch and resend it, provided it works as expected of
course?

Yes, I will do this as soon as I have time for it.


--
Mit freundlichen Grüßen,
With best regards,
  Daniel Schultz



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


Re: [PATCH 3/3] drivers: mtd: nand: omap: Return stat value

2018-02-15 Thread Daniel Schultz

Hi Sascha,


On 01/30/2018 08:11 AM, Sascha Hauer wrote:

On Mon, Jan 29, 2018 at 02:04:11PM +0100, Daniel Schultz wrote:

The read page function should return the total count of flipped bits,
otherwise the caller always thinks no bitflip occured.

Signed-off-by: Daniel Schultz 
---
  drivers/mtd/nand/nand_omap_gpmc.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/nand_omap_gpmc.c 
b/drivers/mtd/nand/nand_omap_gpmc.c
index e18ce63..38f4960 100644
--- a/drivers/mtd/nand/nand_omap_gpmc.c
+++ b/drivers/mtd/nand/nand_omap_gpmc.c
@@ -712,7 +712,7 @@ static int omap_gpmc_read_page_bch_rom_mode(struct mtd_info 
*mtd,
else
mtd->ecc_stats.corrected += stat;
  
-	return 0;

+   return stat;
  }

I'm afraid this is not enough. read_page should return the maximum
number of bitflips in any ECC step. You first have to change
omap_correct_bch() so that it returns this number.
ahh, we worked on this problem a half year ago and it seems like three 
patches are missing upstream:


http://lists.infradead.org/pipermail/barebox/2017-June/030385.html
http://lists.infradead.org/pipermail/barebox/2017-June/030384.html
http://lists.infradead.org/pipermail/barebox/2017-June/030355.html

Daniel


Sascha




--
Mit freundlichen Grüßen,
With best regards,
  Daniel Schultz

- Entwicklung -
Tel.:   +49 6131 92 21 457
d.schu...@phytec.de
www.phytec.de

Sie finden uns auch auf: Facebook, LinkedIn, Xing, YouTube

PHYTEC Messtechnik GmbH | Robert-Koch-Str. 39 | 55129 Mainz, Germany
Geschäftsführer: Dipl.-Ing. Michael Mitezki, Dipl.-Ing. Bodo Huber |
Handelsregister Mainz HRB 4656 | Finanzamt Mainz-Mitte | St.Nr. 266500608,
DE 149059855
This E-Mail may contain confidential or privileged information. If you are
not the intended recipient (or have received this E-Mail in error) please
notify the sender immediately and destroy this E-Mail. Any unauthorized
copying, disclosure or distribution of the material in this E-Mail is
strictly forbidden.


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


[PATCH 3/3] drivers: mtd: nand: omap: Return stat value

2018-01-29 Thread Daniel Schultz
The read page function should return the total count of flipped bits,
otherwise the caller always thinks no bitflip occured.

Signed-off-by: Daniel Schultz 
---
 drivers/mtd/nand/nand_omap_gpmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/nand_omap_gpmc.c 
b/drivers/mtd/nand/nand_omap_gpmc.c
index e18ce63..38f4960 100644
--- a/drivers/mtd/nand/nand_omap_gpmc.c
+++ b/drivers/mtd/nand/nand_omap_gpmc.c
@@ -712,7 +712,7 @@ static int omap_gpmc_read_page_bch_rom_mode(struct mtd_info 
*mtd,
else
mtd->ecc_stats.corrected += stat;
 
-   return 0;
+   return stat;
 }
 
 static int omap_gpmc_eccmode(struct gpmc_nand_info *oinfo,
-- 
2.7.4


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


[PATCH 2/3] ARM: configs: am335x_defconfig: Reorder configs

2018-01-29 Thread Daniel Schultz
These configs were added directly in the config file and not with
menuconfig. Reorder these like menuconfig would place them.

Signed-off-by: Daniel Schultz 
---
 arch/arm/configs/am335x_defconfig | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/arm/configs/am335x_defconfig 
b/arch/arm/configs/am335x_defconfig
index 5a236fb..09dde90 100644
--- a/arch/arm/configs/am335x_defconfig
+++ b/arch/arm/configs/am335x_defconfig
@@ -29,12 +29,14 @@ CONFIG_BOOTM_OFTREE=y
 CONFIG_BLSPEC=y
 CONFIG_CONSOLE_ACTIVATE_NONE=y
 CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
+CONFIG_STATE=y
 CONFIG_RESET_SOURCE=y
 CONFIG_DEBUG_INFO=y
 CONFIG_LONGHELP=y
 CONFIG_CMD_IOMEM=y
 CONFIG_CMD_MEMINFO=y
 CONFIG_CMD_ARM_MMUINFO=y
+CONFIG_CMD_MMC_EXTCSD=y
 # CONFIG_CMD_BOOTU is not set
 CONFIG_CMD_BOOTZ=y
 CONFIG_CMD_GO=y
@@ -87,7 +89,6 @@ CONFIG_CMD_OF_DISPLAY_TIMINGS=y
 CONFIG_CMD_OF_FIXUP_STATUS=y
 CONFIG_CMD_OFTREE=y
 CONFIG_CMD_TIME=y
-CONFIG_CMD_MMC_EXTCSD=y
 CONFIG_CMD_STATE=y
 CONFIG_NET=y
 CONFIG_NET_NFS=y
@@ -124,6 +125,7 @@ CONFIG_USB_MUSB_GADGET=y
 CONFIG_MCI=y
 CONFIG_MCI_STARTUP=y
 CONFIG_MCI_OMAP_HSMMC=y
+CONFIG_STATE_DRV=y
 CONFIG_LED=y
 CONFIG_LED_GPIO=y
 CONFIG_LED_GPIO_OF=y
@@ -143,5 +145,3 @@ CONFIG_FS_FAT_LFN=y
 CONFIG_FS_UBIFS=y
 CONFIG_FS_UBIFS_COMPRESSION_LZO=y
 CONFIG_FS_UBIFS_COMPRESSION_ZLIB=y
-CONFIG_STATE=y
-CONFIG_STATE_DRV=y
-- 
2.7.4


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


[PATCH 1/3] commands: ubi: ubiupdatevol: Reduce error code to 0 or 1

2018-01-29 Thread Daniel Schultz
do_ubiupdatevol can either return 0 or the ioctl return value. This is
not in conformity with the other ubi comannds return values.

Signed-off-by: Daniel Schultz 
---
 commands/ubi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/commands/ubi.c b/commands/ubi.c
index 5e27584..de5633c 100644
--- a/commands/ubi.c
+++ b/commands/ubi.c
@@ -82,7 +82,7 @@ error:
close(fd_vol);
 error_img:
close(fd_img);
-   return ret;
+   return ret ? 1 : 0;
 }
 
 
-- 
2.7.4


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


Re: [PATCH 1/2] common: state: Add property to protect existing data

2018-01-15 Thread Daniel Schultz

Hi,

just wanted to remind you to these patches.

Daniel


On 12/14/2017 04:51 PM, Daniel Schultz wrote:

After an update to a newer barebox version with an enabled state
framework, existing data in storage memories could be overwritten.

Add a new property to check in front of every write task, if the meta
magic field only contains the magic number, zeros or ones.

Signed-off-by: Daniel Schultz 
---
  .../devicetree/bindings/barebox/barebox,state.rst |  3 +++
  common/state/backend_bucket_direct.c  |  2 ++
  common/state/backend_storage.c|  1 +
  common/state/state.c  | 19 ++-
  common/state/state.h  |  2 ++
  5 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/barebox/barebox,state.rst 
b/Documentation/devicetree/bindings/barebox/barebox,state.rst
index cebb5f8..db5b041 100644
--- a/Documentation/devicetree/bindings/barebox/barebox,state.rst
+++ b/Documentation/devicetree/bindings/barebox/barebox,state.rst
@@ -55,6 +55,9 @@ Optional Properties
  * ``algo``: A HMAC algorithm used to detect manipulation of the data
or header, sensible values follow this pattern ``hmac()``,
e.g. ``hmac(sha256)``. Only available for the ``backend-type`` ``raw``.
+* ``keep-previous-content``: Check if a the bucket meta magic field contains
+  other data than the magic value. If so, the backend will not write the state
+  to prevent unconditionally overwrites of existing data.
  
  .. note:: For the ``backend-storage-type`` the keyword ``noncircular`` is still

 supported as a fall back to an old storage format. Recommendation is to not
diff --git a/common/state/backend_bucket_direct.c 
b/common/state/backend_bucket_direct.c
index 958696e..9d6a337 100644
--- a/common/state/backend_bucket_direct.c
+++ b/common/state/backend_bucket_direct.c
@@ -69,6 +69,8 @@ static int state_backend_bucket_direct_read(struct 
state_backend_storage_bucket
if (meta.magic == direct_magic) {
read_len = meta.written_length;
} else {
+   if (meta.magic != ~0 && !!meta.magic)
+   bucket->wrong_magic = 1;
if (!IS_ENABLED(CONFIG_STATE_BACKWARD_COMPATIBLE)) {
dev_err(direct->dev, "No meta data header found\n");
dev_dbg(direct->dev, "Enable backward compatibility or 
increase stride size\n");
diff --git a/common/state/backend_storage.c b/common/state/backend_storage.c
index c6ebe86..f0a169d 100644
--- a/common/state/backend_storage.c
+++ b/common/state/backend_storage.c
@@ -152,6 +152,7 @@ int state_storage_read(struct state_backend_storage 
*storage,
 * one we want to use.
 */
list_for_each_entry(bucket, &storage->buckets, bucket_list) {
+   bucket->wrong_magic = 0;
ret = bucket->read(bucket, &bucket->buf, &bucket->len);
if (ret == -EUCLEAN)
bucket->needs_refresh = 1;
diff --git a/common/state/state.c b/common/state/state.c
index 6399bd3..e110542 100644
--- a/common/state/state.c
+++ b/common/state/state.c
@@ -44,6 +44,9 @@ int state_save(struct state *state)
void *buf;
ssize_t len;
int ret;
+   struct state_backend_storage_bucket *bucket;
+   struct state_backend_storage *storage;
+   bool has_content;
  
  	if (!state->dirty)

return 0;
@@ -55,7 +58,18 @@ int state_save(struct state *state)
return ret;
}
  
-	ret = state_storage_write(&state->storage, buf, len);

+   storage = &state->storage;
+   if (state->keep_prev_content) {
+   has_content = 0;
+   list_for_each_entry(bucket, &storage->buckets, bucket_list)
+   has_content |= bucket->wrong_magic;
+   if (has_content) {
+   dev_dbg(&state->dev, "Found content on a backend.\n");
+   goto out;
+   }
+   }
+
+   ret = state_storage_write(storage, buf, len);
if (ret) {
dev_err(&state->dev, "Failed to write packed state, %d\n", ret);
goto out;
@@ -605,6 +619,9 @@ struct state *state_new_from_node(struct device_node *node, 
char *path,
}
}
  
+	state->keep_prev_content = of_property_read_bool(node,

+   
"keep-previous-content");
+
state->backend_path = xstrdup(path);
  
  	ret = of_property_read_string(node, "backend-type", &backend_type);

diff --git a/common/state/state.h b/common/state/state.h
index fcc6b9f..a411b96 100644
--- a/common/state/state.h
+++ b/common/state/state.h
@@ -46,6 +46,7 @@ struct state_backend_storage_buck

Re: [PATCH] ARM: boards: phytec-som-am335x: Fallback ram timings

2017-12-22 Thread Daniel Schultz

Hi,


On 12/15/2017 08:49 AM, Sascha Hauer wrote:

Hi Daniel,

On Thu, Dec 14, 2017 at 04:51:15PM +0100, Daniel Schultz wrote:

The 'get_ram_size' function can return false values with 1GB RAMs during
warm reset. If a not-existing RAM size will be returned, the fallback
RAM timings get loaded to prevent hangs.

Just continuing with wrong ram size and fallback timing is not really an
option. It doesn't help the user and only changes the bug reports you
get.

Sascha

yes, sorry. I sent a new patch to remove the bug from our MLO and I will 
investigate for this problem next year, because this seems to be a 
little more trickier.


Daniel

Signed-off-by: Daniel Schultz 
---
  arch/arm/boards/phytec-som-am335x/lowlevel.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boards/phytec-som-am335x/lowlevel.c 
b/arch/arm/boards/phytec-som-am335x/lowlevel.c
index b1576ee..5030966 100644
--- a/arch/arm/boards/phytec-som-am335x/lowlevel.c
+++ b/arch/arm/boards/phytec-som-am335x/lowlevel.c
@@ -174,8 +174,9 @@ static noinline void physom_board_init(void *fdt, int 
sdram, int module_family)
/* Find the ram size and set up the correct ram timings */
ramsize = get_ram_size((long *) 0x8000, SZ_1G);
timing = get_timings_by_size(module_family, ramsize);
+   /* In case of a failure, load generic ram timings as fallback */
if (!timing)
-   hang();
+   timing = get_minimal_timings(module_family);
}
  
  	am335x_sdram_init(DDR_IOCTRL, &physom_cmd,

--
2.7.4


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



--
Mit freundlichen Grüßen,
With best regards,
  Daniel Schultz

- Entwicklung -
Tel.:   +49 6131 92 21 457
d.schu...@phytec.de
www.phytec.de

Sie finden uns auch auf: Facebook, LinkedIn, Xing, YouTube

PHYTEC Messtechnik GmbH | Robert-Koch-Str. 39 | 55129 Mainz, Germany
Geschäftsführer: Dipl.-Ing. Michael Mitezki, Dipl.-Ing. Bodo Huber |
Handelsregister Mainz HRB 4656 | Finanzamt Mainz-Mitte | St.Nr. 266500608,
DE 149059855
This E-Mail may contain confidential or privileged information. If you are
not the intended recipient (or have received this E-Mail in error) please
notify the sender immediately and destroy this E-Mail. Any unauthorized
copying, disclosure or distribution of the material in this E-Mail is
strictly forbidden.


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


[PATCH] ARM: boards: phytec-som-am335x: Revert unified MLO for 1GB

2017-12-22 Thread Daniel Schultz
There is a problem in the data path between 1GB RAM devices and the
core, which leads to wrong read operations after DDR initialization
in soft resets. This needs more investigation, but until we didn't
found the problem, we will return to the origin MLO for 1GB RAM devices
with static RAM timings and without memory access.

Signed-off-by: Daniel Schultz 
---
 arch/arm/boards/phytec-som-am335x/lowlevel.c | 1 +
 images/Makefile.am33xx   | 6 ++
 2 files changed, 7 insertions(+)

diff --git a/arch/arm/boards/phytec-som-am335x/lowlevel.c 
b/arch/arm/boards/phytec-som-am335x/lowlevel.c
index bdd7b30..4b74789 100644
--- a/arch/arm/boards/phytec-som-am335x/lowlevel.c
+++ b/arch/arm/boards/phytec-som-am335x/lowlevel.c
@@ -245,6 +245,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_r2_sram_1024mb, 
am335x_phytec_phycore_som_mlo, PHYCORE_R2_MT41K512M16HA125IT_1024MB);
 PHYTEC_ENTRY_UNIFIED_MLO(start_am33xx_phytec_phycore_r2_sram, 
am335x_phytec_phycore_som_mlo, PHYCORE_R2);
 PHYTEC_ENTRY(start_am33xx_phytec_phycore_nand_sdram, 
am335x_phytec_phycore_som_nand);
 PHYTEC_ENTRY(start_am33xx_phytec_phycore_emmc_sdram, 
am335x_phytec_phycore_som_emmc);
diff --git a/images/Makefile.am33xx b/images/Makefile.am33xx
index 3f29143..50fa019 100644
--- a/images/Makefile.am33xx
+++ b/images/Makefile.am33xx
@@ -51,6 +51,12 @@ FILE_barebox-am33xx-phytec-phycore-r2-mlo.spi.img = 
start_am33xx_phytec_phycore_
 am33xx-mlo-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-r2-mlo.img
 am33xx-mlospi-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-r2-mlo.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_phycore_sram_256mb
 FILE_barebox-am33xx-phytec-phycore-mlo-256mb.img = 
start_am33xx_phytec_phycore_sram_256mb.pblx.mlo
 FILE_barebox-am33xx-phytec-phycore-mlo-256mb.spi.img = 
start_am33xx_phytec_phycore_sram_256mb.pblx.mlospi
-- 
2.7.4


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


[PATCH 2/2] ARM: dts: AM335x: Add keep-previous-content property

2017-12-14 Thread Daniel Schultz
Some of our customers may have data in the EEPROM region, which we newly
have assigned as state partition. This property should prevent them of
data loses.

Signed-off-by: Daniel Schultz 
---
 arch/arm/dts/am335x-phytec-state.dtsi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/dts/am335x-phytec-state.dtsi 
b/arch/arm/dts/am335x-phytec-state.dtsi
index fbc35b9..6bca597 100644
--- a/arch/arm/dts/am335x-phytec-state.dtsi
+++ b/arch/arm/dts/am335x-phytec-state.dtsi
@@ -23,6 +23,7 @@
backend-type = "raw";
backend = <&backend_state_eeprom>;
backend-stridesize = <40>;
+   keep-previous-content;
 
#address-cells = <1>;
#size-cells = <1>;
-- 
2.7.4


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


[PATCH] ARM: boards: phytec-som-am335x: Fallback ram timings

2017-12-14 Thread Daniel Schultz
The 'get_ram_size' function can return false values with 1GB RAMs during
warm reset. If a not-existing RAM size will be returned, the fallback
RAM timings get loaded to prevent hangs.

Signed-off-by: Daniel Schultz 
---
 arch/arm/boards/phytec-som-am335x/lowlevel.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boards/phytec-som-am335x/lowlevel.c 
b/arch/arm/boards/phytec-som-am335x/lowlevel.c
index b1576ee..5030966 100644
--- a/arch/arm/boards/phytec-som-am335x/lowlevel.c
+++ b/arch/arm/boards/phytec-som-am335x/lowlevel.c
@@ -174,8 +174,9 @@ static noinline void physom_board_init(void *fdt, int 
sdram, int module_family)
/* Find the ram size and set up the correct ram timings */
ramsize = get_ram_size((long *) 0x8000, SZ_1G);
timing = get_timings_by_size(module_family, ramsize);
+   /* In case of a failure, load generic ram timings as fallback */
if (!timing)
-   hang();
+   timing = get_minimal_timings(module_family);
}
 
am335x_sdram_init(DDR_IOCTRL, &physom_cmd,
-- 
2.7.4


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


[PATCH 1/2] common: state: Add property to protect existing data

2017-12-14 Thread Daniel Schultz
After an update to a newer barebox version with an enabled state
framework, existing data in storage memories could be overwritten.

Add a new property to check in front of every write task, if the meta
magic field only contains the magic number, zeros or ones.

Signed-off-by: Daniel Schultz 
---
 .../devicetree/bindings/barebox/barebox,state.rst |  3 +++
 common/state/backend_bucket_direct.c  |  2 ++
 common/state/backend_storage.c|  1 +
 common/state/state.c  | 19 ++-
 common/state/state.h  |  2 ++
 5 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/barebox/barebox,state.rst 
b/Documentation/devicetree/bindings/barebox/barebox,state.rst
index cebb5f8..db5b041 100644
--- a/Documentation/devicetree/bindings/barebox/barebox,state.rst
+++ b/Documentation/devicetree/bindings/barebox/barebox,state.rst
@@ -55,6 +55,9 @@ Optional Properties
 * ``algo``: A HMAC algorithm used to detect manipulation of the data
   or header, sensible values follow this pattern ``hmac()``,
   e.g. ``hmac(sha256)``. Only available for the ``backend-type`` ``raw``.
+* ``keep-previous-content``: Check if a the bucket meta magic field contains
+  other data than the magic value. If so, the backend will not write the state
+  to prevent unconditionally overwrites of existing data.
 
 .. note:: For the ``backend-storage-type`` the keyword ``noncircular`` is still
supported as a fall back to an old storage format. Recommendation is to not
diff --git a/common/state/backend_bucket_direct.c 
b/common/state/backend_bucket_direct.c
index 958696e..9d6a337 100644
--- a/common/state/backend_bucket_direct.c
+++ b/common/state/backend_bucket_direct.c
@@ -69,6 +69,8 @@ static int state_backend_bucket_direct_read(struct 
state_backend_storage_bucket
if (meta.magic == direct_magic) {
read_len = meta.written_length;
} else {
+   if (meta.magic != ~0 && !!meta.magic)
+   bucket->wrong_magic = 1;
if (!IS_ENABLED(CONFIG_STATE_BACKWARD_COMPATIBLE)) {
dev_err(direct->dev, "No meta data header found\n");
dev_dbg(direct->dev, "Enable backward compatibility or 
increase stride size\n");
diff --git a/common/state/backend_storage.c b/common/state/backend_storage.c
index c6ebe86..f0a169d 100644
--- a/common/state/backend_storage.c
+++ b/common/state/backend_storage.c
@@ -152,6 +152,7 @@ int state_storage_read(struct state_backend_storage 
*storage,
 * one we want to use.
 */
list_for_each_entry(bucket, &storage->buckets, bucket_list) {
+   bucket->wrong_magic = 0;
ret = bucket->read(bucket, &bucket->buf, &bucket->len);
if (ret == -EUCLEAN)
bucket->needs_refresh = 1;
diff --git a/common/state/state.c b/common/state/state.c
index 6399bd3..e110542 100644
--- a/common/state/state.c
+++ b/common/state/state.c
@@ -44,6 +44,9 @@ int state_save(struct state *state)
void *buf;
ssize_t len;
int ret;
+   struct state_backend_storage_bucket *bucket;
+   struct state_backend_storage *storage;
+   bool has_content;
 
if (!state->dirty)
return 0;
@@ -55,7 +58,18 @@ int state_save(struct state *state)
return ret;
}
 
-   ret = state_storage_write(&state->storage, buf, len);
+   storage = &state->storage;
+   if (state->keep_prev_content) {
+   has_content = 0;
+   list_for_each_entry(bucket, &storage->buckets, bucket_list)
+   has_content |= bucket->wrong_magic;
+   if (has_content) {
+   dev_dbg(&state->dev, "Found content on a backend.\n");
+   goto out;
+   }
+   }
+
+   ret = state_storage_write(storage, buf, len);
if (ret) {
dev_err(&state->dev, "Failed to write packed state, %d\n", ret);
goto out;
@@ -605,6 +619,9 @@ struct state *state_new_from_node(struct device_node *node, 
char *path,
}
}
 
+   state->keep_prev_content = of_property_read_bool(node,
+   
"keep-previous-content");
+
state->backend_path = xstrdup(path);
 
ret = of_property_read_string(node, "backend-type", &backend_type);
diff --git a/common/state/state.h b/common/state/state.h
index fcc6b9f..a411b96 100644
--- a/common/state/state.h
+++ b/common/state/state.h
@@ -46,6 +46,7 @@ struct state_backend_storage_bucket {
void *buf;
ssize_t len;
bool needs_refresh;
+   bool wrong_magic;
 };
 

[PATCH] ARM: boards: phytec-som-am335x: Fix SPI boot script

2017-11-17 Thread Daniel Schultz
Because our SPI NOR flashes are too small, we require a root filesystem
in a NAND media. The kernel bootargs has a wrong parameter and lead to:

VFS: Cannot open root device "ubi0:root" or unknown-block(0,0):

Changed 'ubi.mtd=nand0.root' to 'ubi.mtd=root'.

Signed-off-by: Daniel Schultz 
---
 arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi
index a321aa9..611bc24 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi
@@ -4,4 +4,4 @@ global.bootm.image="/dev/m25p0.kernel"
 global.bootm.oftree="/dev/m25p0.oftree"
 
 # Use rootfs from NAND
-global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=nand0.root 
rootfstype=ubifs"
+global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=root rootfstype=ubifs"
-- 
2.7.4


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


[PATCH v3 4/7] common: state: Add variable_type to state_variable

2017-11-03 Thread Daniel Schultz
Add a pointer in state_variable to the corresponding variable_type array
element.

Signed-off-by: Daniel Schultz 
---
Changes:
v2: New patch
v3: struct variable_type is passed as parameter in the create callbacks.

 common/state/state.c   |  2 +-
 common/state/state.h   |  8 +---
 common/state/state_variables.c | 20 +++-
 3 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/common/state/state.c b/common/state/state.c
index 266d211..98a7db3 100644
--- a/common/state/state.c
+++ b/common/state/state.c
@@ -246,7 +246,7 @@ static int state_convert_node_variable(struct state *state,
}
 
if (conv == STATE_CONVERT_FROM_NODE_CREATE) {
-   sv = vtype->create(state, name, node);
+   sv = vtype->create(state, name, node, vtype);
if (IS_ERR(sv)) {
ret = PTR_ERR(sv);
dev_err(&state->dev, "failed to create %s: %s\n", name,
diff --git a/common/state/state.h b/common/state/state.h
index 81aaec2..7dd163c 100644
--- a/common/state/state.h
+++ b/common/state/state.h
@@ -123,15 +123,17 @@ struct variable_type {
int (*export) (struct state_variable *, struct device_node *,
   enum state_convert);
int (*import) (struct state_variable *, struct device_node *);
-   struct state_variable *(*create) (struct state * state,
- const char *name,
- struct device_node *);
+   struct state_variable *(*create) (struct state *,
+ const char *,
+ struct device_node *,
+ const struct variable_type *);
 };
 
 /* instance of a single variable */
 struct state_variable {
struct state *state;
struct list_head list;
+   const struct variable_type *type;
const char *name;
unsigned int start;
unsigned int size;
diff --git a/common/state/state_variables.c b/common/state/state_variables.c
index 56bcd95..688467d 100644
--- a/common/state/state_variables.c
+++ b/common/state/state_variables.c
@@ -101,7 +101,8 @@ static int state_uint8_set(struct param_d *p, void *priv)
 
 static struct state_variable *state_uint8_create(struct state *state,
 const char *name,
-struct device_node *node)
+struct device_node *node,
+ const struct variable_type *vtype)
 {
struct state_uint32 *su32;
struct param_d *param;
@@ -116,6 +117,7 @@ static struct state_variable *state_uint8_create(struct 
state *state,
}
 
su32->param = param;
+   su32->var.type = vtype;
su32->var.size = sizeof(uint8_t);
 #ifdef __LITTLE_ENDIAN
su32->var.raw = &su32->value;
@@ -129,7 +131,8 @@ static struct state_variable *state_uint8_create(struct 
state *state,
 
 static struct state_variable *state_uint32_create(struct state *state,
  const char *name,
- struct device_node *node)
+ struct device_node *node,
+ const struct variable_type *vtype)
 {
struct state_uint32 *su32;
struct param_d *param;
@@ -144,6 +147,7 @@ static struct state_variable *state_uint32_create(struct 
state *state,
}
 
su32->param = param;
+   su32->var.type = vtype;
su32->var.size = sizeof(uint32_t);
su32->var.raw = &su32->value;
su32->var.state = state;
@@ -218,7 +222,8 @@ static int state_enum32_import(struct state_variable *sv,
 
 static struct state_variable *state_enum32_create(struct state *state,
  const char *name,
- struct device_node *node)
+ struct device_node *node,
+ const struct variable_type *vtype)
 {
struct state_enum32 *enum32;
int ret, i, num_names;
@@ -234,6 +239,7 @@ static struct state_variable *state_enum32_create(struct 
state *state,
 
enum32->names = xzalloc(sizeof(char *) * num_names);
enum32->num_names = num_names;
+   enum32->var.type = vtype;
enum32->var.size = sizeof(uint32_t);
enum32->var.raw = &enum32->value;
enum32->var.state = state;
@@ -300,13 +306,15 @@ static int state_mac_import(struct state_variable *sv, 
struct device_node *node)
 
 static struct state_variable *state_mac_create(struct state *state,
 

[PATCH v3 7/7] ARM: phytec-som-am335x: Set MAC addresses from state

2017-11-03 Thread Daniel Schultz
If a state with the name 'am335x_phytec_mac_state' is available, valid
MAC addresses from this state get registerd to their ethernet device.

Signed-off-by: Daniel Schultz 
---
 arch/arm/boards/phytec-som-am335x/board.c | 21 +
 1 file changed, 21 insertions(+)

diff --git a/arch/arm/boards/phytec-som-am335x/board.c 
b/arch/arm/boards/phytec-som-am335x/board.c
index dc3b84a..9f74981 100644
--- a/arch/arm/boards/phytec-som-am335x/board.c
+++ b/arch/arm/boards/phytec-som-am335x/board.c
@@ -21,10 +21,12 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -65,8 +67,16 @@ static char *nandslots[] = {
"/dev/nand0.barebox_backup.bb",
 };
 
+#define ETH_COUNT 2
+static const char *eth_names[ETH_COUNT] = {"mac0", "mac1"};
+
 static int physom_devices_init(void)
 {
+   struct state *state;
+   u8 mac[6];
+   int state_ret;
+   int state_i;
+
if (!of_machine_is_compatible("phytec,am335x-som"))
return 0;
 
@@ -114,6 +124,17 @@ static int physom_devices_init(void)
ARRAY_SIZE(nandslots));
am33xx_bbu_emmc_mlo_register_handler("MLO.emmc", "/dev/mmc1");
 
+   if (IS_ENABLED(CONFIG_STATE)) {
+   state = state_by_name("am335x_phytec_mac_state");
+   if (state)
+   for (state_i = 0; state_i < 2; state_i++) {
+   state_ret = state_read_mac(state,
+ eth_names[state_i], 
&mac[0]);
+   if (state_ret == 6)
+   eth_register_ethaddr(state_i, mac);
+   }
+   }
+
if (IS_ENABLED(CONFIG_SHELL_NONE))
return am33xx_of_register_bootdevice();
 
-- 
2.7.4


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


[PATCH v3 5/7] common: state: Add variable type as enum

2017-11-03 Thread Daniel Schultz
The variable_type struct holds a name of its type. Checking the type of
a variable with this string needs much resources.

This patch introduce a enum of the variable type for better type
checking.

Signed-off-by: Daniel Schultz 
---
Changes:
v3: New patch.

 common/state/state.h   |  9 +
 common/state/state_variables.c | 18 ++
 2 files changed, 27 insertions(+)

diff --git a/common/state/state.h b/common/state/state.h
index 7dd163c..fcc6b9f 100644
--- a/common/state/state.h
+++ b/common/state/state.h
@@ -9,6 +9,14 @@ enum state_flags {
STATE_FLAG_NO_AUTHENTIFICATION = (1 << 0),
 };
 
+enum state_variable_type {
+   STATE_VARIABLE_TYPE_UINT8,
+   STATE_VARIABLE_TYPE_UINT32,
+   STATE_VARIABLE_TYPE_ENUM32,
+   STATE_VARIABLE_TYPE_MAC,
+   STATE_VARIABLE_TYPE_STRING
+};
+
 /**
  * state_backend_storage_bucket - This class describes a single backend storage
  * object copy
@@ -119,6 +127,7 @@ struct state_variable;
 /* A variable type (uint32, enum32) */
 struct variable_type {
const char *type_name;
+   enum state_variable_type type;
struct list_head list;
int (*export) (struct state_variable *, struct device_node *,
   enum state_convert);
diff --git a/common/state/state_variables.c b/common/state/state_variables.c
index 688467d..de9ba4a 100644
--- a/common/state/state_variables.c
+++ b/common/state/state_variables.c
@@ -450,26 +450,31 @@ static struct state_variable *state_string_create(struct 
state *state,
 static struct variable_type types[] = {
{
.type_name = "uint8",
+   .type = STATE_VARIABLE_TYPE_UINT8,
.export = state_uint32_export,
.import = state_uint32_import,
.create = state_uint8_create,
}, {
.type_name = "uint32",
+   .type = STATE_VARIABLE_TYPE_UINT32,
.export = state_uint32_export,
.import = state_uint32_import,
.create = state_uint32_create,
}, {
.type_name = "enum32",
+   .type = STATE_VARIABLE_TYPE_ENUM32,
.export = state_enum32_export,
.import = state_enum32_import,
.create = state_enum32_create,
}, {
.type_name = "mac",
+   .type = STATE_VARIABLE_TYPE_MAC,
.export = state_mac_export,
.import = state_mac_import,
.create = state_mac_create,
}, {
.type_name = "string",
+   .type = STATE_VARIABLE_TYPE_STRING,
.export = state_string_export,
.import = state_string_import,
.create = state_string_create,
@@ -489,6 +494,19 @@ struct variable_type *state_find_type_by_name(const char 
*name)
return NULL;
 }
 
+struct variable_type *state_find_type(const enum state_variable_type type)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(types); i++) {
+   if (type == types[i].type) {
+   return &types[i];
+   }
+   }
+
+   return NULL;
+}
+
 struct state_variable *state_find_var(struct state *state, const char *name)
 {
struct state_variable *sv;
-- 
2.7.4


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


[PATCH v3 3/7] ARM: configs: am335x_defconfig: Add state config

2017-11-03 Thread Daniel Schultz
Enable the state framework for all AM335x boards.
---
 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 dd9c3c5..5a236fb 100644
--- a/arch/arm/configs/am335x_defconfig
+++ b/arch/arm/configs/am335x_defconfig
@@ -88,6 +88,7 @@ CONFIG_CMD_OF_FIXUP_STATUS=y
 CONFIG_CMD_OFTREE=y
 CONFIG_CMD_TIME=y
 CONFIG_CMD_MMC_EXTCSD=y
+CONFIG_CMD_STATE=y
 CONFIG_NET=y
 CONFIG_NET_NFS=y
 CONFIG_NET_NETCONSOLE=y
@@ -142,3 +143,5 @@ CONFIG_FS_FAT_LFN=y
 CONFIG_FS_UBIFS=y
 CONFIG_FS_UBIFS_COMPRESSION_LZO=y
 CONFIG_FS_UBIFS_COMPRESSION_ZLIB=y
+CONFIG_STATE=y
+CONFIG_STATE_DRV=y
-- 
2.7.4


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


[PATCH v3 1/7] ARM: boards: phytec-som-am335x: Add unified MLO

2017-11-03 Thread Daniel Schultz
PCM-060 modules only have one-bank RAMs populated, which allows us to
find out the populated RAM size at run-time.

Therefore, a new entry point was create 'PHYTEC_ENTRY_UNIFIED_MLO'. This
creates a MLO for all modules of one family and all existing PCM-060
MLOs were replaced with this new entry point. To provide backward
compatibility for older modules, these were not affected.

In the first step generic RAM timings for the module family get loaded,
because RAM accesses are only possible with an initialized controller.
After that, the RAM size will be calculated and the RAM controller gets
reinitialized with the correct RAM timings.

Signed-off-by: Daniel Schultz 
---
 arch/arm/boards/phytec-som-am335x/lowlevel.c | 150 +++
 images/Makefile.am33xx   |  24 ++---
 2 files changed, 138 insertions(+), 36 deletions(-)

diff --git a/arch/arm/boards/phytec-som-am335x/lowlevel.c 
b/arch/arm/boards/phytec-som-am335x/lowlevel.c
index 77f436f..b1576ee 100644
--- a/arch/arm/boards/phytec-som-am335x/lowlevel.c
+++ b/arch/arm/boards/phytec-som-am335x/lowlevel.c
@@ -46,6 +46,94 @@ static const struct am33xx_cmd_control physom_cmd = {
.invert_clkout2 = 0x0,
 };
 
+/* Module family for the unified MLO
+ *
+ * NONE:Unified MLO is not supported
+ * PHYCORE_R2:  Unified MLO for PCM-060, PCM-062
+ */
+enum {
+   NONE,
+   PHYCORE_R2,
+};
+
+/* @brief Supplies default ram timings for all ram sizes
+ *
+ * Returns generic ram timings for module families to find the correct
+ * ram size.
+ *
+ * @return struct am335x_sdram_timings* or NULL
+ */
+
+static noinline struct am335x_sdram_timings* get_minimal_timings(
+   int module_family)
+{
+   struct am335x_sdram_timings *timing;
+
+   switch (module_family) {
+   case PHYCORE_R2:
+   timing = &physom_timings[PHYCORE_R2_MT41K512M16HA125IT_1024MB];
+   break;
+   default:
+   timing = NULL;
+   }
+
+   return timing;
+}
+
+/* @brief Converts ramsizes to ram timings for phyCORE-R2 modules
+ *
+ * Returns ram timings for a given ram size or NULL, if this size is
+ * not supported.
+ *
+ * @return struct am335x_sdram_timings* or NULL
+ */
+
+static noinline struct am335x_sdram_timings* convert_phycore_r2_timings(
+   u32 ramsize)
+{
+   struct am335x_sdram_timings *timing;
+
+   switch (ramsize) {
+   case SZ_256M:
+   timing = &physom_timings[PHYCORE_R2_MT41K128M16JT_256MB];
+   break;
+   case SZ_512M:
+   timing = &physom_timings[PHYCORE_R2_MT41K256M16TW107IT_512MB];
+   break;
+   case SZ_1G:
+   timing = &physom_timings[PHYCORE_R2_MT41K512M16HA125IT_1024MB];
+   break;
+   default:
+   timing = NULL;
+   }
+
+   return timing;
+}
+
+/* @brief Converts a module family and ram size to ram timings
+ *
+ * Returns ram timings for a given ram size and module family or NULL,
+ * if the ram size or module family is not supported.
+ *
+ * @return struct am335x_sdram_timings* or NULL
+ */
+
+static noinline struct am335x_sdram_timings* get_timings_by_size(
+   int module_family, u32 ramsize)
+{
+   struct am335x_sdram_timings *timing;
+
+   switch (module_family) {
+   case PHYCORE_R2:
+   timing = convert_phycore_r2_timings(ramsize);
+   break;
+   default:
+   timing = NULL;
+   }
+
+   return timing;
+}
+
 /**
  * @brief The basic entry point for board initialization.
  *
@@ -55,9 +143,10 @@ static const struct am33xx_cmd_control physom_cmd = {
  *
  * @return void
  */
-static noinline void physom_board_init(int sdram, void *fdt)
+static noinline void physom_board_init(void *fdt, int sdram, int module_family)
 {
-   struct am335x_sdram_timings *timing = &physom_timings[sdram];
+   struct am335x_sdram_timings *timing = NULL;
+   u32 ramsize;
 
/*
 * WDT1 is already running when the bootloader gets control
@@ -71,6 +160,24 @@ static noinline void physom_board_init(int sdram, void *fdt)
 
am33xx_pll_init(MPUPLL_M_600, DDRPLL_M_400);
 
+   if (module_family == NONE) {
+   timing = &physom_timings[sdram];
+   } else {
+   /* Load generic DDR3 ram timings to find the ram size */
+   timing = get_minimal_timings(module_family);
+   if (!timing)
+   hang();
+   am335x_sdram_init(DDR_IOCTRL, &physom_cmd,
+   &timing->regs,
+   &timing->data);
+
+   /* Find the ram size and set up the correct ram timings */
+   ramsize = get_ram_size((long *) 0x8000, SZ_1G);
+  

[PATCH v3 6/7] common: state: Add function to read state MAC

2017-11-03 Thread Daniel Schultz
This API function allows to receive a copy of a MAC address from
variables in a state.

Signed-off-by: Daniel Schultz 
---
Changes:
v2: New patch
v3: Changed return values
Switched to the new STATE_VARIABLE_TYPE_* field
Changed to memcpy function, instead of own loop

 common/state/state.c | 21 +
 include/state.h  |  2 ++
 2 files changed, 23 insertions(+)

diff --git a/common/state/state.c b/common/state/state.c
index 98a7db3..6399bd3 100644
--- a/common/state/state.c
+++ b/common/state/state.c
@@ -693,6 +693,27 @@ int state_get_name(const struct state *state, char const 
**name)
return 0;
 }
 
+int state_read_mac(struct state *state, const char *name, u8 *buf)
+{
+   struct state_variable *svar;
+   struct state_mac *mac;
+
+   if (!state || !name || !buf)
+   return -EINVAL;
+
+   svar = state_find_var(state, name);
+   if (IS_ERR(svar))
+   return PTR_ERR(svar);
+
+   if (svar->type->type != STATE_VARIABLE_TYPE_MAC)
+   return -EINVAL;
+
+   mac = to_state_mac(svar);
+   memcpy(buf, mac->value, 6);
+
+   return 0;
+}
+
 void state_info(void)
 {
struct state *state;
diff --git a/include/state.h b/include/state.h
index 63164f9..f1882ae 100644
--- a/include/state.h
+++ b/include/state.h
@@ -23,4 +23,6 @@ int state_load(struct state *state);
 int state_save(struct state *state);
 void state_info(void);
 
+int state_read_mac(struct state *state, const char *name, u8 *buf);
+
 #endif /* __STATE_H */
-- 
2.7.4


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


[PATCH v3 3/3] ARM: phytec-som-am335x: Add autoenable

2017-11-03 Thread Daniel Schultz
Add autoenable for components, which can be populated on an AM335x
phyCORE SoM.

Signed-off-by: Daniel Schultz 
---
 arch/arm/boards/phytec-som-am335x/Kconfig | 13 +
 arch/arm/boards/phytec-som-am335x/board.c | 13 +
 arch/arm/mach-omap/Kconfig|  2 ++
 3 files changed, 28 insertions(+)
 create mode 100644 arch/arm/boards/phytec-som-am335x/Kconfig

diff --git a/arch/arm/boards/phytec-som-am335x/Kconfig 
b/arch/arm/boards/phytec-som-am335x/Kconfig
new file mode 100644
index 000..52fa723
--- /dev/null
+++ b/arch/arm/boards/phytec-som-am335x/Kconfig
@@ -0,0 +1,13 @@
+
+if MACH_PHYTEC_SOM_AM335X
+
+config PHYTEC_SOM_AM335X_OF_AUTOENABLE
+   bool
+   prompt "Autoenable of components"
+   help
+ Say Y to unlock an API for automatically enable either hardware
+ components with existing device drivers or i2c clients. All functions
+ take a device tree path to find the hardware and will fix up the node
+ status in the kernel device tree, if it's accessible.
+
+endif
diff --git a/arch/arm/boards/phytec-som-am335x/board.c 
b/arch/arm/boards/phytec-som-am335x/board.c
index 9f74981..0e9bf5f 100644
--- a/arch/arm/boards/phytec-som-am335x/board.c
+++ b/arch/arm/boards/phytec-som-am335x/board.c
@@ -135,6 +135,19 @@ static int physom_devices_init(void)
}
}
 
+   if (IS_ENABLED(PHYTEC_SOM_AM335X_OF_AUTOENABLE)) {
+   /* Enable NAND */
+   of_autoenable_device_by_path("/ocp/gpmc@5000");
+   /* Enable eMMC */
+   of_autoenable_device_by_path("/ocp/mmc@481d8000");
+   /* Enable SPI NOR */
+   of_autoenable_device_by_path("/ocp/spi@4803/m25p80@0");
+
+   of_autoenable_i2c_by_component("/ocp/i2c@44e0b000/temp@4b");
+   of_autoenable_i2c_by_component("/ocp/i2c@44e0b000/eeprom@52");
+   of_autoenable_i2c_by_component("/ocp/i2c@44e0b000/rtc@68");
+   }
+
if (IS_ENABLED(CONFIG_SHELL_NONE))
return am33xx_of_register_bootdevice();
 
diff --git a/arch/arm/mach-omap/Kconfig b/arch/arm/mach-omap/Kconfig
index 9c41741..e8fc4b8 100644
--- a/arch/arm/mach-omap/Kconfig
+++ b/arch/arm/mach-omap/Kconfig
@@ -192,6 +192,8 @@ config MACH_VSCOM_BALTOS
 
 endif
 
+source arch/arm/boards/phytec-som-am335x/Kconfig
+
 choice
prompt "Select OMAP board"
depends on !OMAP_MULTI_BOARDS
-- 
2.7.4


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


[PATCH v3 2/3] common: oftree: Add autoenable functionality

2017-11-03 Thread Daniel Schultz
This patch adds an API to automatically enable either hardware components
with existing device drivers or i2c clients. All functions take a device
tree path to find the hardware and will fix up the node status in the
kernel device tree, if it's accessible.

Signed-off-by: Daniel Schultz 
---
Changes:
v2: Moved from standalone file to oftree.c
Added of_device_is_available, if a driver is disabled
Added of_property_read_u32
Removed Kconfig
Added of_ prefix to function names
Renamed of_autoenable_i2c_by_path to of_autoenable_i2c_by_component
v3: Removed of_find_device_by_node in of_autoenable_device_by_path. If
a driver is disabled in the Kconfig, but enabled in a DTS file,
it can be autoenabled in the kernel DTS. If a driver is enabled,
must also be enabled in the DTS.

 common/oftree.c | 89 +
 include/of.h| 14 +
 2 files changed, 103 insertions(+)

diff --git a/common/oftree.c b/common/oftree.c
index 09a4455..40eb35f 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define MAX_LEVEL  32  /* how deeply nested we will go */
 
@@ -260,3 +261,91 @@ struct fdt_header *of_get_fixed_tree(struct device_node 
*node)
 
return fdt;
 }
+
+/**
+ * of_autoenable_device_by_path() - Autoenable a device by a device tree path
+ * @param path Device tree path up from the root to the device
+ * @return 0 on success, -enodev on failure. If no device found in the device
+ * tree.
+ *
+ * This function will search for a device and will enable it in the kernel
+ * device tree, if it exists and is loaded.
+ */
+int of_autoenable_device_by_path(char *path)
+{
+   struct device_node *node;
+   int ret;
+
+   node = of_find_node_by_name(NULL, path);
+   if (!node)
+   node = of_find_node_by_path(path);
+
+   if (!node)
+   return -ENODEV;
+
+   if (!of_device_is_available(node))
+   return -ENODEV;
+
+   ret = of_register_set_status_fixup(path, 1);
+   if (!ret)
+   printf("autoenabled %s\n", node->name);
+   return ret;
+}
+
+/**
+ * of_autoenable_i2c_by_component - Autoenable a i2c client by a device tree 
path
+ * @param path Device tree path up from the root to the i2c client
+ * @return 0 on success, -enodev on failure. If no i2c client found in the i2c
+ * device tree.
+ *
+ * This function will search for a i2c client, tries to write to the client and
+ * will enable it in the kernel device tree, if it exists and is accessible.
+ */
+int of_autoenable_i2c_by_component(char *path)
+{
+   struct device_node *node;
+   struct i2c_adapter *i2c_adapter;
+   struct i2c_msg msg;
+   char data[1] = {0x0};
+   int ret;
+   uint32_t addr;
+
+   if (!IS_ENABLED(CONFIG_I2C))
+   return -ENODEV;
+
+   node = of_find_node_by_name(NULL, path);
+   if (!node)
+   node = of_find_node_by_path(path);
+   if (!node)
+   return -ENODEV;
+   if (!node->parent)
+   return -ENODEV;
+
+   ret = of_property_read_u32(node, "reg", &addr);
+   if (ret)
+   return -ENODEV;
+
+   i2c_adapter = of_find_i2c_adapter_by_node(node->parent);
+   if (!i2c_adapter)
+   return -ENODEV;
+
+   msg.buf = data;
+   msg.addr = addr;
+   msg.len = 1;
+
+   /* Try to communicate with the i2c client */
+   ret = i2c_transfer(i2c_adapter, &msg, 1);
+   if (ret == -EREMOTEIO)
+   return -ENODEV;
+   if (ret < 1) {
+   printf("failed to autoenable i2c device on address 0x%x with 
%i\n",
+   addr, ret);
+   return ret;
+   }
+
+   ret = of_register_set_status_fixup(path, 1);
+   if (!ret)
+   printf("autoenabled i2c device %s\n", node->name);
+
+   return ret;
+}
diff --git a/include/of.h b/include/of.h
index 18a4232..9bdbbb5e 100644
--- a/include/of.h
+++ b/include/of.h
@@ -262,6 +262,8 @@ 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,
const char *str);
+int of_autoenable_device_by_path(char *path);
+int of_autoenable_i2c_by_component(char *path);
 #else
 static inline int of_parse_partitions(struct cdev *cdev,
  struct device_node *node)
@@ -664,6 +666,18 @@ static inline struct device_node 
*of_find_node_by_path_or_alias(
 {
return NULL;
 }
+
+static inline int of_autoenable_i2c_by_path(char *path)
+{
+   return -ENODEV;
+}
+
+static inline int of_autoenable_i2

[PATCH v3 2/7] ARM: dts: AM335x: Add state framework

2017-11-03 Thread Daniel Schultz
This patch adds the state framework with an EEPROM partition and two
nodes for MAC addresses. It will be available for all phycore AM335x
images with EEPROMs.

Signed-off-by: Daniel Schultz 
---
 arch/arm/dts/am335x-phytec-phycore-som-emmc.dts|  1 +
 .../dts/am335x-phytec-phycore-som-nand-no-spi.dts  |  1 +
 arch/arm/dts/am335x-phytec-phycore-som-nand.dts|  1 +
 arch/arm/dts/am335x-phytec-state.dtsi  | 52 ++
 4 files changed, 55 insertions(+)
 create mode 100644 arch/arm/dts/am335x-phytec-state.dtsi

diff --git a/arch/arm/dts/am335x-phytec-phycore-som-emmc.dts 
b/arch/arm/dts/am335x-phytec-phycore-som-emmc.dts
index 880700e..f264498 100644
--- a/arch/arm/dts/am335x-phytec-phycore-som-emmc.dts
+++ b/arch/arm/dts/am335x-phytec-phycore-som-emmc.dts
@@ -16,6 +16,7 @@
 
 #include "am33xx.dtsi"
 #include "am335x-phytec-phycore-som.dtsi"
+#include "am335x-phytec-state.dtsi"
 
 / {
model = "Phytec phyCORE EMMC AM335x";
diff --git a/arch/arm/dts/am335x-phytec-phycore-som-nand-no-spi.dts 
b/arch/arm/dts/am335x-phytec-phycore-som-nand-no-spi.dts
index 2c2fab0..b35294c 100644
--- a/arch/arm/dts/am335x-phytec-phycore-som-nand-no-spi.dts
+++ b/arch/arm/dts/am335x-phytec-phycore-som-nand-no-spi.dts
@@ -9,6 +9,7 @@
 
 #include "am33xx.dtsi"
 #include "am335x-phytec-phycore-som.dtsi"
+#include "am335x-phytec-state.dtsi"
 
 / {
model = "Phytec phyCORE AM335x";
diff --git a/arch/arm/dts/am335x-phytec-phycore-som-nand.dts 
b/arch/arm/dts/am335x-phytec-phycore-som-nand.dts
index 6ff2447..4d7606b 100644
--- a/arch/arm/dts/am335x-phytec-phycore-som-nand.dts
+++ b/arch/arm/dts/am335x-phytec-phycore-som-nand.dts
@@ -9,6 +9,7 @@
 
 #include "am33xx.dtsi"
 #include "am335x-phytec-phycore-som.dtsi"
+#include "am335x-phytec-state.dtsi"
 
 / {
model = "Phytec phyCORE AM335x";
diff --git a/arch/arm/dts/am335x-phytec-state.dtsi 
b/arch/arm/dts/am335x-phytec-state.dtsi
new file mode 100644
index 000..fbc35b9
--- /dev/null
+++ b/arch/arm/dts/am335x-phytec-state.dtsi
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2017 PHYTEC Messtechnik GmbH,
+ * Author: Daniel Schultz 
+ *
+ * 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.
+ */
+
+/ {
+   aliases {
+   am335x_phytec_mac_state = &am335x_phytec_mac_state;
+   };
+
+   am335x_phytec_mac_state: am335x_phytec_mac_state {
+   magic = <0x3f45620e>;
+   compatible = "barebox,state";
+   backend-type = "raw";
+   backend = <&backend_state_eeprom>;
+   backend-stridesize = <40>;
+
+   #address-cells = <1>;
+   #size-cells = <1>;
+   mac0 {
+   reg = <0x0 0x6>;
+   type = "mac";
+   };
+   mac1 {
+   reg = <0x6 0x6>;
+   type = "mac";
+   };
+
+   };
+};
+
+&eeprom {
+   status = "okay";
+   partitions {
+   compatible = "fixed-partitions";
+   #size-cells = <1>;
+   #address-cells = <1>;
+   backend_state_eeprom: state@0 {
+   reg = <0x000 0x120>;
+   label = "state-eeprom";
+   };
+   };
+};
-- 
2.7.4


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


[PATCH v3 1/3] ARM: dts: AM335x: Add dummy i2c nodes

2017-11-03 Thread Daniel Schultz
These i2c nodes are needed for autoenable of i2c clients, because
the autoenable API searches for device tree nodes to get the client
address.

Signed-off-by: Daniel Schultz 
---
 arch/arm/dts/am335x-phytec-phycore-som.dtsi | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/arch/arm/dts/am335x-phytec-phycore-som.dtsi 
b/arch/arm/dts/am335x-phytec-phycore-som.dtsi
index dbc6424..cf2eef3 100644
--- a/arch/arm/dts/am335x-phytec-phycore-som.dtsi
+++ b/arch/arm/dts/am335x-phytec-phycore-som.dtsi
@@ -164,6 +164,20 @@
pagesize = <32>;
reg = <0x52>;
};
+
+   /* The following i2c nodes are for the autoenable */
+   i2c_tmp102: temp@4b {
+   compatible = "ti,tmp102";
+   reg = <0x4b>;
+   status = "disabled";
+   };
+
+   i2c_rtc: rtc@68 {
+   compatible = "rv4162";
+   reg = <0x68>;
+   status = "disabled";
+   };
+
 };
 
 &mmc1 {
-- 
2.7.4


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


[PATCH v2 1/3] ARM: dts: AM335x: Add dummy i2c nodes

2017-11-02 Thread Daniel Schultz
These i2c nodes are needed for autoenable of i2c clients, because
the autoenable API searches for device tree nodes to get the client
address.

Signed-off-by: Daniel Schultz 
---
 arch/arm/dts/am335x-phytec-phycore-som.dtsi | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/arch/arm/dts/am335x-phytec-phycore-som.dtsi 
b/arch/arm/dts/am335x-phytec-phycore-som.dtsi
index dbc6424..cf2eef3 100644
--- a/arch/arm/dts/am335x-phytec-phycore-som.dtsi
+++ b/arch/arm/dts/am335x-phytec-phycore-som.dtsi
@@ -164,6 +164,20 @@
pagesize = <32>;
reg = <0x52>;
};
+
+   /* The following i2c nodes are for the autoenable */
+   i2c_tmp102: temp@4b {
+   compatible = "ti,tmp102";
+   reg = <0x4b>;
+   status = "disabled";
+   };
+
+   i2c_rtc: rtc@68 {
+   compatible = "rv4162";
+   reg = <0x68>;
+   status = "disabled";
+   };
+
 };
 
 &mmc1 {
-- 
2.7.4


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


[PATCH v2 3/3] ARM: phytec-som-am335x: Add autoenable

2017-11-02 Thread Daniel Schultz
Add autoenable for components, which can be populated on an AM335x
phyCORE SoM.

Signed-off-by: Daniel Schultz 
---
Changes:
v2: Created Phytec AM335x Kconfig PHYTEC_SOM_AM335X_OF_AUTOENABLE
Changed function names

 arch/arm/boards/phytec-som-am335x/Kconfig | 13 +
 arch/arm/boards/phytec-som-am335x/board.c | 13 +
 arch/arm/mach-omap/Kconfig|  2 ++
 3 files changed, 28 insertions(+)
 create mode 100644 arch/arm/boards/phytec-som-am335x/Kconfig

diff --git a/arch/arm/boards/phytec-som-am335x/Kconfig 
b/arch/arm/boards/phytec-som-am335x/Kconfig
new file mode 100644
index 000..52fa723
--- /dev/null
+++ b/arch/arm/boards/phytec-som-am335x/Kconfig
@@ -0,0 +1,13 @@
+
+if MACH_PHYTEC_SOM_AM335X
+
+config PHYTEC_SOM_AM335X_OF_AUTOENABLE
+   bool
+   prompt "Autoenable of components"
+   help
+ Say Y to unlock an API for automatically enable either hardware
+ components with existing device drivers or i2c clients. All functions
+ take a device tree path to find the hardware and will fix up the node
+ status in the kernel device tree, if it's accessible.
+
+endif
diff --git a/arch/arm/boards/phytec-som-am335x/board.c 
b/arch/arm/boards/phytec-som-am335x/board.c
index 9f74981..0e9bf5f 100644
--- a/arch/arm/boards/phytec-som-am335x/board.c
+++ b/arch/arm/boards/phytec-som-am335x/board.c
@@ -135,6 +135,19 @@ static int physom_devices_init(void)
}
}
 
+   if (IS_ENABLED(PHYTEC_SOM_AM335X_OF_AUTOENABLE)) {
+   /* Enable NAND */
+   of_autoenable_device_by_path("/ocp/gpmc@5000");
+   /* Enable eMMC */
+   of_autoenable_device_by_path("/ocp/mmc@481d8000");
+   /* Enable SPI NOR */
+   of_autoenable_device_by_path("/ocp/spi@4803/m25p80@0");
+
+   of_autoenable_i2c_by_component("/ocp/i2c@44e0b000/temp@4b");
+   of_autoenable_i2c_by_component("/ocp/i2c@44e0b000/eeprom@52");
+   of_autoenable_i2c_by_component("/ocp/i2c@44e0b000/rtc@68");
+   }
+
if (IS_ENABLED(CONFIG_SHELL_NONE))
return am33xx_of_register_bootdevice();
 
diff --git a/arch/arm/mach-omap/Kconfig b/arch/arm/mach-omap/Kconfig
index 9c41741..e8fc4b8 100644
--- a/arch/arm/mach-omap/Kconfig
+++ b/arch/arm/mach-omap/Kconfig
@@ -192,6 +192,8 @@ config MACH_VSCOM_BALTOS
 
 endif
 
+source arch/arm/boards/phytec-som-am335x/Kconfig
+
 choice
prompt "Select OMAP board"
depends on !OMAP_MULTI_BOARDS
-- 
2.7.4


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


[PATCH v2 2/3] common: oftree: Add autoenable functionality

2017-11-02 Thread Daniel Schultz
This patch adds an API to automatically enable either hardware components
with existing device drivers or i2c clients. All functions take a device
tree path to find the hardware and will fix up the node status in the
kernel device tree, if it's accessible.

Signed-off-by: Daniel Schultz 
---
Changes:
v2: Moved from standalone file to oftree.c
Added of_device_is_available, if a driver is disabled
Added of_property_read_u32
Removed Kconfig
Added of_ prefix to function names
Renamed of_autoenable_i2c_by_path to of_autoenable_i2c_by_component

 common/oftree.c | 92 +
 include/of.h| 14 +
 2 files changed, 106 insertions(+)

diff --git a/common/oftree.c b/common/oftree.c
index 09a4455..3b77a7e 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define MAX_LEVEL  32  /* how deeply nested we will go */
 
@@ -260,3 +261,94 @@ struct fdt_header *of_get_fixed_tree(struct device_node 
*node)
 
return fdt;
 }
+
+/**
+ * of_autoenable_device_by_path() - Autoenable a device by a device tree path
+ * @param path Device tree path up from the root to the device
+ * @return 0 on success, -enodev on failure. If no device found in the device
+ * tree.
+ *
+ * This function will search for a device and will enable it in the kernel
+ * device tree, if it exists and is loaded.
+ */
+int of_autoenable_device_by_path(char *path)
+{
+   struct device_d *device;
+   struct device_node *node;
+   int ret;
+
+   node = of_find_node_by_name(NULL, path);
+   if (!node)
+   node = of_find_node_by_path(path);
+
+   if (!node)
+   return -ENODEV;
+
+   device = of_find_device_by_node(node);
+   if (!device)
+   if (!of_device_is_available(node))
+   return -ENODEV;
+
+   ret = of_register_set_status_fixup(path, 1);
+   if (!ret)
+   printf("autoenabled %s\n", node->name);
+   return ret;
+}
+
+/**
+ * of_autoenable_i2c_by_component - Autoenable a i2c client by a device tree 
path
+ * @param path Device tree path up from the root to the i2c client
+ * @return 0 on success, -enodev on failure. If no i2c client found in the i2c
+ * device tree.
+ *
+ * This function will search for a i2c client, tries to write to the client and
+ * will enable it in the kernel device tree, if it exists and is accessible.
+ */
+int of_autoenable_i2c_by_component(char *path)
+{
+   struct device_node *node;
+   struct i2c_adapter *i2c_adapter;
+   struct i2c_msg msg;
+   char data[1] = {0x0};
+   int ret;
+   uint32_t addr;
+
+   if (!IS_ENABLED(CONFIG_I2C))
+   return -ENODEV;
+
+   node = of_find_node_by_name(NULL, path);
+   if (!node)
+   node = of_find_node_by_path(path);
+   if (!node)
+   return -ENODEV;
+   if (!node->parent)
+   return -ENODEV;
+
+   ret = of_property_read_u32(node, "reg", &addr);
+   if (ret)
+   return -ENODEV;
+
+   i2c_adapter = of_find_i2c_adapter_by_node(node->parent);
+   if (!i2c_adapter)
+   return -ENODEV;
+
+   msg.buf = data;
+   msg.addr = addr;
+   msg.len = 1;
+
+   /* Try to communicate with the i2c client */
+   ret = i2c_transfer(i2c_adapter, &msg, 1);
+   if (ret == -EREMOTEIO)
+   return -ENODEV;
+   if (ret < 1) {
+   printf("failed to autoenable i2c device on address 0x%x with 
%i\n",
+   addr, ret);
+   return ret;
+   }
+
+   ret = of_register_set_status_fixup(path, 1);
+   if (!ret)
+   printf("autoenabled i2c device %s\n", node->name);
+
+   return ret;
+}
diff --git a/include/of.h b/include/of.h
index 18a4232..9bdbbb5e 100644
--- a/include/of.h
+++ b/include/of.h
@@ -262,6 +262,8 @@ 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,
const char *str);
+int of_autoenable_device_by_path(char *path);
+int of_autoenable_i2c_by_component(char *path);
 #else
 static inline int of_parse_partitions(struct cdev *cdev,
  struct device_node *node)
@@ -664,6 +666,18 @@ static inline struct device_node 
*of_find_node_by_path_or_alias(
 {
return NULL;
 }
+
+static inline int of_autoenable_i2c_by_path(char *path)
+{
+   return -ENODEV;
+}
+
+static inline int of_autoenable_i2c_by_component(char *path)
+{
+   return -ENODEV;
+}
+
+
 #endif
 
 #define for_each_node_by_name(dn, name) \
-- 
2.7.4


___
barebox

[PATCH v2 2/6] ARM: dts: AM335x: Add state framework

2017-11-02 Thread Daniel Schultz
This patch adds the state framework with an EEPROM partition and two
nodes for MAC addresses. It will be available for all phycore AM335x
images with EEPROMs.

Signed-off-by: Daniel Schultz 
---
 arch/arm/dts/am335x-phytec-phycore-som-emmc.dts|  1 +
 .../dts/am335x-phytec-phycore-som-nand-no-spi.dts  |  1 +
 arch/arm/dts/am335x-phytec-phycore-som-nand.dts|  1 +
 arch/arm/dts/am335x-phytec-state.dtsi  | 52 ++
 4 files changed, 55 insertions(+)
 create mode 100644 arch/arm/dts/am335x-phytec-state.dtsi

diff --git a/arch/arm/dts/am335x-phytec-phycore-som-emmc.dts 
b/arch/arm/dts/am335x-phytec-phycore-som-emmc.dts
index 880700e..f264498 100644
--- a/arch/arm/dts/am335x-phytec-phycore-som-emmc.dts
+++ b/arch/arm/dts/am335x-phytec-phycore-som-emmc.dts
@@ -16,6 +16,7 @@
 
 #include "am33xx.dtsi"
 #include "am335x-phytec-phycore-som.dtsi"
+#include "am335x-phytec-state.dtsi"
 
 / {
model = "Phytec phyCORE EMMC AM335x";
diff --git a/arch/arm/dts/am335x-phytec-phycore-som-nand-no-spi.dts 
b/arch/arm/dts/am335x-phytec-phycore-som-nand-no-spi.dts
index 2c2fab0..b35294c 100644
--- a/arch/arm/dts/am335x-phytec-phycore-som-nand-no-spi.dts
+++ b/arch/arm/dts/am335x-phytec-phycore-som-nand-no-spi.dts
@@ -9,6 +9,7 @@
 
 #include "am33xx.dtsi"
 #include "am335x-phytec-phycore-som.dtsi"
+#include "am335x-phytec-state.dtsi"
 
 / {
model = "Phytec phyCORE AM335x";
diff --git a/arch/arm/dts/am335x-phytec-phycore-som-nand.dts 
b/arch/arm/dts/am335x-phytec-phycore-som-nand.dts
index 6ff2447..4d7606b 100644
--- a/arch/arm/dts/am335x-phytec-phycore-som-nand.dts
+++ b/arch/arm/dts/am335x-phytec-phycore-som-nand.dts
@@ -9,6 +9,7 @@
 
 #include "am33xx.dtsi"
 #include "am335x-phytec-phycore-som.dtsi"
+#include "am335x-phytec-state.dtsi"
 
 / {
model = "Phytec phyCORE AM335x";
diff --git a/arch/arm/dts/am335x-phytec-state.dtsi 
b/arch/arm/dts/am335x-phytec-state.dtsi
new file mode 100644
index 000..fbc35b9
--- /dev/null
+++ b/arch/arm/dts/am335x-phytec-state.dtsi
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2017 PHYTEC Messtechnik GmbH,
+ * Author: Daniel Schultz 
+ *
+ * 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.
+ */
+
+/ {
+   aliases {
+   am335x_phytec_mac_state = &am335x_phytec_mac_state;
+   };
+
+   am335x_phytec_mac_state: am335x_phytec_mac_state {
+   magic = <0x3f45620e>;
+   compatible = "barebox,state";
+   backend-type = "raw";
+   backend = <&backend_state_eeprom>;
+   backend-stridesize = <40>;
+
+   #address-cells = <1>;
+   #size-cells = <1>;
+   mac0 {
+   reg = <0x0 0x6>;
+   type = "mac";
+   };
+   mac1 {
+   reg = <0x6 0x6>;
+   type = "mac";
+   };
+
+   };
+};
+
+&eeprom {
+   status = "okay";
+   partitions {
+   compatible = "fixed-partitions";
+   #size-cells = <1>;
+   #address-cells = <1>;
+   backend_state_eeprom: state@0 {
+   reg = <0x000 0x120>;
+   label = "state-eeprom";
+   };
+   };
+};
-- 
2.7.4


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


[PATCH v2 6/6] ARM: phytec-som-am335x: Set MAC addresses from state

2017-11-02 Thread Daniel Schultz
If a state with the name 'am335x_phytec_mac_state' is available, valid
MAC addresses from this state get registerd to their ethernet device.

Signed-off-by: Daniel Schultz 
---
Changes:
v2: Changed to new 'state_read_mac' function

 arch/arm/boards/phytec-som-am335x/board.c | 21 +
 1 file changed, 21 insertions(+)

diff --git a/arch/arm/boards/phytec-som-am335x/board.c 
b/arch/arm/boards/phytec-som-am335x/board.c
index dc3b84a..9f74981 100644
--- a/arch/arm/boards/phytec-som-am335x/board.c
+++ b/arch/arm/boards/phytec-som-am335x/board.c
@@ -21,10 +21,12 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -65,8 +67,16 @@ static char *nandslots[] = {
"/dev/nand0.barebox_backup.bb",
 };
 
+#define ETH_COUNT 2
+static const char *eth_names[ETH_COUNT] = {"mac0", "mac1"};
+
 static int physom_devices_init(void)
 {
+   struct state *state;
+   u8 mac[6];
+   int state_ret;
+   int state_i;
+
if (!of_machine_is_compatible("phytec,am335x-som"))
return 0;
 
@@ -114,6 +124,17 @@ static int physom_devices_init(void)
ARRAY_SIZE(nandslots));
am33xx_bbu_emmc_mlo_register_handler("MLO.emmc", "/dev/mmc1");
 
+   if (IS_ENABLED(CONFIG_STATE)) {
+   state = state_by_name("am335x_phytec_mac_state");
+   if (state)
+   for (state_i = 0; state_i < 2; state_i++) {
+   state_ret = state_read_mac(state,
+ eth_names[state_i], 
&mac[0]);
+   if (state_ret == 6)
+   eth_register_ethaddr(state_i, mac);
+   }
+   }
+
if (IS_ENABLED(CONFIG_SHELL_NONE))
return am33xx_of_register_bootdevice();
 
-- 
2.7.4


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


[PATCH v2 1/6] ARM: boards: phytec-som-am335x: Add unified MLO

2017-11-02 Thread Daniel Schultz
PCM-060 modules only have one-bank RAMs populated, which allows us to
find out the populated RAM size at run-time.

Therefore, a new entry point was create 'PHYTEC_ENTRY_UNIFIED_MLO'. This
creates a MLO for all modules of one family and all existing PCM-060
MLOs were replaced with this new entry point. To provide backward
compatibility for older modules, these were not affected.

In the first step generic RAM timings for the module family get loaded,
because RAM accesses are only possible with an initialized controller.
After that, the RAM size will be calculated and the RAM controller gets
reinitialized with the correct RAM timings.

Signed-off-by: Daniel Schultz 
---
 arch/arm/boards/phytec-som-am335x/lowlevel.c | 150 +++
 images/Makefile.am33xx   |  24 ++---
 2 files changed, 138 insertions(+), 36 deletions(-)

diff --git a/arch/arm/boards/phytec-som-am335x/lowlevel.c 
b/arch/arm/boards/phytec-som-am335x/lowlevel.c
index 77f436f..b1576ee 100644
--- a/arch/arm/boards/phytec-som-am335x/lowlevel.c
+++ b/arch/arm/boards/phytec-som-am335x/lowlevel.c
@@ -46,6 +46,94 @@ static const struct am33xx_cmd_control physom_cmd = {
.invert_clkout2 = 0x0,
 };
 
+/* Module family for the unified MLO
+ *
+ * NONE:Unified MLO is not supported
+ * PHYCORE_R2:  Unified MLO for PCM-060, PCM-062
+ */
+enum {
+   NONE,
+   PHYCORE_R2,
+};
+
+/* @brief Supplies default ram timings for all ram sizes
+ *
+ * Returns generic ram timings for module families to find the correct
+ * ram size.
+ *
+ * @return struct am335x_sdram_timings* or NULL
+ */
+
+static noinline struct am335x_sdram_timings* get_minimal_timings(
+   int module_family)
+{
+   struct am335x_sdram_timings *timing;
+
+   switch (module_family) {
+   case PHYCORE_R2:
+   timing = &physom_timings[PHYCORE_R2_MT41K512M16HA125IT_1024MB];
+   break;
+   default:
+   timing = NULL;
+   }
+
+   return timing;
+}
+
+/* @brief Converts ramsizes to ram timings for phyCORE-R2 modules
+ *
+ * Returns ram timings for a given ram size or NULL, if this size is
+ * not supported.
+ *
+ * @return struct am335x_sdram_timings* or NULL
+ */
+
+static noinline struct am335x_sdram_timings* convert_phycore_r2_timings(
+   u32 ramsize)
+{
+   struct am335x_sdram_timings *timing;
+
+   switch (ramsize) {
+   case SZ_256M:
+   timing = &physom_timings[PHYCORE_R2_MT41K128M16JT_256MB];
+   break;
+   case SZ_512M:
+   timing = &physom_timings[PHYCORE_R2_MT41K256M16TW107IT_512MB];
+   break;
+   case SZ_1G:
+   timing = &physom_timings[PHYCORE_R2_MT41K512M16HA125IT_1024MB];
+   break;
+   default:
+   timing = NULL;
+   }
+
+   return timing;
+}
+
+/* @brief Converts a module family and ram size to ram timings
+ *
+ * Returns ram timings for a given ram size and module family or NULL,
+ * if the ram size or module family is not supported.
+ *
+ * @return struct am335x_sdram_timings* or NULL
+ */
+
+static noinline struct am335x_sdram_timings* get_timings_by_size(
+   int module_family, u32 ramsize)
+{
+   struct am335x_sdram_timings *timing;
+
+   switch (module_family) {
+   case PHYCORE_R2:
+   timing = convert_phycore_r2_timings(ramsize);
+   break;
+   default:
+   timing = NULL;
+   }
+
+   return timing;
+}
+
 /**
  * @brief The basic entry point for board initialization.
  *
@@ -55,9 +143,10 @@ static const struct am33xx_cmd_control physom_cmd = {
  *
  * @return void
  */
-static noinline void physom_board_init(int sdram, void *fdt)
+static noinline void physom_board_init(void *fdt, int sdram, int module_family)
 {
-   struct am335x_sdram_timings *timing = &physom_timings[sdram];
+   struct am335x_sdram_timings *timing = NULL;
+   u32 ramsize;
 
/*
 * WDT1 is already running when the bootloader gets control
@@ -71,6 +160,24 @@ static noinline void physom_board_init(int sdram, void *fdt)
 
am33xx_pll_init(MPUPLL_M_600, DDRPLL_M_400);
 
+   if (module_family == NONE) {
+   timing = &physom_timings[sdram];
+   } else {
+   /* Load generic DDR3 ram timings to find the ram size */
+   timing = get_minimal_timings(module_family);
+   if (!timing)
+   hang();
+   am335x_sdram_init(DDR_IOCTRL, &physom_cmd,
+   &timing->regs,
+   &timing->data);
+
+   /* Find the ram size and set up the correct ram timings */
+   ramsize = get_ram_size((long *) 0x8000, SZ_1G);
+  

[PATCH v2 4/6] common: state: Add variable_type to state_variable

2017-11-02 Thread Daniel Schultz
Add a pointer in state_variable to the corresponding variable_type array
element.

Signed-off-by: Daniel Schultz 
---
Changes:
v2: New patch

 common/state/state.h   | 1 +
 common/state/state_variables.c | 5 +
 2 files changed, 6 insertions(+)

diff --git a/common/state/state.h b/common/state/state.h
index 81aaec2..14b54aa 100644
--- a/common/state/state.h
+++ b/common/state/state.h
@@ -132,6 +132,7 @@ struct variable_type {
 struct state_variable {
struct state *state;
struct list_head list;
+   struct variable_type *type;
const char *name;
unsigned int start;
unsigned int size;
diff --git a/common/state/state_variables.c b/common/state/state_variables.c
index 56bcd95..e6571be 100644
--- a/common/state/state_variables.c
+++ b/common/state/state_variables.c
@@ -116,6 +116,7 @@ static struct state_variable *state_uint8_create(struct 
state *state,
}
 
su32->param = param;
+   su32->var.type = state_find_type_by_name("uint8");
su32->var.size = sizeof(uint8_t);
 #ifdef __LITTLE_ENDIAN
su32->var.raw = &su32->value;
@@ -144,6 +145,7 @@ static struct state_variable *state_uint32_create(struct 
state *state,
}
 
su32->param = param;
+   su32->var.type = state_find_type_by_name("uint32");
su32->var.size = sizeof(uint32_t);
su32->var.raw = &su32->value;
su32->var.state = state;
@@ -234,6 +236,7 @@ static struct state_variable *state_enum32_create(struct 
state *state,
 
enum32->names = xzalloc(sizeof(char *) * num_names);
enum32->num_names = num_names;
+   enum32->var.type = state_find_type_by_name("enum32");
enum32->var.size = sizeof(uint32_t);
enum32->var.raw = &enum32->value;
enum32->var.state = state;
@@ -307,6 +310,7 @@ static struct state_variable *state_mac_create(struct state 
*state,
 
mac = xzalloc(sizeof(*mac));
 
+   mac->var.type = state_find_type_by_name("mac");
mac->var.size = ARRAY_SIZE(mac->value);
mac->var.raw = mac->value;
mac->var.state = state;
@@ -420,6 +424,7 @@ static struct state_variable *state_string_create(struct 
state *state,
return ERR_PTR(-EILSEQ);
 
string = xzalloc(sizeof(*string) + start_size[1]);
+   string->var.type = state_find_type_by_name("string");
string->var.size = start_size[1];
string->var.raw = &string->raw;
string->var.state = state;
-- 
2.7.4


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


[PATCH v2 5/6] common: state: Add function to read state MAC

2017-11-02 Thread Daniel Schultz
This API function allows to receive a copy of a MAC address from
variables in a state.

Signed-off-by: Daniel Schultz 
---
Changes:
v2: New patch

 common/state/state.c | 23 +++
 include/state.h  |  2 ++
 2 files changed, 25 insertions(+)

diff --git a/common/state/state.c b/common/state/state.c
index 266d211..063e03e 100644
--- a/common/state/state.c
+++ b/common/state/state.c
@@ -693,6 +693,29 @@ int state_get_name(const struct state *state, char const 
**name)
return 0;
 }
 
+int state_read_mac(struct state *state, const char *name, u8 *buf)
+{
+   struct state_variable *svar;
+   struct state_mac *mac;
+   int i;
+
+   if (!state || !name || !buf)
+   return -EINVAL;
+
+   svar = state_find_var(state, name);
+   if (IS_ERR(svar))
+   return PTR_ERR(svar);
+
+   if (!strcmp(svar->type->type_name, "mac")) {
+   mac = to_state_mac(svar);
+   for (i = 0; i < 6; i++)
+   buf[i] = mac->value[i];
+   return 6;
+   }
+
+   return 0;
+}
+
 void state_info(void)
 {
struct state *state;
diff --git a/include/state.h b/include/state.h
index 63164f9..f1882ae 100644
--- a/include/state.h
+++ b/include/state.h
@@ -23,4 +23,6 @@ int state_load(struct state *state);
 int state_save(struct state *state);
 void state_info(void);
 
+int state_read_mac(struct state *state, const char *name, u8 *buf);
+
 #endif /* __STATE_H */
-- 
2.7.4


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


[PATCH v2 3/6] ARM: configs: am335x_defconfig: Add state config

2017-11-02 Thread Daniel Schultz
Enable the state framework for all AM335x boards.
---
 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 dd9c3c5..5a236fb 100644
--- a/arch/arm/configs/am335x_defconfig
+++ b/arch/arm/configs/am335x_defconfig
@@ -88,6 +88,7 @@ CONFIG_CMD_OF_FIXUP_STATUS=y
 CONFIG_CMD_OFTREE=y
 CONFIG_CMD_TIME=y
 CONFIG_CMD_MMC_EXTCSD=y
+CONFIG_CMD_STATE=y
 CONFIG_NET=y
 CONFIG_NET_NFS=y
 CONFIG_NET_NETCONSOLE=y
@@ -142,3 +143,5 @@ CONFIG_FS_FAT_LFN=y
 CONFIG_FS_UBIFS=y
 CONFIG_FS_UBIFS_COMPRESSION_LZO=y
 CONFIG_FS_UBIFS_COMPRESSION_ZLIB=y
+CONFIG_STATE=y
+CONFIG_STATE_DRV=y
-- 
2.7.4


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


[PATCH 1/5] ARM: boards: phytec-som-am335x: Add unified MLO

2017-10-27 Thread Daniel Schultz
PCM-060 modules only have one-bank RAMs populated, which allows us to
find out the populated RAM size at run-time.

Therefore, a new entry point was create 'PHYTEC_ENTRY_UNIFIED_MLO'. This
creates a MLO for all modules of one family and all existing PCM-060
MLOs were replaced with this new entry point. To provide backward
compatibility for older modules, these were not affected.

In the first step generic RAM timings for the module family get loaded,
because RAM accesses are only possible with an initialized controller.
After that, the RAM size will be calculated and the RAM controller gets
reinitialized with the correct RAM timings.

Signed-off-by: Daniel Schultz 
---
 arch/arm/boards/phytec-som-am335x/lowlevel.c | 150 +++
 images/Makefile.am33xx   |  24 ++---
 2 files changed, 138 insertions(+), 36 deletions(-)

diff --git a/arch/arm/boards/phytec-som-am335x/lowlevel.c 
b/arch/arm/boards/phytec-som-am335x/lowlevel.c
index 77f436f..b1576ee 100644
--- a/arch/arm/boards/phytec-som-am335x/lowlevel.c
+++ b/arch/arm/boards/phytec-som-am335x/lowlevel.c
@@ -46,6 +46,94 @@ static const struct am33xx_cmd_control physom_cmd = {
.invert_clkout2 = 0x0,
 };
 
+/* Module family for the unified MLO
+ *
+ * NONE:Unified MLO is not supported
+ * PHYCORE_R2:  Unified MLO for PCM-060, PCM-062
+ */
+enum {
+   NONE,
+   PHYCORE_R2,
+};
+
+/* @brief Supplies default ram timings for all ram sizes
+ *
+ * Returns generic ram timings for module families to find the correct
+ * ram size.
+ *
+ * @return struct am335x_sdram_timings* or NULL
+ */
+
+static noinline struct am335x_sdram_timings* get_minimal_timings(
+   int module_family)
+{
+   struct am335x_sdram_timings *timing;
+
+   switch (module_family) {
+   case PHYCORE_R2:
+   timing = &physom_timings[PHYCORE_R2_MT41K512M16HA125IT_1024MB];
+   break;
+   default:
+   timing = NULL;
+   }
+
+   return timing;
+}
+
+/* @brief Converts ramsizes to ram timings for phyCORE-R2 modules
+ *
+ * Returns ram timings for a given ram size or NULL, if this size is
+ * not supported.
+ *
+ * @return struct am335x_sdram_timings* or NULL
+ */
+
+static noinline struct am335x_sdram_timings* convert_phycore_r2_timings(
+   u32 ramsize)
+{
+   struct am335x_sdram_timings *timing;
+
+   switch (ramsize) {
+   case SZ_256M:
+   timing = &physom_timings[PHYCORE_R2_MT41K128M16JT_256MB];
+   break;
+   case SZ_512M:
+   timing = &physom_timings[PHYCORE_R2_MT41K256M16TW107IT_512MB];
+   break;
+   case SZ_1G:
+   timing = &physom_timings[PHYCORE_R2_MT41K512M16HA125IT_1024MB];
+   break;
+   default:
+   timing = NULL;
+   }
+
+   return timing;
+}
+
+/* @brief Converts a module family and ram size to ram timings
+ *
+ * Returns ram timings for a given ram size and module family or NULL,
+ * if the ram size or module family is not supported.
+ *
+ * @return struct am335x_sdram_timings* or NULL
+ */
+
+static noinline struct am335x_sdram_timings* get_timings_by_size(
+   int module_family, u32 ramsize)
+{
+   struct am335x_sdram_timings *timing;
+
+   switch (module_family) {
+   case PHYCORE_R2:
+   timing = convert_phycore_r2_timings(ramsize);
+   break;
+   default:
+   timing = NULL;
+   }
+
+   return timing;
+}
+
 /**
  * @brief The basic entry point for board initialization.
  *
@@ -55,9 +143,10 @@ static const struct am33xx_cmd_control physom_cmd = {
  *
  * @return void
  */
-static noinline void physom_board_init(int sdram, void *fdt)
+static noinline void physom_board_init(void *fdt, int sdram, int module_family)
 {
-   struct am335x_sdram_timings *timing = &physom_timings[sdram];
+   struct am335x_sdram_timings *timing = NULL;
+   u32 ramsize;
 
/*
 * WDT1 is already running when the bootloader gets control
@@ -71,6 +160,24 @@ static noinline void physom_board_init(int sdram, void *fdt)
 
am33xx_pll_init(MPUPLL_M_600, DDRPLL_M_400);
 
+   if (module_family == NONE) {
+   timing = &physom_timings[sdram];
+   } else {
+   /* Load generic DDR3 ram timings to find the ram size */
+   timing = get_minimal_timings(module_family);
+   if (!timing)
+   hang();
+   am335x_sdram_init(DDR_IOCTRL, &physom_cmd,
+   &timing->regs,
+   &timing->data);
+
+   /* Find the ram size and set up the correct ram timings */
+   ramsize = get_ram_size((long *) 0x8000, SZ_1G);
+  

[PATCH 4/5] common: state: Make find_var public

2017-10-27 Thread Daniel Schultz
Make find_var public to grant access to state variables.

Make also the MAC node public to receive the stored address.

Signed-off-by: Daniel Schultz 
---
 common/state/state.h | 27 +--
 include/state.h  | 26 ++
 2 files changed, 27 insertions(+), 26 deletions(-)

diff --git a/common/state/state.h b/common/state/state.h
index 81aaec2..0fca848 100644
--- a/common/state/state.h
+++ b/common/state/state.h
@@ -1,6 +1,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct state;
 struct mtd_info_user;
@@ -128,16 +129,6 @@ struct variable_type {
  struct device_node *);
 };
 
-/* instance of a single variable */
-struct state_variable {
-   struct state *state;
-   struct list_head list;
-   const char *name;
-   unsigned int start;
-   unsigned int size;
-   void *raw;
-};
-
 /*
  *  uint32
  */
@@ -161,16 +152,6 @@ struct state_enum32 {
 };
 
 /*
- *  MAC address
- */
-struct state_mac {
-   struct state_variable var;
-   struct param_d *param;
-   uint8_t value[6];
-   uint8_t value_default[6];
-};
-
-/*
  *  string
  */
 struct state_string {
@@ -204,7 +185,6 @@ int state_backend_bucket_circular_create(struct device_d 
*dev, const char *path,
 int state_backend_bucket_cached_create(struct device_d *dev,
   struct state_backend_storage_bucket *raw,
   struct state_backend_storage_bucket 
**out);
-struct state_variable *state_find_var(struct state *state, const char *name);
 struct digest *state_backend_format_raw_get_digest(struct state_backend_format
   *format);
 void state_backend_set_readonly(struct state *state);
@@ -229,11 +209,6 @@ static inline struct state_enum32 *to_state_enum32(struct 
state_variable *s)
return container_of(s, struct state_enum32, var);
 }
 
-static inline struct state_mac *to_state_mac(struct state_variable *s)
-{
-   return container_of(s, struct state_mac, var);
-}
-
 static inline struct state_string *to_state_string(struct state_variable *s)
 {
return container_of(s, struct state_string, var);
diff --git a/include/state.h b/include/state.h
index 63164f9..ae67d95 100644
--- a/include/state.h
+++ b/include/state.h
@@ -5,6 +5,30 @@
 
 struct state;
 
+/* instance of a single variable */
+struct state_variable {
+   struct state *state;
+   struct list_head list;
+   const char *name;
+   unsigned int start;
+   unsigned int size;
+   void *raw;
+};
+
+/*
+ *  MAC address
+ */
+struct state_mac {
+   struct state_variable var;
+   struct param_d *param;
+   uint8_t value[6];
+   uint8_t value_default[6];
+};
+static inline struct state_mac *to_state_mac(struct state_variable *s)
+{
+   return container_of(s, struct state_mac, var);
+}
+
 int state_backend_dtb_file(struct state *state, const char *of_path,
const char *path);
 int state_backend_raw_file(struct state *state, const char *of_path,
@@ -23,4 +47,6 @@ int state_load(struct state *state);
 int state_save(struct state *state);
 void state_info(void);
 
+struct state_variable *state_find_var(struct state *state, const char *name);
+
 #endif /* __STATE_H */
-- 
2.7.4


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


[PATCH 2/3] ARM: dts: AM335x: Add dummy i2c nodes

2017-10-27 Thread Daniel Schultz
These i2c nodes are needed for autoenable of i2c clients, because
the autoenable API searches for device tree nodes to get the client
address.

Signed-off-by: Daniel Schultz 
---
 arch/arm/dts/am335x-phytec-phycore-som.dtsi | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/arch/arm/dts/am335x-phytec-phycore-som.dtsi 
b/arch/arm/dts/am335x-phytec-phycore-som.dtsi
index dbc6424..cf2eef3 100644
--- a/arch/arm/dts/am335x-phytec-phycore-som.dtsi
+++ b/arch/arm/dts/am335x-phytec-phycore-som.dtsi
@@ -164,6 +164,20 @@
pagesize = <32>;
reg = <0x52>;
};
+
+   /* The following i2c nodes are for the autoenable */
+   i2c_tmp102: temp@4b {
+   compatible = "ti,tmp102";
+   reg = <0x4b>;
+   status = "disabled";
+   };
+
+   i2c_rtc: rtc@68 {
+   compatible = "rv4162";
+   reg = <0x68>;
+   status = "disabled";
+   };
+
 };
 
 &mmc1 {
-- 
2.7.4


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


[PATCH 2/5] ARM: dts: AM335x: Add state framework

2017-10-27 Thread Daniel Schultz
This patch adds the state framework with an EEPROM partition and two
nodes for MAC addresses. It will be available for all phycore AM335x
images with EEPROMs.

Signed-off-by: Daniel Schultz 
---
 arch/arm/dts/am335x-phytec-phycore-som-emmc.dts|  1 +
 .../dts/am335x-phytec-phycore-som-nand-no-spi.dts  |  1 +
 arch/arm/dts/am335x-phytec-phycore-som-nand.dts|  1 +
 arch/arm/dts/am335x-phytec-state.dtsi  | 52 ++
 4 files changed, 55 insertions(+)
 create mode 100644 arch/arm/dts/am335x-phytec-state.dtsi

diff --git a/arch/arm/dts/am335x-phytec-phycore-som-emmc.dts 
b/arch/arm/dts/am335x-phytec-phycore-som-emmc.dts
index 880700e..f264498 100644
--- a/arch/arm/dts/am335x-phytec-phycore-som-emmc.dts
+++ b/arch/arm/dts/am335x-phytec-phycore-som-emmc.dts
@@ -16,6 +16,7 @@
 
 #include "am33xx.dtsi"
 #include "am335x-phytec-phycore-som.dtsi"
+#include "am335x-phytec-state.dtsi"
 
 / {
model = "Phytec phyCORE EMMC AM335x";
diff --git a/arch/arm/dts/am335x-phytec-phycore-som-nand-no-spi.dts 
b/arch/arm/dts/am335x-phytec-phycore-som-nand-no-spi.dts
index 2c2fab0..b35294c 100644
--- a/arch/arm/dts/am335x-phytec-phycore-som-nand-no-spi.dts
+++ b/arch/arm/dts/am335x-phytec-phycore-som-nand-no-spi.dts
@@ -9,6 +9,7 @@
 
 #include "am33xx.dtsi"
 #include "am335x-phytec-phycore-som.dtsi"
+#include "am335x-phytec-state.dtsi"
 
 / {
model = "Phytec phyCORE AM335x";
diff --git a/arch/arm/dts/am335x-phytec-phycore-som-nand.dts 
b/arch/arm/dts/am335x-phytec-phycore-som-nand.dts
index 6ff2447..4d7606b 100644
--- a/arch/arm/dts/am335x-phytec-phycore-som-nand.dts
+++ b/arch/arm/dts/am335x-phytec-phycore-som-nand.dts
@@ -9,6 +9,7 @@
 
 #include "am33xx.dtsi"
 #include "am335x-phytec-phycore-som.dtsi"
+#include "am335x-phytec-state.dtsi"
 
 / {
model = "Phytec phyCORE AM335x";
diff --git a/arch/arm/dts/am335x-phytec-state.dtsi 
b/arch/arm/dts/am335x-phytec-state.dtsi
new file mode 100644
index 000..fbc35b9
--- /dev/null
+++ b/arch/arm/dts/am335x-phytec-state.dtsi
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2017 PHYTEC Messtechnik GmbH,
+ * Author: Daniel Schultz 
+ *
+ * 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.
+ */
+
+/ {
+   aliases {
+   am335x_phytec_mac_state = &am335x_phytec_mac_state;
+   };
+
+   am335x_phytec_mac_state: am335x_phytec_mac_state {
+   magic = <0x3f45620e>;
+   compatible = "barebox,state";
+   backend-type = "raw";
+   backend = <&backend_state_eeprom>;
+   backend-stridesize = <40>;
+
+   #address-cells = <1>;
+   #size-cells = <1>;
+   mac0 {
+   reg = <0x0 0x6>;
+   type = "mac";
+   };
+   mac1 {
+   reg = <0x6 0x6>;
+   type = "mac";
+   };
+
+   };
+};
+
+&eeprom {
+   status = "okay";
+   partitions {
+   compatible = "fixed-partitions";
+   #size-cells = <1>;
+   #address-cells = <1>;
+   backend_state_eeprom: state@0 {
+   reg = <0x000 0x120>;
+   label = "state-eeprom";
+   };
+   };
+};
-- 
2.7.4


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


[PATCH 1/3] common: Add autoenable for components

2017-10-27 Thread Daniel Schultz
This patch adds an API to automatically enable either hardware components
with existing device drivers or i2c clients. All functions take a device
tree path to find the hardware and will fix up the node status in the
kernel device tree, if it's accessible.

Signed-off-by: Daniel Schultz 
---
 common/Kconfig   |   9 +
 common/Makefile  |   1 +
 common/autoenable.c  | 109 +++
 include/autoenable.h |  21 ++
 4 files changed, 140 insertions(+)
 create mode 100644 common/autoenable.c
 create mode 100644 include/autoenable.h

diff --git a/common/Kconfig b/common/Kconfig
index 57418ca..8d2a3e6 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -712,6 +712,15 @@ config CONSOLE_NONE
 
 endchoice
 
+config KERNEL_AUTOENABLE
+   bool
+   prompt "Autoenable of components"
+   help
+ Say Y to unlock an API for automatically enable either hardware
+ components with existing device drivers or i2c clients. All functions
+ take a device tree path to find the hardware and will fix up the node
+ status in the kernel device tree, if it's accessible.
+
 choice
prompt "Console activation strategy"
depends on CONSOLE_FULL
diff --git a/common/Makefile b/common/Makefile
index 8cd0ab3..4d7b0f9 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -31,6 +31,7 @@ obj-$(CONFIG_FLEXIBLE_BOOTARGS)   += bootargs.o
 obj-$(CONFIG_GLOBALVAR)+= globalvar.o
 obj-$(CONFIG_GREGORIAN_CALENDER) += date.o
 obj-$(CONFIG_KALLSYMS) += kallsyms.o
+obj-$(CONFIG_KERNEL_AUTOENABLE) += autoenable.o
 obj-$(CONFIG_MALLOC_DLMALLOC)  += dlmalloc.o
 obj-$(CONFIG_MALLOC_TLSF)  += tlsf_malloc.o tlsf.o
 obj-$(CONFIG_MALLOC_DUMMY) += dummy_malloc.o
diff --git a/common/autoenable.c b/common/autoenable.c
new file mode 100644
index 000..be76942
--- /dev/null
+++ b/common/autoenable.c
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2017 PHYTEC Messtechnik GmbH,
+ * Author: Daniel Schultz 
+ *
+ * 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 
+
+/**
+ * autoenable_device_by_path() - Autoenable a device by a device tree path
+ * @param path Device tree path up from the root to the device
+ * @return 0 on success, -enodev on failure. If no device found in the device
+ * tree.
+ *
+ * This function will search for a device and will enable it in the kernel
+ * device tree, if it exists and is loaded.
+ */
+int autoenable_device_by_path(char *path)
+{
+   struct device_d *device;
+   struct device_node *node;
+   int ret;
+
+   node = of_find_node_by_name(NULL, path);
+   if (!node)
+   node = of_find_node_by_path(path);
+
+   if (!node)
+   return -ENODEV;
+
+   device = of_find_device_by_node(node);
+   if (!device)
+   return -ENODEV;
+
+   ret = of_register_set_status_fixup(path, 1);
+   if (!ret)
+   printf("autoenabled %s\n", device->name);
+   return ret;
+}
+
+/**
+ * autoenable_i2c_by_path - Autoenable a i2c client by a device tree path
+ * @param path Device tree path up from the root to the i2c client
+ * @return 0 on success, -enodev on failure. If no i2c client found in the i2c
+ * device tree.
+ *
+ * This function will search for a i2c client, tries to write to the client and
+ * will enable it in the kernel device tree, if it exists and is accessible.
+ */
+int autoenable_i2c_by_path(char *path)
+{
+   struct device_node *node;
+   struct i2c_adapter *i2c_adapter;
+   struct i2c_msg msg;
+   char data[1] = {0x0};
+   int addr;
+   const __be32 *ip;
+   int ret;
+
+   node = of_find_node_by_name(NULL, path);
+   if (!node)
+   node = of_find_node_by_path(path);
+   if (!node)
+   return -ENODEV;
+   if (!node->parent)
+   return -ENODEV;
+
+   ip = of_get_property(node, "reg", NULL);
+   if (!ip)
+   return -ENODEV;
+   addr = be32_to_cpup(ip);
+
+   i2c_adapter = of_find_i2c_adapter_by_node(node->parent);
+   if (!i2c_adapter)
+   return -ENODEV;
+
+   msg.buf = data;
+   msg.addr = addr;
+   msg.len = 1;
+
+   /* Try to communicate with the i2c client */
+   ret = i2c_transfer(i2c_adapter, &msg, 1);
+   if (ret == -EREMOTEIO) {
+   return -ENODEV;
+   }
+   if (ret < 1) {
+   

[PATCH 3/3] ARM: phytec-som-am335x: Add autoenable

2017-10-27 Thread Daniel Schultz
Add autoenable for components, which can be populated on an AM335x
phyCORE SoM.

Signed-off-by: Daniel Schultz 
---
 arch/arm/boards/phytec-som-am335x/board.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/arch/arm/boards/phytec-som-am335x/board.c 
b/arch/arm/boards/phytec-som-am335x/board.c
index 34d4df1..5d13471 100644
--- a/arch/arm/boards/phytec-som-am335x/board.c
+++ b/arch/arm/boards/phytec-som-am335x/board.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -136,6 +137,17 @@ static int physom_devices_init(void)
}
}
 
+   /* Enable NAND */
+   autoenable_device_by_path("/ocp/gpmc@5000");
+   /* Enable eMMC */
+   autoenable_device_by_path("/ocp/mmc@481d8000");
+   /* Enable SPI NOR */
+   autoenable_device_by_path("/ocp/spi@4803/m25p80@0");
+
+   autoenable_i2c_by_path("/ocp/i2c@44e0b000/temp@4b");
+   autoenable_i2c_by_path("/ocp/i2c@44e0b000/eeprom@52");
+   autoenable_i2c_by_path("/ocp/i2c@44e0b000/rtc@68");
+
if (IS_ENABLED(CONFIG_SHELL_NONE))
return am33xx_of_register_bootdevice();
 
-- 
2.7.4


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


[PATCH 3/5] ARM: configs: am335x_defconfig: Add state config

2017-10-27 Thread Daniel Schultz
Enable the state framework for all AM335x boards.
---
 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 dd9c3c5..5a236fb 100644
--- a/arch/arm/configs/am335x_defconfig
+++ b/arch/arm/configs/am335x_defconfig
@@ -88,6 +88,7 @@ CONFIG_CMD_OF_FIXUP_STATUS=y
 CONFIG_CMD_OFTREE=y
 CONFIG_CMD_TIME=y
 CONFIG_CMD_MMC_EXTCSD=y
+CONFIG_CMD_STATE=y
 CONFIG_NET=y
 CONFIG_NET_NFS=y
 CONFIG_NET_NETCONSOLE=y
@@ -142,3 +143,5 @@ CONFIG_FS_FAT_LFN=y
 CONFIG_FS_UBIFS=y
 CONFIG_FS_UBIFS_COMPRESSION_LZO=y
 CONFIG_FS_UBIFS_COMPRESSION_ZLIB=y
+CONFIG_STATE=y
+CONFIG_STATE_DRV=y
-- 
2.7.4


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


[PATCH 5/5] ARM: phytec-som-am335x: Set MAC addresses from state

2017-10-27 Thread Daniel Schultz
If a state with the name 'am335x_phytec_mac_state' is available, valid MAC
addresses from this state get registerd to their ethernet device.

Signed-off-by: Daniel Schultz 
---
 arch/arm/boards/phytec-som-am335x/board.c | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/arch/arm/boards/phytec-som-am335x/board.c 
b/arch/arm/boards/phytec-som-am335x/board.c
index dc3b84a..34d4df1 100644
--- a/arch/arm/boards/phytec-som-am335x/board.c
+++ b/arch/arm/boards/phytec-som-am335x/board.c
@@ -21,10 +21,12 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -67,6 +69,10 @@ static char *nandslots[] = {
 
 static int physom_devices_init(void)
 {
+   struct state *state;
+   struct state_variable *sv;
+   struct state_mac *mac;
+
if (!of_machine_is_compatible("phytec,am335x-som"))
return 0;
 
@@ -114,6 +120,22 @@ static int physom_devices_init(void)
ARRAY_SIZE(nandslots));
am33xx_bbu_emmc_mlo_register_handler("MLO.emmc", "/dev/mmc1");
 
+   if (IS_ENABLED(CONFIG_STATE)) {
+   state = state_by_name("am335x_phytec_mac_state");
+   if (state) {
+   sv = state_find_var(state, "mac0");
+   if (!IS_ERR(sv)) {
+   mac = to_state_mac(sv);
+   eth_register_ethaddr(0, mac->value);
+   }
+   sv = state_find_var(state, "mac1");
+   if (!IS_ERR(sv)) {
+   mac = to_state_mac(sv);
+   eth_register_ethaddr(1, mac->value);
+   }
+   }
+   }
+
if (IS_ENABLED(CONFIG_SHELL_NONE))
return am33xx_of_register_bootdevice();
 
-- 
2.7.4


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


Re: [RFC v4 01/10] Add initial RISC-V architecture support

2017-10-05 Thread Daniel Schultz

Hi,

On 10/03/2017 12:21 AM, Antony Pavlov wrote:

On Mon, 2 Oct 2017 12:08:58 +0200
Daniel Schultz  wrote:


Hi,


On 09/29/2017 02:07 PM, Oleksij Rempel wrote:

Hi,

hm... mostly looks identical with existing arch

Am 29.09.2017 um 01:12 schrieb Antony Pavlov:

Signed-off-by: Antony Pavlov 
--
TODOs:

* split patch;
---
   arch/riscv/Kconfig   | 73 +
   arch/riscv/Makefile  | 68 +++
   arch/riscv/boot/Makefile |  2 +
   arch/riscv/boot/main_entry.c | 40 
   arch/riscv/boot/start.S  | 74 ++
   arch/riscv/dts/.gitignore|  >  arch/riscv/dts/Makefile   
   |  9 
   arch/riscv/dts/skeleton.dtsi | 13 ++
   arch/riscv/include/asm/barebox.h |  1 +
   arch/riscv/include/asm/bitops.h  | 35 ++
   arch/riscv/include/asm/bitsperlong.h | 10 
   arch/riscv/include/asm/byteorder.h   | 10 
   arch/riscv/include/asm/common.h  |  6 +++
   arch/riscv/include/asm/elf.h | 11 +
   arch/riscv/include/asm/io.h  |  8 
   arch/riscv/include/asm/mmu.h |  6 +++
   arch/riscv/include/asm/posix_types.h |  1 +
   arch/riscv/include/asm/sections.h|  1 +
   arch/riscv/include/asm/string.h  |  1 +
   arch/riscv/include/asm/swab.h|  6 +++
   arch/riscv/include/asm/types.h   | 60 
   arch/riscv/include/asm/unaligned.h   | 19 
   arch/riscv/lib/.gitignore|  1 +
   arch/riscv/lib/Makefile  |  9 
   arch/riscv/lib/ashldi3.c | 28 
   arch/riscv/lib/ashrdi3.c | 30 
   arch/riscv/lib/asm-offsets.c | 12 +
   arch/riscv/lib/barebox.lds.S | 89 

   arch/riscv/lib/dtb.c | 41 +
   arch/riscv/lib/libgcc.h  | 29 
   arch/riscv/lib/lshrdi3.c | 28 
   arch/riscv/lib/riscv_timer.c | 68 +++
   drivers/of/Kconfig   |  2 +-
   33 files changed, 791 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
new file mode 100644
index 0..b2f0817ef
--- /dev/null
+++ b/arch/riscv/Kconfig
@@ -0,0 +1,73 @@
+config RISCV
+   bool
+   select GENERIC_FIND_NEXT_BIT
+   select HAVE_CONFIGURABLE_MEMORY_LAYOUT
+   select HAVE_CONFIGURABLE_TEXT_BASE
+   select GPIOLIB
+   select OFTREE
+   select COMMON_CLK
+   select COMMON_CLK_OF_PROVIDER
+   select CLKDEV_LOOKUP
+   default y
+
+config ARCH_TEXT_BASE
+   hex
+   default 0x0
+
+config GENERIC_LINKER_SCRIPT
+   bool
+   default y
+
+menu "Machine selection"
+
+choice
+   prompt "CPU selection"
+   default CPU_RV_GENERIC
+
+config CPU_RV_GENERIC
+   bool "Generic RISC-V"
+   select CPU_SUPPORTS_32BIT_KERNEL
+   select CPU_SUPPORTS_64BIT_KERNEL
+
+endchoice
+
+config CPU_SUPPORTS_32BIT_KERNEL
+   bool
+config CPU_SUPPORTS_64BIT_KERNEL
+   bool
+
+choice
+   prompt "barebox code model"
+   default 64BIT
+
+config 32BIT
+   bool "32-bit barebox"
+   depends on CPU_SUPPORTS_32BIT_KERNEL
+   help
+ Select this option to build a 32-bit barebox.
+
+config 64BIT
+   bool "64-bit barebox"
+   depends on CPU_SUPPORTS_64BIT_KERNEL
+   help
+ Select this option to build a 64-bit barebox.
+
+endchoice
+
+config BUILTIN_DTB
+   bool "link a DTB into the barebox image"
+   depends on OFTREE
+
+config BUILTIN_DTB_NAME
+   string "DTB to build into the barebox image"
+   depends on BUILTIN_DTB
+
+endmenu
+
+source common/Kconfig
+source commands/Kconfig
+source net/Kconfig
+source drivers/Kconfig
+source fs/Kconfig
+source lib/Kconfig
+source crypto/Kconfig
diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
new file mode 100644
index 0..4e3318cf1
--- /dev/null
+++ b/arch/riscv/Makefile
@@ -0,0 +1,68 @@
+CPPFLAGS += -fno-strict-aliasing
+
+cflags-y += -fno-pic -pipe
+cflags-y += -Wall -Wmissing-prototypes -Wstrict-prototypes \
+   -Wno-uninitialized -Wno-format -Wno-main -mcmodel=medany
+
+LDFLAGS += $(ldflags-y)
+LDFLAGS_barebox += -nostdlib
+
+TEXT_BASE = $(CONFIG_TEXT_BASE)
+CPPFLAGS += -DTEXT_BASE=$(CONFIG_TEXT_BASE)
+
+ifndef CONFIG_MODULES
+# Add cleanup flags
+CPPFLAGS += -fdata-sections -ffunction-sections
+LDFLAGS_barebox += -static --gc-sections
+endif
+
+KBUILD_BINARY := barebox.bin
+
+machdirs := $(patsubst %,arch/riscv/mach-%/,$(machine-y))
+
+ifneq ($(board-y),)
+BOARD := arch/riscv/boards/$(board-y)/
+else
+BOARD :=
+endif
+
+ifeq ($(KBUILD_SRC),)
+CPPFLAGS += -I$(BOARD)/include
+else
+CPPFLAGS += -I$(srctree)/$(BOARD)/include
+endif
+
+ifeq ($(KBUILD_SRC),)
+CPPFLAGS += $(patsu

Re: [RFC v4 01/10] Add initial RISC-V architecture support

2017-10-02 Thread Daniel Schultz
unsigned int) uu.s.high << bm;
+
+   w.s.high = (unsigned int) uu.s.high >> b;
+   w.s.low = ((unsigned int) uu.s.low >> b) | carries;
+   }
+
+   return w.ll;
+}
+EXPORT_SYMBOL(__lshrdi3);
diff --git a/arch/riscv/lib/riscv_timer.c b/arch/riscv/lib/riscv_timer.c
new file mode 100644
index 0..46181f877
--- /dev/null
+++ b/arch/riscv/lib/riscv_timer.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2017 Antony Pavlov 
+ *
+ * This file is part of barebox.
+ * 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.
+ *
+ */
+
+/**
+ * @file
+ * @brief Clocksource based on RISCV cycle CSR timer
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static uint64_t rdcycle_read(void)
+{
+   register unsigned long __v;
+
+   __asm__ __volatile__ ("rdcycle %0" : "=r" (__v));
+

Maybe you should also add support for 32-bit cores.

+   return __v;
+}
+
+static struct clocksource rdcycle_cs = {
+   .read   = rdcycle_read,
+   .mask   = CLOCKSOURCE_MASK(32),
+};
+


--
Mit freundlichen Grüßen,
With best regards,
  Daniel Schultz


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


Re: [RFC v4 01/10] Add initial RISC-V architecture support

2017-10-02 Thread Daniel Schultz

Hi,


On 09/30/2017 01:57 PM, Antony Pavlov wrote:

On Fri, 29 Sep 2017 14:07:09 +0200
Oleksij Rempel  wrote:


Hi,

hm... mostly looks identical with existing arch

What do you mean when you say "existing arch"?

...


Am 29.09.2017 um 01:12 schrieb Antony Pavlov:

...

diff --git a/arch/riscv/boot/start.S b/arch/riscv/boot/start.S
new file mode 100644
index 0..2fd00f63d
--- /dev/null
+++ b/arch/riscv/boot/start.S
@@ -0,0 +1,74 @@
+/*
+ * Startup Code for MIPS CPU
+ *
+ * based on coreboot/src/arch/riscv/bootblock.S
+ *
+ * Copyright (C) 2016 Antony Pavlov 
+ *
+ * This file is part of barebox.
+ * 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 
+
+   .text
+   .section ".text_entry"
+   .align 2
+
+.globl _start
+_start:
+   li sp, STACK_BASE + STACK_SIZE
+
+   # make room for HLS and initialize it
+   addi sp, sp, -64 /* MENTRY_FRAME_SIZE */
+
+   # poison the stack
+   li t1, STACK_BASE
+   li t0, 0xdeadbeef
+   sw t0, 0(t1)
+
+   # clear any pending interrupts
+   //csrwi mip, 0

should be removed.

Actually not!

I have imported this code from coreboot.

I have commented this line because csrwi does not worked in some cases.

But I have to make additional investigations on csrwi.

CSRRWI is part of the base integer instruction set and the machine mode 
is mandatory. If there are troubles with this instruction, the core has 
a faulty design. So executing this line should be okay even if there is 
no interrupt controller.


--
Mit freundlichen Grüßen,
With best regards,
  Daniel Schultz


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


[PATCH 4/4] arm: configs: AM335x: Enable mmc-extcsd command

2017-08-21 Thread Daniel Schultz
This tool is for setting up eMMC devices.

Signed-off-by: Daniel Schultz 
---
 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 382133b..dd9c3c5 100644
--- a/arch/arm/configs/am335x_defconfig
+++ b/arch/arm/configs/am335x_defconfig
@@ -87,6 +87,7 @@ CONFIG_CMD_OF_DISPLAY_TIMINGS=y
 CONFIG_CMD_OF_FIXUP_STATUS=y
 CONFIG_CMD_OFTREE=y
 CONFIG_CMD_TIME=y
+CONFIG_CMD_MMC_EXTCSD=y
 CONFIG_NET=y
 CONFIG_NET_NFS=y
 CONFIG_NET_NETCONSOLE=y
-- 
2.7.4


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


[PATCH 3/4] arm: dts: am335x: Add phycore emmc device tree

2017-08-21 Thread Daniel Schultz
Add a new device tree for phyCORE SOMs with EMMC enabled and NAND
disabled.

Signed-off-by: Daniel Schultz 
---
 arch/arm/boards/phytec-som-am335x/lowlevel.c|  1 +
 arch/arm/dts/Makefile   |  1 +
 arch/arm/dts/am335x-phytec-phycore-som-emmc.dts | 35 +
 images/Makefile.am33xx  |  4 +++
 4 files changed, 41 insertions(+)
 create mode 100644 arch/arm/dts/am335x-phytec-phycore-som-emmc.dts

diff --git a/arch/arm/boards/phytec-som-am335x/lowlevel.c 
b/arch/arm/boards/phytec-som-am335x/lowlevel.c
index 91a5473..77f436f 100644
--- a/arch/arm/boards/phytec-som-am335x/lowlevel.c
+++ b/arch/arm/boards/phytec-som-am335x/lowlevel.c
@@ -126,6 +126,7 @@ PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_r2_sram_512mb, 
am335x_phytec_phycor
 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_nand_sdram, 
am335x_phytec_phycore_som_nand);
+PHYTEC_ENTRY(start_am33xx_phytec_phycore_emmc_sdram, 
am335x_phytec_phycore_som_emmc);
 PHYTEC_ENTRY(start_am33xx_phytec_phycore_nand_no_spi_sdram, 
am335x_phytec_phycore_som_nand_no_spi);
 PHYTEC_ENTRY(start_am33xx_phytec_phycore_nand_no_eeprom_sdram, 
am335x_phytec_phycore_som_nand_no_eeprom);
 PHYTEC_ENTRY(start_am33xx_phytec_phycore_nand_no_spi_no_eeprom_sdram, 
am335x_phytec_phycore_som_nand_no_spi_no_eeprom);
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 17bba3a..cf9d8ea 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -43,6 +43,7 @@ pbl-dtb-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
am335x-phytec-phyflex-som.dtb.o am33
am335x-phytec-phycore-som-mlo.dtb.o \
am335x-phytec-phycore-som-nand.dtb.o 
am335x-phytec-phycore-som-nand-no-spi.dtb.o \
am335x-phytec-phycore-som-nand-no-eeprom.dtb.o 
am335x-phytec-phycore-som-nand-no-spi-no-eeprom.dtb.o \
+   am335x-phytec-phycore-som-emmc.dtb.o \
am335x-phytec-phycard-som.dtb.o am335x-phytec-phycard-som-mlo.dtb.o
 pbl-dtb-$(CONFIG_MACH_PHYTEC_SOM_IMX6) += imx6q-phytec-pbaa03.dtb.o \
imx6s-phytec-pbab01.dtb.o \
diff --git a/arch/arm/dts/am335x-phytec-phycore-som-emmc.dts 
b/arch/arm/dts/am335x-phytec-phycore-som-emmc.dts
new file mode 100644
index 000..880700e
--- /dev/null
+++ b/arch/arm/dts/am335x-phytec-phycore-som-emmc.dts
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2017 PHYTEC Messtechnik GmbH,
+ * Author: Daniel Schultz 
+ *
+ * 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.
+ */
+
+/dts-v1/;
+
+#include "am33xx.dtsi"
+#include "am335x-phytec-phycore-som.dtsi"
+
+/ {
+   model = "Phytec phyCORE EMMC AM335x";
+   compatible = "phytec,phycore-am335x-som", "phytec,am335x-som", 
"ti,am33xx";
+};
+
+&mmc2 {
+   status = "okay";
+};
+
+&spi0 {
+   status = "okay";
+};
+
+&eeprom {
+   status = "okay";
+};
diff --git a/images/Makefile.am33xx b/images/Makefile.am33xx
index d82627b..e86d4e9 100644
--- a/images/Makefile.am33xx
+++ b/images/Makefile.am33xx
@@ -29,6 +29,10 @@ pblx-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
start_am33xx_phytec_phycore_nand_sdram
 FILE_barebox-am33xx-phytec-phycore.img = 
start_am33xx_phytec_phycore_nand_sdram.pblx
 am33xx-barebox-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore.img
 
+pblx-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += start_am33xx_phytec_phycore_emmc_sdram
+FILE_barebox-am33xx-phytec-phycore-emmc.img = 
start_am33xx_phytec_phycore_emmc_sdram.pblx
+am33xx-barebox-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-emmc.img
+
 pblx-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
start_am33xx_phytec_phycore_nand_no_spi_sdram
 FILE_barebox-am33xx-phytec-phycore-no-spi.img = 
start_am33xx_phytec_phycore_nand_no_spi_sdram.pblx
 am33xx-barebox-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-no-spi.img
-- 
2.7.4


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


[PATCH 2/4] arm: dts: Enable NAND in DTS instead of DTSI

2017-08-21 Thread Daniel Schultz
Starting with PCM-062, NAND isn't the main non-volatile memory for the
AM335x. Because that, NAND has be disabled in the SOM dtsi file and will
be enabled in a specific NAND SOM file.

Signed-off-by: Daniel Schultz 
---
 arch/arm/boards/phytec-som-am335x/lowlevel.c |  8 
 arch/arm/dts/Makefile|  5 +++--
 dts => am335x-phytec-phycore-som-nand-no-eeprom.dts} |  4 
 ... am335x-phytec-phycore-som-nand-no-spi-no-eeprom.dts} |  4 
 ...som.dts => am335x-phytec-phycore-som-nand-no-spi.dts} |  2 +-
 ...som-no-spi.dts => am335x-phytec-phycore-som-nand.dts} |  8 
 arch/arm/dts/am335x-phytec-phycore-som.dtsi  |  2 +-
 images/Makefile.am33xx   | 16 
 8 files changed, 33 insertions(+), 16 deletions(-)
 rename arch/arm/dts/{am335x-phytec-phycore-som-no-eeprom.dts => 
am335x-phytec-phycore-som-nand-no-eeprom.dts} (94%)
 rename arch/arm/dts/{am335x-phytec-phycore-som-no-spi-no-eeprom.dts => 
am335x-phytec-phycore-som-nand-no-spi-no-eeprom.dts} (94%)
 rename arch/arm/dts/{am335x-phytec-phycore-som.dts => 
am335x-phytec-phycore-som-nand-no-spi.dts} (98%)
 rename arch/arm/dts/{am335x-phytec-phycore-som-no-spi.dts => 
am335x-phytec-phycore-som-nand.dts} (89%)

diff --git a/arch/arm/boards/phytec-som-am335x/lowlevel.c 
b/arch/arm/boards/phytec-som-am335x/lowlevel.c
index 03c7e98..91a5473 100644
--- a/arch/arm/boards/phytec-som-am335x/lowlevel.c
+++ b/arch/arm/boards/phytec-som-am335x/lowlevel.c
@@ -125,10 +125,10 @@ 
PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_2x512mb, am335x_phytec_phycore
 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);
-PHYTEC_ENTRY(start_am33xx_phytec_phycore_no_spi_no_eeprom_sdram, 
am335x_phytec_phycore_som_no_spi_no_eeprom);
+PHYTEC_ENTRY(start_am33xx_phytec_phycore_nand_sdram, 
am335x_phytec_phycore_som_nand);
+PHYTEC_ENTRY(start_am33xx_phytec_phycore_nand_no_spi_sdram, 
am335x_phytec_phycore_som_nand_no_spi);
+PHYTEC_ENTRY(start_am33xx_phytec_phycore_nand_no_eeprom_sdram, 
am335x_phytec_phycore_som_nand_no_eeprom);
+PHYTEC_ENTRY(start_am33xx_phytec_phycore_nand_no_spi_no_eeprom_sdram, 
am335x_phytec_phycore_som_nand_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 0ec03bc..17bba3a 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -40,8 +40,9 @@ 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-phycore-som-mlo.dtb.o \
+   am335x-phytec-phycore-som-nand.dtb.o 
am335x-phytec-phycore-som-nand-no-spi.dtb.o \
+   am335x-phytec-phycore-som-nand-no-eeprom.dtb.o 
am335x-phytec-phycore-som-nand-no-spi-no-eeprom.dtb.o \
am335x-phytec-phycard-som.dtb.o am335x-phytec-phycard-som-mlo.dtb.o
 pbl-dtb-$(CONFIG_MACH_PHYTEC_SOM_IMX6) += imx6q-phytec-pbaa03.dtb.o \
imx6s-phytec-pbab01.dtb.o \
diff --git a/arch/arm/dts/am335x-phytec-phycore-som-no-eeprom.dts 
b/arch/arm/dts/am335x-phytec-phycore-som-nand-no-eeprom.dts
similarity index 94%
rename from arch/arm/dts/am335x-phytec-phycore-som-no-eeprom.dts
rename to arch/arm/dts/am335x-phytec-phycore-som-nand-no-eeprom.dts
index 3dd130e..9f0da37 100644
--- a/arch/arm/dts/am335x-phytec-phycore-som-no-eeprom.dts
+++ b/arch/arm/dts/am335x-phytec-phycore-som-nand-no-eeprom.dts
@@ -16,6 +16,10 @@
compatible = "phytec,phycore-am335x-som", "phytec,am335x-som", 
"ti,am33xx";
 };
 
+&gpmc {
+   status = "okay";
+};
+
 &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-nand-no-spi-no-eeprom.dts
similari

[PATCH 1/4] arm: dts: am335x: Add emmc node to phycore-som

2017-08-21 Thread Daniel Schultz
Add the EMMC node to the phycore-som device tree. It's by default
disabled, because NAND is the primary boot device.

Signed-off-by: Daniel Schultz 
---
 arch/arm/dts/am335x-phytec-phycore-som.dtsi | 24 
 1 file changed, 24 insertions(+)

diff --git a/arch/arm/dts/am335x-phytec-phycore-som.dtsi 
b/arch/arm/dts/am335x-phytec-phycore-som.dtsi
index 0b8c454..0025bc7 100644
--- a/arch/arm/dts/am335x-phytec-phycore-som.dtsi
+++ b/arch/arm/dts/am335x-phytec-phycore-som.dtsi
@@ -58,6 +58,21 @@
>;
};
 
+   emmc_pins: pinmux_emmc_pins {
+   pinctrl-single,pins = <
+   0x80 (PIN_INPUT_PULLUP | MUX_MODE2) /* 
gpmc_csn1.mmc1_clk */
+   0x84 (PIN_INPUT_PULLUP | MUX_MODE2) /* 
gpmc_csn2.mmc1_cmd */
+   0x00 (PIN_INPUT_PULLUP | MUX_MODE1) /* 
gpmc_ad0.mmc1_dat0 */
+   0x04 (PIN_INPUT_PULLUP | MUX_MODE1) /* 
gpmc_ad1.mmc1_dat1 */
+   0x08 (PIN_INPUT_PULLUP | MUX_MODE1) /* 
gpmc_ad2.mmc1_dat2 */
+   0x0c (PIN_INPUT_PULLUP | MUX_MODE1) /* 
gpmc_ad3.mmc1_dat3 */
+   0x10 (PIN_INPUT_PULLUP | MUX_MODE1) /* 
gpmc_ad4.mmc1_dat4 */
+   0x14 (PIN_INPUT_PULLUP | MUX_MODE1) /* 
gpmc_ad5.mmc1_dat5 */
+   0x18 (PIN_INPUT_PULLUP | MUX_MODE1) /* 
gpmc_ad6.mmc1_dat6 */
+   0x1c (PIN_INPUT_PULLUP | MUX_MODE1) /* 
gpmc_ad7.mmc1_dat7 */
+   >;
+   };
+
emac_rmii1_pins: pinmux_emac_rmii1_pins {
pinctrl-single,pins = <
0x10c (PIN_INPUT_PULLDOWN | MUX_MODE1)  /* 
mii1_crs.rmii1_crs_dv */
@@ -157,6 +172,15 @@
status = "okay";
 };
 
+&mmc2 {
+   pinctrl-names = "default";
+   pinctrl-0 = <&emmc_pins>;
+   bus-width = <8>;
+   status = "disabled";
+   ti,vcc-aux-disable-is-sleep;
+   non-removable;
+};
+
 &spi0 {
pinctrl-names = "default";
pinctrl-0 = <&spi0_pins>;
-- 
2.7.4


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


[PATCH v6] arm: boards: phytec-som-am335x: Update boot scripts

2017-06-27 Thread Daniel Schultz
Expand the boot scripts by eMMC and clean them up.
Add NV variable files and removed unnecessary kernel bootargs from the
boot scripts.
Add "rootflags='data=journal'" bootarg to SD card boot script.

Signed-off-by: Daniel Schultz 
---
 .../phytec-som-am335x/defaultenv-physom-am335x/boot/emmc |  5 +
 .../phytec-som-am335x/defaultenv-physom-am335x/boot/mmc  |  7 +++
 .../phytec-som-am335x/defaultenv-physom-am335x/boot/nand |  2 +-
 .../phytec-som-am335x/defaultenv-physom-am335x/boot/spi  |  2 +-
 .../defaultenv-physom-am335x/init/bootsource | 16 
 .../defaultenv-physom-am335x/nv/allow_color  |  1 +
 .../defaultenv-physom-am335x/nv/boot.watchdog_timeout|  1 +
 .../defaultenv-physom-am335x/nv/linux.bootargs.base  |  1 +
 .../defaultenv-physom-am335x/nv/linux.bootargs.rootfs|  1 +
 9 files changed, 26 insertions(+), 10 deletions(-)
 create mode 100644 
arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
 create mode 100644 
arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/nv/allow_color
 create mode 100644 
arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/nv/boot.watchdog_timeout
 create mode 100644 
arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/nv/linux.bootargs.base
 create mode 100644 
arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/nv/linux.bootargs.rootfs

diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
new file mode 100644
index 000..b1792a6
--- /dev/null
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+global.bootm.image=/mnt/mmc1.0/linuximage
+global.bootm.oftree=/mnt/mmc1.0/oftree
+global.linux.bootargs.dyn.root="root=/dev/mmcblk1p2 rootflags='data=journal'"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc
index 834669d..77a076d 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc
@@ -1,6 +1,5 @@
 #!/bin/sh
 
-global.bootm.image=/boot/linuximage
-global.bootm.oftree=/boot/oftree
-
-global.linux.bootargs.dyn.root="root=/dev/mmcblk0p2 rw rootwait"
+global.bootm.image=/mnt/mmc0.0/linuximage
+global.bootm.oftree=/mnt/mmc0.0/oftree
+global.linux.bootargs.dyn.root="root=/dev/mmcblk0p2 rootflags='data=journal'"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand
index ece44b7..33f5f02 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand
@@ -5,4 +5,4 @@
 global.bootm.image="/dev/nand0.root.ubi.kernel"
 global.bootm.oftree="/dev/nand0.root.ubi.oftree"
 
-global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=root rw 
rootfstype=ubifs"
+global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=root rootfstype=ubifs"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi
index 71c5834..a321aa9 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi
@@ -4,4 +4,4 @@ global.bootm.image="/dev/m25p0.kernel"
 global.bootm.oftree="/dev/m25p0.oftree"
 
 # Use rootfs from NAND
-global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=nand0.root rw 
rootfstype=ubifs"
+global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=nand0.root 
rootfstype=ubifs"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource
index 3f2ff4b..61a0879 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource
@@ -4,12 +4,20 @@ if [ -n "$nv.boot.default" ]; then
exit
 fi
 
-if [ $bootsource = mmc ]; then
-   global.boot.default="mmc nand spi net"
+if [ -e /dev/mmc1.0 ]; then
+   nvmem="emmc"
+else
+   nvmem="nand"
+fi
+
+if [ $bootsource = mmc -a $bootsource_instance = 1 ]; then
+   global.boot.default="emmc mmc spi net"
+elif [ $bootsource = mmc -a $bootsource_instance = 0 ]; then
+   global.boot.default="mmc $nvmem spi net"
 elif [ $bootsource = nand ]; then
global.boot.default="nand spi mmc net"
 elif [ $bootsource = spi ]; then
-   global.boot.default="spi nand mmc net"
+   glo

Re: [PATCH] defaultenv: bin: init: Add sourcing of config-expansions

2017-06-27 Thread Daniel Schultz

Hi,

Am 26.06.2017 um 08:25 schrieb Sascha Hauer:

On Tue, Jun 20, 2017 at 05:50:56PM +0200, Daniel Schultz wrote:

Hi,

Am 19.06.2017 um 09:34 schrieb Sascha Hauer:

On Tue, Jun 13, 2017 at 03:37:00PM +0200, Daniel Schultz wrote:

This patch adds a further layer to the config hierarchy. It allows a
dynamic configuration of expansions.

Signed-off-by: Daniel Schultz 
---
   defaultenv/defaultenv-2-base/bin/init | 1 +
   1 file changed, 1 insertion(+)

diff --git a/defaultenv/defaultenv-2-base/bin/init 
b/defaultenv/defaultenv-2-base/bin/init
index 7af3c7d..a93ea58 100644
--- a/defaultenv/defaultenv-2-base/bin/init
+++ b/defaultenv/defaultenv-2-base/bin/init
@@ -25,6 +25,7 @@ magicvar -a global.allow_color "Allow color on the console 
(boolean)"
   [ -z "${global.editcmd}" ] && global.editcmd=sedit
   [ -e /env/config-board ] && /env/config-board
+[ -e /env/config-expansions ] && /env/config-expansions


I read the last thread again and I think my question remains
unanswered. Why can't you put the config-expansions to /env/init/ and
let it be executed automatically without changing /bin/init?


I can change the path of the config-expanions file without problems, but I
thought there could be more who need a config for expansions. So, they have
config files with a same behavior in different dirs.


I think we are talking at cross-purposes. All files in /env/init/ are
executed by the init script, so adding stuff that shall be executed
during init to that directory would be the natural way to "expand the
config".

Okay, so I misunderstood you. I will add all config-expansions to 
/env/init, sorry!



Sascha



--
Mit freundlichen Grüßen,
With best regards,
  Daniel Schultz

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


Re: [PATCH v5] arm: boards: phytec-som-am335x: Update boot scripts

2017-06-27 Thread Daniel Schultz

Hi Sascha,

Am 26.06.2017 um 08:35 schrieb Sascha Hauer:

On Tue, Jun 20, 2017 at 05:42:22PM +0200, Daniel Schultz wrote:

Expand the boot scripts with EMMC and add a default file source for
expansions.

Removed "rw" and "rootwait" bootargs from existing boot scripts.


Why is "rootwait" removed? From my experience adding "rootwait" is
pretty essential when booting from mmc. Has that changed?

Ah that's a good point! We add these commands in Yocto, but I forgot the 
use case without Yocto. So I will add a nv/linux.bootargs.rootfs file 
with "rootwait ro fsck.repair=yes" (fsck.repair is a systemd unit).


  
-if [ $bootsource = mmc ]; then

-   global.boot.default="mmc nand spi net"
+if [ -e /dev/mmc1.0 ]; then
+   nvmem="emmc"
+else
+   nvmem="nand"
+fi
+
+if [ $bootsource = mmc -a $bootsource_instance = 1 ]; then
+   global.boot.default="emmc mmc spi net"
+elif [ $bootsource = mmc -a $bootsource_instance = 0 ]; then
+   global.boot.default="mmc $nvmem spi net"
  elif [ $bootsource = nand ]; then
global.boot.default="nand spi mmc net"
  elif [ $bootsource = spi ]; then
-   global.boot.default="spi nand mmc net"
+   global.boot.default="spi $nvmem mmc net"
  elif [ $bootsource = net ]; then
-   global.boot.default="net nand spi mmc"
+   global.boot.default="net $nvmem spi mmc"
  fi


Normally the desired behaviour is that the bootsource can be changed
persistently by setting nv.boot.default to the desired source. This
does not work when global.boot.default gets overwritten after the nvvars
have been read from the environment.

This behaviour is not changed with this patch, but I would welcome a
patch that changes this script to the desired behaviour. This could
be done by changing global.boot.default only when nv.boot.default is
empty.



This is already implemented by a test above these changes, isn't it?

snippet from init/bootsource:
  1 #!/bin/sh 

  2 

  3 if [ -n "$nv.boot.default" ]; then 

  4 exit 

  5 fi 

  6 


  7 if [ -e /dev/mmc1.0 ]; then
  ...


Sascha



--
Mit freundlichen Grüßen,
With best regards,
  Daniel Schultz

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


Re: [PATCH v4] arm: boards: phytec-som-am335x: Update boot scripts

2017-06-20 Thread Daniel Schultz

Hi Sascha,

Am 19.06.2017 um 09:25 schrieb Sascha Hauer:

On Tue, Jun 13, 2017 at 03:37:08PM +0200, Daniel Schultz wrote:

Expand the boot scripts with EMMC and add a default file source for
expansions.

Removed "rw" and "rootwait" bootargs from existing boot scripts.
Added "rootflags='data=journal'" bootarg to SD card boot script.

Signed-off-by: Daniel Schultz 
---
+#!/bin/sh
+
+path="/mnt/tftp"
+
+global.bootm.image="${path}/${global.user}-linux-${global.hostname}"
+
+oftree="${path}/${global.user}-oftree-${global.hostname}"
+if [ -f "${oftree}" ]; then
+global.bootm.oftree="$oftree"
+fi
+
+nfsroot="/nfsroot/${global.hostname}"


This assumed there is one nfsroot for all users. The intention with the
original naming was that each user can create a link in his home
directory to wherever the nfsroot lives, which may include some globally
available nfsroot for all users. Why change it?

Seems like this was an older script. We will switch to the Barebox 
network boot script.



+bootargs-ip
+
+global.linux.bootargs.dyn.root="root=/dev/nfs nfsroot=$nfsroot,vers=3,udp"


Why udp? Normally tcp is preferred, no?


UDP is used as default by the nfsroot kernel system and also by tftp.
Additionally, we had troubles with booting in tcp mode.


Sascha



--
Mit freundlichen Grüßen,
With best regards,
  Daniel Schultz

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


Re: [PATCH] defaultenv: bin: init: Add sourcing of config-expansions

2017-06-20 Thread Daniel Schultz

Hi,

Am 19.06.2017 um 09:34 schrieb Sascha Hauer:

On Tue, Jun 13, 2017 at 03:37:00PM +0200, Daniel Schultz wrote:

This patch adds a further layer to the config hierarchy. It allows a
dynamic configuration of expansions.

Signed-off-by: Daniel Schultz 
---
  defaultenv/defaultenv-2-base/bin/init | 1 +
  1 file changed, 1 insertion(+)

diff --git a/defaultenv/defaultenv-2-base/bin/init 
b/defaultenv/defaultenv-2-base/bin/init
index 7af3c7d..a93ea58 100644
--- a/defaultenv/defaultenv-2-base/bin/init
+++ b/defaultenv/defaultenv-2-base/bin/init
@@ -25,6 +25,7 @@ magicvar -a global.allow_color "Allow color on the console 
(boolean)"
  [ -z "${global.editcmd}" ] && global.editcmd=sedit
  
  [ -e /env/config-board ] && /env/config-board

+[ -e /env/config-expansions ] && /env/config-expansions


I read the last thread again and I think my question remains
unanswered. Why can't you put the config-expansions to /env/init/ and
let it be executed automatically without changing /bin/init?

I can change the path of the config-expanions file without problems, but 
I thought there could be more who need a config for expansions. So, they 
have config files with a same behavior in different dirs.


--
Mit freundlichen Grüßen,
With best regards,
  Daniel Schultz

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


[PATCH v5] arm: boards: phytec-som-am335x: Update boot scripts

2017-06-20 Thread Daniel Schultz
Expand the boot scripts with EMMC and add a default file source for
expansions.

Removed "rw" and "rootwait" bootargs from existing boot scripts.
Added "rootflags='data=journal'" bootarg to SD card boot script.

Signed-off-by: Daniel Schultz 
---
 .../phytec-som-am335x/defaultenv-physom-am335x/boot/emmc |  5 +
 .../phytec-som-am335x/defaultenv-physom-am335x/boot/mmc  |  7 +++
 .../phytec-som-am335x/defaultenv-physom-am335x/boot/nand |  2 +-
 .../phytec-som-am335x/defaultenv-physom-am335x/boot/spi  |  2 +-
 .../defaultenv-physom-am335x/init/bootsource | 16 
 5 files changed, 22 insertions(+), 10 deletions(-)
 create mode 100644 
arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc

diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
new file mode 100644
index 000..b1792a6
--- /dev/null
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+global.bootm.image=/mnt/mmc1.0/linuximage
+global.bootm.oftree=/mnt/mmc1.0/oftree
+global.linux.bootargs.dyn.root="root=/dev/mmcblk1p2 rootflags='data=journal'"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc
index 834669d..77a076d 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc
@@ -1,6 +1,5 @@
 #!/bin/sh
 
-global.bootm.image=/boot/linuximage
-global.bootm.oftree=/boot/oftree
-
-global.linux.bootargs.dyn.root="root=/dev/mmcblk0p2 rw rootwait"
+global.bootm.image=/mnt/mmc0.0/linuximage
+global.bootm.oftree=/mnt/mmc0.0/oftree
+global.linux.bootargs.dyn.root="root=/dev/mmcblk0p2 rootflags='data=journal'"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand
index ece44b7..33f5f02 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand
@@ -5,4 +5,4 @@
 global.bootm.image="/dev/nand0.root.ubi.kernel"
 global.bootm.oftree="/dev/nand0.root.ubi.oftree"
 
-global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=root rw 
rootfstype=ubifs"
+global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=root rootfstype=ubifs"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi
index 71c5834..a321aa9 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi
@@ -4,4 +4,4 @@ global.bootm.image="/dev/m25p0.kernel"
 global.bootm.oftree="/dev/m25p0.oftree"
 
 # Use rootfs from NAND
-global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=nand0.root rw 
rootfstype=ubifs"
+global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=nand0.root 
rootfstype=ubifs"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource
index 3f2ff4b..61a0879 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource
@@ -4,12 +4,20 @@ if [ -n "$nv.boot.default" ]; then
exit
 fi
 
-if [ $bootsource = mmc ]; then
-   global.boot.default="mmc nand spi net"
+if [ -e /dev/mmc1.0 ]; then
+   nvmem="emmc"
+else
+   nvmem="nand"
+fi
+
+if [ $bootsource = mmc -a $bootsource_instance = 1 ]; then
+   global.boot.default="emmc mmc spi net"
+elif [ $bootsource = mmc -a $bootsource_instance = 0 ]; then
+   global.boot.default="mmc $nvmem spi net"
 elif [ $bootsource = nand ]; then
global.boot.default="nand spi mmc net"
 elif [ $bootsource = spi ]; then
-   global.boot.default="spi nand mmc net"
+   global.boot.default="spi $nvmem mmc net"
 elif [ $bootsource = net ]; then
-   global.boot.default="net nand spi mmc"
+   global.boot.default="net $nvmem spi mmc"
 fi
-- 
1.9.1


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


[PATCH] defaultenv: bin: init: Add sourcing of config-expansions

2017-06-13 Thread Daniel Schultz
This patch adds a further layer to the config hierarchy. It allows a
dynamic configuration of expansions.

Signed-off-by: Daniel Schultz 
---
 defaultenv/defaultenv-2-base/bin/init | 1 +
 1 file changed, 1 insertion(+)

diff --git a/defaultenv/defaultenv-2-base/bin/init 
b/defaultenv/defaultenv-2-base/bin/init
index 7af3c7d..a93ea58 100644
--- a/defaultenv/defaultenv-2-base/bin/init
+++ b/defaultenv/defaultenv-2-base/bin/init
@@ -25,6 +25,7 @@ magicvar -a global.allow_color "Allow color on the console 
(boolean)"
 [ -z "${global.editcmd}" ] && global.editcmd=sedit
 
 [ -e /env/config-board ] && /env/config-board
+[ -e /env/config-expansions ] && /env/config-expansions
 /env/config
 
 # allow to stop the boot before execute the /env/init/*
-- 
1.9.1


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


Re: [PATCH v4] arm: boards: phytec-som-am335x: Update boot scripts

2017-06-13 Thread Daniel Schultz

could you also please apply these patches to the next release?

ls: Fix showing links to directories
fs: Implement links to directories
fs: drop path_check_prereq()
errno: Include string for ELOOP
arm: mach-omap: Change mountpoint of boot partitions
fs: Create automount entries for the default mount pathes

Daniel

Am 13.06.2017 um 15:37 schrieb Daniel Schultz:

Expand the boot scripts with EMMC and add a default file source for
expansions.

Removed "rw" and "rootwait" bootargs from existing boot scripts.
Added "rootflags='data=journal'" bootarg to SD card boot script.

Signed-off-by: Daniel Schultz 
---
  .../phytec-som-am335x/defaultenv-physom-am335x/boot/emmc |  5 +
  .../phytec-som-am335x/defaultenv-physom-am335x/boot/mmc  |  7 +++
  .../phytec-som-am335x/defaultenv-physom-am335x/boot/nand |  2 +-
  .../phytec-som-am335x/defaultenv-physom-am335x/boot/net  | 15 +++
  .../phytec-som-am335x/defaultenv-physom-am335x/boot/spi  |  2 +-
  .../defaultenv-physom-am335x/init/bootsource | 16 
  6 files changed, 37 insertions(+), 10 deletions(-)
  create mode 100644 
arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
  create mode 100644 
arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/net

diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
new file mode 100644
index 000..b1792a6
--- /dev/null
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+global.bootm.image=/mnt/mmc1.0/linuximage
+global.bootm.oftree=/mnt/mmc1.0/oftree
+global.linux.bootargs.dyn.root="root=/dev/mmcblk1p2 rootflags='data=journal'"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc
index 834669d..77a076d 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc
@@ -1,6 +1,5 @@
  #!/bin/sh
  
-global.bootm.image=/boot/linuximage

-global.bootm.oftree=/boot/oftree
-
-global.linux.bootargs.dyn.root="root=/dev/mmcblk0p2 rw rootwait"
+global.bootm.image=/mnt/mmc0.0/linuximage
+global.bootm.oftree=/mnt/mmc0.0/oftree
+global.linux.bootargs.dyn.root="root=/dev/mmcblk0p2 rootflags='data=journal'"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand
index ece44b7..33f5f02 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand
@@ -5,4 +5,4 @@
  global.bootm.image="/dev/nand0.root.ubi.kernel"
  global.bootm.oftree="/dev/nand0.root.ubi.oftree"
  
-global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=root rw rootfstype=ubifs"

+global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=root rootfstype=ubifs"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/net 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/net
new file mode 100644
index 000..1005199
--- /dev/null
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/net
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+path="/mnt/tftp"
+
+global.bootm.image="${path}/${global.user}-linux-${global.hostname}"
+
+oftree="${path}/${global.user}-oftree-${global.hostname}"
+if [ -f "${oftree}" ]; then
+global.bootm.oftree="$oftree"
+fi
+
+nfsroot="/nfsroot/${global.hostname}"
+bootargs-ip
+
+global.linux.bootargs.dyn.root="root=/dev/nfs nfsroot=$nfsroot,vers=3,udp"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi
index 71c5834..a321aa9 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi
@@ -4,4 +4,4 @@ global.bootm.image="/dev/m25p0.kernel"
  global.bootm.oftree="/dev/m25p0.oftree"
  
  # Use rootfs from NAND

-global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=nand0.root rw 
rootfstype=ubifs"
+global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=nand0.root 
rootfstype=ubifs"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource
index 3f2ff4b..61a0879 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource
@@ -4,12 +4,20 @@ if [ -n "$nv.boot.default" ]

[PATCH v4] arm: boards: phytec-som-am335x: Update boot scripts

2017-06-13 Thread Daniel Schultz
Expand the boot scripts with EMMC and add a default file source for
expansions.

Removed "rw" and "rootwait" bootargs from existing boot scripts.
Added "rootflags='data=journal'" bootarg to SD card boot script.

Signed-off-by: Daniel Schultz 
---
 .../phytec-som-am335x/defaultenv-physom-am335x/boot/emmc |  5 +
 .../phytec-som-am335x/defaultenv-physom-am335x/boot/mmc  |  7 +++
 .../phytec-som-am335x/defaultenv-physom-am335x/boot/nand |  2 +-
 .../phytec-som-am335x/defaultenv-physom-am335x/boot/net  | 15 +++
 .../phytec-som-am335x/defaultenv-physom-am335x/boot/spi  |  2 +-
 .../defaultenv-physom-am335x/init/bootsource | 16 
 6 files changed, 37 insertions(+), 10 deletions(-)
 create mode 100644 
arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
 create mode 100644 
arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/net

diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
new file mode 100644
index 000..b1792a6
--- /dev/null
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+global.bootm.image=/mnt/mmc1.0/linuximage
+global.bootm.oftree=/mnt/mmc1.0/oftree
+global.linux.bootargs.dyn.root="root=/dev/mmcblk1p2 rootflags='data=journal'"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc
index 834669d..77a076d 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc
@@ -1,6 +1,5 @@
 #!/bin/sh
 
-global.bootm.image=/boot/linuximage
-global.bootm.oftree=/boot/oftree
-
-global.linux.bootargs.dyn.root="root=/dev/mmcblk0p2 rw rootwait"
+global.bootm.image=/mnt/mmc0.0/linuximage
+global.bootm.oftree=/mnt/mmc0.0/oftree
+global.linux.bootargs.dyn.root="root=/dev/mmcblk0p2 rootflags='data=journal'"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand
index ece44b7..33f5f02 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand
@@ -5,4 +5,4 @@
 global.bootm.image="/dev/nand0.root.ubi.kernel"
 global.bootm.oftree="/dev/nand0.root.ubi.oftree"
 
-global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=root rw 
rootfstype=ubifs"
+global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=root rootfstype=ubifs"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/net 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/net
new file mode 100644
index 000..1005199
--- /dev/null
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/net
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+path="/mnt/tftp"
+
+global.bootm.image="${path}/${global.user}-linux-${global.hostname}"
+
+oftree="${path}/${global.user}-oftree-${global.hostname}"
+if [ -f "${oftree}" ]; then
+global.bootm.oftree="$oftree"
+fi
+
+nfsroot="/nfsroot/${global.hostname}"
+bootargs-ip
+
+global.linux.bootargs.dyn.root="root=/dev/nfs nfsroot=$nfsroot,vers=3,udp"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi
index 71c5834..a321aa9 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi
@@ -4,4 +4,4 @@ global.bootm.image="/dev/m25p0.kernel"
 global.bootm.oftree="/dev/m25p0.oftree"
 
 # Use rootfs from NAND
-global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=nand0.root rw 
rootfstype=ubifs"
+global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=nand0.root 
rootfstype=ubifs"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource
index 3f2ff4b..61a0879 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource
@@ -4,12 +4,20 @@ if [ -n "$nv.boot.default" ]; then
exit
 fi
 
-if [ $bootsource = mmc ]; then
-   global.boot.default="mmc nand spi net"
+if [ -e /dev/mmc1.0 ]; then
+   nvmem="emmc"
+else
+   nvmem="nand"
+fi
+
+if [ $bootsource = mmc -a $bootsource_instance = 1 ]; then
+   global.boot.default="emmc mmc spi net"
+elif [ $bootsource = mmc -a $bootsour

Re: [PATCH] mtd: nand: omap: Fix BCH bit correction

2017-06-13 Thread Daniel Schultz

Hi Sascha,

Am 12.06.2017 um 15:41 schrieb Sascha Hauer:

Hi Daniel,

On Fri, Jun 09, 2017 at 03:28:59PM +0200, Daniel Schultz wrote:

Hi,

Am 09.06.2017 um 11:08 schrieb Sascha Hauer:

On Fri, Jun 09, 2017 at 10:17:55AM +0200, Daniel Schultz wrote:

Hi Sascha,



And can not work. Additionally eccsteps must be set to 1 in
omap_correct_bch(). This effectively makes the loop in this function
unnecessary which can then removed.


Which then means omap_gpmc_read_page_bch_rom_mode() has to iterate over
ecc.steps itself, just like the other read_page implementations in the
framework do.


So, the previous assignment of eccsteps was fine?


I just sent an updated patch(-series). Could you give it a try?


It works, but the current version only changes the local copy of the
pointer. As a result of that it will only check the first 512 Bytes.
I appended a double pointer workaround for this problem :)


The pointer should be incremented by the caller, not by
omap_correct_bch().




omap_correct_data() also calls omap_correct_bch(). Does Barebox correct NAND
partitions? I have never seen this. Maybe we need here also a loop.


The core already loops around eccsteps when calling ecc.correct.

I digged a bit further and this is what I can come up with. Anyway, I am
getting less and less confident that the patch can work.

Please give it a try and see if it works. If it doesn't and we can't
find out what's wrong I tend to take your original patch, although I
still think this is the wrong solution.



With these changes it works, but I only testes with nand_bitflip. Idk if 
there're better ways to test NAND ECC. However, after 6 bitflips on one 
subpage it will successfully boot in the backup partition, with less 
than 6 it will boot the bitflipped-partition.


Daniel

diff --git a/drivers/mtd/nand/nand_omap_gpmc.c 
b/drivers/mtd/nand/nand_omap_gpmc.c

index 2e130bf..9006e2e 100644
--- a/drivers/mtd/nand/nand_omap_gpmc.c
+++ b/drivers/mtd/nand/nand_omap_gpmc.c
@@ -684,10 +684,10 @@ static int omap_gpmc_read_page_bch_rom_mode(struct 
mtd_info *mtd,


__omap_calculate_ecc(mtd, buf, ecc_calc, 1);

-   for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) {
-   stat = omap_correct_bch(mtd, p, ecc_code, ecc_calc);
-   ecc_code += eccsize + 1;
-   ecc_calc += eccsize;
+   for (i = 0; eccsteps; eccsteps--, i += eccbytes, buf += eccsize) {
+   stat = omap_correct_bch(mtd, buf, ecc_code, ecc_calc);
+   ecc_code += eccbytes + 1;
+   ecc_calc += eccbytes;
if (stat < 0) {
mtd->ecc_stats.failed++;
} else {



Sascha

8<--

 From 2c65a009dbcf2136e037f009b50306aa080e2920 Mon Sep 17 00:00:00 2001
From: Sascha Hauer 
Date: Fri, 9 Jun 2017 10:45:21 +0200
Subject: [PATCH] mtd: nand_omap_gpmc: Fix ecc size

The ECC size for BCH correction is always 512 byte. Correct the ecc.size
for the OMAP_ECC_BCH8_CODE_HW mode from 2048 to 512. This change will
let the framework iterate over the 4 ecc steps and we no longer need
special cases in omap_correct_bch().

Signed-off-by: Sascha Hauer 
---
  drivers/mtd/nand/nand_omap_gpmc.c | 130 +-
  1 file changed, 57 insertions(+), 73 deletions(-)

diff --git a/drivers/mtd/nand/nand_omap_gpmc.c 
b/drivers/mtd/nand/nand_omap_gpmc.c
index e18ce6358a..2e130bfd9a 100644
--- a/drivers/mtd/nand/nand_omap_gpmc.c
+++ b/drivers/mtd/nand/nand_omap_gpmc.c
@@ -297,85 +297,59 @@ 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, eccflag;
const uint8_t *erased_ecc_vec;
unsigned int err_loc[8];
int bitflip_count;
int bch_max_err;
-
-   int eccsteps = (nand->ecc.mode == NAND_ECC_HW) &&
-   (nand->ecc.size == 2048) ? 4 : 1;
int eccsize = oinfo->nand.ecc.bytes;
+   bool is_error_reported = false;
  
-	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;
-   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");
-   return -EINVAL;
-   }
-
-   totalcount = 0;
+   erased_ecc_vec = bch8_vector;
+   bch_max_err = BCH8_MAX_ERROR;
  
-	for (i = 0; 

Re: [PATCH] mtd: nand: omap: Fix BCH bit correction

2017-06-09 Thread Daniel Schultz

Hi,

Am 09.06.2017 um 11:08 schrieb Sascha Hauer:

On Fri, Jun 09, 2017 at 10:17:55AM +0200, Daniel Schultz wrote:

Hi Sascha,



And can not work. Additionally eccsteps must be set to 1 in
omap_correct_bch(). This effectively makes the loop in this function
unnecessary which can then removed.


Which then means omap_gpmc_read_page_bch_rom_mode() has to iterate over
ecc.steps itself, just like the other read_page implementations in the
framework do.


So, the previous assignment of eccsteps was fine?


I just sent an updated patch(-series). Could you give it a try?

It works, but the current version only changes the local copy of the 
pointer. As a result of that it will only check the first 512 Bytes.

I appended a double pointer workaround for this problem :)


omap_correct_data() also calls omap_correct_bch(). Does Barebox correct 
NAND partitions? I have never seen this. Maybe we need here also a loop.




From 2b104598933b00cd33a85333ce72a49de7230507 Mon Sep 17 00:00:00 2001
From: Daniel Schultz 
Date: Fri, 9 Jun 2017 15:15:30 +0200
Subject: [PATCH] Add double pointer to current OMAP NAND ECC patch stack

Signed-off-by: Daniel Schultz 
---
 drivers/mtd/nand/nand_omap_gpmc.c | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/mtd/nand/nand_omap_gpmc.c 
b/drivers/mtd/nand/nand_omap_gpmc.c

index 334014a..7608545 100644
--- a/drivers/mtd/nand/nand_omap_gpmc.c
+++ b/drivers/mtd/nand/nand_omap_gpmc.c
@@ -292,8 +292,8 @@ static int omap_calculate_ecc(struct mtd_info *mtd, 
const uint8_t *dat,

return __omap_calculate_ecc(mtd, dat, ecc_code, 0);
 }

-static int omap_correct_bch(struct mtd_info *mtd, uint8_t *dat,
-uint8_t *read_ecc, uint8_t *calc_ecc)
+static int omap_correct_bch(struct mtd_info *mtd, uint8_t **dat,
+uint8_t **read_ecc, uint8_t **calc_ecc)
 {
struct nand_chip *nand = (struct nand_chip *)(mtd->priv);
struct gpmc_nand_info *oinfo = (struct gpmc_nand_info *)(nand->priv);
@@ -328,14 +328,14 @@ static int omap_correct_bch(struct mtd_info *mtd, 
uint8_t *dat,


/* 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) {
-   if (memcmp(calc_ecc, erased_ecc_vec, actual_eccsize) == 0) {
+   if (memcmp(*calc_ecc, erased_ecc_vec, actual_eccsize) == 0) {
/*
 * calc_ecc[] matches pattern for ECC
 * (all 0xff) so this is definitely
@@ -343,7 +343,7 @@ static int omap_correct_bch(struct mtd_info *mtd, 
uint8_t *dat,

 */
} else {
bitflip_count = nand_check_erased_ecc_chunk(
-   dat, oinfo->nand.ecc.size, read_ecc,
+   *dat, oinfo->nand.ecc.size, *read_ecc,
eccsize, NULL, 0, bch_max_err);
if (bitflip_count < 0)
is_error_reported = true;
@@ -352,22 +352,22 @@ static int omap_correct_bch(struct mtd_info *mtd, 
uint8_t *dat,


if (is_error_reported) {
bitflip_count = omap_gpmc_decode_bch(1,
-   calc_ecc, err_loc);
+   *calc_ecc, err_loc);
if (bitflip_count < 0)
return bitflip_count;

for (j = 0; j < bitflip_count; j++) {
if (err_loc[j] < 4096)
-   dat[err_loc[j] >> 3] ^=
+   (*dat)[err_loc[j] >> 3] ^=
1 << (err_loc[j] & 7);
/* else, not interested to correct ecc */
}
}

totalcount += bitflip_count;
-   calc_ecc = calc_ecc + actual_eccsize;
-   read_ecc = read_ecc + eccsize;
-   dat += 512;
+   *calc_ecc += actual_eccsize;
+   *read_ecc += eccsize;
+   *dat += 512;

return totalcount;
 }
@@ -449,7 +449,7 @@ static int omap_correct_data(struct mtd_info *mtd, 
uint8_t *dat,

 * this time with oob data.
 */
__omap_calculate_ecc(mtd, dat, calc_ecc, 0);
-   return omap_correct_bch(mtd, dat, read_ecc, calc_ecc);
+   return omap_correct_bch(mtd, &dat, &read_ecc, &calc_ecc);
default:
return -EINVAL;
}
@@ -705,7 +705,7 @@ static int omap_gpmc_read_page_bch_rom_mode(struct 
mtd_info *mtd,

__omap_calculate_ecc(mtd, buf, ecc_calc, 1);

for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) {

Re: [PATCH] mtd: nand: omap: Fix BCH bit correction

2017-06-09 Thread Daniel Schultz

Hi Sascha,

Am 07.06.2017 um 08:53 schrieb Sascha Hauer:

On Wed, Jun 07, 2017 at 08:49:09AM +0200, Sascha Hauer wrote:

On Wed, Jun 07, 2017 at 08:45:08AM +0200, Sascha Hauer wrote:

+Cc Matt Reimer 

On Tue, Jun 06, 2017 at 06:10:25PM +0200, Daniel Schultz wrote:

After commit dec7b4d2bf9 was applied our barebox only corrected the
first 512 Bytes of NAND pages.

This patch separates between Hamming and BCH when finding out the
eccsteps, because BCH always works with 2kB pages.

Before this patch:

barebox@Phytec phyCORE AM335x:/ nand_bitflip -r -n 5 /dev/nand0.barebox
nand0.barebox: Flipping bit 5 @ 1796
nand0.barebox: Flipping bit 6 @ 1258
nand0.barebox: Flipping bit 5 @ 1062
nand0.barebox: Flipping bit 2 @ 1399
nand0.barebox: Flipping bit 6 @ 1243
No bitflips found on block 0, offset 0x
barebox@Phytec phyCORE AM335x:/ nand_bitflip -r -n 5 /dev/nand0.barebox
nand0.barebox: Flipping bit 2 @ 872
nand0.barebox: Flipping bit 4 @ 252
nand0.barebox: Flipping bit 3 @ 568
nand0.barebox: Flipping bit 2 @ 247
nand0.barebox: Flipping bit 5 @ 401
page at block 0, offset 0x has 3 bitflips

After this patch:

barebox@Phytec phyCORE AM335x:/ nand_bitflip -r -n 5 /dev/nand0.barebox
nand0.barebox: Flipping bit 2 @ 1962
nand0.barebox: Flipping bit 0 @ 1563
nand0.barebox: Flipping bit 0 @ 1808
nand0.barebox: Flipping bit 6 @ 1460
nand0.barebox: Flipping bit 7 @ 2034
page at block 0, offset 0x has 5 bitflips
barebox@Phytec phyCORE AM335x:/ nand_bitflip -r -n 5 /dev/nand0.barebox
nand0.barebox: Flipping bit 1 @ 1352
nand0.barebox: Flipping bit 7 @ 1542
nand0.barebox: Flipping bit 2 @ 1021
nand0.barebox: Flipping bit 7 @ 691
nand0.barebox: Flipping bit 6 @ 1196
page at block 0, offset 0x has 10 bitflips, needs cleanup

Signed-off-by: Daniel Schultz 
---
  drivers/mtd/nand/nand_omap_gpmc.c | 11 +--
  1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/nand_omap_gpmc.c 
b/drivers/mtd/nand/nand_omap_gpmc.c
index 05c8486..61220da 100644
--- a/drivers/mtd/nand/nand_omap_gpmc.c
+++ b/drivers/mtd/nand/nand_omap_gpmc.c
@@ -302,10 +302,17 @@ static int omap_correct_bch(struct mtd_info *mtd, uint8_t 
*dat,
unsigned int err_loc[8];
int bitflip_count;
int bch_max_err;
+   int eccsteps;
  
-	int eccsteps = (nand->ecc.mode == NAND_ECC_HW) &&

-   (nand->ecc.size == 2048) ? 4 : 1;
int eccsize = oinfo->nand.ecc.bytes;
+   if (oinfo->ecc_mode == OMAP_ECC_HAMMING_CODE_HW_ROMCODE)


This is wrong. When in Hamming ECC mode you shouldn't get into this
function. The test should always fail.

That's why I added this test. I don't know why this change was made [1]



+   if ((nand->ecc.mode == NAND_ECC_HW) &&
+   (nand->ecc.size == 2048))
+   eccsteps = 4;
+   else
+   eccsteps = 1;


The question is why ecc.size is set to the wrong value in the first
place:

case OMAP_ECC_BCH8_CODE_HW:
...
oinfo->nand.ecc.size = 512 * 4;

This seems to be wrong. The BCH controller works in 512 Byte chunks, so
ecc.size should be 512. This would make the special cases in
omap_correct_bch() unnecessary.
Only OMAP_ECC_BCH8_CODE_HW_ROMCODE can call 
omap_gpmc_read_page_bch_rom_mode(). So, this should be no problem, but 
this multiplying is not in the kernel. Maybe this can affect older 
systems (OMAP_ECC_BCH8_CODE_HW is only used by old phycards).


In dec7b4d2bf9 Matt said:

|  The fix is to pull over a bit of code from the kernel's
|  omap_correct_data() that sets eccsteps = 4 when the page size is 2048
|  bytes and hardware ECC is being used.

In fact, this piece is in the kernel code:

/* Ex NAND_ECC_HW12_2048 */
if ((info->nand.ecc.mode == NAND_ECC_HW) &&
(info->nand.ecc.size  == 2048))
blockCnt = 4;
else
blockCnt = 1;

[1] since this is from the Hamming logic and not BCH.

This is a snippet from the linux-ti kernel:

 case OMAP_ECC_HAM1_CODE_HW: 

 pr_info("nand: using OMAP_ECC_HAM1_CODE_HW\n"); 

 nand_chip->ecc.mode = NAND_ECC_HW; 

 nand_chip->ecc.bytes= 3; 

 nand_chip->ecc.size = 512; 

 nand_chip->ecc.strength = 1; 

 nand_chip->ecc.calculate= omap_calculate_ecc; 

 nand_chip->ecc.hwctl= omap_enable_hwecc; 

 nand_chip->ecc.correct  = omap_correct_data; 

 /* define ECC layout */ 


 ecclayout->eccbytes = nand_chip->ecc.bytes
 ...

 case OMAP_ECC_BCH8_CODE_HW: 

 nand_chip->ecc.mode   = NAND_ECC_HW; 


[PATCH] mtd: nand: omap: Fix BCH bit correction

2017-06-06 Thread Daniel Schultz
After commit dec7b4d2bf9 was applied our barebox only corrected the
first 512 Bytes of NAND pages.

This patch separates between Hamming and BCH when finding out the
eccsteps, because BCH always works with 2kB pages.

Before this patch:

barebox@Phytec phyCORE AM335x:/ nand_bitflip -r -n 5 /dev/nand0.barebox
nand0.barebox: Flipping bit 5 @ 1796
nand0.barebox: Flipping bit 6 @ 1258
nand0.barebox: Flipping bit 5 @ 1062
nand0.barebox: Flipping bit 2 @ 1399
nand0.barebox: Flipping bit 6 @ 1243
No bitflips found on block 0, offset 0x
barebox@Phytec phyCORE AM335x:/ nand_bitflip -r -n 5 /dev/nand0.barebox
nand0.barebox: Flipping bit 2 @ 872
nand0.barebox: Flipping bit 4 @ 252
nand0.barebox: Flipping bit 3 @ 568
nand0.barebox: Flipping bit 2 @ 247
nand0.barebox: Flipping bit 5 @ 401
page at block 0, offset 0x has 3 bitflips

After this patch:

barebox@Phytec phyCORE AM335x:/ nand_bitflip -r -n 5 /dev/nand0.barebox
nand0.barebox: Flipping bit 2 @ 1962
nand0.barebox: Flipping bit 0 @ 1563
nand0.barebox: Flipping bit 0 @ 1808
nand0.barebox: Flipping bit 6 @ 1460
nand0.barebox: Flipping bit 7 @ 2034
page at block 0, offset 0x has 5 bitflips
barebox@Phytec phyCORE AM335x:/ nand_bitflip -r -n 5 /dev/nand0.barebox
nand0.barebox: Flipping bit 1 @ 1352
nand0.barebox: Flipping bit 7 @ 1542
nand0.barebox: Flipping bit 2 @ 1021
nand0.barebox: Flipping bit 7 @ 691
nand0.barebox: Flipping bit 6 @ 1196
page at block 0, offset 0x has 10 bitflips, needs cleanup

Signed-off-by: Daniel Schultz 
---
 drivers/mtd/nand/nand_omap_gpmc.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/nand_omap_gpmc.c 
b/drivers/mtd/nand/nand_omap_gpmc.c
index 05c8486..61220da 100644
--- a/drivers/mtd/nand/nand_omap_gpmc.c
+++ b/drivers/mtd/nand/nand_omap_gpmc.c
@@ -302,10 +302,17 @@ static int omap_correct_bch(struct mtd_info *mtd, uint8_t 
*dat,
unsigned int err_loc[8];
int bitflip_count;
int bch_max_err;
+   int eccsteps;
 
-   int eccsteps = (nand->ecc.mode == NAND_ECC_HW) &&
-   (nand->ecc.size == 2048) ? 4 : 1;
int eccsize = oinfo->nand.ecc.bytes;
+   if (oinfo->ecc_mode == OMAP_ECC_HAMMING_CODE_HW_ROMCODE)
+   if ((nand->ecc.mode == NAND_ECC_HW) &&
+   (nand->ecc.size == 2048))
+   eccsteps = 4;
+   else
+   eccsteps = 1;
+   else
+   eccsteps = oinfo->nand.ecc.steps;
 
switch (oinfo->ecc_mode) {
case OMAP_ECC_BCH8_CODE_HW:
-- 
1.9.1


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


[PATCH] mtd: nand: omap: Return corrected bits for BCH

2017-06-06 Thread Daniel Schultz
If using ECC mode OMAP_ECC_HAMMING_CODE_HW_ROMCODE (which is default for
all AM335x with DTS support) the page_read function won't return the
corrected bitflips.

Signed-off-by: Daniel Schultz 
---
 drivers/mtd/nand/nand_omap_gpmc.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/nand_omap_gpmc.c 
b/drivers/mtd/nand/nand_omap_gpmc.c
index e18ce63..05c8486 100644
--- a/drivers/mtd/nand/nand_omap_gpmc.c
+++ b/drivers/mtd/nand/nand_omap_gpmc.c
@@ -707,10 +707,12 @@ static int omap_gpmc_read_page_bch_rom_mode(struct 
mtd_info *mtd,
__omap_calculate_ecc(mtd, buf, ecc_calc, 1);
 
stat = omap_correct_bch(mtd, buf, ecc_code, ecc_calc);
-   if (stat < 0)
+   if (stat < 0) {
mtd->ecc_stats.failed++;
-   else
+   } else {
mtd->ecc_stats.corrected += stat;
+   return stat;
+   }
 
return 0;
 }
-- 
1.9.1


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


Re: [PATCH v3 4/4] arm: boards: beaglebone: Delete default env

2017-06-06 Thread Daniel Schultz

Hi Sascha,

Am 17.05.2017 um 08:35 schrieb Sascha Hauer:

On Fri, May 12, 2017 at 01:07:19PM +0200, Daniel Schultz wrote:

The Beaglebone environment should be set from outside with an application
specific environment.

Signed-off-by: Daniel Schultz 
---
  arch/arm/boards/beaglebone/Makefile | 1 -
  arch/arm/boards/beaglebone/board.c  | 2 --
  arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/sd| 6 --
  .../arm/boards/beaglebone/defaultenv-beaglebone/init/usb-limit-1300 | 5 -
  4 files changed, 14 deletions(-)
  delete mode 100644 arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/sd
  delete mode 100644 
arch/arm/boards/beaglebone/defaultenv-beaglebone/init/usb-limit-1300

--- a/arch/arm/boards/beaglebone/defaultenv-beaglebone/init/usb-limit-1300
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-
-echo -n "changing USB current limit to 1300 mA... "
-i2c_write -b 0 -a 0x24 -r 0x01 0x3e
-echo "done"


We need this on the beagleboard. We can't just delete it without doing
this somewhere else.

Also I still do not understand the reasoning behind this change. Where
is "outside", to which application should the environment be specific
to?

Please revoke this patch. Sorry.



Sascha



--
Mit freundlichen Grüßen,
With best regards,
  Daniel Schultz

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


Re: [PATCH v3 3/4] arm: boards: phytec-som-am335x: Update boot scripts

2017-06-06 Thread Daniel Schultz

Hi Sascha,

Am 06.06.2017 um 07:46 schrieb Sascha Hauer:

Hi Daniel,

On Fri, Jun 02, 2017 at 10:07:34AM +0200, Daniel Schultz wrote:

Hi,

Am 17.05.2017 um 08:30 schrieb Sascha Hauer:

On Fri, May 12, 2017 at 01:07:18PM +0200, Daniel Schultz wrote:

Expand the boot scripts with EMMC and add a default file source for
expansions.

Removed "rw" and "rootwait" bootargs from existing boot scripts.
Added "rootflags='data=journal'" bootarg to SD card boot script.

Signed-off-by: Daniel Schultz 
---
   .../defaultenv-physom-am335x/boot/emmc  |  7 +++
   .../phytec-som-am335x/defaultenv-physom-am335x/boot/mmc |  7 ---
   .../defaultenv-physom-am335x/boot/nand  |  4 +++-
   .../phytec-som-am335x/defaultenv-physom-am335x/boot/net | 17 
+
   .../phytec-som-am335x/defaultenv-physom-am335x/boot/spi |  4 +++-
   .../defaultenv-physom-am335x/init/bootsource| 16 
   6 files changed, 46 insertions(+), 9 deletions(-)
   create mode 100644 
arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
   create mode 100644 
arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/net

diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
new file mode 100644
index 000..6ad5f87
--- /dev/null
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+[ -e /env/config-expansions ] && /env/config-expansions


What do you have in these config-expansions or what do you expect to be
there?



These config-expanions files contain source commands for different
expansions like HDMI, LCD, WiFi, ... and are written from Yocto. We don't
want to bring these mainline, but without this line we have to overwrite
each boot script file from Yocto.

Maybe this could be a good feature since we're not the only one with
expansion configurations.


I am generally open to such expansions, I just want to understand what's
missing first.
In this case I'd like to understand why you can't add an init script to
/env/bin/init/ instead. If you want to extend the kernel commandline you
could also add a nv variable to /env/nv/linux.bootargs.yocto.



Oh I didn't know this part of the bin/init script. What do you think 
about this change? This would complete the config hierarchy by expensions:


+++ b/defaultenv/defaultenv-2-base/bin/init
@@ -25,6 +25,7 @@ magicvar -a global.allow_color "Allow color on the 
console (boolean)"

 [ -z "${global.editcmd}" ] && global.editcmd=sedit

 [ -e /env/config-board ] && /env/config-board
+[ -e /env/config-expansions ] && /env/config-expansions
 /env/config

 # allow to stop the boot before execute the /env/init/*

Otherwise I would move the config-expanions scripts to init/

The problem with the nv vars are the differences between the 
bootsources. Is there a way to add these vars with something like 
linux.bootargs.rootfs.mmc ?


--
Mit freundlichen Grüßen,
With best regards,
  Daniel Schultz

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


[PATCH] fs: Makefile: Add parseopt to all builds

2017-06-02 Thread Daniel Schultz
parseopt.h was included to fs.c with commit 9248b, but parseopt.o has a
dependency to CONFIG_FS_NFS.

Moved parseopt.o to the default build to eliminate build failures.

Signed-off-by: Daniel Schultz 
---
 fs/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/Makefile b/fs/Makefile
index f2bb702..b3f929f 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -4,11 +4,11 @@ obj-$(CONFIG_FS_RAMFS)+= ramfs.o
 obj-y  += devfs-core.o
 obj-$(CONFIG_FS_DEVFS) += devfs.o
 obj-$(CONFIG_FS_FAT)   += fat/
-obj-y  += fs.o
+obj-y  += fs.o parseopt.o
 obj-$(CONFIG_FS_UBIFS) += ubifs/
 obj-$(CONFIG_FS_TFTP)  += tftp.o
 obj-$(CONFIG_FS_OMAP4_USBBOOT) += omap4_usbbootfs.o
-obj-$(CONFIG_FS_NFS)   += nfs.o parseopt.o
+obj-$(CONFIG_FS_NFS)   += nfs.o
 obj-$(CONFIG_FS_BPKFS) += bpkfs.o
 obj-$(CONFIG_FS_UIMAGEFS)  += uimagefs.o
 obj-$(CONFIG_FS_EFI)+= efi.o
-- 
1.9.1


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


Re: [PATCH v3 3/4] arm: boards: phytec-som-am335x: Update boot scripts

2017-06-02 Thread Daniel Schultz

Hi,

Am 17.05.2017 um 08:30 schrieb Sascha Hauer:

On Fri, May 12, 2017 at 01:07:18PM +0200, Daniel Schultz wrote:

Expand the boot scripts with EMMC and add a default file source for
expansions.

Removed "rw" and "rootwait" bootargs from existing boot scripts.
Added "rootflags='data=journal'" bootarg to SD card boot script.

Signed-off-by: Daniel Schultz 
---
  .../defaultenv-physom-am335x/boot/emmc  |  7 +++
  .../phytec-som-am335x/defaultenv-physom-am335x/boot/mmc |  7 ---
  .../defaultenv-physom-am335x/boot/nand  |  4 +++-
  .../phytec-som-am335x/defaultenv-physom-am335x/boot/net | 17 +
  .../phytec-som-am335x/defaultenv-physom-am335x/boot/spi |  4 +++-
  .../defaultenv-physom-am335x/init/bootsource| 16 
  6 files changed, 46 insertions(+), 9 deletions(-)
  create mode 100644 
arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
  create mode 100644 
arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/net

diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
new file mode 100644
index 000..6ad5f87
--- /dev/null
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+[ -e /env/config-expansions ] && /env/config-expansions


What do you have in these config-expansions or what do you expect to be
there?



These config-expanions files contain source commands for different 
expansions like HDMI, LCD, WiFi, ... and are written from Yocto. We 
don't want to bring these mainline, but without this line we have to 
overwrite each boot script file from Yocto.


Maybe this could be a good feature since we're not the only one with 
expansion configurations.


--
Mit freundlichen Grüßen,
With best regards,
  Daniel Schultz

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


Re: [PATCH v3 2/4] arm: boards: phytec-som-am335x: Add automount script

2017-06-02 Thread Daniel Schultz

Hi,

Am 17.05.2017 um 08:26 schrieb Sascha Hauer:

On Fri, May 12, 2017 at 01:07:17PM +0200, Daniel Schultz wrote:

Each MMC boot source is mounted to /mnt/mmcN.0. To make the not-mounted
boot source available in Barebox, an automount script mounts
this device also to /mnt/, if the directory will be accessed.

Signed-off-by: Daniel Schultz 
---
  .../defaultenv-physom-am335x/init/automount | 21 +
  1 file changed, 21 insertions(+)
  create mode 100644 
arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/automount


This should not be needed when "fs: Create automount entries for the
default mount pathes" is applied, right?


If your patch will mount every mountable device to /mnt/, this patch is 
not necessary.


Daniel


Sascha



diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/automount 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/automount
new file mode 100644
index 000..53ecbe3
--- /dev/null
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/automount
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+# automount tftp server based on $eth0.serverip
+
+mkdir -p /mnt/tftp
+automount /mnt/tftp 'ifup eth0 && mount -t tftp $eth0.serverip /mnt/tftp'
+
+# automount nfs server's nfsroot
+
+mkdir -p /mnt/nfs
+automount /mnt/nfs 'ifup eth0 && mount -t nfs 
${eth0.serverip}:/home/${global.user}/nfsroot/${global.hostname} /mnt/nfs'
+
+#automount SD card and EMMC boot partitions
+
+if [ $bootsource = mmc -a $bootsource_instance = 1 ]; then
+   mkdir -p /mnt/mmc0.0
+   automount /mnt/mmc0.0 '[ -e /dev/mmc0.0 ] && mount /dev/mmc0.0 
/mnt/mmc0.0'
+else
+   mkdir -p /mnt/mmc1.0
+   automount /mnt/mmc1.0 '[ -e /dev/mmc1.0 ] && mount /dev/mmc1.0 
/mnt/mmc1.0'
+fi
--
1.9.1


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





--
Mit freundlichen Grüßen,
With best regards,
  Daniel Schultz

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


Re: [PATCH] mtd: nand_omap_gpmc: fix BCH error correction

2017-05-26 Thread Daniel Schultz

Hi Matt,

could you give me some more informations about how you figured out this 
problem and how you tested it?


The Linux kernel and Barebox differs a lot in this driver. Your 
conditional assignment of eccsteps is from the omap_correct_data 
function, which will only be called if Hamming error correction is used, 
but BCH uses either omap_elm_correct_data or nand_bch_correct_data. 
These two function use the old way of getting eccsteps.


After I applied your patch, only the first 512 Bytes of a page was 
corrected (I made omap_correct_bch more verbose), before that the whole 
page was corrected. BCH in Barebox (which is default by the DTS) can 
only use the ROMCODE one, which has a default ECC size of 512 Bytes. So, 
eccsteps would always be 1, instead of 4.


Since hamming is using the omap_correct_hamming function, maybe this 
patch isn't needed?


--
Mit freundlichen Grüßen,
With best regards,
  Daniel Schultz

Am 14.04.2017 um 20:32 schrieb Matt Reimer:

BCH error detection and correction was only looking at the first
of four syndrome polynomials, which meant it was failing to detect
and correct bitflips in the last 3/4 of the data. In effect, only
the first 512 bytes of a 2048 byte page were being protected by ECC.

The syndrome polynomials (BCH error codes) are stored in the NAND's
OOB, each of which protects 512 bytes of data. The driver used
eccsteps = 1 which effectively made it only use the first polynomial,
and therefore was only protecting the first 512 bytes of the page.

The fix is to pull over a bit of code from the kernel's
omap_correct_data() that sets eccsteps = 4 when the page size is 2048
bytes and hardware ECC is being used.

Signed-off-by: Matt Reimer 
---
  drivers/mtd/nand/nand_omap_gpmc.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/nand_omap_gpmc.c 
b/drivers/mtd/nand/nand_omap_gpmc.c
index 9d9d27e..2fe6a10 100644
--- a/drivers/mtd/nand/nand_omap_gpmc.c
+++ b/drivers/mtd/nand/nand_omap_gpmc.c
@@ -302,7 +302,8 @@ static int omap_correct_bch(struct mtd_info *mtd, uint8_t 
*dat,
unsigned int err_loc[8];
int select_4_8;
  
-	int eccsteps = oinfo->nand.ecc.steps;

+int eccsteps = (nand->ecc.mode == NAND_ECC_HW) &&
+(nand->ecc.size == 2048) ? 4 : 1;
int eccsize = oinfo->nand.ecc.bytes;
  
  	switch (oinfo->ecc_mode) {






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


Re: [PATCH v2 1/5] arm: mach-omap: Change mountpoint of boot partitions

2017-05-12 Thread Daniel Schultz

Hi,

Am 11.05.2017 um 11:14 schrieb Sascha Hauer:

Hi Daniel,

Your series wasn't forgotten. It's only that it took me some time to try
and implement links to directories. With this series I just sent and
"fs: Create automount entries for the default mount pathes" you should
be able to make this series a bit nicer. What I think of is that /boot
becomes a link to /mnt/mmcx.y or whatever provided /boot previously.

Could you give it a try?
I added this to the newest patch series. Now, all AM335x boards can 
either boot from /boot or one of the /mnt/ boot partitions. Non Phytec 
Boards won't need an environment change. Thanks!


You can decide if you want the 4th path (delete BBB environment).

Daniel



Sascha


If using EMMC and SD as bootsources, mounting the boot partition of both
devices to /boot makes trouble. Either the correct device is mounted to
/boot or a remount of /boot has to be performed.

To ensure this problem each MMCn bootsource will be mounted to his own
path in /mnt/mmcN.0

Signed-off-by: Daniel Schultz 
---
 arch/arm/mach-omap/omap_generic.c | 31 ---
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/arch/arm/mach-omap/omap_generic.c 
b/arch/arm/mach-omap/omap_generic.c
index 1d03eac..aa7424d 100644
--- a/arch/arm/mach-omap/omap_generic.c
+++ b/arch/arm/mach-omap/omap_generic.c
@@ -113,12 +113,15 @@ const char *omap_get_bootmmc_devname(void)
 }

 #if defined(CONFIG_ENV_HANDLING)
-#define ENV_PATH "/boot/barebox.env"
+static char *envpath = "/mnt/mmc0.0/barebox.env";
+
 static int omap_env_init(void)
 {
-   char *partname;
-   const char *diskdev;
int ret;
+   const char *diskdev;
+   char *partname;
+   struct cdev *cdev;
+   const char *rootpath;

if (bootsource_get() != BOOTSOURCE_MMC)
return 0;
@@ -129,18 +132,24 @@ static int omap_env_init(void)
diskdev = "disk0";

device_detect_by_name(diskdev);
+   partname = basprintf("%s.0", diskdev);
+   cdev = cdev_by_name(partname);
+   if (cdev == NULL) {
+   pr_err("Failed to get device %s\n", partname);
+   goto out;
+   }

-   partname = basprintf("/dev/%s.0", diskdev);
-
-   mkdir("/boot", 0666);
-   ret = mount(partname, "fat", "/boot", NULL);
-   if (ret) {
-   pr_err("Failed to load environment: mount %s failed (%d)\n", 
partname, ret);
+   rootpath = cdev_mount_default(cdev, NULL);
+   if (IS_ERR(rootpath)) {
+   pr_err("Failed to load environment: mount %s failed (%d)\n",
+   cdev->name, IS_ERR(rootpath));
goto out;
}
+   envpath = basprintf("%s/barebox.env", rootpath);

-   pr_debug("Loading default env from %s on device %s\n", ENV_PATH, 
partname);
-   default_environment_path_set(ENV_PATH);
+   pr_debug("Loading default env from %s on device %s\n", envpath,
+   partname);
+   default_environment_path_set(envpath);

 out:
free(partname);
--
1.9.1


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





--
Mit freundlichen Grüßen,
With best regards,
  Daniel Schultz

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


[PATCH v3 1/4] arm: mach-omap: Change mountpoint of boot partitions

2017-05-12 Thread Daniel Schultz
If using EMMC and SD as bootsources, mounting the boot partition of both
devices to /boot makes trouble. Either the correct device is mounted to
/boot or a remount of /boot has to be performed.

To ensure this problem each MMCn bootsource will be mounted to his own
path in /mnt/mmcN.0

Signed-off-by: Daniel Schultz 
---
Changes:
v3: Added symlink from rootpath to BOOT_PATH

 arch/arm/mach-omap/omap_generic.c | 36 +---
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/arch/arm/mach-omap/omap_generic.c 
b/arch/arm/mach-omap/omap_generic.c
index 1d03eac..694c951 100644
--- a/arch/arm/mach-omap/omap_generic.c
+++ b/arch/arm/mach-omap/omap_generic.c
@@ -113,12 +113,15 @@ const char *omap_get_bootmmc_devname(void)
 }
 
 #if defined(CONFIG_ENV_HANDLING)
-#define ENV_PATH "/boot/barebox.env"
+static char *envpath = "/mnt/mmc0.0/barebox.env";
+
 static int omap_env_init(void)
 {
-   char *partname;
-   const char *diskdev;
int ret;
+   const char *diskdev;
+   char *partname;
+   struct cdev *cdev;
+   const char *rootpath;
 
if (bootsource_get() != BOOTSOURCE_MMC)
return 0;
@@ -129,18 +132,29 @@ static int omap_env_init(void)
diskdev = "disk0";
 
device_detect_by_name(diskdev);
+   partname = basprintf("%s.0", diskdev);
+   cdev = cdev_by_name(partname);
+   if (cdev == NULL) {
+   pr_err("Failed to get device %s\n", partname);
+   goto out;
+   }
 
-   partname = basprintf("/dev/%s.0", diskdev);
-
-   mkdir("/boot", 0666);
-   ret = mount(partname, "fat", "/boot", NULL);
-   if (ret) {
-   pr_err("Failed to load environment: mount %s failed (%d)\n", 
partname, ret);
+   rootpath = cdev_mount_default(cdev, NULL);
+   if (IS_ERR(rootpath)) {
+   pr_err("Failed to load environment: mount %s failed (%d)\n",
+   cdev->name, IS_ERR(rootpath));
goto out;
}
+   ret = symlink(rootpath, "/boot");
+   if (ret < 0)
+   pr_warn("Failed to create symlink from %s to %s\n", rootpath
+   , "/boot");
+
+   envpath = basprintf("%s/barebox.env", rootpath);
 
-   pr_debug("Loading default env from %s on device %s\n", ENV_PATH, 
partname);
-   default_environment_path_set(ENV_PATH);
+   pr_debug("Loading default env from %s on device %s\n", envpath,
+   partname);
+   default_environment_path_set(envpath);
 
 out:
free(partname);
-- 
1.9.1


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


[PATCH v3 3/4] arm: boards: phytec-som-am335x: Update boot scripts

2017-05-12 Thread Daniel Schultz
Expand the boot scripts with EMMC and add a default file source for
expansions.

Removed "rw" and "rootwait" bootargs from existing boot scripts.
Added "rootflags='data=journal'" bootarg to SD card boot script.

Signed-off-by: Daniel Schultz 
---
 .../defaultenv-physom-am335x/boot/emmc  |  7 +++
 .../phytec-som-am335x/defaultenv-physom-am335x/boot/mmc |  7 ---
 .../defaultenv-physom-am335x/boot/nand  |  4 +++-
 .../phytec-som-am335x/defaultenv-physom-am335x/boot/net | 17 +
 .../phytec-som-am335x/defaultenv-physom-am335x/boot/spi |  4 +++-
 .../defaultenv-physom-am335x/init/bootsource| 16 
 6 files changed, 46 insertions(+), 9 deletions(-)
 create mode 100644 
arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
 create mode 100644 
arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/net

diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
new file mode 100644
index 000..6ad5f87
--- /dev/null
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+[ -e /env/config-expansions ] && /env/config-expansions
+
+global.bootm.image=/mnt/mmc1.0/linuximage
+global.bootm.oftree=/mnt/mmc1.0/oftree
+global.linux.bootargs.dyn.root="root=/dev/mmcblk1p2 rootflags='data=journal'"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc
index 834669d..0fefeb2 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc
@@ -1,6 +1,7 @@
 #!/bin/sh
 
-global.bootm.image=/boot/linuximage
-global.bootm.oftree=/boot/oftree
+[ -e /env/config-expansions ] && /env/config-expansions
 
-global.linux.bootargs.dyn.root="root=/dev/mmcblk0p2 rw rootwait"
+global.bootm.image=/mnt/mmc0.0/linuximage
+global.bootm.oftree=/mnt/mmc0.0/oftree
+global.linux.bootargs.dyn.root="root=/dev/mmcblk0p2 rootflags='data=journal'"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand
index ece44b7..fa695bb 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand
@@ -1,8 +1,10 @@
 #!/bin/sh
 
+[ -e /env/config-expansions ] && /env/config-expansions
+
 [ ! -e /dev/nand0.root.ubi ] && ubiattach /dev/nand0.root
 
 global.bootm.image="/dev/nand0.root.ubi.kernel"
 global.bootm.oftree="/dev/nand0.root.ubi.oftree"
 
-global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=root rw 
rootfstype=ubifs"
+global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=root rootfstype=ubifs"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/net 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/net
new file mode 100644
index 000..6dbd2aa
--- /dev/null
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/net
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+path="/mnt/tftp"
+
+global.bootm.image="${path}/${global.user}-linux-${global.hostname}"
+
+oftree="${path}/${global.user}-oftree-${global.hostname}"
+if [ -f "${oftree}" ]; then
+global.bootm.oftree="$oftree"
+fi
+
+nfsroot="/nfsroot/${global.hostname}"
+bootargs-ip
+
+[ -e /env/config-expansions ] && /env/config-expansions
+
+global.linux.bootargs.dyn.root="root=/dev/nfs nfsroot=$nfsroot,vers=3,udp"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi
index 71c5834..2d88626 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi
@@ -1,7 +1,9 @@
 #!/bin/sh
 
+[ -e /env/config-expansions ] && /env/config-expansions
+
 global.bootm.image="/dev/m25p0.kernel"
 global.bootm.oftree="/dev/m25p0.oftree"
 
 # Use rootfs from NAND
-global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=nand0.root rw 
rootfstype=ubifs"
+global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=nand0.root 
rootfstype=ubifs"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource
index 3f2ff4b..61a0879 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource
@@ -4

[PATCH v3 2/4] arm: boards: phytec-som-am335x: Add automount script

2017-05-12 Thread Daniel Schultz
Each MMC boot source is mounted to /mnt/mmcN.0. To make the not-mounted
boot source available in Barebox, an automount script mounts
this device also to /mnt/, if the directory will be accessed.

Signed-off-by: Daniel Schultz 
---
 .../defaultenv-physom-am335x/init/automount | 21 +
 1 file changed, 21 insertions(+)
 create mode 100644 
arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/automount

diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/automount 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/automount
new file mode 100644
index 000..53ecbe3
--- /dev/null
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/automount
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+# automount tftp server based on $eth0.serverip
+
+mkdir -p /mnt/tftp
+automount /mnt/tftp 'ifup eth0 && mount -t tftp $eth0.serverip /mnt/tftp'
+
+# automount nfs server's nfsroot
+
+mkdir -p /mnt/nfs
+automount /mnt/nfs 'ifup eth0 && mount -t nfs 
${eth0.serverip}:/home/${global.user}/nfsroot/${global.hostname} /mnt/nfs'
+
+#automount SD card and EMMC boot partitions
+
+if [ $bootsource = mmc -a $bootsource_instance = 1 ]; then
+   mkdir -p /mnt/mmc0.0
+   automount /mnt/mmc0.0 '[ -e /dev/mmc0.0 ] && mount /dev/mmc0.0 
/mnt/mmc0.0'
+else
+   mkdir -p /mnt/mmc1.0
+   automount /mnt/mmc1.0 '[ -e /dev/mmc1.0 ] && mount /dev/mmc1.0 
/mnt/mmc1.0'
+fi
-- 
1.9.1


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


[PATCH v3 4/4] arm: boards: beaglebone: Delete default env

2017-05-12 Thread Daniel Schultz
The Beaglebone environment should be set from outside with an application
specific environment.

Signed-off-by: Daniel Schultz 
---
 arch/arm/boards/beaglebone/Makefile | 1 -
 arch/arm/boards/beaglebone/board.c  | 2 --
 arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/sd| 6 --
 .../arm/boards/beaglebone/defaultenv-beaglebone/init/usb-limit-1300 | 5 -
 4 files changed, 14 deletions(-)
 delete mode 100644 arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/sd
 delete mode 100644 
arch/arm/boards/beaglebone/defaultenv-beaglebone/init/usb-limit-1300

diff --git a/arch/arm/boards/beaglebone/Makefile 
b/arch/arm/boards/beaglebone/Makefile
index 21a1a29..092c31d 100644
--- a/arch/arm/boards/beaglebone/Makefile
+++ b/arch/arm/boards/beaglebone/Makefile
@@ -1,3 +1,2 @@
 lwl-y += lowlevel.o
 obj-y += board.o
-bbenv-y += defaultenv-beaglebone
diff --git a/arch/arm/boards/beaglebone/board.c 
b/arch/arm/boards/beaglebone/board.c
index 5717c45..fc16aea 100644
--- a/arch/arm/boards/beaglebone/board.c
+++ b/arch/arm/boards/beaglebone/board.c
@@ -85,8 +85,6 @@ static int beaglebone_devices_init(void)
 
black = is_beaglebone_black();
 
-   defaultenv_append_directory(defaultenv_beaglebone);
-
globalvar_add_simple("board.variant", black ? "boneblack" : "bone");
 
printf("detected 'BeagleBone %s'\n", black ? "Black" : "White");
diff --git a/arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/sd 
b/arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/sd
deleted file mode 100644
index aa94b2f..000
--- a/arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/sd
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/sh
-
-global.bootm.image=/boot/uImage
-global.bootm.oftree=/boot/oftree
-#global.bootm.initrd=
-global.linux.bootargs.dyn.root="root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
diff --git 
a/arch/arm/boards/beaglebone/defaultenv-beaglebone/init/usb-limit-1300 
b/arch/arm/boards/beaglebone/defaultenv-beaglebone/init/usb-limit-1300
deleted file mode 100644
index 56313bf..000
--- a/arch/arm/boards/beaglebone/defaultenv-beaglebone/init/usb-limit-1300
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-
-echo -n "changing USB current limit to 1300 mA... "
-i2c_write -b 0 -a 0x24 -r 0x01 0x3e
-echo "done"
-- 
1.9.1


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


Re: [PATCH v2 4/5] arm: boards: beaglebone: Delete default env

2017-05-09 Thread Daniel Schultz

Hi Sascha,

Am 08.05.2017 um 14:57 schrieb Sascha Hauer:

Hi Daniel,

On Fri, May 05, 2017 at 04:46:57PM +0200, Daniel Schultz wrote:

The Beaglebone environment should be set from outside with an application
specific environment.


I don't understand this. What are you trying to archieve and why?

I thought you prefer the bootloader spec way without a predefined 
environment, but maybe I just had misunderstood you. If so, I will only 
change the mount path of the boot partition.


--
Mit freundlichen Grüßen,
With best regards,
  Daniel Schultz


Sascha



Signed-off-by: Daniel Schultz 
---
 arch/arm/boards/beaglebone/Makefile | 1 -
 arch/arm/boards/beaglebone/board.c  | 2 --
 arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/sd| 6 --
 .../arm/boards/beaglebone/defaultenv-beaglebone/init/usb-limit-1300 | 5 -
 4 files changed, 14 deletions(-)
 delete mode 100644 arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/sd
 delete mode 100644 
arch/arm/boards/beaglebone/defaultenv-beaglebone/init/usb-limit-1300

diff --git a/arch/arm/boards/beaglebone/Makefile 
b/arch/arm/boards/beaglebone/Makefile
index 21a1a29..092c31d 100644
--- a/arch/arm/boards/beaglebone/Makefile
+++ b/arch/arm/boards/beaglebone/Makefile
@@ -1,3 +1,2 @@
 lwl-y += lowlevel.o
 obj-y += board.o
-bbenv-y += defaultenv-beaglebone
diff --git a/arch/arm/boards/beaglebone/board.c 
b/arch/arm/boards/beaglebone/board.c
index 5717c45..fc16aea 100644
--- a/arch/arm/boards/beaglebone/board.c
+++ b/arch/arm/boards/beaglebone/board.c
@@ -85,8 +85,6 @@ static int beaglebone_devices_init(void)

black = is_beaglebone_black();

-   defaultenv_append_directory(defaultenv_beaglebone);
-
globalvar_add_simple("board.variant", black ? "boneblack" : "bone");

printf("detected 'BeagleBone %s'\n", black ? "Black" : "White");
diff --git a/arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/sd 
b/arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/sd
deleted file mode 100644
index aa94b2f..000
--- a/arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/sd
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/sh
-
-global.bootm.image=/boot/uImage
-global.bootm.oftree=/boot/oftree
-#global.bootm.initrd=
-global.linux.bootargs.dyn.root="root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
diff --git 
a/arch/arm/boards/beaglebone/defaultenv-beaglebone/init/usb-limit-1300 
b/arch/arm/boards/beaglebone/defaultenv-beaglebone/init/usb-limit-1300
deleted file mode 100644
index 56313bf..000
--- a/arch/arm/boards/beaglebone/defaultenv-beaglebone/init/usb-limit-1300
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-
-echo -n "changing USB current limit to 1300 mA... "
-i2c_write -b 0 -a 0x24 -r 0x01 0x3e
-echo "done"
--
1.9.1


___
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


GCC 6.3 Linker error

2017-05-05 Thread Daniel Schultz

Hi everyone,

when I build the Barebox with GCC 6.3 and am335x_defconfig, I get the 
following error:



|   LD  commands/built-in.o
|   LD  drivers/usb/built-in.o
|   PBLLD   drivers/usb/built-in-pbl.o
|   LD  fs/built-in.o
|   PBLLD   fs/built-in-pbl.o
|   LD  drivers/mtd/ubi/built-in.o
|   LD  drivers/mtd/built-in.o
|   PBLLD   drivers/mtd/built-in-pbl.o
|   LD  drivers/built-in.o
|   PBLLD   drivers/built-in-pbl.o
|   GEN .version
|   CHK include/generated/compile.h
|   UPD include/generated/compile.h
|   CC  common/version.o
|   LD  common/built-in.o
|   LD  .tmp_barebox1
| arm-phytec-linux-gnueabi-ld: .tmp_barebox1: Not enough room for 
program headers, try linking with -N

| arm-phytec-linux-gnueabi-ld: final link failed: Bad value
| make[2]: *** [.tmp_barebox1] Error 1
| make[1]: *** [_all] Error 2
| make: *** [all] Error 2
| ERROR: Function failed: do_compile (log file is located at 
/home/schultz/yocto/PD17.2.0/build/tmp/work/phyboard_wega_am335x_2-phytec-linux-gnueabi/barebox/2017.03.0-phy1-r7.0/temp/log.do_compile.23997)
ERROR: Task 
(/home/schultz/yocto/PD17.2.0/sources/poky/../meta-phytec/recipes-bsp/barebox/barebox_2017.03.0-phy1.bb:do_compile) 
failed with exit code '1'
NOTE: Tasks Summary: Attempted 497 tasks of which 495 didn't need to be 
rerun and 1 failed.

NOTE: Writing buildhistory


has somebody else faced with this problem? I figured out that linking 
with "-nmagic" fix this problem.


--
Mit freundlichen Grüßen,
With best regards,
  Daniel Schultz

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


[PATCH v2 3/5] arm: boards: phytec-som-am335x: Update boot scripts

2017-05-05 Thread Daniel Schultz
Expand the boot scripts with EMMC and add a default file source for
expansions.

Removed "rw" and "rootwait" bootargs from existing boot scripts.
Added "rootflags='data=journal'" bootarg to SD card boot script.

Signed-off-by: Daniel Schultz 
---
 .../defaultenv-physom-am335x/boot/emmc  |  7 +++
 .../phytec-som-am335x/defaultenv-physom-am335x/boot/mmc |  7 ---
 .../defaultenv-physom-am335x/boot/nand  |  4 +++-
 .../phytec-som-am335x/defaultenv-physom-am335x/boot/net | 17 +
 .../phytec-som-am335x/defaultenv-physom-am335x/boot/spi |  4 +++-
 .../defaultenv-physom-am335x/init/bootsource| 16 
 6 files changed, 46 insertions(+), 9 deletions(-)
 create mode 100644 
arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
 create mode 100644 
arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/net

diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
new file mode 100644
index 000..6ad5f87
--- /dev/null
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+[ -e /env/config-expansions ] && /env/config-expansions
+
+global.bootm.image=/mnt/mmc1.0/linuximage
+global.bootm.oftree=/mnt/mmc1.0/oftree
+global.linux.bootargs.dyn.root="root=/dev/mmcblk1p2 rootflags='data=journal'"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc
index 834669d..0fefeb2 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc
@@ -1,6 +1,7 @@
 #!/bin/sh
 
-global.bootm.image=/boot/linuximage
-global.bootm.oftree=/boot/oftree
+[ -e /env/config-expansions ] && /env/config-expansions
 
-global.linux.bootargs.dyn.root="root=/dev/mmcblk0p2 rw rootwait"
+global.bootm.image=/mnt/mmc0.0/linuximage
+global.bootm.oftree=/mnt/mmc0.0/oftree
+global.linux.bootargs.dyn.root="root=/dev/mmcblk0p2 rootflags='data=journal'"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand
index ece44b7..fa695bb 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand
@@ -1,8 +1,10 @@
 #!/bin/sh
 
+[ -e /env/config-expansions ] && /env/config-expansions
+
 [ ! -e /dev/nand0.root.ubi ] && ubiattach /dev/nand0.root
 
 global.bootm.image="/dev/nand0.root.ubi.kernel"
 global.bootm.oftree="/dev/nand0.root.ubi.oftree"
 
-global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=root rw 
rootfstype=ubifs"
+global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=root rootfstype=ubifs"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/net 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/net
new file mode 100644
index 000..6dbd2aa
--- /dev/null
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/net
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+path="/mnt/tftp"
+
+global.bootm.image="${path}/${global.user}-linux-${global.hostname}"
+
+oftree="${path}/${global.user}-oftree-${global.hostname}"
+if [ -f "${oftree}" ]; then
+global.bootm.oftree="$oftree"
+fi
+
+nfsroot="/nfsroot/${global.hostname}"
+bootargs-ip
+
+[ -e /env/config-expansions ] && /env/config-expansions
+
+global.linux.bootargs.dyn.root="root=/dev/nfs nfsroot=$nfsroot,vers=3,udp"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi
index 71c5834..2d88626 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi
@@ -1,7 +1,9 @@
 #!/bin/sh
 
+[ -e /env/config-expansions ] && /env/config-expansions
+
 global.bootm.image="/dev/m25p0.kernel"
 global.bootm.oftree="/dev/m25p0.oftree"
 
 # Use rootfs from NAND
-global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=nand0.root rw 
rootfstype=ubifs"
+global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=nand0.root 
rootfstype=ubifs"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource
index 3f2ff4b..61a0879 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource
@@ -4

[PATCH v2 1/5] arm: mach-omap: Change mountpoint of boot partitions

2017-05-05 Thread Daniel Schultz
If using EMMC and SD as bootsources, mounting the boot partition of both
devices to /boot makes trouble. Either the correct device is mounted to
/boot or a remount of /boot has to be performed.

To ensure this problem each MMCn bootsource will be mounted to his own
path in /mnt/mmcN.0

Signed-off-by: Daniel Schultz 
---
 arch/arm/mach-omap/omap_generic.c | 31 ---
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/arch/arm/mach-omap/omap_generic.c 
b/arch/arm/mach-omap/omap_generic.c
index 1d03eac..aa7424d 100644
--- a/arch/arm/mach-omap/omap_generic.c
+++ b/arch/arm/mach-omap/omap_generic.c
@@ -113,12 +113,15 @@ const char *omap_get_bootmmc_devname(void)
 }
 
 #if defined(CONFIG_ENV_HANDLING)
-#define ENV_PATH "/boot/barebox.env"
+static char *envpath = "/mnt/mmc0.0/barebox.env";
+
 static int omap_env_init(void)
 {
-   char *partname;
-   const char *diskdev;
int ret;
+   const char *diskdev;
+   char *partname;
+   struct cdev *cdev;
+   const char *rootpath;
 
if (bootsource_get() != BOOTSOURCE_MMC)
return 0;
@@ -129,18 +132,24 @@ static int omap_env_init(void)
diskdev = "disk0";
 
device_detect_by_name(diskdev);
+   partname = basprintf("%s.0", diskdev);
+   cdev = cdev_by_name(partname);
+   if (cdev == NULL) {
+   pr_err("Failed to get device %s\n", partname);
+   goto out;
+   }
 
-   partname = basprintf("/dev/%s.0", diskdev);
-
-   mkdir("/boot", 0666);
-   ret = mount(partname, "fat", "/boot", NULL);
-   if (ret) {
-   pr_err("Failed to load environment: mount %s failed (%d)\n", 
partname, ret);
+   rootpath = cdev_mount_default(cdev, NULL);
+   if (IS_ERR(rootpath)) {
+   pr_err("Failed to load environment: mount %s failed (%d)\n",
+   cdev->name, IS_ERR(rootpath));
goto out;
}
+   envpath = basprintf("%s/barebox.env", rootpath);
 
-   pr_debug("Loading default env from %s on device %s\n", ENV_PATH, 
partname);
-   default_environment_path_set(ENV_PATH);
+   pr_debug("Loading default env from %s on device %s\n", envpath,
+   partname);
+   default_environment_path_set(envpath);
 
 out:
free(partname);
-- 
1.9.1


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


[PATCH v2 2/5] arm: boards: phytec-som-am335x: Add automount script

2017-05-05 Thread Daniel Schultz
Each MMC boot source is mounted to /mnt/mmcN.0. To make the not-mounted
boot source available in Barebox, an automount script mounts
this device also to /mnt/, if the directory will be accessed.

Signed-off-by: Daniel Schultz 
---
 .../defaultenv-physom-am335x/init/automount | 21 +
 1 file changed, 21 insertions(+)
 create mode 100644 
arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/automount

diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/automount 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/automount
new file mode 100644
index 000..53ecbe3
--- /dev/null
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/automount
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+# automount tftp server based on $eth0.serverip
+
+mkdir -p /mnt/tftp
+automount /mnt/tftp 'ifup eth0 && mount -t tftp $eth0.serverip /mnt/tftp'
+
+# automount nfs server's nfsroot
+
+mkdir -p /mnt/nfs
+automount /mnt/nfs 'ifup eth0 && mount -t nfs 
${eth0.serverip}:/home/${global.user}/nfsroot/${global.hostname} /mnt/nfs'
+
+#automount SD card and EMMC boot partitions
+
+if [ $bootsource = mmc -a $bootsource_instance = 1 ]; then
+   mkdir -p /mnt/mmc0.0
+   automount /mnt/mmc0.0 '[ -e /dev/mmc0.0 ] && mount /dev/mmc0.0 
/mnt/mmc0.0'
+else
+   mkdir -p /mnt/mmc1.0
+   automount /mnt/mmc1.0 '[ -e /dev/mmc1.0 ] && mount /dev/mmc1.0 
/mnt/mmc1.0'
+fi
-- 
1.9.1


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


[PATCH v2 4/5] arm: boards: beaglebone: Delete default env

2017-05-05 Thread Daniel Schultz
The Beaglebone environment should be set from outside with an application
specific environment.

Signed-off-by: Daniel Schultz 
---
 arch/arm/boards/beaglebone/Makefile | 1 -
 arch/arm/boards/beaglebone/board.c  | 2 --
 arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/sd| 6 --
 .../arm/boards/beaglebone/defaultenv-beaglebone/init/usb-limit-1300 | 5 -
 4 files changed, 14 deletions(-)
 delete mode 100644 arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/sd
 delete mode 100644 
arch/arm/boards/beaglebone/defaultenv-beaglebone/init/usb-limit-1300

diff --git a/arch/arm/boards/beaglebone/Makefile 
b/arch/arm/boards/beaglebone/Makefile
index 21a1a29..092c31d 100644
--- a/arch/arm/boards/beaglebone/Makefile
+++ b/arch/arm/boards/beaglebone/Makefile
@@ -1,3 +1,2 @@
 lwl-y += lowlevel.o
 obj-y += board.o
-bbenv-y += defaultenv-beaglebone
diff --git a/arch/arm/boards/beaglebone/board.c 
b/arch/arm/boards/beaglebone/board.c
index 5717c45..fc16aea 100644
--- a/arch/arm/boards/beaglebone/board.c
+++ b/arch/arm/boards/beaglebone/board.c
@@ -85,8 +85,6 @@ static int beaglebone_devices_init(void)
 
black = is_beaglebone_black();
 
-   defaultenv_append_directory(defaultenv_beaglebone);
-
globalvar_add_simple("board.variant", black ? "boneblack" : "bone");
 
printf("detected 'BeagleBone %s'\n", black ? "Black" : "White");
diff --git a/arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/sd 
b/arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/sd
deleted file mode 100644
index aa94b2f..000
--- a/arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/sd
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/sh
-
-global.bootm.image=/boot/uImage
-global.bootm.oftree=/boot/oftree
-#global.bootm.initrd=
-global.linux.bootargs.dyn.root="root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
diff --git 
a/arch/arm/boards/beaglebone/defaultenv-beaglebone/init/usb-limit-1300 
b/arch/arm/boards/beaglebone/defaultenv-beaglebone/init/usb-limit-1300
deleted file mode 100644
index 56313bf..000
--- a/arch/arm/boards/beaglebone/defaultenv-beaglebone/init/usb-limit-1300
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-
-echo -n "changing USB current limit to 1300 mA... "
-i2c_write -b 0 -a 0x24 -r 0x01 0x3e
-echo "done"
-- 
1.9.1


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


[PATCH v2 5/5] arm: boards: afi-gf: Update SD card boot script

2017-05-05 Thread Daniel Schultz
The default mount path for SD cards changed from /boot to /mnt/mmc0.0.
Updated paths in SD card boot script.

Signed-off-by: Daniel Schultz 
---
 arch/arm/boards/afi-gf/defaultenv-gf/boot/sd | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boards/afi-gf/defaultenv-gf/boot/sd 
b/arch/arm/boards/afi-gf/defaultenv-gf/boot/sd
index aa94b2f..1a6fab5 100644
--- a/arch/arm/boards/afi-gf/defaultenv-gf/boot/sd
+++ b/arch/arm/boards/afi-gf/defaultenv-gf/boot/sd
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-global.bootm.image=/boot/uImage
-global.bootm.oftree=/boot/oftree
+global.bootm.image=/mnt/mmc0.0/uImage
+global.bootm.oftree=/mnt/mmc0.0/oftree
 #global.bootm.initrd=
 global.linux.bootargs.dyn.root="root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
-- 
1.9.1


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


[PATCH 4/7] arm: boards: phytec-som-am335x: Add automount script

2017-04-28 Thread Daniel Schultz
Each boot source is mounted to either /mnt/mmc or /mnt/emmc. To make the
not-mounted boot source available in Barebox, an automount script mounts
this device to /mnt/{mmc, emmc}, if the directory will be accessed.

Signed-off-by: Daniel Schultz 
---
 .../defaultenv-physom-am335x/init/automount   | 19 +++
 1 file changed, 19 insertions(+)
 create mode 100644 
arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/automount

diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/automount 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/automount
new file mode 100644
index 000..3d109ec
--- /dev/null
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/automount
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+# automount tftp server based on $eth0.serverip
+
+mkdir -p /mnt/tftp
+automount /mnt/tftp 'ifup eth0 && mount -t tftp $eth0.serverip /mnt/tftp'
+
+# automount nfs server's nfsroot
+
+mkdir -p /mnt/nfs
+automount /mnt/nfs 'ifup eth0 && mount -t nfs 
${eth0.serverip}:/home/${global.user}/nfsroot/${global.hostname} /mnt/nfs'
+
+#automount SD card and EMMC boot partitions
+
+if [ $bootsource = mmc -a $bootsource_instance = 1 ]; then
+   automount /mnt/mmc '[ -e /dev/mmc0.0 ] && mount /dev/mmc0.0 /mnt/mmc'
+else
+   automount /mnt/emmc '[ -e /dev/mmc1.0 ] && mount /dev/mmc1.0 /mnt/emmc'
+fi
-- 
1.9.1


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


[PATCH 1/7] arm: mach-omap: Change file flags in emmc handler

2017-04-28 Thread Daniel Schultz
This handler tries to read from a file descriptor with 'write only'
flags and fails. Add read permissions for the file, so the handler can
read the partition layout.

Signed-off-by: Daniel Schultz 
---
 arch/arm/mach-omap/am33xx_bbu_emmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-omap/am33xx_bbu_emmc.c 
b/arch/arm/mach-omap/am33xx_bbu_emmc.c
index 3220575..d3adb37 100644
--- a/arch/arm/mach-omap/am33xx_bbu_emmc.c
+++ b/arch/arm/mach-omap/am33xx_bbu_emmc.c
@@ -39,7 +39,7 @@ static int emmc_mlo_handler(struct bbu_handler *handler, 
struct bbu_data *data)
if (ret != 0)
return ret;
 
-   fd = open(handler->devicefile, O_WRONLY);
+   fd = open(handler->devicefile, O_RDWR);
if (fd < 0) {
pr_err("could not open %s: %s\n", handler->devicefile,
errno_str());
-- 
1.9.1


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


[PATCH 6/7] arm: boards: beaglebone: Update boot scripts

2017-04-28 Thread Daniel Schultz
Remove the current SD boot script and add support for MMC, EMMC and
network bootsources.

Signed-off-by: Daniel Schultz 
---
 arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/emmc  |  9 +
 arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/mmc   |  9 +
 arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/sd|  6 --
 .../boards/beaglebone/defaultenv-beaglebone/init/bootsource | 13 +
 4 files changed, 31 insertions(+), 6 deletions(-)
 create mode 100644 arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/emmc
 create mode 100644 arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/mmc
 delete mode 100644 arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/sd
 create mode 100644 
arch/arm/boards/beaglebone/defaultenv-beaglebone/init/bootsource

diff --git a/arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/emmc 
b/arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/emmc
new file mode 100644
index 000..5734e3b
--- /dev/null
+++ b/arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/emmc
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+if [ -e /mnt/emmc/linuximage ]
+   global.bootm.image=/mnt/emmc/linuximage
+else
+   global.bootm.image=/mnt/emmc/uImage
+fi
+global.bootm.oftree=/mnt/emmc/oftree
+global.linux.bootargs.dyn.root="root=/dev/mmcblk1p2 rootflags='data=journal'"
diff --git a/arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/mmc 
b/arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/mmc
new file mode 100644
index 000..e8bd769
--- /dev/null
+++ b/arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/mmc
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+if [ -e /mnt/mmc/linuximage ]
+   global.bootm.image=/mnt/mmc/linuximage
+else
+   global.bootm.image=/mnt/mmc/uImage
+fi
+global.bootm.oftree=/mnt/mmc/oftree
+global.linux.bootargs.dyn.root="root=/dev/mmcblk0p2 rootflags='data=journal'"
diff --git a/arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/sd 
b/arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/sd
deleted file mode 100644
index aa94b2f..000
--- a/arch/arm/boards/beaglebone/defaultenv-beaglebone/boot/sd
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/sh
-
-global.bootm.image=/boot/uImage
-global.bootm.oftree=/boot/oftree
-#global.bootm.initrd=
-global.linux.bootargs.dyn.root="root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
diff --git a/arch/arm/boards/beaglebone/defaultenv-beaglebone/init/bootsource 
b/arch/arm/boards/beaglebone/defaultenv-beaglebone/init/bootsource
new file mode 100644
index 000..6301d1d
--- /dev/null
+++ b/arch/arm/boards/beaglebone/defaultenv-beaglebone/init/bootsource
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+if [ -n "$nv.boot.default" ]; then
+exit
+fi
+
+if [ $bootsource = mmc -a $bootsource_instance = 1 ]; then
+global.boot.default="emmc mmc net"
+elif [ $bootsource = mmc -a $bootsource_instance = 0 ]; then
+global.boot.default="mmc emmc net"
+elif [ $bootsource = net ]; then
+global.boot.default="net emmc mmc"
+fi
-- 
1.9.1


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


[PATCH 7/7] arm: boards: afi-gf: Update SD card boot script

2017-04-28 Thread Daniel Schultz
The default mount path for SD cards changed from /boot to /mnt/mmc.
Updated paths in SD card boot script.

Signed-off-by: Daniel Schultz 
---
 arch/arm/boards/afi-gf/defaultenv-gf/boot/sd | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boards/afi-gf/defaultenv-gf/boot/sd 
b/arch/arm/boards/afi-gf/defaultenv-gf/boot/sd
index aa94b2f..30f373e 100644
--- a/arch/arm/boards/afi-gf/defaultenv-gf/boot/sd
+++ b/arch/arm/boards/afi-gf/defaultenv-gf/boot/sd
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-global.bootm.image=/boot/uImage
-global.bootm.oftree=/boot/oftree
+global.bootm.image=/mnt/mmc/uImage
+global.bootm.oftree=/mnt/mmc/oftree
 #global.bootm.initrd=
 global.linux.bootargs.dyn.root="root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
-- 
1.9.1


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


[PATCH 2/7] arm: boards: Add MLO handler for EMMC devices

2017-04-28 Thread Daniel Schultz
This patch enables the barebox handler to flash MLOs on EMMC devices
with 'barebox_update'.

Signed-off-by: Daniel Schultz 
---
 arch/arm/boards/phytec-som-am335x/board.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/boards/phytec-som-am335x/board.c 
b/arch/arm/boards/phytec-som-am335x/board.c
index 7f62453..dc3b84a 100644
--- a/arch/arm/boards/phytec-som-am335x/board.c
+++ b/arch/arm/boards/phytec-som-am335x/board.c
@@ -112,6 +112,7 @@ static int physom_devices_init(void)
xloadslots, ARRAY_SIZE(xloadslots));
am33xx_bbu_nand_slots_register_handler("nand", nandslots,
ARRAY_SIZE(nandslots));
+   am33xx_bbu_emmc_mlo_register_handler("MLO.emmc", "/dev/mmc1");
 
if (IS_ENABLED(CONFIG_SHELL_NONE))
return am33xx_of_register_bootdevice();
-- 
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: Update boot scripts

2017-04-28 Thread Daniel Schultz
Expand the boot scripts with EMMC and add a default file source for
expansions.

Removed "rw" and "rootwait" bootargs from existing boot scripts.
Added "rootflags='data=journal'" bootarg to SD card boot script.

Signed-off-by: Daniel Schultz 
---
 .../defaultenv-physom-am335x/boot/emmc  |  7 +++
 .../phytec-som-am335x/defaultenv-physom-am335x/boot/mmc |  7 ---
 .../defaultenv-physom-am335x/boot/nand  |  4 +++-
 .../phytec-som-am335x/defaultenv-physom-am335x/boot/net | 17 +
 .../phytec-som-am335x/defaultenv-physom-am335x/boot/spi |  4 +++-
 .../defaultenv-physom-am335x/init/bootsource| 16 
 6 files changed, 46 insertions(+), 9 deletions(-)
 create mode 100644 
arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
 create mode 100644 
arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/net

diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
new file mode 100644
index 000..ed0f240
--- /dev/null
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/emmc
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+[ -e /env/config-expansions ] && /env/config-expansions
+
+global.bootm.image=/mnt/emmc/linuximage
+global.bootm.oftree=/mnt/emmc/oftree
+global.linux.bootargs.dyn.root="root=/dev/mmcblk1p2 rootflags='data=journal'"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc
index 834669d..21b16f4 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc
@@ -1,6 +1,7 @@
 #!/bin/sh
 
-global.bootm.image=/boot/linuximage
-global.bootm.oftree=/boot/oftree
+[ -e /env/config-expansions ] && /env/config-expansions
 
-global.linux.bootargs.dyn.root="root=/dev/mmcblk0p2 rw rootwait"
+global.bootm.image=/mnt/mmc/linuximage
+global.bootm.oftree=/mnt/mmc/oftree
+global.linux.bootargs.dyn.root="root=/dev/mmcblk0p2 rootflags='data=journal'"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand
index ece44b7..fa695bb 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/nand
@@ -1,8 +1,10 @@
 #!/bin/sh
 
+[ -e /env/config-expansions ] && /env/config-expansions
+
 [ ! -e /dev/nand0.root.ubi ] && ubiattach /dev/nand0.root
 
 global.bootm.image="/dev/nand0.root.ubi.kernel"
 global.bootm.oftree="/dev/nand0.root.ubi.oftree"
 
-global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=root rw 
rootfstype=ubifs"
+global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=root rootfstype=ubifs"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/net 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/net
new file mode 100644
index 000..6dbd2aa
--- /dev/null
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/net
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+path="/mnt/tftp"
+
+global.bootm.image="${path}/${global.user}-linux-${global.hostname}"
+
+oftree="${path}/${global.user}-oftree-${global.hostname}"
+if [ -f "${oftree}" ]; then
+global.bootm.oftree="$oftree"
+fi
+
+nfsroot="/nfsroot/${global.hostname}"
+bootargs-ip
+
+[ -e /env/config-expansions ] && /env/config-expansions
+
+global.linux.bootargs.dyn.root="root=/dev/nfs nfsroot=$nfsroot,vers=3,udp"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi
index 71c5834..2d88626 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/spi
@@ -1,7 +1,9 @@
 #!/bin/sh
 
+[ -e /env/config-expansions ] && /env/config-expansions
+
 global.bootm.image="/dev/m25p0.kernel"
 global.bootm.oftree="/dev/m25p0.oftree"
 
 # Use rootfs from NAND
-global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=nand0.root rw 
rootfstype=ubifs"
+global.linux.bootargs.dyn.root="root=ubi0:root ubi.mtd=nand0.root 
rootfstype=ubifs"
diff --git 
a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource 
b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource
index 3f2ff4b..61a0879 100644
--- a/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource
+++ b/arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/init/bootsource
@@ -4

[PATCH 3/7] arm: mach-omap: Change mountpoint of boot partitions

2017-04-28 Thread Daniel Schultz
If using EMMC and SD as bootsources, mounting the boot partition of both
devices to /boot makes trouble. Either the correct device is mounted to
/boot or a remount of /boot has to be performed.

To ensure this problem each MMCn bootsource will be mounted to his own
path in /mnt/{mmc,emmc}.

Signed-off-by: Daniel Schultz 
---
 arch/arm/mach-omap/omap_generic.c | 24 +++-
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/arch/arm/mach-omap/omap_generic.c 
b/arch/arm/mach-omap/omap_generic.c
index 1d03eac..7c50806 100644
--- a/arch/arm/mach-omap/omap_generic.c
+++ b/arch/arm/mach-omap/omap_generic.c
@@ -113,10 +113,15 @@ const char *omap_get_bootmmc_devname(void)
 }
 
 #if defined(CONFIG_ENV_HANDLING)
-#define ENV_PATH "/boot/barebox.env"
+#define MMC_PATH "/mnt/mmc/"
+#define MMC_ENV_PATH MMC_PATH "barebox.env"
+#define EMMC_PATH "/mnt/emmc/"
+#define EMMC_ENV_PATH EMMC_PATH "barebox.env"
 static int omap_env_init(void)
 {
char *partname;
+   char *mntpath;
+   char *envpath;
const char *diskdev;
int ret;
 
@@ -132,15 +137,24 @@ static int omap_env_init(void)
 
partname = basprintf("/dev/%s.0", diskdev);
 
-   mkdir("/boot", 0666);
-   ret = mount(partname, "fat", "/boot", NULL);
+   if (bootsource_get_instance() == 1) {
+   mntpath = EMMC_PATH;
+   envpath = EMMC_ENV_PATH;
+   } else {
+   mntpath = MMC_PATH;
+   envpath = MMC_ENV_PATH;
+   }
+   mkdir("/mnt", 0666);
+   mkdir(MMC_PATH, 0666);
+   mkdir(EMMC_PATH, 0666);
+   ret = mount(partname, "fat", mntpath, NULL);
if (ret) {
pr_err("Failed to load environment: mount %s failed (%d)\n", 
partname, ret);
goto out;
}
 
-   pr_debug("Loading default env from %s on device %s\n", ENV_PATH, 
partname);
-   default_environment_path_set(ENV_PATH);
+   pr_debug("Loading default env from %s on device %s\n", envpath, 
partname);
+   default_environment_path_set(envpath);
 
 out:
free(partname);
-- 
1.9.1


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


Re: Directory mirroring

2017-04-06 Thread Daniel Schultz

Hi Sascha,

Am 06.04.2017 um 09:06 schrieb Sascha Hauer:

Hi Daniel,

On Tue, Apr 04, 2017 at 12:11:09PM +0200, Daniel Schultz wrote:

Hi everyone,

my boot partition is mounted to /boot/. Now, I want to make it accessible in
/mnt/ as mmc or emmc, depending to the bootsource. Sadly, ln can only create
symlinks for files and two mounts for one device seems not to work.

Are there other ways to mirror a file system?


Not that I know of. You could implement directory links, but why do you
want to have it accessible under /mnt in the first place?

I think it would be good, if all mountable boot devices are accessible 
in /mnt, but the boot source still remains at /boot.

1) All boot scripts can use /mnt
2) Barebox environment always lies in /boot

--
Mit freundlichen Grüßen,
With best regards,
  Daniel Schultz

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


Directory mirroring

2017-04-04 Thread Daniel Schultz

Hi everyone,

my boot partition is mounted to /boot/. Now, I want to make it 
accessible in /mnt/ as mmc or emmc, depending to the bootsource. Sadly, 
ln can only create symlinks for files and two mounts for one device 
seems not to work.


Are there other ways to mirror a file system?

--
Mit freundlichen Grüßen,
With best regards,
  Daniel Schultz

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


[PATCH v2] arm: boards: phytec-som-am335x: Remove 1GB RAM type

2017-02-28 Thread Daniel Schultz
This machine was a prototype and was never shipped to customers.

Since it has no dependencies to any image, it can be removed.

Signed-off-by: Daniel Schultz 
---
Changes:
v2: Removed machine in Makefile

 arch/arm/boards/phytec-som-am335x/lowlevel.c|  1 -
 arch/arm/boards/phytec-som-am335x/ram-timings.h | 21 -
 images/Makefile.am33xx  |  6 --
 3 files changed, 28 deletions(-)

diff --git a/arch/arm/boards/phytec-som-am335x/lowlevel.c 
b/arch/arm/boards/phytec-som-am335x/lowlevel.c
index 33e83c5..03c7e98 100644
--- a/arch/arm/boards/phytec-som-am335x/lowlevel.c
+++ b/arch/arm/boards/phytec-som-am335x/lowlevel.c
@@ -122,7 +122,6 @@ 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_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);
diff --git a/arch/arm/boards/phytec-som-am335x/ram-timings.h 
b/arch/arm/boards/phytec-som-am335x/ram-timings.h
index 4ea654d..d1947b5 100644
--- a/arch/arm/boards/phytec-som-am335x/ram-timings.h
+++ b/arch/arm/boards/phytec-som-am335x/ram-timings.h
@@ -29,7 +29,6 @@ enum {
PHYCORE_MT41J64M1615IT_128MB,
PHYCORE_MT41J256M16HA15EIT_512MB,
PHYCORE_MT41J512M8125IT_2x512MB,
-   PHYCORE_IM8G16D3FBBG15EI_1024MB,
PHYCORE_R2_MT41K256M16TW107IT_512MB,
PHYCORE_R2_MT41K128M16JT_256MB,
PHYCORE_R2_MT41K512M16HA125IT_1024MB,
@@ -162,26 +161,6 @@ struct am335x_sdram_timings physom_timings[] = {
},
},
 
-   /* 1024MB */
-   [PHYCORE_IM8G16D3FBBG15EI_1024MB] = {
-   .regs = {
-   .emif_read_latency  = 0x7,
-   .emif_tim1  = 0x0AAAE4DB,
-   .emif_tim2  = 0x268F7FDA,
-   .emif_tim3  = 0x501F88BF,
-   .ocp_config = 0x003d3d3d,
-   .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 8168fe4..d1c432e 100644
--- a/images/Makefile.am33xx
+++ b/images/Makefile.am33xx
@@ -77,12 +77,6 @@ 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_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
-- 
1.9.1


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


Re: GPLv3 file in barebox

2017-02-28 Thread Daniel Schultz

Acked-by: Daniel Schultz 

Thanks

--
Mit freundlichen Grüßen,
With best regards,
  Daniel Schultz

Am 09.02.2017 um 10:53 schrieb Sascha Hauer:

Hi Daniel,

We have found that commands/mmc_extcsd.c is licensed under GPLv3 which
is incompatible to the barebox GPLv2 license. Are you ok with
relicensing this file? Otherwise we would have to remove it from
barebox.
If you're ok with relicensing the file please just ack the following
patch.

Sascha

-8<

From f75fdb6741fa7f20a810798007ec1ebc12886370 Mon Sep 17 00:00:00 2001
From: Sascha Hauer 
Date: Thu, 9 Feb 2017 10:51:49 +0100
Subject: [PATCH] commands/mmc_extcsd: Relicense under GPLv2+

GPLv3 is incompatible with the projects license. Relicense file
under GPLv2+

Signed-off-by: Sascha Hauer 
---
 commands/mmc_extcsd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/commands/mmc_extcsd.c b/commands/mmc_extcsd.c
index d7fc50697c..42adfe0860 100644
--- a/commands/mmc_extcsd.c
+++ b/commands/mmc_extcsd.c
@@ -5,7 +5,7 @@
  *
  * 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, either version 3 of the License, or
+ * the Free Software Foundation, either version 2 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,





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


[PATCH] arm: boards: phytec-som-am335x: Remove 1GB RAM type

2017-02-01 Thread Daniel Schultz
This machine was a prototype and was never shipped to customers.

Since it has no dependencies to any image, it can be removed.

Signed-off-by: Daniel Schultz 
---
 arch/arm/boards/phytec-som-am335x/lowlevel.c|  1 -
 arch/arm/boards/phytec-som-am335x/ram-timings.h | 21 -
 2 files changed, 22 deletions(-)

diff --git a/arch/arm/boards/phytec-som-am335x/lowlevel.c 
b/arch/arm/boards/phytec-som-am335x/lowlevel.c
index 33e83c5..03c7e98 100644
--- a/arch/arm/boards/phytec-som-am335x/lowlevel.c
+++ b/arch/arm/boards/phytec-som-am335x/lowlevel.c
@@ -122,7 +122,6 @@ 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_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);
diff --git a/arch/arm/boards/phytec-som-am335x/ram-timings.h 
b/arch/arm/boards/phytec-som-am335x/ram-timings.h
index 4ea654d..d1947b5 100644
--- a/arch/arm/boards/phytec-som-am335x/ram-timings.h
+++ b/arch/arm/boards/phytec-som-am335x/ram-timings.h
@@ -29,7 +29,6 @@ enum {
PHYCORE_MT41J64M1615IT_128MB,
PHYCORE_MT41J256M16HA15EIT_512MB,
PHYCORE_MT41J512M8125IT_2x512MB,
-   PHYCORE_IM8G16D3FBBG15EI_1024MB,
PHYCORE_R2_MT41K256M16TW107IT_512MB,
PHYCORE_R2_MT41K128M16JT_256MB,
PHYCORE_R2_MT41K512M16HA125IT_1024MB,
@@ -162,26 +161,6 @@ struct am335x_sdram_timings physom_timings[] = {
},
},
 
-   /* 1024MB */
-   [PHYCORE_IM8G16D3FBBG15EI_1024MB] = {
-   .regs = {
-   .emif_read_latency  = 0x7,
-   .emif_tim1  = 0x0AAAE4DB,
-   .emif_tim2  = 0x268F7FDA,
-   .emif_tim3  = 0x501F88BF,
-   .ocp_config = 0x003d3d3d,
-   .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 = {
-- 
1.9.1


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


[PATCH] arm: am33xx: Initialize EMIF REG_PR_OLD_COUNT

2017-01-26 Thread Daniel Schultz
This patch is based on a patch from the U-Boot and fixes two errors with
the LCDC. Original commit message from Jyri Sarha [1]:
"Initialize EMIF OCP_CONFIG registers REG_COS_COUNT_1, REG_COS_COUNT_2,
and REG_PR_OLD_COUNT field for Beaglebone-Black and am335x-evm. With
the default values LCDC suffers from DMA FIFO underflows and frame
synchronization lost errors. The initialization values are the highest
that work flawlessly when heavy memory load is generated by CPU. 32bpp
colors were used in the test. On BBB the video mode used 110MHz pixel
clock. The mode supported by the panel of am335x-evm uses 30MHz pixel
clock."

The register values are generated by testing, because there is no formula
to calculate them. Also from Jyri Sarha [1]:
"In practice the only rule to find an optimal value is to find as high as
possible REG_PR_OLD_COUNT value that does not produce LCDC FIFO
underflows under worst case scenario. The worst case happens when the
highest pixel clock videomode with maximum bpp is used while memory
subsystem is stressed by endless stream of writes hitting the same
memory memory bank (can be the same address)."

It only contains the BeagleBone Black and the Phytec SoM, because I
don't have other boards.

[1] https://patchwork.ozlabs.org/patch/704013/

Signed-off-by: Daniel Schultz 
---
 arch/arm/boards/beaglebone/lowlevel.c|  2 ++
 arch/arm/boards/phytec-som-am335x/ram-timings.h  | 11 +++
 arch/arm/mach-omap/am33xx_generic.c  |  3 +++
 arch/arm/mach-omap/include/mach/am33xx-silicon.h |  2 ++
 4 files changed, 18 insertions(+)

diff --git a/arch/arm/boards/beaglebone/lowlevel.c 
b/arch/arm/boards/beaglebone/lowlevel.c
index 100f64f..a56b4b6 100644
--- a/arch/arm/boards/beaglebone/lowlevel.c
+++ b/arch/arm/boards/beaglebone/lowlevel.c
@@ -41,6 +41,7 @@ static const struct am33xx_emif_regs ddr2_regs = {
.emif_tim1  = 0x0666B3C9,
.emif_tim2  = 0x243631CA,
.emif_tim3  = 0x033F,
+   .ocp_config = 0x00141414,
.sdram_config   = 0x41805332,
.sdram_config2  = 0x41805332,
.sdram_ref_ctrl = 0x081A,
@@ -97,6 +98,7 @@ static const struct am33xx_emif_regs ddr3_regs = {
.emif_tim1  = 0x0AAAD4DB,
.emif_tim2  = 0x266B7FDA,
.emif_tim3  = 0x501F867F,
+   .ocp_config = 0x00141414,
.zq_config  = 0x50074BE4,
.sdram_config   = 0x61C05332,
.sdram_config2  = 0x0,
diff --git a/arch/arm/boards/phytec-som-am335x/ram-timings.h 
b/arch/arm/boards/phytec-som-am335x/ram-timings.h
index 9576d26..4ea654d 100644
--- a/arch/arm/boards/phytec-som-am335x/ram-timings.h
+++ b/arch/arm/boards/phytec-som-am335x/ram-timings.h
@@ -45,6 +45,7 @@ struct am335x_sdram_timings physom_timings[] = {
.emif_tim1  = 0x0AAAD4DB,
.emif_tim2  = 0x26437FDA,
.emif_tim3  = 0x501F83FF,
+   .ocp_config = 0x003d3d3d,
.sdram_config   = 0x61C052B2,
.zq_config  = 0x50074BE4,
.sdram_ref_ctrl = 0x0C30,
@@ -66,6 +67,7 @@ struct am335x_sdram_timings physom_timings[] = {
.emif_tim1  = 0x0AAAE4DB,
.emif_tim2  = 0x266B7FDA,
.emif_tim3  = 0x501F867F,
+   .ocp_config = 0x003d3d3d,
.sdram_config   = 0x61C05332,
.zq_config  = 0x50074BE4,
.sdram_ref_ctrl = 0x0C30,
@@ -87,6 +89,7 @@ struct am335x_sdram_timings physom_timings[] = {
.emif_tim1  = 0x0AAAD4DB,
.emif_tim2  = 0x26437FDA,
.emif_tim3  = 0x501F83FF,
+   .ocp_config = 0x003d3d3d,
.sdram_config   = 0x61C052B2,
.zq_config  = 0x50074BE4,
.sdram_ref_ctrl = 0x0C30,
@@ -106,6 +109,7 @@ struct am335x_sdram_timings physom_timings[] = {
.emif_tim1  = 0x0AAAE4DB,
.emif_tim2  = 0x262F7FDA,
.emif_tim3  = 0x501F82BF,
+   .ocp_config = 0x003d3d3d,
.sdram_config   = 0x61C05232,
.zq_config  = 0x50074BE4,
.sdram_ref_ctrl = 0x0C30,
@@ -125,6 +129,7 @@ struct am335x_sdram_timings physom_timings[] = {
.emif_tim1  = 0x0AAAE4DB,
 

Re: [PATCH 3/3] arm: dts: Added ocotp support for i.MX6UL

2016-12-08 Thread Daniel Schultz



Am 30.11.2016 um 17:38 schrieb Andrey Smirnov:

On Wed, Nov 30, 2016 at 3:10 AM, Daniel Schultz  wrote:

Ocotp is available for the iMX6(q|sx|sl) SoCs. This patch will extend the
iMX6ul DT from the mainline kernel to support the ocotp driver on the
iMX6ul SoC.

Signed-off-by: Daniel Schultz 
---
  arch/arm/dts/imx6ul-phytec-phycore-som.dts |  1 +
  arch/arm/dts/imx6ul.dtsi   | 20 
  2 files changed, 21 insertions(+)
  create mode 100644 arch/arm/dts/imx6ul.dtsi

diff --git a/arch/arm/dts/imx6ul-phytec-phycore-som.dts 
b/arch/arm/dts/imx6ul-phytec-phycore-som.dts
index be4556a..285ea62 100644
--- a/arch/arm/dts/imx6ul-phytec-phycore-som.dts
+++ b/arch/arm/dts/imx6ul-phytec-phycore-som.dts
@@ -13,6 +13,7 @@
  /dts-v1/;

  #include 
+#include "imx6ul.dtsi"

  / {
 model = "Phytec phyCORE-i.MX6 Ultra Lite SOM";
diff --git a/arch/arm/dts/imx6ul.dtsi b/arch/arm/dts/imx6ul.dtsi
new file mode 100644
index 000..2e02d27
--- /dev/null
+++ b/arch/arm/dts/imx6ul.dtsi
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2016 PHYTEC Messtechnik GmbH
+ * Author: Daniel Schultz 
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+&aips2 {
+   ocotp: ocotp-ctrl@21bc000 {
+   compatible = "fsl,imx6ul-ocotp";
+   reg = <0x021bc000 0x4000>;
+   clocks = <&clks IMX6UL_CLK_OCOTP>;


Just as my two cents, I'd say that all of the above (that is
instantiation of OCOT on AIPS2) should go via Linux kernel and trickle
down via syncing with its .dts tree ( in particular).
At least that's what I had to do for OCOTP in Vybrid. Although your
case might be more complicated since there are no bindings for
"fsl,imx6ul-ocotp" upstream, so take this with a grain of salt


Hi Andrey,

thanks, that's way better. I have sent a patch to the mainline kernel 
with this change. Sascha Hauer got a notification, so when it apply he 
can remove the patch.


--
Mit freundlichen Grüßen,
With best regards,
  Daniel Schultz


Cheers,
Andrey



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


[PATCH 1/3] arm: imx6: ocotp: Added support for the i.MX6UL

2016-11-30 Thread Daniel Schultz
This patch adds support for the i.MX6UL SoC.
Also, the driver was extended to handle two MAC addresses.

Signed-off-by: Daniel Schultz 
---
 arch/arm/mach-imx/ocotp.c| 82 +---
 dts/Bindings/nvmem/imx-ocotp.txt |  7 ++--
 2 files changed, 73 insertions(+), 16 deletions(-)

diff --git a/arch/arm/mach-imx/ocotp.c b/arch/arm/mach-imx/ocotp.c
index e1d0c25..9efa46a 100644
--- a/arch/arm/mach-imx/ocotp.c
+++ b/arch/arm/mach-imx/ocotp.c
@@ -70,11 +70,13 @@
 #define FUSE_REGS_COUNT(16 * 8)
 #define IMX6_OTP_DATA_ERROR_VAL0xBADABADA
 #define DEF_RELAX  20
-#define MAC_OFFSET (0x22 * 4)
+#define MAC0_OFFSET(0x22 * 4)
+#define MAC1_OFFSET(0x23 * 4)
 #define MAC_BYTES  8
 
 struct imx_ocotp_data {
int num_regs;
+   bool scnd_mac_addr;
 };
 
 struct ocotp_priv {
@@ -84,7 +86,7 @@ struct ocotp_priv {
struct device_d dev;
int permanent_write_enable;
int sense_enable;
-   char ethaddr[6];
+   char ethaddr[2][6];
struct regmap_config map_config;
 };
 
@@ -394,38 +396,79 @@ static void imx_ocotp_init_dt(struct device_d *dev, void 
__iomem *base)
}
 }
 
-static int imx_ocotp_get_mac(struct param_d *param, void *priv)
+static int imx_ocotp_get_mac(unsigned int mac_no, struct param_d *param,
+void *priv)
 {
struct ocotp_priv *ocotp_priv = priv;
char buf[8];
int i, ret;
+   int offset;
 
-   ret = regmap_bulk_read(ocotp_priv->map, MAC_OFFSET, buf, MAC_BYTES);
+   if (mac_no > 1)
+   return -EINVAL;
+
+   ret = regmap_bulk_read(ocotp_priv->map,
+  (mac_no == 0) ? MAC0_OFFSET : MAC1_OFFSET, buf,
+  MAC_BYTES);
if (ret < 0)
return ret;
 
+   offset = mac_no << 1;
for (i = 0; i < 6; i++)
-   ocotp_priv->ethaddr[i] = buf[5 - i];
+   ocotp_priv->ethaddr[mac_no][i] = buf[5 - i + offset];
 
return 0;
 }
 
-static int imx_ocotp_set_mac(struct param_d *param, void *priv)
+static inline int imx_ocotp_get_mac0(struct param_d *param, void *priv)
+{
+   return imx_ocotp_get_mac(0, param, priv);
+}
+static inline int imx_ocotp_get_mac1(struct param_d *param, void *priv)
+{
+   return imx_ocotp_get_mac(1, param, priv);
+}
+
+static int imx_ocotp_set_mac(unsigned int mac_no, struct param_d *param,
+void *priv)
 {
struct ocotp_priv *ocotp_priv = priv;
char buf[8];
int i, ret;
+   int offset;
+
+   if (mac_no > 1)
+   return -EINVAL;
+
+   offset = mac_no << 1;
+   if (mac_no == 0) {
+   buf[6] = ocotp_priv->ethaddr[1][5];
+   buf[7] = ocotp_priv->ethaddr[1][4];
+   } else {
+   buf[0] = ocotp_priv->ethaddr[0][1];
+   buf[1] = ocotp_priv->ethaddr[0][0];
+   }
 
for (i = 0; i < 6; i++)
-   buf[5 - i] = ocotp_priv->ethaddr[i];
-   buf[6] = 0; buf[7] = 0;
+   buf[5 - i + offset] = ocotp_priv->ethaddr[mac_no][i];
 
-   ret = regmap_bulk_write(ocotp_priv->map, MAC_OFFSET, buf, MAC_BYTES);
+   ret = regmap_bulk_write(ocotp_priv->map,
+   (mac_no == 0) ? MAC0_OFFSET : MAC1_OFFSET, buf,
+   MAC_BYTES);
if (ret < 0)
return ret;
 
return 0;
 }
+static inline int imx_ocotp_set_mac0(struct param_d *param, void *priv)
+{
+   return imx_ocotp_set_mac(0, param, priv);
+}
+
+static inline int imx_ocotp_set_mac1(struct param_d *param, void *priv)
+{
+   return imx_ocotp_set_mac(1, param, priv);
+}
 
 static struct regmap_bus imx_ocotp_regmap_bus = {
.reg_write = imx_ocotp_reg_write,
@@ -482,9 +525,15 @@ static int imx_ocotp_probe(struct device_d *dev)
NULL, NULL, &priv->permanent_write_enable, 
NULL);
}
 
-   if (IS_ENABLED(CONFIG_NET))
-   dev_add_param_mac(&(priv->dev), "mac_addr", imx_ocotp_set_mac,
-   imx_ocotp_get_mac, priv->ethaddr, priv);
+   if (IS_ENABLED(CONFIG_NET)) {
+   dev_add_param_mac(&(priv->dev), "mac_addr", imx_ocotp_set_mac0,
+   imx_ocotp_get_mac0, priv->ethaddr[0], priv);
+
+   if (data->scnd_mac_addr)
+   dev_add_param_mac(&(priv->dev), "mac_addr1",
+imx_ocotp_set_mac1, imx_ocotp_get_mac1,
+priv->ethaddr[1], priv);
+   }
 
dev_add_param_bool(&(priv->dev), "sense_enable", NULL, NULL, 
&priv->sense_enab

[PATCH 2/3] arm: imx6: ocotp: Added write check

2016-11-30 Thread Daniel Schultz
Since it's forbidden to use a multicast address as ethernet address,
the driver should check the addresses before they got written.

Signed-off-by: Daniel Schultz 
---
 arch/arm/mach-imx/ocotp.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm/mach-imx/ocotp.c b/arch/arm/mach-imx/ocotp.c
index 9efa46a..f8978c0 100644
--- a/arch/arm/mach-imx/ocotp.c
+++ b/arch/arm/mach-imx/ocotp.c
@@ -452,6 +452,12 @@ static int imx_ocotp_set_mac(unsigned int mac_no, struct 
param_d *param,
for (i = 0; i < 6; i++)
buf[5 - i + offset] = ocotp_priv->ethaddr[mac_no][i];
 
+   if (0x01 & buf[5 + offset]) {
+   dev_err(&ocotp_priv->dev,
+   "this MAC address is a broadcast/multicast\n");
+   return -EINVAL;
+   }
+
ret = regmap_bulk_write(ocotp_priv->map,
(mac_no == 0) ? MAC0_OFFSET : MAC1_OFFSET, buf,
MAC_BYTES);
-- 
1.9.1


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


[PATCH 3/3] arm: dts: Added ocotp support for i.MX6UL

2016-11-30 Thread Daniel Schultz
Ocotp is available for the iMX6(q|sx|sl) SoCs. This patch will extend the
iMX6ul DT from the mainline kernel to support the ocotp driver on the
iMX6ul SoC.

Signed-off-by: Daniel Schultz 
---
 arch/arm/dts/imx6ul-phytec-phycore-som.dts |  1 +
 arch/arm/dts/imx6ul.dtsi   | 20 
 2 files changed, 21 insertions(+)
 create mode 100644 arch/arm/dts/imx6ul.dtsi

diff --git a/arch/arm/dts/imx6ul-phytec-phycore-som.dts 
b/arch/arm/dts/imx6ul-phytec-phycore-som.dts
index be4556a..285ea62 100644
--- a/arch/arm/dts/imx6ul-phytec-phycore-som.dts
+++ b/arch/arm/dts/imx6ul-phytec-phycore-som.dts
@@ -13,6 +13,7 @@
 /dts-v1/;
 
 #include 
+#include "imx6ul.dtsi"
 
 / {
model = "Phytec phyCORE-i.MX6 Ultra Lite SOM";
diff --git a/arch/arm/dts/imx6ul.dtsi b/arch/arm/dts/imx6ul.dtsi
new file mode 100644
index 000..2e02d27
--- /dev/null
+++ b/arch/arm/dts/imx6ul.dtsi
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2016 PHYTEC Messtechnik GmbH
+ * Author: Daniel Schultz 
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+&aips2 {
+   ocotp: ocotp-ctrl@21bc000 {
+   compatible = "fsl,imx6ul-ocotp";
+   reg = <0x021bc000 0x4000>;
+   clocks = <&clks IMX6UL_CLK_OCOTP>;
+   barebox,provide-mac-address = <&fec1 0x620 &fec2 0x632>;
+   };
+};
-- 
1.9.1


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


[PATCH v2 2/2] ARM: am335x: Register eMMC MLO handler

2015-09-07 Thread Daniel Schultz
Register the eMMC MLO handler to the barebox_update command.

Signed-off-by: Daniel Schultz 
---

Changes:
v2:
No changes

 arch/arm/boards/beaglebone/board.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/boards/beaglebone/board.c 
b/arch/arm/boards/beaglebone/board.c
index 4e0e374..5717c45 100644
--- a/arch/arm/boards/beaglebone/board.c
+++ b/arch/arm/boards/beaglebone/board.c
@@ -38,6 +38,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "beaglebone.h"
 
@@ -92,6 +93,9 @@ static int beaglebone_devices_init(void)
 
armlinux_set_architecture(MACH_TYPE_BEAGLEBONE);
 
+   /* Register update handler */
+   am33xx_bbu_emmc_mlo_register_handler("MLO.emmc", "/dev/mmc1");
+
if (IS_ENABLED(CONFIG_SHELL_NONE))
return am33xx_of_register_bootdevice();
 
-- 
1.9.1


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


[PATCH v2 1/2] ARM: am33xx: Add barebox_update eMMC option

2015-09-07 Thread Daniel Schultz
With this patch the barebox_update command will be extended by the possibility
to flash the MLO to eMMC devices.

The MLO will be flashed to the following addresses:
0x0
0x2
0x4
0x6

Because the first 512 Bytes of the MLO are reserved for the CHSETTINGS header
and this only use ~80 Bytes, there is space for the partition table in the
header.

The command will overwrite the bootstrap code area and will hold the
partition table and the Boot signature.

Signed-off-by: Daniel Schultz 
---

Changes:
v2:
The MLO will also written to 0x0

 arch/arm/configs/am335x_defconfig |  1 +
 arch/arm/mach-omap/Kconfig|  7 +++
 arch/arm/mach-omap/Makefile   |  1 +
 arch/arm/mach-omap/am33xx_bbu_emmc.c  | 96 +++
 arch/arm/mach-omap/include/mach/bbu.h | 18 +++
 5 files changed, 123 insertions(+)
 create mode 100644 arch/arm/mach-omap/am33xx_bbu_emmc.c

diff --git a/arch/arm/configs/am335x_defconfig 
b/arch/arm/configs/am335x_defconfig
index 0db2075..234042f 100644
--- a/arch/arm/configs/am335x_defconfig
+++ b/arch/arm/configs/am335x_defconfig
@@ -1,6 +1,7 @@
 CONFIG_ARCH_OMAP=y
 CONFIG_BAREBOX_UPDATE_AM33XX_SPI_NOR_MLO=y
 CONFIG_BAREBOX_UPDATE_AM33XX_NAND=y
+CONFIG_BAREBOX_UPDATE_AM33XX_EMMC=y
 CONFIG_OMAP_MULTI_BOARDS=y
 CONFIG_MACH_AFI_GF=y
 CONFIG_MACH_BEAGLEBONE=y
diff --git a/arch/arm/mach-omap/Kconfig b/arch/arm/mach-omap/Kconfig
index 0b59afc..5c68062 100644
--- a/arch/arm/mach-omap/Kconfig
+++ b/arch/arm/mach-omap/Kconfig
@@ -97,6 +97,13 @@ config BAREBOX_UPDATE_AM33XX_NAND
  This also includes a handler for updating the regular barebox binary
  in NAND.
 
+config BAREBOX_UPDATE_AM33XX_EMMC
+   prompt "barebox update eMMC handler"
+   bool
+   depends on BAREBOX_UPDATE
+   help
+ Say Y for barebox update eMMC handler.
+
 config ARCH_TEXT_BASE
hex
default 0x80e8 if MACH_OMAP343xSDP
diff --git a/arch/arm/mach-omap/Makefile b/arch/arm/mach-omap/Makefile
index db2856d..a84e94e 100644
--- a/arch/arm/mach-omap/Makefile
+++ b/arch/arm/mach-omap/Makefile
@@ -36,3 +36,4 @@ pbl-$(CONFIG_OMAP3_USBBOOT) += omap3_xload_usb.o
 obj-$(CONFIG_CMD_BOOT_ORDER) += boot_order.o
 obj-$(CONFIG_BAREBOX_UPDATE_AM33XX_SPI_NOR_MLO) += am33xx_bbu_spi_mlo.o
 obj-$(CONFIG_BAREBOX_UPDATE_AM33XX_NAND) += am33xx_bbu_nand.o
+obj-$(CONFIG_BAREBOX_UPDATE_AM33XX_EMMC) += am33xx_bbu_emmc.o
diff --git a/arch/arm/mach-omap/am33xx_bbu_emmc.c 
b/arch/arm/mach-omap/am33xx_bbu_emmc.c
new file mode 100644
index 000..418cf61
--- /dev/null
+++ b/arch/arm/mach-omap/am33xx_bbu_emmc.c
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2015 Phytec Messtechnik GmbH
+ * Author: Daniel Schultz 
+ *
+ * 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 
+
+#define PART_TABLE_SIZE66
+#define PART_TABLE_OFFSET  0x1BE
+
+static int emmc_mlo_handler(struct bbu_handler *handler, struct bbu_data *data)
+{
+   int ret = 0;
+   int i = 0;
+   int fd;
+   const void *image = data->image;
+   size_t size = data->len;
+   u8 *part_table = 0;
+
+   if (file_detect_type(image, size) != filetype_ch_image) {
+   pr_err("%s is not a valid ch-image\n", data->imagefile);
+   return -EINVAL;
+   }
+   ret = bbu_confirm(data);
+   if (ret != 0)
+   return ret;
+
+   fd = open(handler->devicefile, O_WRONLY);
+   if (fd < 0) {
+   pr_err("could not open %s: %s\n", handler->devicefile,
+   errno_str());
+   return fd;
+   }
+
+   /* save the partition table */
+   part_table = xmalloc(PART_TABLE_SIZE);
+   ret = pread(fd, part_table, PART_TABLE_SIZE, PART_TABLE_OFFSET);
+   if (ret < 0) {
+   pr_err("could not read partition table from fd %s: %s\n",
+   handler->devicefile, errno_str());
+   goto error;
+   }
+
+   /* write the MLOs */
+   for (i = 0; i < 4; i++) {
+   ret = pwrite(fd, image, size, i * 0x2);
+   if (ret < 0) {
+   pr_err("could not write MLO %i/4 to fd %s: %s\n",
+   i + 1, handler->devicefile, errno_str());
+   goto error_save_part_table;
+   }
+   }
+
+error_save_part_table:
+   /* write the partition table back */
+   ret = pwrite(fd, part_table, PART_TABLE_SIZ

[PATCH v4 4/4] commands: Add MMC ext. CSD register tool

2015-09-07 Thread Daniel Schultz
This tools can read/write to the extended CSD register of MMC devices.

Signed-off-by: Daniel Schultz 
---

Changes:
v2:
Changed patch order

v3:
Splitted output in different functions to reduce the indentation.
Minimized strings and optimized printfs.
Refactored main function

v4:
Stripped strings

 commands/Kconfig  |   16 +
 commands/Makefile |1 +
 commands/mmc_extcsd.c | 2042 +
 3 files changed, 2059 insertions(+)
 create mode 100644 commands/mmc_extcsd.c

diff --git a/commands/Kconfig b/commands/Kconfig
index 630cb12..0853ffd 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -242,6 +242,22 @@ config CMD_VERSION
 
  barebox 2014.05.0-00142-gb289373 #177 Mon May 12 20:35:55 CEST 2014
 
+config CMD_MMC_EXTCSD
+   tristate
+   prompt "read/write eMMC ext. CSD register"
+   depends on MCI
+   help
+ Read or write the extended CSD register of a MMC device.
+
+ Usage: mmc_extcsd dev [-r | -i index [-r | -v value -y]]
+
+ Options:
+ -i  field index of the register
+ -r  print the register as raw data
+ -v  value which will be written
+ -y  don't request when writing to one time programmable 
fields
+ __CAUTION__: this could damage the device!
+
 # end Information commands
 endmenu
 
diff --git a/commands/Makefile b/commands/Makefile
index 3d594c3..d985341 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -114,3 +114,4 @@ obj-$(CONFIG_CMD_STATE) += state.o
 obj-$(CONFIG_CMD_DHCP) += dhcp.o
 obj-$(CONFIG_CMD_DHRYSTONE)+= dhrystone.o
 obj-$(CONFIG_CMD_SPD_DECODE)   += spd_decode.o
+obj-$(CONFIG_CMD_MMC_EXTCSD)   += mmc_extcsd.o
diff --git a/commands/mmc_extcsd.c b/commands/mmc_extcsd.c
new file mode 100644
index 000..d235f65
--- /dev/null
+++ b/commands/mmc_extcsd.c
@@ -0,0 +1,2042 @@
+/*
+ *
+ * (C) Copyright 2015 Phytec Messtechnik GmbH
+ * Author: Daniel Schultz 
+ *
+ * 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, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 
+
+#define EXT_CSD_BLOCKSIZE  512
+
+/* Access types */
+#define R  "R"
+#define RW "R/W"
+#define RWaR   "R/W & R"
+#define RWaRWE "R/W & R/W/E"
+#define RWaRWC_P   "R/W & R/W/C_P"
+#define RWaRWC_PaRWE_P "R/W, R/W/C_P & R/W/E_P"
+#define WE "W/E"
+#define RWE"R/W/E"
+#define RWEaR  "R/W/E & R"
+#define RWEaRWE_P  "R/W/E & R/W/E_P"
+#define RWC_P  "R/W/C_P"
+#define RWE_P  "R/W/E_P"
+#define WE_P   "W/E_P"
+
+#define print_field_caption(reg_name, access_mode)\
+   do {   \
+   printf(#reg_name"[%u]:\n", EXT_CSD_##reg_name);\
+   printf("\tValue: %#02x\n", reg[index]);\
+   printf("\tAccess: "access_mode"\n");   \
+   } while (false);
+
+#define print_field_caption_with_offset(reg_name, offset, access_mode)\
+   do {   \
+   printf(#reg_name"[%u]:\n", EXT_CSD_##reg_name + offset);   \
+   printf("\tValue: %#02x\n", reg[index]);\
+   printf("\tAccess: "access_mode"\n");   \
+   } while (false);
+
+#define get_field_val(reg_name, offset, mask) \
+   ((reg[EXT_CSD_##reg_name] >> offset) & mask)
+
+#define get_field_val_with_index(index, offset, mask) \
+   ((reg[index] >> offset) & mask)
+
+static void print_access_type_key(void)
+{
+   printf("\nR:\tRead only\n"
+   "W:\tOne time programmable\n"
+   "E:\tMultiple programmable\n"
+   "C_P:\tValue cleared by power failure\n"
+   "E_P:\tValue cleared by power failure and CMD0\n");
+}
+
+static int print_f

  1   2   >