[PATCH 11/20] Audit <flash.h> inclusion

Tom Rini trini at konsulko.com
Sat Jul 23 19:05:03 CEST 2022


A large number of files include <flash.h> as it used to be how various
SPI flash related functions were found, or for other reasons entirely.
In order to migrate some further CONFIG symbols to Kconfig we need to
not include flash.h in cases where we don't have a NOR flash of some
sort enabled.  Furthermore, in cases where we are in common code and it
doesn't make sense to try and further refactor the code itself in to new
files we need to guard this inclusion.

Signed-off-by: Tom Rini <trini at konsulko.com>
---
 board/atmel/at91sam9263ek/at91sam9263ek.c  | 3 +--
 board/buffalo/lsxl/lsxl.c                  | 1 -
 board/freescale/common/fsl_validate.c      | 3 ++-
 board/gardena/smart-gateway-mt7688/board.c | 1 -
 board/logicpd/omap3som/omap3logic.c        | 1 -
 board/siemens/taurus/taurus.c              | 1 -
 board/socrates/socrates.c                  | 2 --
 board/toradex/common/tdx-cfg-block.c       | 2 ++
 cmd/bootm.c                                | 1 -
 cmd/cramfs.c                               | 2 +-
 cmd/cros_ec.c                              | 1 -
 cmd/flash.c                                | 1 -
 cmd/jffs2.c                                | 5 ++---
 cmd/load.c                                 | 2 ++
 cmd/mem.c                                  | 2 ++
 cmd/mvebu/bubt.c                           | 1 -
 cmd/sf.c                                   | 1 -
 common/board_r.c                           | 2 ++
 common/flash.c                             | 2 --
 common/update.c                            | 5 ++---
 drivers/dfu/dfu_sf.c                       | 1 -
 drivers/fastboot/fb_command.c              | 1 -
 drivers/fastboot/fb_mmc.c                  | 1 -
 drivers/fastboot/fb_nand.c                 | 1 -
 drivers/misc/cros_ec.c                     | 1 -
 drivers/mtd/spi/sf_dataflash.c             | 1 -
 drivers/mtd/spi/sf_mtd.c                   | 1 -
 drivers/mtd/spi/spi-nor-core.c             | 1 -
 env/flash.c                                | 2 +-
 env/sf.c                                   | 1 -
 fs/cramfs/cramfs.c                         | 3 +--
 fs/jffs2/jffs2_1pass.c                     | 4 ++--
 include/flash.h                            | 5 +----
 include/mtd/cfi_flash.h                    | 1 -
 net/nfs.c                                  | 2 ++
 post/drivers/flash.c                       | 4 +---
 36 files changed, 24 insertions(+), 45 deletions(-)

diff --git a/board/atmel/at91sam9263ek/at91sam9263ek.c b/board/atmel/at91sam9263ek/at91sam9263ek.c
index c3e1734dda0c..86b4050c4c17 100644
--- a/board/atmel/at91sam9263ek/at91sam9263ek.c
+++ b/board/atmel/at91sam9263ek/at91sam9263ek.c
@@ -7,7 +7,6 @@
 
 #include <common.h>
 #include <debug_uart.h>
-#include <flash.h>
 #include <init.h>
 #include <net.h>
 #include <vsprintf.h>
@@ -140,7 +139,7 @@ static void at91sam9263ek_lcd_hw_init(void)
 #include <version.h>
 
 #ifdef CONFIG_MTD_NOR_FLASH
-extern flash_info_t flash_info[];
+#include <flash.h>
 #endif
 
 void lcd_show_board_info(void)
diff --git a/board/buffalo/lsxl/lsxl.c b/board/buffalo/lsxl/lsxl.c
index 738b6bc25cea..31d532b75294 100644
--- a/board/buffalo/lsxl/lsxl.c
+++ b/board/buffalo/lsxl/lsxl.c
@@ -12,7 +12,6 @@
 #include <command.h>
 #include <env.h>
 #include <env_internal.h>
-#include <flash.h>
 #include <init.h>
 #include <net.h>
 #include <malloc.h>
