Message ID | 20180816170550.16089-1-arnout@mind.be |
---|---|
State | Accepted |
Headers | show |
Series | [v2] UBI handler: allow mtd device to be specified by name | expand |
Hi Arnout, On 16/08/2018 19:05, Arnout Vandecappelle (Essensium/Mind) wrote: > It is often more convenient to specify the partition by name instead > of by number. This is especially true for boards with multiple chips, > where the numbering may change after an update of the kernel. > > If get_mtd_from_device fails, fall back to get_mtd_from_name. In other > words, if mtd partition mtd5 is named "mtd0" (which would be a stupid > thing to do), "mtd0" will still resolve to /dev/mtd0. > > Note that currently, the flash handler (i.e., the handler for images > with type = flash) already has this feature. However, for the flash > handler, you have to use 'device' if you specify the mtd number and > 'mtdname' if you specify the mtd name. For the ubivol handler (where > the mtd device is specified in the 'partitions' section, not in the > 'images' section, so it's not entirely comparable), we choose to > use 'device' both for the mtd number and the mtd name. > > The description of this feature is added to sw-description.rst. > > Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be> > --- > v2: > - rework commit message > - add documentation > > In the review of v1, Stefano asked to document the behaviour is > doc/source/handlers.rst. However, the information given for the UBI > handler in that section is currently not consistent with reality, > which makes it hard to do it there. Instead, I've documented the > feature in sw-description.rst in this patch, and I'll make a separate > patch next week to correct handlers.rst. Fine. > --- > doc/source/sw-description.rst | 6 +++++- > handlers/ubivol_handler.c | 4 ++++ > 2 files changed, 9 insertions(+), 1 deletion(-) > > diff --git a/doc/source/sw-description.rst b/doc/source/sw-description.rst > index 55821ad..ec32e8e 100644 > --- a/doc/source/sw-description.rst > +++ b/doc/source/sw-description.rst > @@ -294,7 +294,11 @@ in kernel. > > All fields are mandatory. SWUpdate searches for a volume of the > selected name and adjusts the size, or creates a new volume if > -no volume with the given name exists. > +no volume with the given name exists. In the latter case, it is > +created on the UBI device attached to the MTD device given by > +"device". "device" can be given by number (e.g. "mtd4") or by name > +(the name of the MTD device, e.g. "ubi_partition"). The UBI device > +is attached automatically. > > images > ------ > diff --git a/handlers/ubivol_handler.c b/handlers/ubivol_handler.c > index 247a644..909a215 100644 > --- a/handlers/ubivol_handler.c > +++ b/handlers/ubivol_handler.c > @@ -169,6 +169,10 @@ static int adjust_volume(struct img_type *cfg, > * Other MTD are not touched > */ > mtdnum = get_mtd_from_device(cfg->device); > + if (mtdnum < 0) { > + /* Allow device to be specified by name OR number */ > + mtdnum = get_mtd_from_name(cfg->device); > + } > if (mtdnum < 0 || !mtd_dev_present(flash->libmtd, mtdnum)) { > ERROR("%s does not exist: partitioning not possible", > cfg->device); > Acked-by: Stefano Babic <sbabic@denx.de> Best regards, Stefano Babic
diff --git a/doc/source/sw-description.rst b/doc/source/sw-description.rst index 55821ad..ec32e8e 100644 --- a/doc/source/sw-description.rst +++ b/doc/source/sw-description.rst @@ -294,7 +294,11 @@ in kernel. All fields are mandatory. SWUpdate searches for a volume of the selected name and adjusts the size, or creates a new volume if -no volume with the given name exists. +no volume with the given name exists. In the latter case, it is +created on the UBI device attached to the MTD device given by +"device". "device" can be given by number (e.g. "mtd4") or by name +(the name of the MTD device, e.g. "ubi_partition"). The UBI device +is attached automatically. images ------ diff --git a/handlers/ubivol_handler.c b/handlers/ubivol_handler.c index 247a644..909a215 100644 --- a/handlers/ubivol_handler.c +++ b/handlers/ubivol_handler.c @@ -169,6 +169,10 @@ static int adjust_volume(struct img_type *cfg, * Other MTD are not touched */ mtdnum = get_mtd_from_device(cfg->device); + if (mtdnum < 0) { + /* Allow device to be specified by name OR number */ + mtdnum = get_mtd_from_name(cfg->device); + } if (mtdnum < 0 || !mtd_dev_present(flash->libmtd, mtdnum)) { ERROR("%s does not exist: partitioning not possible", cfg->device);
It is often more convenient to specify the partition by name instead of by number. This is especially true for boards with multiple chips, where the numbering may change after an update of the kernel. If get_mtd_from_device fails, fall back to get_mtd_from_name. In other words, if mtd partition mtd5 is named "mtd0" (which would be a stupid thing to do), "mtd0" will still resolve to /dev/mtd0. Note that currently, the flash handler (i.e., the handler for images with type = flash) already has this feature. However, for the flash handler, you have to use 'device' if you specify the mtd number and 'mtdname' if you specify the mtd name. For the ubivol handler (where the mtd device is specified in the 'partitions' section, not in the 'images' section, so it's not entirely comparable), we choose to use 'device' both for the mtd number and the mtd name. The description of this feature is added to sw-description.rst. Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be> --- v2: - rework commit message - add documentation In the review of v1, Stefano asked to document the behaviour is doc/source/handlers.rst. However, the information given for the UBI handler in that section is currently not consistent with reality, which makes it hard to do it there. Instead, I've documented the feature in sw-description.rst in this patch, and I'll make a separate patch next week to correct handlers.rst. --- doc/source/sw-description.rst | 6 +++++- handlers/ubivol_handler.c | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-)