From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 4/5] scripts/common: Add write_full() and read_full()
Date: Wed, 6 Oct 2021 16:22:53 +0200 [thread overview]
Message-ID: <20211006142254.1751864-5-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20211006142254.1751864-1-s.hauer@pengutronix.de>
We have different implementations of read_full() and write_full() in our
host tools, use a common implementation for these.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
scripts/common.c | 36 ++++++++++++++++++++++++++++++++++++
scripts/common.h | 2 ++
scripts/rkimage.c | 39 +++------------------------------------
scripts/socfpga_mkimage.c | 20 --------------------
4 files changed, 41 insertions(+), 56 deletions(-)
diff --git a/scripts/common.c b/scripts/common.c
index 5e0139278a..bff08b0810 100644
--- a/scripts/common.c
+++ b/scripts/common.c
@@ -130,3 +130,39 @@ out:
return ret;
}
+
+int read_full(int fd, void *buf, size_t size)
+{
+ size_t insize = size;
+ int now;
+ int total = 0;
+
+ while (size) {
+ now = read(fd, buf, size);
+ if (now == 0)
+ return total;
+ if (now < 0)
+ return now;
+ total += now;
+ size -= now;
+ buf += now;
+ }
+
+ return insize;
+}
+
+int write_full(int fd, void *buf, size_t size)
+{
+ size_t insize = size;
+ int now;
+
+ while (size) {
+ now = write(fd, buf, size);
+ if (now <= 0)
+ return now;
+ size -= now;
+ buf += now;
+ }
+
+ return insize;
+}
diff --git a/scripts/common.h b/scripts/common.h
index a15691f039..820108c52c 100644
--- a/scripts/common.h
+++ b/scripts/common.h
@@ -4,5 +4,7 @@
int read_file_2(const char *filename, size_t *size, void **outbuf, size_t max_size);
void *read_file(const char *filename, size_t *size);
int write_file(const char *filename, const void *buf, size_t size);
+int read_full(int fd, void *buf, size_t size);
+int write_full(int fd, void *buf, size_t size);
#endif /* __COMMON_H */
diff --git a/scripts/rkimage.c b/scripts/rkimage.c
index dde9724886..be89c1ad34 100644
--- a/scripts/rkimage.c
+++ b/scripts/rkimage.c
@@ -13,6 +13,9 @@
#include <errno.h>
#include <stdbool.h>
+#include "../common.h"
+#include "../common.c"
+
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
@@ -149,42 +152,6 @@ static void usage(const char *prgname)
prgname);
}
-static int read_full(int fd, void *buf, size_t size)
-{
- size_t insize = size;
- int now;
- int total = 0;
-
- while (size) {
- now = read(fd, buf, size);
- if (now == 0)
- return total;
- if (now < 0)
- return now;
- total += now;
- size -= now;
- buf += now;
- }
-
- return insize;
-}
-
-static int write_full(int fd, void *buf, size_t size)
-{
- size_t insize = size;
- int now;
-
- while (size) {
- now = write(fd, buf, size);
- if (now <= 0)
- return now;
- size -= now;
- buf += now;
- }
-
- return insize;
-}
-
int main(int argc, char *argv[])
{
int opt, i, fd;
diff --git a/scripts/socfpga_mkimage.c b/scripts/socfpga_mkimage.c
index 3ef41edf8f..d37ca8585a 100644
--- a/scripts/socfpga_mkimage.c
+++ b/scripts/socfpga_mkimage.c
@@ -68,26 +68,6 @@ static uint32_t bb_header[] = {
0xea00006b, /* entry. b 0x200 (offset may be adjusted) */
};
-static int read_full(int fd, void *buf, size_t size)
-{
- size_t insize = size;
- int now;
- int total = 0;
-
- while (size) {
- now = read(fd, buf, size);
- if (now == 0)
- return total;
- if (now < 0)
- return now;
- total += now;
- size -= now;
- buf += now;
- }
-
- return insize;
-}
-
static const uint32_t crc_table[256] = {
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,
--
2.30.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2021-10-06 14:24 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-06 14:22 [PATCH 0/5] scripts: Common functions for host tools and rk-usb-loader Sascha Hauer
2021-10-06 14:22 ` [PATCH 1/5] scripts: Add Kconfig option for most host tools Sascha Hauer
2021-10-06 14:22 ` [PATCH 2/5] scripts: Add common library functions Sascha Hauer
2021-10-11 14:37 ` Masahiro Yamada
2021-10-11 14:52 ` Sascha Hauer
2021-10-11 16:38 ` Masahiro Yamada
2021-10-06 14:22 ` [PATCH 3/5] scripts/common: Add write_file() Sascha Hauer
2021-10-06 14:22 ` Sascha Hauer [this message]
2021-10-06 14:22 ` [PATCH 5/5] scripts: Add rk-usb-loader tool Sascha Hauer
2021-10-08 14:25 ` Michael Riesch
2021-10-11 7:18 ` Sascha Hauer
2021-10-11 9:46 ` Michael Riesch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211006142254.1751864-5-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox