diff mbox series

Support MTD names in copy handler

Message ID 20250604075427.880339-1-joakim.tjernlund@infinera.com
State Accepted
Delegated to: Stefano Babic
Headers show
Series Support MTD names in copy handler | expand

Commit Message

Joakim Tjernlund June 4, 2025, 7:54 a.m. UTC
with this one can do:
  scripts:({
           name="u-boot";
           type = "copy";
           mtdname = "u-boot-b";
           installed-directly = true;
           properties : {
                 copyfrom = "mtd:u-boot-a";
                 type = "preinstall";
                 chain = "raw";
           }
  });

Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
---
 handlers/copy_handler.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

Comments

Joakim Tjernlund (Nokia) June 14, 2025, 12:35 p.m. UTC | #1
Ping ?

On Wed, 2025-06-04 at 09:54 +0200, 'Joakim Tjernlund' via swupdate wrote:
>
> CAUTION: This is an external email. Please be very careful when clicking links or opening attachments. See the URL
> nok.it/ext for additional information.
>
>
>
> with this one can do:
>   scripts:({
>            name="u-boot";
>            type = "copy";
>            mtdname = "u-boot-b";
>            installed-directly = true;
>            properties : {
>                  copyfrom = "mtd:u-boot-a";
>                  type = "preinstall";
>                  chain = "raw";
>            }
>   });
>
> Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
> ---
>  handlers/copy_handler.c | 23 +++++++++++++++++++++--
>  1 file changed, 21 insertions(+), 2 deletions(-)
>
> diff --git a/handlers/copy_handler.c b/handlers/copy_handler.c
> index bea0899e..9666bf32 100644
> --- a/handlers/copy_handler.c
> +++ b/handlers/copy_handler.c
> @@ -30,6 +30,7 @@
>  #include "progress.h"
>  #include "handler.h"
>  #include "util.h"
> +#include "flash.h"
>  #include "handler_helpers.h"
>  #include "installer.h"
>
> @@ -213,7 +214,15 @@ static int copy_image_file(struct img_type *img, void *data)
>         script_data = data;
>
>         base_img = img;
> -
> +       if(strlen(img->mtdname) ){
> +               int mtdnum = get_mtd_from_name(img->mtdname);
> +               if (mtdnum < 0) {
> +                       ERROR("Wrong MTD name in description: %s",
> +                             img->mtdname);
> +                       return -1;
> +               }
> +               snprintf(img->device, sizeof(img->device), "/dev/mtdblock%d", mtdnum);
> +       }
>         proplist = dict_get_list(&img->properties, "type");
>         if (proplist) {
>                 entry = LIST_FIRST(proplist);
> @@ -236,7 +245,17 @@ static int copy_image_file(struct img_type *img, void *data)
>                 ERROR("Missing source device, no copyfrom property");
>                 return -EINVAL;
>         }
> -
> +       if (!strncmp("mtd:", entry->value, 4)) {
> +               int mtdnum = get_mtd_from_name(entry->value + 4);
> +               if (mtdnum < 0) {
> +                       ERROR("Wrong MTD name in copyfrom: %s",
> +                             entry->value);
> +                       return -1;
> +               }
> +               free(entry->value);
> +               entry->value = malloc(20+1); /* to hold "/dev/mtdblockXX */
> +               snprintf(entry->value, 20, "/dev/mtdblock%d", mtdnum);
> +       }
>         copyfrom = realpath(entry->value, NULL);
>         if (!copyfrom) {
>                 ERROR("%s cannot be resolved", entry->value);
> --
> 2.49.0
>
> --
> You received this message because you are subscribed to the Google Groups "swupdate" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> swupdate+unsubscribe@googlegroups.com.
> To view this discussion visit
> https://groups.google.com/d/msgid/swupdate/20250604075427.880339-1-joakim.tjernlund%40infinera.com
> .
Joakim Tjernlund (Nokia) July 25, 2025, 4:07 p.m. UTC | #2
Yet a ping ...

On Sat, 2025-06-14 at 14:35 +0200, jocke at jocke wrote:
> Ping ?
>
> On Wed, 2025-06-04 at 09:54 +0200, 'Joakim Tjernlund' via swupdate wrote:
> >
> > CAUTION: This is an external email. Please be very careful when clicking links or opening attachments. See the URL
> > nok.it/ext for additional information.
> >
> >
> >
> > with this one can do:
> >   scripts:({
> >            name="u-boot";
> >            type = "copy";
> >            mtdname = "u-boot-b";
> >            installed-directly = true;
> >            properties : {
> >                  copyfrom = "mtd:u-boot-a";
> >                  type = "preinstall";
> >                  chain = "raw";
> >            }
> >   });
> >
> > Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
> > ---
> >  handlers/copy_handler.c | 23 +++++++++++++++++++++--
> >  1 file changed, 21 insertions(+), 2 deletions(-)
> >
> > diff --git a/handlers/copy_handler.c b/handlers/copy_handler.c
> > index bea0899e..9666bf32 100644
> > --- a/handlers/copy_handler.c
> > +++ b/handlers/copy_handler.c
> > @@ -30,6 +30,7 @@
> >  #include "progress.h"
> >  #include "handler.h"
> >  #include "util.h"
> > +#include "flash.h"
> >  #include "handler_helpers.h"
> >  #include "installer.h"
> >
> > @@ -213,7 +214,15 @@ static int copy_image_file(struct img_type *img, void *data)
> >         script_data = data;
> >
> >         base_img = img;
> > -
> > +       if(strlen(img->mtdname) ){
> > +               int mtdnum = get_mtd_from_name(img->mtdname);
> > +               if (mtdnum < 0) {
> > +                       ERROR("Wrong MTD name in description: %s",
> > +                             img->mtdname);
> > +                       return -1;
> > +               }
> > +               snprintf(img->device, sizeof(img->device), "/dev/mtdblock%d", mtdnum);
> > +       }
> >         proplist = dict_get_list(&img->properties, "type");
> >         if (proplist) {
> >                 entry = LIST_FIRST(proplist);
> > @@ -236,7 +245,17 @@ static int copy_image_file(struct img_type *img, void *data)
> >                 ERROR("Missing source device, no copyfrom property");
> >                 return -EINVAL;
> >         }
> > -
> > +       if (!strncmp("mtd:", entry->value, 4)) {
> > +               int mtdnum = get_mtd_from_name(entry->value + 4);
> > +               if (mtdnum < 0) {
> > +                       ERROR("Wrong MTD name in copyfrom: %s",
> > +                             entry->value);
> > +                       return -1;
> > +               }
> > +               free(entry->value);
> > +               entry->value = malloc(20+1); /* to hold "/dev/mtdblockXX */
> > +               snprintf(entry->value, 20, "/dev/mtdblock%d", mtdnum);
> > +       }
> >         copyfrom = realpath(entry->value, NULL);
> >         if (!copyfrom) {
> >                 ERROR("%s cannot be resolved", entry->value);
> > --
> > 2.49.0
> >
> > --
> > You received this message because you are subscribed to the Google Groups "swupdate" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to
> > swupdate+unsubscribe@googlegroups.com.
> > To view this discussion visit
> > https://groups.google.com/d/msgid/swupdate/20250604075427.880339-1-joakim.tjernlund%40infinera.com
> > .
Stefano Babic July 27, 2025, 7 a.m. UTC | #3
Hi Joachim,

On 25.07.25 18:07, 'Joakim Tjernlund (Nokia)' via swupdate wrote:
> Yet a ping ...
> 
> On Sat, 2025-06-14 at 14:35 +0200, jocke at jocke wrote:
>> Ping ?

Even pong, but I do not know what is supposed I should do. I merged this 
patch a while ago.

Best regards,
Stefano

>>
>> On Wed, 2025-06-04 at 09:54 +0200, 'Joakim Tjernlund' via swupdate wrote:
>>>
>>> CAUTION: This is an external email. Please be very careful when clicking links or opening attachments. See the URL
>>> nok.it/ext for additional information.
>>>
>>>
>>>
>>> with this one can do:
>>>    scripts:({
>>>             name="u-boot";
>>>             type = "copy";
>>>             mtdname = "u-boot-b";
>>>             installed-directly = true;
>>>             properties : {
>>>                   copyfrom = "mtd:u-boot-a";
>>>                   type = "preinstall";
>>>                   chain = "raw";
>>>             }
>>>    });
>>>
>>> Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
>>> ---
>>>   handlers/copy_handler.c | 23 +++++++++++++++++++++--
>>>   1 file changed, 21 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/handlers/copy_handler.c b/handlers/copy_handler.c
>>> index bea0899e..9666bf32 100644
>>> --- a/handlers/copy_handler.c
>>> +++ b/handlers/copy_handler.c
>>> @@ -30,6 +30,7 @@
>>>   #include "progress.h"
>>>   #include "handler.h"
>>>   #include "util.h"
>>> +#include "flash.h"
>>>   #include "handler_helpers.h"
>>>   #include "installer.h"
>>>
>>> @@ -213,7 +214,15 @@ static int copy_image_file(struct img_type *img, void *data)
>>>          script_data = data;
>>>
>>>          base_img = img;
>>> -
>>> +       if(strlen(img->mtdname) ){
>>> +               int mtdnum = get_mtd_from_name(img->mtdname);
>>> +               if (mtdnum < 0) {
>>> +                       ERROR("Wrong MTD name in description: %s",
>>> +                             img->mtdname);
>>> +                       return -1;
>>> +               }
>>> +               snprintf(img->device, sizeof(img->device), "/dev/mtdblock%d", mtdnum);
>>> +       }
>>>          proplist = dict_get_list(&img->properties, "type");
>>>          if (proplist) {
>>>                  entry = LIST_FIRST(proplist);
>>> @@ -236,7 +245,17 @@ static int copy_image_file(struct img_type *img, void *data)
>>>                  ERROR("Missing source device, no copyfrom property");
>>>                  return -EINVAL;
>>>          }
>>> -
>>> +       if (!strncmp("mtd:", entry->value, 4)) {
>>> +               int mtdnum = get_mtd_from_name(entry->value + 4);
>>> +               if (mtdnum < 0) {
>>> +                       ERROR("Wrong MTD name in copyfrom: %s",
>>> +                             entry->value);
>>> +                       return -1;
>>> +               }
>>> +               free(entry->value);
>>> +               entry->value = malloc(20+1); /* to hold "/dev/mtdblockXX */
>>> +               snprintf(entry->value, 20, "/dev/mtdblock%d", mtdnum);
>>> +       }
>>>          copyfrom = realpath(entry->value, NULL);
>>>          if (!copyfrom) {
>>>                  ERROR("%s cannot be resolved", entry->value);
>>> --
>>> 2.49.0
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups "swupdate" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an email to
>>> swupdate+unsubscribe@googlegroups.com.
>>> To view this discussion visit
>>> https://groups.google.com/d/msgid/swupdate/20250604075427.880339-1-joakim.tjernlund%40infinera.com
>>> .
>
diff mbox series

Patch

diff --git a/handlers/copy_handler.c b/handlers/copy_handler.c
index bea0899e..9666bf32 100644
--- a/handlers/copy_handler.c
+++ b/handlers/copy_handler.c
@@ -30,6 +30,7 @@ 
 #include "progress.h"
 #include "handler.h"
 #include "util.h"
+#include "flash.h"
 #include "handler_helpers.h"
 #include "installer.h"
 
@@ -213,7 +214,15 @@  static int copy_image_file(struct img_type *img, void *data)
 	script_data = data;
 
 	base_img = img;
-
+	if(strlen(img->mtdname) ){
+		int mtdnum = get_mtd_from_name(img->mtdname);
+		if (mtdnum < 0) {
+			ERROR("Wrong MTD name in description: %s",
+			      img->mtdname);
+			return -1;
+		}
+		snprintf(img->device, sizeof(img->device), "/dev/mtdblock%d", mtdnum);
+	}
 	proplist = dict_get_list(&img->properties, "type");
 	if (proplist) {
 		entry = LIST_FIRST(proplist);
@@ -236,7 +245,17 @@  static int copy_image_file(struct img_type *img, void *data)
 		ERROR("Missing source device, no copyfrom property");
 		return -EINVAL;
 	}
-
+	if (!strncmp("mtd:", entry->value, 4)) {
+		int mtdnum = get_mtd_from_name(entry->value + 4);
+		if (mtdnum < 0) {
+			ERROR("Wrong MTD name in copyfrom: %s",
+			      entry->value);
+			return -1;
+		}
+		free(entry->value);
+		entry->value = malloc(20+1); /* to hold "/dev/mtdblockXX */
+		snprintf(entry->value, 20, "/dev/mtdblock%d", mtdnum);
+	}
 	copyfrom = realpath(entry->value, NULL);
 	if (!copyfrom) {
 		ERROR("%s cannot be resolved", entry->value);