diff --git a/board/freescale/common/fsl_validate.c b/board/freescale/common/fsl_validate.c
index f1a0b0cfc34c..f56e4e857af1 100644
--- a/board/freescale/common/fsl_validate.c
+++ b/board/freescale/common/fsl_validate.c
@@ -6,7 +6,6 @@
 
 #include <common.h>
 #include <dm.h>
-#include <flash.h>
 #include <fsl_validate.h>
 #include <fsl_secboot_err.h>
 #include <fsl_sfp.h>
@@ -79,6 +78,8 @@ static u32 check_ie(struct fsl_secboot_img_priv *img)
  * address
  */
 #if defined(CONFIG_MPC85xx)
+#include <flash.h>
+
 int get_csf_base_addr(u32 *csf_addr, u32 *flash_base_addr)
 {
 	struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
diff --git a/board/gardena/smart-gateway-mt7688/board.c b/board/gardena/smart-gateway-mt7688/board.c
index aa833a030fd9..0cfde91c94c6 100644
--- a/board/gardena/smart-gateway-mt7688/board.c
+++ b/board/gardena/smart-gateway-mt7688/board.c
@@ -7,7 +7,6 @@
 #include <command.h>
 #include <env.h>
 #include <env_internal.h>
-#include <flash.h>
 #include <init.h>
 #include <led.h>
 #include <log.h>
diff --git a/board/logicpd/omap3som/omap3logic.c b/board/logicpd/omap3som/omap3logic.c
index 2379b521904a..559192e9001e 100644
--- a/board/logicpd/omap3som/omap3logic.c
+++ b/board/logicpd/omap3som/omap3logic.c
@@ -15,7 +15,6 @@
 #include <init.h>
 #include <net.h>
 #include <ns16550.h>
-#include <flash.h>
 #include <nand.h>
 #include <i2c.h>
 #include <serial.h>
diff --git a/board/siemens/taurus/taurus.c b/board/siemens/taurus/taurus.c
index dae064d4654a..6c44afb44875 100644
--- a/board/siemens/taurus/taurus.c
+++ b/board/siemens/taurus/taurus.c
@@ -15,7 +15,6 @@
 #include <common.h>
 #include <dm.h>
 #include <env.h>
-#include <flash.h>
 #include <init.h>
 #include <asm/global_data.h>
 #include <asm/io.h>
diff --git a/board/socrates/socrates.c b/board/socrates/socrates.c
index 27aad4eaae3a..f9e1bc631648 100644
--- a/board/socrates/socrates.c
+++ b/board/socrates/socrates.c
@@ -30,8 +30,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-extern flash_info_t flash_info[];	/* FLASH chips info */
-
 void local_bus_init (void);
 ulong flash_get_size (ulong base, int banknum);
 
diff --git a/board/toradex/common/tdx-cfg-block.c b/board/toradex/common/tdx-cfg-block.c
index 9305709a3c0d..5c4657e5ea92 100644
--- a/board/toradex/common/tdx-cfg-block.c
+++ b/board/toradex/common/tdx-cfg-block.c
@@ -25,7 +25,9 @@
 #include <cli.h>
 #include <console.h>
 #include <env.h>
+#ifdef CONFIG_TDX_CFG_BLOCK_IS_IN_NOR
 #include <flash.h>
+#endif
 #include <malloc.h>
 #include <mmc.h>
 #include <nand.h>
diff --git a/cmd/bootm.c b/cmd/bootm.c
index 1f70ee9e911b..9fe8ce4a27cf 100644
--- a/cmd/bootm.c
+++ b/cmd/bootm.c
@@ -31,7 +31,6 @@ static int image_info(unsigned long addr);
 #if defined(CONFIG_CMD_IMLS)
 #include <flash.h>
 #include <mtd/cfi_flash.h>
-extern flash_info_t flash_info[]; /* info for FLASH chips */
 #endif
 
 #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
diff --git a/cmd/cramfs.c b/cmd/cramfs.c
index 2aad50c6724c..57e2afa2472b 100644
--- a/cmd/cramfs.c
+++ b/cmd/cramfs.c
@@ -33,11 +33,11 @@
 # define DEBUGF(fmt, args...)
 #endif
 
-#include <flash.h>
 
 #ifndef CONFIG_MTD_NOR_FLASH
 # define OFFSET_ADJUSTMENT	0
 #else
+#include <flash.h>
 # define OFFSET_ADJUSTMENT	(flash_info[id.num].start[0])
 #endif
 
diff --git a/cmd/cros_ec.c b/cmd/cros_ec.c
index ad49905d67bb..90921cecf602 100644
--- a/cmd/cros_ec.c
+++ b/cmd/cros_ec.c
@@ -10,7 +10,6 @@
 #include <command.h>
 #include <cros_ec.h>
 #include <dm.h>
-#include <flash.h>
 #include <log.h>
 #include <dm/device-internal.h>
 #include <dm/uclass-internal.h>
diff --git a/cmd/flash.c b/cmd/flash.c
index db4bb2529c6a..f4f85ecc7a8e 100644
--- a/cmd/flash.c
+++ b/cmd/flash.c
@@ -25,7 +25,6 @@ int find_dev_and_part(const char *id, struct mtd_device **dev,
 #ifdef CONFIG_MTD_NOR_FLASH
 #include <flash.h>
 #include <mtd/cfi_flash.h>
-extern flash_info_t flash_info[];	/* info for FLASH chips */
 
 /*
  * The user interface starts numbering for Flash banks with 1
diff --git a/cmd/jffs2.c b/cmd/jffs2.c
index 914a7beeed95..e00fcc202266 100644
--- a/cmd/jffs2.c
+++ b/cmd/jffs2.c
@@ -73,7 +73,9 @@
 #include <common.h>
 #include <command.h>
 #include <env.h>
+#if defined(CONFIG_CMD_FLASH)
 #include <flash.h>
+#endif
 #include <image.h>
 #include <malloc.h>
 #include <jffs2/jffs2.h>
@@ -156,7 +158,6 @@ static int mtd_device_validate(u8 type, u8 num, u32 *size)
 	if (type == MTD_DEV_TYPE_NOR) {
 #if defined(CONFIG_CMD_FLASH)
 		if (num < CONFIG_SYS_MAX_FLASH_BANKS) {
-			extern flash_info_t flash_info[];
 			*size = flash_info[num].size;
 
 			return 0;
@@ -260,8 +261,6 @@ static inline u32 get_part_sector_size_nand(struct mtdids *id)
 static inline u32 get_part_sector_size_nor(struct mtdids *id, struct part_info *part)
 {
 #if defined(CONFIG_CMD_FLASH)
-	extern flash_info_t flash_info[];
-
 	u32 end_phys, start_phys, sector_size = 0, size = 0;
 	int i;
 	flash_info_t *flash;
diff --git a/cmd/load.c b/cmd/load.c
index 1224a7f85bb3..e44ae0d56b75 100644
--- a/cmd/load.c
+++ b/cmd/load.c
@@ -14,7 +14,9 @@
 #include <efi_loader.h>
 #include <env.h>
 #include <exports.h>
+#ifdef CONFIG_MTD_NOR_FLASH
 #include <flash.h>
+#endif
 #include <image.h>
 #include <lmb.h>
 #include <mapmem.h>
diff --git a/cmd/mem.c b/cmd/mem.c
index b7511382d3ac..1f4e3fcdede1 100644
--- a/cmd/mem.c
+++ b/cmd/mem.c
@@ -16,7 +16,9 @@
 #include <cli.h>
 #include <command.h>
 #include <console.h>
+#ifdef CONFIG_MTD_NOR_FLASH
 #include <flash.h>
+#endif
 #include <hash.h>
 #include <log.h>
 #include <mapmem.h>
diff --git a/cmd/mvebu/bubt.c b/cmd/mvebu/bubt.c
index 1362c03bcee5..92101cfc8058 100644
--- a/cmd/mvebu/bubt.c
+++ b/cmd/mvebu/bubt.c
@@ -8,7 +8,6 @@
 #include <common.h>
 #include <command.h>
 #include <env.h>
-#include <flash.h>
 #include <image.h>
 #include <net.h>
 #include <vsprintf.h>
diff --git a/cmd/sf.c b/cmd/sf.c
index cd50b38081c2..058635cb2f83 100644
--- a/cmd/sf.c
+++ b/cmd/sf.c
@@ -9,7 +9,6 @@
 #include <command.h>
 #include <div64.h>
 #include <dm.h>
-#include <flash.h>
 #include <log.h>
 #include <malloc.h>
 #include <mapmem.h>
diff --git a/common/board_r.c b/common/board_r.c
index ed29069d2de6..e702f0234ee7 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -14,7 +14,9 @@
 #include <bootstage.h>
 #include <cpu_func.h>
 #include <exports.h>
+#ifdef CONFIG_MTD_NOR_FLASH
 #include <flash.h>
+#endif
 #include <hang.h>
 #include <image.h>
 #include <irq_func.h>
diff --git a/common/flash.c b/common/flash.c
index f939c2f9e954..848f44e59dfd 100644
--- a/common/flash.c
+++ b/common/flash.c
@@ -13,8 +13,6 @@
 
 #include <mtd/cfi_flash.h>
 
-extern flash_info_t  flash_info[]; /* info for FLASH chips */
-
 /*-----------------------------------------------------------------------
  * Functions
  */
diff --git a/common/update.c b/common/update.c
index b9ad475d9d44..80f16af65358 100644
--- a/common/update.c
+++ b/common/update.c
@@ -20,14 +20,12 @@
 
 #include <command.h>
 #include <env.h>
-#include <flash.h>
 #include <net.h>
 #include <net/tftp.h>
 #include <malloc.h>
 #include <mapmem.h>
 #include <dfu.h>
 #include <errno.h>
-#include <mtd/cfi_flash.h>
 
 #if defined(CONFIG_DFU_TFTP) || defined(CONFIG_UPDATE_TFTP)
 /* env variable holding the location of the update file */
@@ -49,7 +47,8 @@
 extern ulong tftp_timeout_ms;
 extern int tftp_timeout_count_max;
 #ifdef CONFIG_MTD_NOR_FLASH
-extern flash_info_t flash_info[];
+#include <flash.h>
+#include <mtd/cfi_flash.h>
 static uchar *saved_prot_info;
 #endif
 static int update_load(char *filename, ulong msec_max, int cnt_max, ulong addr)
diff --git a/drivers/dfu/dfu_sf.c b/drivers/dfu/dfu_sf.c
index 25a9c8185037..2dae15937064 100644
--- a/drivers/dfu/dfu_sf.c
+++ b/drivers/dfu/dfu_sf.c
@@ -4,7 +4,6 @@
  */
 
 #include <common.h>
-#include <flash.h>
 #include <malloc.h>
 #include <errno.h>
 #include <div64.h>
diff --git a/drivers/fastboot/fb_command.c b/drivers/fastboot/fb_command.c
index 98eccc34556b..bdfdf262c8a3 100644
--- a/drivers/fastboot/fb_command.c
+++ b/drivers/fastboot/fb_command.c
@@ -10,7 +10,6 @@
 #include <fastboot-internal.h>
 #include <fb_mmc.h>
 #include <fb_nand.h>
-#include <flash.h>
 #include <part.h>
 #include <stdlib.h>
 
diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
index c62e414306c3..033c510bc096 100644
--- a/drivers/fastboot/fb_mmc.c
+++ b/drivers/fastboot/fb_mmc.c
@@ -10,7 +10,6 @@
 #include <fastboot.h>
 #include <fastboot-internal.h>
 #include <fb_mmc.h>
-#include <flash.h>
 #include <image-sparse.h>
 #include <image.h>
 #include <log.h>
diff --git a/drivers/fastboot/fb_nand.c b/drivers/fastboot/fb_nand.c
index eb8a36f29222..6d3a900c7728 100644
--- a/drivers/fastboot/fb_nand.c
+++ b/drivers/fastboot/fb_nand.c
@@ -7,7 +7,6 @@
 #include <config.h>
 #include <common.h>
 #include <blk.h>
-#include <flash.h>
 
 #include <fastboot.h>
 #include <image-sparse.h>
diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c
index e131eccd281f..621d1752176a 100644
--- a/drivers/misc/cros_ec.c
+++ b/drivers/misc/cros_ec.c
@@ -18,7 +18,6 @@
 #include <common.h>
 #include <command.h>
 #include <dm.h>
-#include <flash.h>
 #include <i2c.h>
 #include <cros_ec.h>
 #include <fdtdec.h>
diff --git a/drivers/mtd/spi/sf_dataflash.c b/drivers/mtd/spi/sf_dataflash.c
index 85867817c786..e19e34244d1f 100644
--- a/drivers/mtd/spi/sf_dataflash.c
+++ b/drivers/mtd/spi/sf_dataflash.c
@@ -10,7 +10,6 @@
 #include <dm.h>
 #include <errno.h>
 #include <fdtdec.h>
-#include <flash.h>
 #include <log.h>
 #include <spi.h>
 #include <spi_flash.h>
diff --git a/drivers/mtd/spi/sf_mtd.c b/drivers/mtd/spi/sf_mtd.c
index 0aed28a52b78..071b25ac67f2 100644
--- a/drivers/mtd/spi/sf_mtd.c
+++ b/drivers/mtd/spi/sf_mtd.c
@@ -4,7 +4,6 @@
  */
 
 #include <common.h>
-#include <flash.h>
 #include <malloc.h>
 #include <linux/errno.h>
 #include <linux/mtd/mtd.h>
diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
index 8a226a7af553..26a356baf841 100644
--- a/drivers/mtd/spi/spi-nor-core.c
+++ b/drivers/mtd/spi/spi-nor-core.c
@@ -10,7 +10,6 @@
  */
 
 #include <common.h>
-#include <flash.h>
 #include <log.h>
 #include <watchdog.h>
 #include <dm.h>
diff --git a/env/flash.c b/env/flash.c
index 9c8abfa016c4..1e75f8c004ee 100644
--- a/env/flash.c
+++ b/env/flash.c
@@ -13,7 +13,6 @@
 #include <command.h>
 #include <env.h>
 #include <env_internal.h>
-#include <flash.h>
 #include <log.h>
 #include <asm/global_data.h>
 #include <linux/stddef.h>
@@ -26,6 +25,7 @@ DECLARE_GLOBAL_DATA_PTR;
 
 #ifndef CONFIG_SPL_BUILD
 # if defined(CONFIG_CMD_SAVEENV) && defined(CONFIG_CMD_FLASH)
+#  include <flash.h>
 #  define CMD_SAVEENV
 # elif defined(CONFIG_ENV_ADDR_REDUND)
 #  error CONFIG_ENV_ADDR_REDUND must have CONFIG_CMD_SAVEENV & CONFIG_CMD_FLASH
diff --git a/env/sf.c b/env/sf.c
index 4b768542c14c..a425ecc11c8e 100644
--- a/env/sf.c
+++ b/env/sf.c
@@ -12,7 +12,6 @@
 #include <dm.h>
 #include <env.h>
 #include <env_internal.h>
-#include <flash.h>
 #include <malloc.h>
 #include <spi.h>
 #include <spi_flash.h>
diff --git a/fs/cramfs/cramfs.c b/fs/cramfs/cramfs.c
index 7ef48bbc064c..6c017cebc50f 100644
--- a/fs/cramfs/cramfs.c
+++ b/fs/cramfs/cramfs.c
@@ -25,7 +25,6 @@
  */
 
 #include <common.h>
-#include <flash.h>
 #include <malloc.h>
 #include <asm/byteorder.h>
 #include <linux/stat.h>
@@ -43,7 +42,7 @@ struct cramfs_super super;
 /* CPU address space offset calculation macro, struct part_info offset is
  * device address space offset, so we need to shift it by a device start address. */
 #if defined(CONFIG_MTD_NOR_FLASH)
-extern flash_info_t flash_info[];
+#include <flash.h>
 #define PART_OFFSET(x)	((ulong)x->offset + \
 			 flash_info[x->dev->id->num].start[0])
 #else
diff --git a/fs/jffs2/jffs2_1pass.c b/fs/jffs2/jffs2_1pass.c
index 1818e8121569..ef7b302725ca 100644
--- a/fs/jffs2/jffs2_1pass.c
+++ b/fs/jffs2/jffs2_1pass.c
@@ -113,7 +113,6 @@
 
 #include <common.h>
 #include <config.h>
-#include <flash.h>
 #include <malloc.h>
 #include <div64.h>
 #include <linux/compiler.h>
@@ -381,6 +380,8 @@ static void put_fl_mem_onenand(void *buf)
 
 
 #if defined(CONFIG_CMD_FLASH)
+#include <flash.h>
+
 /*
  * Support for jffs2 on top of NOR-flash
  *
@@ -392,7 +393,6 @@ static inline void *get_fl_mem_nor(u32 off, u32 size, void *ext_buf)
 	u32 addr = off;
 	struct mtdids *id = current_part->dev->id;
 
-	extern flash_info_t flash_info[];
 	flash_info_t *flash = &flash_info[id->num];
 
 	addr += flash->start[0];
diff --git a/include/flash.h b/include/flash.h
index f3959f501202..95992fa689bb 100644
--- a/include/flash.h
+++ b/include/flash.h
@@ -7,10 +7,6 @@
 #ifndef _FLASH_H_
 #define _FLASH_H_
 
-#ifndef CONFIG_SYS_MAX_FLASH_SECT
-#define CONFIG_SYS_MAX_FLASH_SECT	512
-#endif
-
 /*-----------------------------------------------------------------------
  * FLASH Info: contains chip specific data, per FLASH bank
  */
@@ -91,6 +87,7 @@ int flash_sect_erase(ulong addr_first, ulong addr_last);
 int flash_sect_protect(int flag, ulong addr_first, ulong addr_last);
 int flash_sect_roundb(ulong *addr);
 unsigned long flash_sector_size(flash_info_t *info, flash_sect_t sect);
+void flash_cmd_reset(flash_info_t *info);
 void flash_set_verbose(uint v);
 
 /* common/flash.c */
diff --git a/include/mtd/cfi_flash.h b/include/mtd/cfi_flash.h
index d4aeea7e464b..1321da191028 100644
--- a/include/mtd/cfi_flash.h
+++ b/include/mtd/cfi_flash.h
@@ -176,7 +176,6 @@ extern int cfi_flash_num_flash_banks;
 
 phys_addr_t cfi_flash_bank_addr(int i);
 unsigned long cfi_flash_bank_size(int i);
-void flash_cmd_reset(flash_info_t *info);
 
 #ifdef CONFIG_CFI_FLASH_USE_WEAK_ACCESSORS
 void flash_write8(u8 value, void *addr);
diff --git a/net/nfs.c b/net/nfs.c
index 9152ab742ef1..9f65cfb20dc9 100644
--- a/net/nfs.c
+++ b/net/nfs.c
@@ -28,7 +28,9 @@
 
 #include <common.h>
 #include <command.h>
+#ifdef CONFIG_SYS_DIRECT_FLASH_NFS
 #include <flash.h>
+#endif
 #include <image.h>
 #include <log.h>
 #include <net.h>
diff --git a/post/drivers/flash.c b/post/drivers/flash.c
index 07eab332d21b..7d65f46d9fea 100644
--- a/post/drivers/flash.c
+++ b/post/drivers/flash.c
@@ -6,12 +6,12 @@
  * Licensed under the GPL-2 or later.
  */
 
+#if CONFIG_POST & CONFIG_SYS_POST_FLASH
 #include <common.h>
 #include <malloc.h>
 #include <post.h>
 #include <flash.h>
 
-#if CONFIG_POST & CONFIG_SYS_POST_FLASH
 
 /*
  * This code will walk over the declared sectors erasing them,
@@ -30,8 +30,6 @@
 # error "invalid flash block start/end"
 #endif
 
-extern flash_info_t flash_info[];
-
 static void *seed_src_data(void *ptr, ulong *old_len, ulong new_len)
 {
 	unsigned char *p;
-- 
2.25.1



More information about the U-Boot mailing list