Skip to contentSkip to conversation

mtd: sf: Set SF parameters as env variables

PATCH In review Marek Vasut 4 participants 12 messages Sep 14, 2021 – Dec 2, 2021 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: sf: Set SF parameters as env variables

Set the SF page size, erase block size and total size as an environment variable after "sf probe". This lets us discern boards with multiple distinct SPI flash options and also e.g. set mtdparts accordingly.

---
 drivers/mtd/spi/spi-nor-core.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/mtd/spi/spi-nor-core.c +4 -0
index d5d905fa5a1..448653b9931 100644
@@ -15,6 +15,7 @@
 #include <dm.h>
 #include <dm/device_compat.h>
 #include <dm/devres.h>
+#include <env.h>
 #include <linux/bitops.h>
 #include <linux/err.h>
 #include <linux/errno.h>
@@ -3829,8 +3830,11 @@ int spi_nor_scan(struct spi_nor *nor)
 #ifndef CONFIG_SPL_BUILD
 	printf("SF: Detected %s with page size ", nor->name);
 	print_size(nor->page_size, ", erase size ");
+	env_set_hex("sf_pagesize", nor->page_size);
 	print_size(nor->erase_size, ", total ");
+	env_set_hex("sf_erasesize", nor->erase_size);
 	print_size(nor->size, "");
+	env_set_hex("sf_size", nor->size);
 	puts("\n");
 #endif
 
Signature · 1 line
2.33.0
#1 lore raw
Quoted 3 lines · Marek Vasut

Set the SF page size, erase block size and total size as an environment variable after "sf probe". This lets us discern boards with multiple distinct SPI flash options and also e.g. set mtdparts accordingly.

I don't quite follow the rationale for making these environment variables. Wouldn't you be better off finding this info out via mtd or sf command?

Quoted 35 lines
---
 drivers/mtd/spi/spi-nor-core.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/mtd/spi/spi-nor-core.c +4 -0
index d5d905fa5a1..448653b9931 100644
@@ -15,6 +15,7 @@
 #include <dm.h>
 #include <dm/device_compat.h>
 #include <dm/devres.h>
+#include <env.h>
 #include <linux/bitops.h>
 #include <linux/err.h>
 #include <linux/errno.h>
@@ -3829,8 +3830,11 @@ int spi_nor_scan(struct spi_nor *nor)
 #ifndef CONFIG_SPL_BUILD
 	printf("SF: Detected %s with page size ", nor->name);
 	print_size(nor->page_size, ", erase size ");
+	env_set_hex("sf_pagesize", nor->page_size);
 	print_size(nor->erase_size, ", total ");
+	env_set_hex("sf_erasesize", nor->erase_size);
 	print_size(nor->size, "");
+	env_set_hex("sf_size", nor->size);
 	puts("\n");
 #endif
 
Signature · 1 line
2.33.0
Signature · 3 lines
Regards,
Pratyush Yadav
Texas Instruments Inc.
#2 lore raw
Quoted 8 lines · Pratyush Yadav
Quoted 3 lines · Marek Vasut

Set the SF page size, erase block size and total size as an environment variable after "sf probe". This lets us discern boards with multiple distinct SPI flash options and also e.g. set mtdparts accordingly.

I don't quite follow the rationale for making these environment variables. Wouldn't you be better off finding this info out via mtd or sf command?

I need to use that info in a script, that's why these env vars.

#3 lore raw
Quoted 11 lines · Marek Vasut
Quoted 8 lines · Pratyush Yadav
Quoted 3 lines · Marek Vasut

Set the SF page size, erase block size and total size as an environment variable after "sf probe". This lets us discern boards with multiple distinct SPI flash options and also e.g. set mtdparts accordingly.

I don't quite follow the rationale for making these environment variables. Wouldn't you be better off finding this info out via mtd or sf command?

I need to use that info in a script, that's why these env vars.

Ok. Honestly, it doesn't feel quite right to me.

