[U-Boot] [PATCH 3/4] mtd: Delete partitions attached to the device when a device is deleted

Heiko Schocher hs at denx.de
Mon Nov 19 06:16:53 UTC 2018


Hello Boris,

Am 17.11.2018 um 10:19 schrieb Boris Brezillon:
> On Fri, 16 Nov 2018 15:40:25 +0100
> Boris Brezillon <boris.brezillon at bootlin.com> wrote:
> 
>> If we don't do that, partitions might still be exposed while the
>> underlying device is gone.
>>
>> Fixes: 2a74930da57f ("mtd: mtdpart: implement proper partition handling")
>> Signed-off-by: Boris Brezillon <boris.brezillon at bootlin.com>
>> ---
>>   drivers/mtd/mtdcore.c   |  1 +
>>   include/linux/mtd/mtd.h | 14 ++++++++++++++
>>   2 files changed, 15 insertions(+)
>>
>> diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
>> index 7a15ded8c883..46657fe7c949 100644
>> --- a/drivers/mtd/mtdcore.c
>> +++ b/drivers/mtd/mtdcore.c
>> @@ -528,6 +528,7 @@ int del_mtd_device(struct mtd_info *mtd)
>>   	struct mtd_notifier *not;
>>   #endif
>>   
>> +	del_mtd_partitions(mtd);
>>   	mutex_lock(&mtd_table_mutex);
>>   
>>   	if (idr_find(&mtd_idr, mtd->index) != mtd) {
>> diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
>> index d20ebd820289..c5b58dd3f0f7 100644
>> --- a/include/linux/mtd/mtd.h
>> +++ b/include/linux/mtd/mtd.h
>> @@ -562,8 +562,22 @@ unsigned mtd_mmap_capabilities(struct mtd_info *mtd);
>>   /* drivers/mtd/mtdcore.h */
>>   int add_mtd_device(struct mtd_info *mtd);
>>   int del_mtd_device(struct mtd_info *mtd);
>> +
>> +#ifdef CONFIG_MTD_PARTITIONS
>>   int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int);
>>   int del_mtd_partitions(struct mtd_info *);
>> +#else
>> +static inline int add_mtd_partitions(struct mtd_info *,
>> +				     const struct mtd_partition *, int)
> 
> Args should have names.
> 
>> +{
>> +	return 0;
>> +}
>> +
>> +static int del_mtd_partitions(struct mtd_info *)
> 
> Missing inline here.
> 
> I'll send a v2 fixing those 2 bugs.

Thanks!

I tried your patchset, with them "ubi part ubi" does now work, also
after a "sf probe" ...

There is one problem, see log [1].

If you have an ubi partition attached (In my example on the NAND),
and issue "sf probe", the following "mtd list" shows not anymore
the SPI NOR MTD partitions. (It prints an error message
"Partition "ubi" already in use, aborting")

If I detach UBI from the NAND MTD partition, the MTD Partitions on
the SPI NOR are again found after a "sf probe" before "mtd list" [2]

bye,
Heiko

[1] U-Boot log
=> mtd list
List of MTD devices:
* nand0
   - type: NAND flash
   - block size: 0x20000 bytes
   - min I/O: 0x800 bytes
   - OOB size: 64 bytes
   - OOB available: 0 bytes
   - ECC strength: 8 bits
   - ECC step size: 512 bytes
   - bitflip threshold: 6 bits
   - 0x000000000000-0x000008000000 : "nand0"
           - 0x000000000000-0x000008000000 : "ubi"
* nor0
   - type: NOR flash
   - block size: 0x10000 bytes
   - min I/O: 0x1 bytes
   - 0x000000000000-0x000000800000 : "nor0"
           - 0x000000000000-0x000000010000 : "spl"
           - 0x000000010000-0x0000000d0000 : "u-boot"
           - 0x0000000d0000-0x0000000e0000 : "env"
           - 0x0000000e0000-0x0000000f0000 : "env-red"
           - 0x0000000f0000-0x000000800000 : "rescue"
=> ubi part ubi
ubi0: attaching mtd2
ubi0: scanning is finished
ubi0: attached mtd2 (name "ubi", size 128 MiB)
ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
ubi0: good PEBs: 1020, bad PEBs: 4, corrupted PEBs: 0
ubi0: user volume: 4, internal volumes: 1, max. volumes count: 128
ubi0: max/mean erase counter: 52/46, WL threshold: 4096, image sequence number: 2030005227
ubi0: available PEBs: 8, total reserved PEBs: 1012, PEBs reserved for bad PEB handling: 16
=> ubi part ubi
ubi0: detaching mtd2
ubi0: mtd2 is detached
ubi0: attaching mtd2
ubi0: scanning is finished
ubi0: attached mtd2 (name "ubi", size 128 MiB)
ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
ubi0: good PEBs: 1020, bad PEBs: 4, corrupted PEBs: 0
ubi0: user volume: 4, internal volumes: 1, max. volumes count: 128
ubi0: max/mean erase counter: 52/46, WL threshold: 4096, image sequence number: 2030005227
ubi0: available PEBs: 8, total reserved PEBs: 1012, PEBs reserved for bad PEB handling: 16
=> mtd list
List of MTD devices:
* nand0
   - type: NAND flash
   - block size: 0x20000 bytes
   - min I/O: 0x800 bytes
   - OOB size: 64 bytes
   - OOB available: 0 bytes
   - ECC strength: 8 bits
   - ECC step size: 512 bytes
   - bitflip threshold: 6 bits
   - 0x000000000000-0x000008000000 : "nand0"
           - 0x000000000000-0x000008000000 : "ubi"
