diff mbox series

[1/2] mtd-interface: add UBIATTACH config option

Message ID 20180821145630.19389-1-arnout@mind.be
State Superseded
Headers show
Series [1/2] mtd-interface: add UBIATTACH config option | expand

Commit Message

Arnout Vandecappelle Aug. 21, 2018, 2:56 p.m. UTC
Attaching random MTD devices as a UBI device is potentially dangerous,
because the kernel will start writing to it if it is found to be
erased. This may e.g. destroy a bootloader on it.

Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
---
Some parts of the code are only relevant when UBIATTACH is enabled but
are not #ifdef'ed away for simplicity. In particular, all the support
code for blacklisting is not relevant.
---
 corelib/mtd-interface.c |  4 ++++
 handlers/Config.in      | 19 ++++++++++++++++---
 2 files changed, 20 insertions(+), 3 deletions(-)

Comments

Stefano Babic Aug. 22, 2018, 3:33 p.m. UTC | #1
On 21/08/2018 16:56, Arnout Vandecappelle (Essensium/Mind) wrote:
> Attaching random MTD devices as a UBI device is potentially dangerous,
> because the kernel will start writing to it if it is found to be
> erased. This may e.g. destroy a bootloader on it.
> 
> Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
> ---
> Some parts of the code are only relevant when UBIATTACH is enabled but
> are not #ifdef'ed away for simplicity. In particular, all the support
> code for blacklisting is not relevant.
> ---
>  corelib/mtd-interface.c |  4 ++++
>  handlers/Config.in      | 19 ++++++++++++++++---
>  2 files changed, 20 insertions(+), 3 deletions(-)
> 
> diff --git a/corelib/mtd-interface.c b/corelib/mtd-interface.c
> index fa9c1f7..d9bd6d5 100644
> --- a/corelib/mtd-interface.c
> +++ b/corelib/mtd-interface.c
> @@ -311,6 +311,7 @@ static void scan_for_ubi_devices(void)
>  	}
>  }
>  
> +#if defined(CONFIG_UBIATTACH)
>  static void scan_ubi_partitions(int mtd)
>  {
>  	struct flash_description *flash = get_flash_info();
> @@ -371,6 +372,7 @@ static void scan_ubi_partitions(int mtd)
>  	scan_ubi_volumes(mtd_info);
>  }
>  #endif
> +#endif
>  
>  int scan_mtd_devices (void)
>  {
> @@ -465,6 +467,7 @@ int scan_mtd_devices (void)
>  	 */
>  	scan_for_ubi_devices();
>  
> +#if defined(CONFIG_UBIATTACH)
>  	/*
>  	 * Search for volumes in MTD that are not attached, default case
>  	 */
> @@ -476,6 +479,7 @@ int scan_mtd_devices (void)
>  				flash->mtd_info[i].mtd.type != MTD_UBIVOLUME)
>  			scan_ubi_partitions(i);
>  	}
> +#endif
>  #endif
>  
>  	return mtd_info->mtd_dev_cnt;
> diff --git a/handlers/Config.in b/handlers/Config.in
> index 1137acd..12a50b4 100644
> --- a/handlers/Config.in
> +++ b/handlers/Config.in
> @@ -18,9 +18,22 @@ config UBIVOL
>  comment "ubivol support needs libubi"
>  	depends on !HAVE_LIBUBI
>  
> +config UBIATTACH
> +	bool "Automatically attach UBI devices"
> +	default y
> +	depends on UBIVOL
> +	help
> +	  If this option is enabled, swupdate will try to attach
> +	  UBI devices to all MTD devices.
> +
> +	  Make sure UBIBLACKLIST or UBIWHITELIST is set correctly,
> +	  since attaching a UBI device will write to it if it is
> +	  found to be empty, and that may destroy already existing
> +	  content on that device.
> +
>  config UBIBLACKLIST
>  	string "List of MTD devices to be excluded for UBI"
> -	depends on UBIVOL
> +	depends on UBIATTACH
>  	help
>  	  Define a list of MTD devices that are excluded
>  	  by scan_mtd_device. The devices are still available
> @@ -31,7 +44,7 @@ config UBIBLACKLIST
>  
>  config UBIWHITELIST
>  	string "List of MTD devices that must have UBI"
> -	depends on UBIVOL
> +	depends on UBIATTACH
>  	help
>  	  Define a list of MTD devices that are planned to have
>  	  always UBI. If first attach fails, the device is erased
> @@ -43,7 +56,7 @@ config UBIWHITELIST
>  
>  config UBIVIDOFFSET
>  	int "VID Header Offset"
> -	depends on UBIVOL
> +	depends on UBIATTACH
>  	default 0
>  	help
>  	  Force UBI to set a VID header offset to be 2048 bytes
> 

Reviewed-by: Stefano Babic <sbabic@denx.de>

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/corelib/mtd-interface.c b/corelib/mtd-interface.c
index fa9c1f7..d9bd6d5 100644
--- a/corelib/mtd-interface.c
+++ b/corelib/mtd-interface.c
@@ -311,6 +311,7 @@  static void scan_for_ubi_devices(void)
 	}
 }
 
+#if defined(CONFIG_UBIATTACH)
 static void scan_ubi_partitions(int mtd)
 {
 	struct flash_description *flash = get_flash_info();
@@ -371,6 +372,7 @@  static void scan_ubi_partitions(int mtd)
 	scan_ubi_volumes(mtd_info);
 }
 #endif
+#endif
 
 int scan_mtd_devices (void)
 {
@@ -465,6 +467,7 @@  int scan_mtd_devices (void)
 	 */
 	scan_for_ubi_devices();
 
+#if defined(CONFIG_UBIATTACH)
 	/*
 	 * Search for volumes in MTD that are not attached, default case
 	 */
@@ -476,6 +479,7 @@  int scan_mtd_devices (void)
 				flash->mtd_info[i].mtd.type != MTD_UBIVOLUME)
 			scan_ubi_partitions(i);
 	}
+#endif
 #endif
 
 	return mtd_info->mtd_dev_cnt;
diff --git a/handlers/Config.in b/handlers/Config.in
index 1137acd..12a50b4 100644
--- a/handlers/Config.in
+++ b/handlers/Config.in
@@ -18,9 +18,22 @@  config UBIVOL
 comment "ubivol support needs libubi"
 	depends on !HAVE_LIBUBI
 
+config UBIATTACH
+	bool "Automatically attach UBI devices"
+	default y
+	depends on UBIVOL
+	help
+	  If this option is enabled, swupdate will try to attach
+	  UBI devices to all MTD devices.
+
+	  Make sure UBIBLACKLIST or UBIWHITELIST is set correctly,
+	  since attaching a UBI device will write to it if it is
+	  found to be empty, and that may destroy already existing
+	  content on that device.
+
 config UBIBLACKLIST
 	string "List of MTD devices to be excluded for UBI"
-	depends on UBIVOL
+	depends on UBIATTACH
 	help
 	  Define a list of MTD devices that are excluded
 	  by scan_mtd_device. The devices are still available
@@ -31,7 +44,7 @@  config UBIBLACKLIST
 
 config UBIWHITELIST
 	string "List of MTD devices that must have UBI"
-	depends on UBIVOL
+	depends on UBIATTACH
 	help
 	  Define a list of MTD devices that are planned to have
 	  always UBI. If first attach fails, the device is erased
@@ -43,7 +56,7 @@  config UBIWHITELIST
 
 config UBIVIDOFFSET
 	int "VID Header Offset"
-	depends on UBIVOL
+	depends on UBIATTACH
 	default 0
 	help
 	  Force UBI to set a VID header offset to be 2048 bytes