I haven't played with U-Boot's shell too much but is there no way to assign variables from command outputs? For example, can we do something like foo=$(cat a.txt)? If that is possible, maybe add some new subcommands to "sf" that return this information?

Signature · 3 lines
Regards,
Pratyush Yadav
Texas Instruments Inc.
#4 lore raw
Quoted 11 lines · Pratyush Yadav
Quoted 10 lines · Marek Vasut
Quoted 8 lines · Pratyush Yadav
Quoted 3 lines · Marek Vasut

Set the SF page size, erase block size and total size as an environment variable after "sf probe". This lets us discern boards with multiple distinct SPI flash options and also e.g. set mtdparts accordingly.

I don't quite follow the rationale for making these environment variables. Wouldn't you be better off finding this info out via mtd or sf command?

Quoted 6 lines
Quoted 1 line

I need to use that info in a script, that's why these env vars.

Ok. Honestly, it doesn't feel quite right to me.

I haven't played with U-Boot's shell too much but is there no way to assign variables from command outputs?

Not that I know of.

Quoted 3 lines

For example, can we do something
like foo=$(cat a.txt)? If that is possible, maybe add some new subcommands to "sf" that return this information?

What you would want to have is per-device runtime properties, kind-of like reduced sysfs, which would need VFS in U-Boot, and we do not have that yet.

#5 lore raw
Quoted 19 lines · Marek Vasut
Quoted 11 lines · Pratyush Yadav
Quoted 10 lines · Marek Vasut
Quoted 8 lines · Pratyush Yadav
Quoted 3 lines · Marek Vasut

Set the SF page size, erase block size and total size as an environment variable after "sf probe". This lets us discern boards with multiple distinct SPI flash options and also e.g. set mtdparts accordingly.

I don't quite follow the rationale for making these environment variables. Wouldn't you be better off finding this info out via mtd or sf command?

Quoted 6 lines
Quoted 1 line

I need to use that info in a script, that's why these env vars.

Ok. Honestly, it doesn't feel quite right to me.

I haven't played with U-Boot's shell too much but is there no way to assign variables from command outputs?

Quoted 7 lines

Not that I know of.

Quoted 3 lines

For example, can we do something
like foo=$(cat a.txt)? If that is possible, maybe add some new subcommands to "sf" that return this information?

What you would want to have is per-device runtime properties, kind-of like reduced sysfs, which would need VFS in U-Boot, and we do not have that yet.

Are there any news on this patch ?

#6 lore raw

Hi Marek,

Quoted 27 lines · Marek Vasut
Quoted 26 lines · Marek Vasut
Quoted 12 lines · Pratyush Yadav
Quoted 11 lines · Marek Vasut
Quoted 9 lines · Pratyush Yadav
Quoted 4 lines · Marek Vasut

Set the SF page size, erase block size and total size as an environment
variable after "sf probe". This lets us discern boards with multiple distinct SPI flash options and also e.g. set mtdparts accordingly.

I don't quite follow the rationale for making these environment variables. Wouldn't you be better off finding this info out via mtd or sf command?

Quoted 6 lines
Quoted 1 line

I need to use that info in a script, that's why these env vars.

Ok. Honestly, it doesn't feel quite right to me.

I haven't played with U-Boot's shell too much but is there no way to assign variables from command outputs?

Not that I know of.

Quoted 3 lines

For example, can we do something
like foo=$(cat a.txt)? If that is possible, maybe add some new subcommands to "sf" that return this information?

Quoted 5 lines
Quoted 3 lines

What you would want to have is per-device runtime properties, kind-of like reduced sysfs, which would need VFS in U-Boot, and we do not have that yet.

Are there any news on this patch ?

All I would say is that I do not particularly like what this patch is doing, but I also can't give you an alternative solution to the problem unfortunately. So I drop my $0.02 here and leave it up to you and Jagan to figure it out.

Signature · 3 lines
Regards,
Pratyush Yadav
Texas Instruments Inc.
#7 lore raw
In reply to Pratyush Yadav
Quoted 11 lines · Pratyush Yadav
Quoted 10 lines · Marek Vasut
Quoted 8 lines · Pratyush Yadav
Quoted 3 lines · Marek Vasut