* nor0
   - type: NOR flash
   - block size: 0x10000 bytes
   - min I/O: 0x1 bytes
   - 0x000000000000-0x000000800000 : "nor0"
           - 0x000000000000-0x000000010000 : "spl"
           - 0x000000010000-0x0000000d0000 : "u-boot"
           - 0x0000000d0000-0x0000000e0000 : "env"
           - 0x0000000e0000-0x0000000f0000 : "env-red"
           - 0x0000000f0000-0x000000800000 : "rescue"
=> sf probe
SF: Detected s25f064l with page size 256 Bytes, erase size 64 KiB, total 8 MiB
=> mtd list
Partition "ubi" already in use, aborting
List of MTD devices:
* nand0
   - type: NAND flash
   - block size: 0x20000 bytes
   - min I/O: 0x800 bytes
   - OOB size: 64 bytes
   - OOB available: 0 bytes
   - ECC strength: 8 bits
   - ECC step size: 512 bytes
   - bitflip threshold: 6 bits
   - 0x000000000000-0x000008000000 : "nand0"
           - 0x000000000000-0x000008000000 : "ubi"
* nor0
   - type: NOR flash
   - block size: 0x10000 bytes
   - min I/O: 0x1 bytes
   - 0x000000000000-0x000000800000 : "nor0"
=> ubi part ubi
ubi0: detaching mtd2
ubi0: mtd2 is detached
ubi0: attaching mtd2
ubi0: scanning is finished
ubi0: attached mtd2 (name "ubi", size 128 MiB)
ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
ubi0: good PEBs: 1020, bad PEBs: 4, corrupted PEBs: 0
ubi0: user volume: 4, internal volumes: 1, max. volumes count: 128
ubi0: max/mean erase counter: 52/46, WL threshold: 4096, image sequence number: 2030005227
ubi0: available PEBs: 8, total reserved PEBs: 1012, PEBs reserved for bad PEB handling: 16
=> mtd list
List of MTD devices:
* nand0
   - type: NAND flash
   - block size: 0x20000 bytes
   - min I/O: 0x800 bytes
   - OOB size: 64 bytes
   - OOB available: 0 bytes
   - ECC strength: 8 bits
   - ECC step size: 512 bytes
   - bitflip threshold: 6 bits
   - 0x000000000000-0x000008000000 : "nand0"
           - 0x000000000000-0x000008000000 : "ubi"
* nor0
   - type: NOR flash
   - block size: 0x10000 bytes
   - min I/O: 0x1 bytes
   - 0x000000000000-0x000000800000 : "nor0"
=>
=> mtd read spl 81000000
MTD device spl not found, ret -19
=>

[2] mtd list after ubi detach
=> ubi detach
ubi0: detaching mtd2
ubi0: mtd2 is detached
=> mtd list
List of MTD devices:
* nand0
   - type: NAND flash
   - block size: 0x20000 bytes
   - min I/O: 0x800 bytes
   - OOB size: 64 bytes
   - OOB available: 0 bytes
   - ECC strength: 8 bits
   - ECC step size: 512 bytes
   - bitflip threshold: 6 bits
   - 0x000000000000-0x000008000000 : "nand0"
           - 0x000000000000-0x000008000000 : "ubi"
* nor0
   - type: NOR flash
   - block size: 0x10000 bytes
   - min I/O: 0x1 bytes
   - 0x000000000000-0x000000800000 : "nor0"
=> sf probe
SF: Detected s25f064l with page size 256 Bytes, erase size 64 KiB, total 8 MiB
=> mtd list
List of MTD devices:
* nand0
   - type: NAND flash
   - block size: 0x20000 bytes
   - min I/O: 0x800 bytes
   - OOB size: 64 bytes
   - OOB available: 0 bytes
   - ECC strength: 8 bits
   - ECC step size: 512 bytes
   - bitflip threshold: 6 bits
   - 0x000000000000-0x000008000000 : "nand0"
           - 0x000000000000-0x000008000000 : "ubi"
* nor0
   - type: NOR flash
   - block size: 0x10000 bytes
   - min I/O: 0x1 bytes
   - 0x000000000000-0x000000800000 : "nor0"
           - 0x000000000000-0x000000010000 : "spl"
           - 0x000000010000-0x0000000d0000 : "u-boot"
           - 0x0000000d0000-0x0000000e0000 : "env"
           - 0x0000000e0000-0x0000000f0000 : "env-red"
           - 0x0000000f0000-0x000000800000 : "rescue"
=>

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de


More information about the U-Boot mailing list