[PATCH 1/2] core/util: add ustrtoul

54 views
Skip to first unread message

Georges Savoundararadj

unread,
Mar 30, 2017, 5:58:26 PM3/30/17
to swup...@googlegroups.com, st...@witekio.us, Georges Savoundararadj
This function is copied from
* remote: git://git.denx.de/u-boot.git
* branch: master
* commit hash: b91c6a1209e7da1a7f989d9ac35d0d8be0b7b710

Signed-off-by: Georges Savoundararadj <gsavoun...@witekio.us>
---
core/util.c | 24 ++++++++++++++++++++++++
include/util.h | 2 ++
2 files changed, 26 insertions(+)

diff --git a/core/util.c b/core/util.c
index 9b28508..bb29457 100644
--- a/core/util.c
+++ b/core/util.c
@@ -520,3 +520,27 @@ char** string_split(char* s, const char d)

return result;
}
+
+unsigned long ustrtoul(const char *cp, char **endp, unsigned int base)
+{
+ unsigned long result = strtoul(cp, endp, base);
+
+ switch (**endp) {
+ case 'G':
+ result *= 1024;
+ /* fall through */
+ case 'M':
+ result *= 1024;
+ /* fall through */
+ case 'K':
+ case 'k':
+ result *= 1024;
+ if ((*endp)[1] == 'i') {
+ if ((*endp)[2] == 'B')
+ (*endp) += 3;
+ else
+ (*endp) += 2;
+ }
+ }
+ return result;
+}
diff --git a/include/util.h b/include/util.h
index 5e7c2eb..ca3a5cf 100644
--- a/include/util.h
+++ b/include/util.h
@@ -184,4 +184,6 @@ unsigned char *get_aes_ivt(void);
/* Getting global information */
int get_install_info(sourcetype *source, char *buf, int len);

+unsigned long ustrtoul(const char *cp, char **endp, unsigned int base);
+
#endif
--
2.11.1

Georges Savoundararadj

unread,
Mar 30, 2017, 5:58:27 PM3/30/17
to swup...@googlegroups.com, st...@witekio.us, Georges Savoundararadj
This new property allows the user to specify a specific offset from a
raw device and not rely only on the partition.
This is useful for example to update a kernel or a bootloader which is
not part of a partition

It handles the following multiplicative suffixes: K=1024 and M=1024*1024.

This commit has been tested:
* with and without signature
* with and without compression

Signed-off-by: Sid-Ali TEIR <st...@witekio.us>
Signed-off-by: Georges Savoundararadj <gsavoun...@witekio.us>
---
core/cpio_utils.c | 30 ++++++++++++++++++++++++++----
corelib/stream_interface.c | 6 +++---
doc/source/sw-description.rst | 14 ++++++++++++++
include/globals.h | 1 +
include/swupdate.h | 1 +
include/util.h | 1 +
parser/parse_external.c | 4 ++++
parser/parser.c | 1 +
8 files changed, 51 insertions(+), 7 deletions(-)

diff --git a/core/cpio_utils.c b/core/cpio_utils.c
index db5753e..025eddb 100644
--- a/core/cpio_utils.c
+++ b/core/cpio_utils.c
@@ -17,8 +17,10 @@
* Foundation, Inc.
*/

+#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
+#include <sys/types.h>
#include <unistd.h>
#include <errno.h>

@@ -109,7 +111,7 @@ static int copy_write(void *out, const void *buf, int len)
return 0;
}