Set the SF page size, erase block size and total size as an environment variable after "sf probe". This lets us discern boards with multiple distinct SPI flash options and also e.g. set mtdparts accordingly.

I don't quite follow the rationale for making these environment variables. Wouldn't you be better off finding this info out via mtd or sf command?

Quoted 9 lines
Quoted 1 line

I need to use that info in a script, that's why these env vars.

Ok. Honestly, it doesn't feel quite right to me.

I haven't played with U-Boot's shell too much but is there no way to assign variables from command outputs? For example, can we do something like foo=$(cat a.txt)? If that is possible, maybe add some new subcommands to "sf" that return this information?

There is not.

IMO the current solution (exporting to environment variables in an ad-hoc manner) is rather ugly, but fixing it is difficult :)

--Sean

#8 lore raw
In reply to Marek Vasut
Quoted 25 lines · Marek Vasut

Set the SF page size, erase block size and total size as an environment variable after "sf probe". This lets us discern boards with multiple distinct SPI flash options and also e.g. set mtdparts accordingly.

---
 drivers/mtd/spi/spi-nor-core.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/mtd/spi/spi-nor-core.c +1 -0
index d5d905fa5a1..448653b9931 100644
@@ -15,6 +15,7 @@
 #include <dm.h>
 #include <dm/device_compat.h>
 #include <dm/devres.h>
+#include <env.h>
 #include <linux/bitops.h>
 #include <linux/err.h>
 #include <linux/errno.h>

drivers/mtd/spi/spi-nor-core.c int spi_nor_scan(struct spi_nor *nor) · line 3838

Quoted 9 lines
drivers/mtd/spi/spi-nor-core.c +3 -0
@@ -3829,8 +3830,11 @@ int spi_nor_scan(struct spi_nor *nor)
 #ifndef CONFIG_SPL_BUILD
        printf("SF: Detected %s with page size ", nor->name);
        print_size(nor->page_size, ", erase size ");
+       env_set_hex("sf_pagesize", nor->page_size);
        print_size(nor->erase_size, ", total ");
+       env_set_hex("sf_erasesize", nor->erase_size);
        print_size(nor->size, "");
+       env_set_hex("sf_size", nor->size);
        puts("\n");

I feel this unnecessarily add env variables which are not needed for those SF enabled boards, isn't it?

Jagan.

#9 lore raw
Quoted 30 lines · Jagan Teki
Quoted 29 lines · Marek Vasut

Set the SF page size, erase block size and total size as an environment variable after "sf probe". This lets us discern boards with multiple distinct SPI flash options and also e.g. set mtdparts accordingly.

---
  drivers/mtd/spi/spi-nor-core.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/mtd/spi/spi-nor-core.c +2 -0
index d5d905fa5a1..448653b9931 100644
@@ -15,6 +15,7 @@
  #include <dm.h>
  #include <dm/device_compat.h>
  #include <dm/devres.h>
+#include <env.h>
  #include <linux/bitops.h>
  #include <linux/err.h>
  #include <linux/errno.h>
@@ -3829,8 +3830,11 @@ int spi_nor_scan(struct spi_nor *nor)
  #ifndef CONFIG_SPL_BUILD
         printf("SF: Detected %s with page size ", nor->name);
         print_size(nor->page_size, ", erase size ");
+       env_set_hex("sf_pagesize", nor->page_size);
Quoted 8 lines

drivers/mtd/spi/spi-nor-core.c int spi_nor_scan(struct spi_nor *nor) · line 3838

Quoted 5 lines
drivers/mtd/spi/spi-nor-core.c +2 -0
         print_size(nor->erase_size, ", total ");
+       env_set_hex("sf_erasesize", nor->erase_size);
         print_size(nor->size, "");
+       env_set_hex("sf_size", nor->size);
         puts("\n");

I feel this unnecessarily add env variables which are not needed for those SF enabled boards, isn't it?

So, how do you determine current SPI NOR size from U-Boot shell ?

#10 lore raw
Quoted 41 lines · Marek Vasut
Quoted 30 lines · Jagan Teki
Quoted 29 lines · Marek Vasut

Set the SF page size, erase block size and total size as an environment variable after "sf probe". This lets us discern boards with multiple distinct SPI flash options and also e.g. set mtdparts accordingly.

---
  drivers/mtd/spi/spi-nor-core.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/mtd/spi/spi-nor-core.c +2 -0
index d5d905fa5a1..448653b9931 100644
@@ -15,6 +15,7 @@
  #include <dm.h>
  #include <dm/device_compat.h>
  #include <dm/devres.h>
+#include <env.h>
  #include <linux/bitops.h>
  #include <linux/err.h>
  #include <linux/errno.h>
@@ -3829,8 +3830,11 @@ int spi_nor_scan(struct spi_nor *nor)
  #ifndef CONFIG_SPL_BUILD
         printf("SF: Detected %s with page size ", nor->name);
         print_size(nor->page_size, ", erase size ");
+       env_set_hex("sf_pagesize", nor->page_size);
Quoted 8 lines

drivers/mtd/spi/spi-nor-core.c int spi_nor_scan(struct spi_nor *nor) · line 3838

Quoted 5 lines
drivers/mtd/spi/spi-nor-core.c +2 -0
         print_size(nor->erase_size, ", total ");
+       env_set_hex("sf_erasesize", nor->erase_size);
         print_size(nor->size, "");
+       env_set_hex("sf_size", nor->size);
         puts("\n");

I feel this unnecessarily add env variables which are not needed for those SF enabled boards, isn't it?

Quoted 1 line

So, how do you determine current SPI NOR size from U-Boot shell ?

I think we need to know the size for those who enabled mtd command (or mtdparts), any way to preserve it via mtd command or set the env via mtd command side.

Jagan.

#11 lore raw
Quoted 42 lines · Jagan Teki
Quoted 41 lines · Marek Vasut
Quoted 38 lines · Jagan Teki
Quoted 25 lines · Marek Vasut

Set the SF page size, erase block size and total size as an environment variable after "sf probe". This lets us discern boards with multiple distinct SPI flash options and also e.g. set mtdparts accordingly.

---
   drivers/mtd/spi/spi-nor-core.c | 4 ++++
   1 file changed, 4 insertions(+)
drivers/mtd/spi/spi-nor-core.c +1 -0
index d5d905fa5a1..448653b9931 100644
@@ -15,6 +15,7 @@
   #include <dm.h>
   #include <dm/device_compat.h>
   #include <dm/devres.h>
+#include <env.h>
   #include <linux/bitops.h>
   #include <linux/err.h>
   #include <linux/errno.h>

drivers/mtd/spi/spi-nor-core.c int spi_nor_scan(struct spi_nor *nor) · line 3838

Quoted 9 lines
drivers/mtd/spi/spi-nor-core.c +3 -0
@@ -3829,8 +3830,11 @@ int spi_nor_scan(struct spi_nor *nor)
   #ifndef CONFIG_SPL_BUILD
          printf("SF: Detected %s with page size ", nor->name);
          print_size(nor->page_size, ", erase size ");
+       env_set_hex("sf_pagesize", nor->page_size);
          print_size(nor->erase_size, ", total ");
+       env_set_hex("sf_erasesize", nor->erase_size);
          print_size(nor->size, "");
+       env_set_hex("sf_size", nor->size);
          puts("\n");

I feel this unnecessarily add env variables which are not needed for those SF enabled boards, isn't it?

Quoted 5 lines
Quoted 1 line

So, how do you determine current SPI NOR size from U-Boot shell ?

I think we need to know the size for those who enabled mtd command (or mtdparts), any way to preserve it via mtd command or set the env via mtd command side.

I need to know the size of SPI NOR flash to use it in an U-Boot script which handle different board population options. This has nothing to do with mtd command.