-int copyfile(int fdin, void *out, int nbytes, unsigned long *offs,
+int copyfile(int fdin, void *out, int nbytes, unsigned long *offs, const char *seek_str,
int skip_file, int __attribute__ ((__unused__)) compressed,
uint32_t *checksum, unsigned char *hash, int encrypted, writeimage callback)
{
@@ -130,6 +132,17 @@ int copyfile(int fdin, void *out, int nbytes, unsigned long *offs,
unsigned char *aes_key;
unsigned char *ivt;
int fdout = -1;
+ unsigned long seek = 0;
+ char *endp = NULL;
+
+ if (seek_str != NULL && strnlen(seek_str, MAX_SEEK_STRING_SIZE) != 0) {
+ errno = 0;
+ seek = ustrtoul(seek_str, &endp, 0);
+ if (seek_str == endp || (seek == ULONG_MAX && errno == ERANGE)) {
+ ERROR("offset argument: ustrtoul failed");
+ return -EFAULT;
+ }
+ }

if (!callback) {
callback = copy_write;
@@ -174,6 +187,14 @@ int copyfile(int fdin, void *out, int nbytes, unsigned long *offs,
}
}

+ if (seek) {
+ TRACE("offset has been defined: %lu bytes\n", seek);
+ if (lseek(fdout, seek, SEEK_SET) < 0) {
+ ERROR("offset argument: seek failed\n");
+ return -EFAULT;
+ }
+ }
+
#ifdef CONFIG_GUNZIP
if (compressed) {
ret = decompress_image(fdin, offs, nbytes, fdout, checksum, dgst);
@@ -288,6 +309,7 @@ int copyimage(void *out, struct img_type *img, writeimage callback)
out,
img->size,
(unsigned long *)&img->offset,
+ img->seek_str,
0, /* no skip */
img->compressed,
&img->checksum,
@@ -356,7 +378,7 @@ off_t extract_sw_description(int fd, const char *descfile, off_t start)
close(fdout);
return -1;
}
- if (copyfile(fd, &fdout, fdh.size, &offset, 0, 0, &checksum, NULL, 0, NULL) < 0) {
+ if (copyfile(fd, &fdout, fdh.size, &offset, NULL, 0, 0, &checksum, NULL, 0, NULL) < 0) {
ERROR("%s corrupted or not valid\n", descfile);
close(fdout);
return -1;
@@ -418,7 +440,7 @@ off_t extract_next_file(int fd, int fdout, off_t start, int compressed,

if (lseek(fd, offset, SEEK_SET) < 0)
ERROR("CPIO file corrupted : %s\n", strerror(errno));
- if (copyfile(fd, &fdout, fdh.size, &offset, 0, compressed, &checksum, hash, encrypted, NULL) < 0) {
+ if (copyfile(fd, &fdout, fdh.size, &offset, NULL, 0, compressed, &checksum, hash, encrypted, NULL) < 0) {
ERROR("Error copying extracted file\n");
}

@@ -467,7 +489,7 @@ int cpio_scan(int fd, struct swupdate_cfg *cfg, off_t start)
* use copyfile for checksum verification, as we skip file
* we do not have to provide fdout
*/
- if (copyfile(fd, NULL, fdh.size, &offset, 1, 0, &checksum, NULL, 0, NULL) != 0) {
+ if (copyfile(fd, NULL, fdh.size, &offset, NULL, 1, 0, &checksum, NULL, 0, NULL) != 0) {
ERROR("invalid archive\n");
return -1;
}
diff --git a/corelib/stream_interface.c b/corelib/stream_interface.c
index 429b046..d292d40 100644
--- a/corelib/stream_interface.c
+++ b/corelib/stream_interface.c
@@ -105,7 +105,7 @@ static int extract_file_to_tmp(int fd, const char *fname, unsigned long *poffs)
if (fdout < 0)
return -1;

- if (copyfile(fd, &fdout, fdh.size, poffs, 0, 0, &checksum, NULL, 0, NULL) < 0) {
+ if (copyfile(fd, &fdout, fdh.size, poffs, NULL, 0, 0, &checksum, NULL, 0, NULL) < 0) {
close(fdout);
return -1;
}
@@ -209,7 +209,7 @@ static int extract_files(int fd, struct swupdate_cfg *software)
fdout = openfileoutput(img->extract_file);
if (fdout < 0)
return -1;
- if (copyfile(fd, &fdout, fdh.size, &offset, 0, 0, &checksum, img->sha256, 0, NULL) < 0) {
+ if (copyfile(fd, &fdout, fdh.size, &offset, NULL, 0, 0, &checksum, img->sha256, 0, NULL) < 0) {
close(fdout);
return -1;
}
@@ -223,7 +223,7 @@ static int extract_files(int fd, struct swupdate_cfg *software)
break;

case SKIP_FILE:
- if (copyfile(fd, &fdout, fdh.size, &offset, skip, 0, &checksum, NULL, 0, NULL) < 0) {
+ if (copyfile(fd, &fdout, fdh.size, &offset, NULL, skip, 0, &checksum, NULL, 0, NULL) < 0) {
return -1;
}
if (checksum != (unsigned long)fdh.chksum) {
diff --git a/doc/source/sw-description.rst b/doc/source/sw-description.rst
index 6af71de..a360cf7 100644
--- a/doc/source/sw-description.rst
+++ b/doc/source/sw-description.rst
@@ -173,6 +173,8 @@ The syntax is:
device[optional] = <destination volume>;
mtdname[optional] = <destination mtd name>;
type[optional] = <handler>;
+ /* optionally, the image can be copied at a specific offset in raw mode */
+ offset[optional] = <offset>;
/* optionally, the image can be compressed if it is in raw mode */
compressed;
},
@@ -205,6 +207,18 @@ To update an image in raw mode, the syntax is:
device = "/dev/mmcblk0p1";
}

+To flash am image at a specific offset, the syntax is:
+
+
+::
+
+ {
+ filename = "u-boot.bin";
+ device = "/dev/mmcblk0p1";
+ offset = "16K";
+ }
+
+The offset handles the following multiplicative suffixes: K=1024 and M=1024*1024.

However, writing to flash in raw mode must be managed in a special
way. Flashes must be erased before copying, and writing into NAND
diff --git a/include/globals.h b/include/globals.h
index ddb42de..43b5d61 100644
--- a/include/globals.h
+++ b/include/globals.h
@@ -31,6 +31,7 @@
#define UBOOT_VAR_LENGTH 16
#define MAX_REVISION_LENGTH SWUPDATE_GENERAL_STRING_SIZE
#define MAX_UBOOT_SCRIPT_LINE_LENGTH 1024
+#define MAX_SEEK_STRING_SIZE 32

/* These are fixed path to temporary files */
#define SCRIPTS_DIR TMPDIR "scripts/"
diff --git a/include/swupdate.h b/include/swupdate.h
index bff757e..4d3246b 100644
--- a/include/swupdate.h
+++ b/include/swupdate.h
@@ -69,6 +69,7 @@ struct img_type {
char type_data[SWUPDATE_GENERAL_STRING_SIZE]; /* Data for handler */
char extract_file[MAX_IMAGE_FNAME];
char filesystem[MAX_IMAGE_FNAME];
+ char seek_str[MAX_SEEK_STRING_SIZE];
int required;
int provided;
int compressed;
diff --git a/include/util.h b/include/util.h
index ca3a5cf..6678b15 100644
--- a/include/util.h
+++ b/include/util.h
@@ -154,6 +154,7 @@ void unlock_uboot_env(int lock);

int openfile(const char *filename);
int copyfile(int fdin, void *out, int nbytes, unsigned long *offs,
+ const char *seek_str,
int skip_file, int compressed, uint32_t *checksum,
unsigned char *hash, int encrypted, writeimage callback);
int copyimage(void *out, struct img_type *img, writeimage callback);
diff --git a/parser/parse_external.c b/parser/parse_external.c
index 7c5cce2..0247552 100644
--- a/parser/parse_external.c
+++ b/parser/parse_external.c
@@ -43,6 +43,7 @@
static void sw_append_stream(struct img_type *img, const char *key,
const char *value)
{
+ const char offset[] = "offset";

if (!strcmp(key, "type"))
strncpy(img->type, value,
@@ -75,6 +76,9 @@ static void sw_append_stream(struct img_type *img, const char *key,
if (!strcmp(key, "device"))
strncpy(img->device, value,
sizeof(img->device));
+ if (!strncmp(key, offset, sizeof(offset)))
+ strncpy(img->seek_str, value,
+ sizeof(img->seek_str));
if (!strcmp(key, "script"))
img->is_script = 1;
if (!strcmp(key, "path"))
diff --git a/parser/parser.c b/parser/parser.c
index 33a4960..ec2c0fc 100644
--- a/parser/parser.c
+++ b/parser/parser.c
@@ -389,6 +389,7 @@ static void parse_images(parsertype p, void *cfg, struct swupdate_cfg *swcfg)
GET_FIELD_STRING(p, elem, "device", image->device);
GET_FIELD_STRING(p, elem, "mtdname", image->path);
GET_FIELD_STRING(p, elem, "type", image->type);
+ GET_FIELD_STRING(p, elem, "offset", image->seek_str);
GET_FIELD_STRING(p, elem, "data", image->type_data);
get_hash_value(p, elem, image->sha256);

--
2.11.1

Stefano Babic

unread,
Apr 3, 2017, 4:18:25 AM4/3/17
to Georges Savoundararadj, swup...@googlegroups.com, st...@witekio.us
Hi Georges,

thanks for patch - some comments from my side:

On 30/03/2017 23:58, Georges Savoundararadj wrote:
> This new property allows the user to specify a specific offset from a
> raw device and not rely only on the partition.
> This is useful for example to update a kernel or a bootloader which is
> not part of a partition
>
> It handles the following multiplicative suffixes: K=1024 and M=1024*1024.
>
> This commit has been tested:
> * with and without signature
> * with and without compression
>
> Signed-off-by: Sid-Ali TEIR <st...@witekio.us>
> Signed-off-by: Georges Savoundararadj <gsavoun...@witekio.us>
> ---
> core/cpio_utils.c | 30 ++++++++++++++++++++++++++----
> corelib/stream_interface.c | 6 +++---
> doc/source/sw-description.rst | 14 ++++++++++++++
^-- Thanks ! Documentation must be always updated !
It is quite strange that an offset is passed to the copyfile() function
as string instead of value. This is not consistent with the other
parameters: then why offs is a long and not a string ? (Ok, I do not
want that offs becomes a string, anyway).

I think it is better that the parsing of the string happens in the
parser (parser.c), where it belongs. seek_str should be turned into
"seek" with a long long value (be careful due to the conversion when int
or long are used).

Apart of that, I do not have other issues and feature can be pushed in
to mainline soon.
The offset property becomes independent from the selected handler. "raw
mode" can be wrongly interpreted as "raw handler".
Best regards,
Stefano Babic

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

Stefano Babic

unread,
Apr 3, 2017, 4:19:02 AM4/3/17
to Georges Savoundararadj, swup...@googlegroups.com, st...@witekio.us
On 30/03/2017 23:58, Georges Savoundararadj wrote:
Acked-by: Stefano Babic <sba...@denx.de>

Sid-Ali Teir

unread,
Apr 4, 2017, 4:07:17 PM4/4/17
to swup...@googlegroups.com, gsavoun...@witekio.us, Sid-Ali Teir
From: Georges Savoundararadj <gsavoun...@witekio.us>

This function is copied from
* remote: git://git.denx.de/u-boot.git
* branch: master
* commit hash: 7df54d316e70e2d6ae080ef98aa9d2388bbb8af9

Signed-off-by: Georges Savoundararadj <gsavoun...@witekio.us>
Signed-off-by: Sid-Ali Teir <st...@witekio.us>
Acked-by: Stefano Babic <sba...@denx.de>
---
Changes since v1:
* Change ustrtoul to ustrtoull

core/util.c | 24 ++++++++++++++++++++++++
include/util.h | 2 ++
2 files changed, 26 insertions(+)

diff --git a/core/util.c b/core/util.c
index 9b28508..2a2dee9 100644
--- a/core/util.c
+++ b/core/util.c
@@ -520,3 +520,27 @@ char** string_split(char* s, const char d)

return result;
}
+
+unsigned long long ustrtoull(const char *cp, char **endp, unsigned int base)
+{
+ unsigned long long result = strtoull(cp, endp, base);
+
+ switch (**endp) {
+ case 'G':
+ result *= 1024;
+ /* fall through */
+ case 'M':
+ result *= 1024;
+ /* fall through */
+ case 'K':
+ case 'k':
+ result *= 1024;
+ if ((*endp)[1] == 'i') {
+ if ((*endp)[2] == 'B')
+ (*endp) += 3;
+ else
+ (*endp) += 2;
+ }
+ }
+ return result;
+}
diff --git a/include/util.h b/include/util.h
index 5e7c2eb..27d99a5 100644
--- a/include/util.h
+++ b/include/util.h
@@ -184,4 +184,6 @@ unsigned char *get_aes_ivt(void);
/* Getting global information */
int get_install_info(sourcetype *source, char *buf, int len);

+unsigned long long ustrtoull(const char *cp, char **endp, unsigned int base);
+
#endif
--
2.7.4

Sid-Ali Teir

unread,
Apr 4, 2017, 4:08:23 PM4/4/17
to swup...@googlegroups.com, gsavoun...@witekio.us, Sid-Ali Teir
From: Georges Savoundararadj <gsavoun...@witekio.us>

This new property allows the user to specify a specific offset from a
raw device and not rely only on the partition.
This is useful for example to update a kernel or a bootloader which is
not part of a partition

It handles the following multiplicative suffixes: K=1024 and M=1024*1024.

This commit has been tested:
* with and without signature
* with and without compression

Signed-off-by: Georges Savoundararadj <gsavoun...@witekio.us>
Signed-off-by: Sid-Ali Teir <st...@witekio.us>
---
Changes since v1:
* Parse the offset string in parser.c and parser_external.c
* Improve documentation

core/cpio_utils.c | 18 ++++++++++++++----
corelib/stream_interface.c | 6 +++---
doc/source/sw-description.rst | 14 ++++++++++++++
include/globals.h | 1 +
include/swupdate.h | 1 +
include/util.h | 1 +
parser/parse_external.c | 19 +++++++++++++++++++
parser/parser.c | 16 ++++++++++++++++
8 files changed, 69 insertions(+), 7 deletions(-)

diff --git a/core/cpio_utils.c b/core/cpio_utils.c
index db5753e..02c196e 100644
--- a/core/cpio_utils.c
+++ b/core/cpio_utils.c
@@ -109,7 +109,7 @@ static int copy_write(void *out, const void *buf, int len)
return 0;
}

-int copyfile(int fdin, void *out, int nbytes, unsigned long *offs,
+int copyfile(int fdin, void *out, int nbytes, unsigned long *offs, unsigned long long seek,
int skip_file, int __attribute__ ((__unused__)) compressed,
uint32_t *checksum, unsigned char *hash, int encrypted, writeimage callback)
{
@@ -174,6 +174,15 @@ int copyfile(int fdin, void *out, int nbytes, unsigned long *offs,
}
}

+ if (seek) {
+ TRACE("offset has been defined: %llu bytes\n", seek);
+ if (lseek(fdout, seek, SEEK_SET) < 0) {
+ ERROR("offset argument: seek failed\n");
+ ret = -EFAULT;
+ goto copyfile_exit;
+ }
+ }
+
#ifdef CONFIG_GUNZIP
if (compressed) {
ret = decompress_image(fdin, offs, nbytes, fdout, checksum, dgst);
@@ -288,6 +297,7 @@ int copyimage(void *out, struct img_type *img, writeimage callback)
out,
img->size,
(unsigned long *)&img->offset,
+ img->seek,
0, /* no skip */
img->compressed,
&img->checksum,
@@ -356,7 +366,7 @@ off_t extract_sw_description(int fd, const char *descfile, off_t start)
close(fdout);
return -1;
}
- if (copyfile(fd, &fdout, fdh.size, &offset, 0, 0, &checksum, NULL, 0, NULL) < 0) {
+ if (copyfile(fd, &fdout, fdh.size, &offset, 0, 0, 0, &checksum, NULL, 0, NULL) < 0) {
ERROR("%s corrupted or not valid\n", descfile);
close(fdout);
return -1;
@@ -418,7 +428,7 @@ off_t extract_next_file(int fd, int fdout, off_t start, int compressed,

if (lseek(fd, offset, SEEK_SET) < 0)
ERROR("CPIO file corrupted : %s\n", strerror(errno));
- if (copyfile(fd, &fdout, fdh.size, &offset, 0, compressed, &checksum, hash, encrypted, NULL) < 0) {
+ if (copyfile(fd, &fdout, fdh.size, &offset, 0, 0, compressed, &checksum, hash, encrypted, NULL) < 0) {
ERROR("Error copying extracted file\n");
}

@@ -467,7 +477,7 @@ int cpio_scan(int fd, struct swupdate_cfg *cfg, off_t start)
* use copyfile for checksum verification, as we skip file
* we do not have to provide fdout
*/
- if (copyfile(fd, NULL, fdh.size, &offset, 1, 0, &checksum, NULL, 0, NULL) != 0) {
+ if (copyfile(fd, NULL, fdh.size, &offset, 0, 1, 0, &checksum, NULL, 0, NULL) != 0) {
ERROR("invalid archive\n");
return -1;
}
diff --git a/corelib/stream_interface.c b/corelib/stream_interface.c
index 429b046..f4c240a 100644
--- a/corelib/stream_interface.c
+++ b/corelib/stream_interface.c
@@ -105,7 +105,7 @@ static int extract_file_to_tmp(int fd, const char *fname, unsigned long *poffs)
if (fdout < 0)
return -1;

- if (copyfile(fd, &fdout, fdh.size, poffs, 0, 0, &checksum, NULL, 0, NULL) < 0) {
+ if (copyfile(fd, &fdout, fdh.size, poffs, 0, 0, 0, &checksum, NULL, 0, NULL) < 0) {
close(fdout);
return -1;
}
@@ -209,7 +209,7 @@ static int extract_files(int fd, struct swupdate_cfg *software)
fdout = openfileoutput(img->extract_file);
if (fdout < 0)
return -1;
- if (copyfile(fd, &fdout, fdh.size, &offset, 0, 0, &checksum, img->sha256, 0, NULL) < 0) {
+ if (copyfile(fd, &fdout, fdh.size, &offset, 0, 0, 0, &checksum, img->sha256, 0, NULL) < 0) {
close(fdout);
return -1;
}
@@ -223,7 +223,7 @@ static int extract_files(int fd, struct swupdate_cfg *software)
break;

case SKIP_FILE:
- if (copyfile(fd, &fdout, fdh.size, &offset, skip, 0, &checksum, NULL, 0, NULL) < 0) {
+ if (copyfile(fd, &fdout, fdh.size, &offset, 0, skip, 0, &checksum, NULL, 0, NULL) < 0) {
return -1;
}
if (checksum != (unsigned long)fdh.chksum) {
diff --git a/doc/source/sw-description.rst b/doc/source/sw-description.rst
index 6af71de..76a761a 100644
--- a/doc/source/sw-description.rst
+++ b/doc/source/sw-description.rst
@@ -173,6 +173,8 @@ The syntax is:
device[optional] = <destination volume>;
mtdname[optional] = <destination mtd name>;
type[optional] = <handler>;
+ /* optionally, the image can be copied at a specific offset */
index bff757e..879a2dc 100644
--- a/include/swupdate.h
+++ b/include/swupdate.h
@@ -69,6 +69,7 @@ struct img_type {
char type_data[SWUPDATE_GENERAL_STRING_SIZE]; /* Data for handler */
char extract_file[MAX_IMAGE_FNAME];
char filesystem[MAX_IMAGE_FNAME];
+ unsigned long long seek;
int required;
int provided;
int compressed;
diff --git a/include/util.h b/include/util.h
index 27d99a5..3c07346 100644
--- a/include/util.h
+++ b/include/util.h
@@ -154,6 +154,7 @@ void unlock_uboot_env(int lock);

int openfile(const char *filename);
int copyfile(int fdin, void *out, int nbytes, unsigned long *offs,
+ unsigned long long seek,
int skip_file, int compressed, uint32_t *checksum,
unsigned char *hash, int encrypted, writeimage callback);
int copyimage(void *out, struct img_type *img, writeimage callback);
diff --git a/parser/parse_external.c b/parser/parse_external.c
index 7c5cce2..c4a3234 100644
--- a/parser/parse_external.c
+++ b/parser/parse_external.c
@@ -20,6 +20,7 @@
*/


+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -43,6 +44,9 @@
static void sw_append_stream(struct img_type *img, const char *key,
const char *value)
{
+ const char offset[] = "offset";
+ char seek_str[MAX_SEEK_STRING_SIZE];
+ char *endp = NULL;

if (!strcmp(key, "type"))
strncpy(img->type, value,
@@ -75,6 +79,21 @@ static void sw_append_stream(struct img_type *img, const char *key,
if (!strcmp(key, "device"))
strncpy(img->device, value,
sizeof(img->device));
+ if (!strncmp(key, offset, sizeof(offset))) {
+ strncpy(seek_str, value,
+ sizeof(seek_str));
+ /* convert the offset handling multiplicative suffixes */
+ if (seek_str != NULL && strnlen(seek_str, MAX_SEEK_STRING_SIZE) != 0) {
+ errno = 0;
+ image->seek = ustrtoull(seek_str, &endp, 0);
+ if (seek_str == endp || (mage->seek == ULLONG_MAX && \
+ errno == ERANGE)) {
+ ERROR("offset argument: ustrtoull failed");
+ return;
+ }
+ } else
+ image->seek = 0;
+ }
if (!strcmp(key, "script"))
img->is_script = 1;
if (!strcmp(key, "path"))
diff --git a/parser/parser.c b/parser/parser.c
index 33a4960..a578d48 100644
--- a/parser/parser.c
+++ b/parser/parser.c
@@ -17,6 +17,7 @@
* Foundation, Inc.
*/

+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -354,6 +355,8 @@ static void parse_images(parsertype p, void *cfg, struct swupdate_cfg *swcfg)
void *setting, *elem;
int count, i;
struct img_type *image;
+ char seek_str[MAX_SEEK_STRING_SIZE];
+ char *endp = NULL;

setting = find_node(p, cfg, "images", swcfg);

@@ -389,9 +392,22 @@ static void parse_images(parsertype p, void *cfg, struct swupdate_cfg *swcfg)
GET_FIELD_STRING(p, elem, "device", image->device);
GET_FIELD_STRING(p, elem, "mtdname", image->path);
GET_FIELD_STRING(p, elem, "type", image->type);
+ GET_FIELD_STRING(p, elem, "offset", seek_str);
GET_FIELD_STRING(p, elem, "data", image->type_data);
get_hash_value(p, elem, image->sha256);

+ /* convert the offset handling multiplicative suffixes */
+ if (seek_str != NULL && strnlen(seek_str, MAX_SEEK_STRING_SIZE) != 0) {
+ errno = 0;
+ image->seek = ustrtoull(seek_str, &endp, 0);
+ if (seek_str == endp || (image->seek == ULLONG_MAX && \
+ errno == ERANGE)) {
+ ERROR("offset argument: ustrtoull failed");
+ return;
+ }
+ } else
+ image->seek = 0;
+
/* if the handler is not explicit set, try to find the right one */
if (!strlen(image->type)) {
if (strlen(image->volname))
--
2.7.4

Stefano Babic

unread,
Apr 10, 2017, 7:12:56 AM4/10/17
to Sid-Ali Teir, swup...@googlegroups.com, gsavoun...@witekio.us
^----- ???

At least, there is a compile error. Have you tested this code ?

Best regards,
Stefano Babic

Stefano Babic

unread,
Apr 10, 2017, 7:13:38 AM4/10/17
to Sid-Ali Teir, swup...@googlegroups.com, gsavoun...@witekio.us
On 04/04/2017 22:06, Sid-Ali Teir wrote:
Aplied to -master, thanks !

Sid-Ali Teir

unread,
Apr 10, 2017, 3:54:02 PM4/10/17
to swup...@googlegroups.com, gsavoun...@witekio.us

Hi Stefano,

I did not test with CONFIG_LUAEXTERNAL.
The following patch fixes that compilation issue.

Regards,
Sid-Ali

Sid-Ali Teir

unread,
Apr 10, 2017, 3:54:13 PM4/10/17
to swup...@googlegroups.com, gsavoun...@witekio.us, Sid-Ali Teir
From: Georges Savoundararadj <gsavoun...@witekio.us>

This new property allows the user to specify a specific offset from a
raw device and not rely only on the partition.
This is useful for example to update a kernel or a bootloader which is
not part of a partition

It handles the following multiplicative suffixes: K=1024 and M=1024*1024.

This commit has been tested:
* with and without signature
* with and without compression

Signed-off-by: Sid-Ali Teir <st...@witekio.us>
Signed-off-by: Georges Savoundararadj <gsavoun...@witekio.us>
---
Changes since v2:
* Fix compilation error in parser/parse_external.c
index 7c5cce2..3cff335 100644
+ img->seek = ustrtoull(seek_str, &endp, 0);
+ if (seek_str == endp || (img->seek == ULLONG_MAX && \
+ errno == ERANGE)) {
+ ERROR("offset argument: ustrtoull failed");
+ return;
+ }
+ } else
+ img->seek = 0;
2.7.4

Reply all
Reply to author
Forward
0 new messages