From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 1/2] add fix size tools
Date: Sat, 14 Sep 2013 14:27:18 +0200 [thread overview]
Message-ID: <1379161639-27488-1-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <20130914120725.GB21829@ns203013.ovh.net>
this will allow to write the size of barebox at an offset of the binary
this is needed for ARM when using relocated binary
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
scripts/Makefile | 1 +
scripts/fix_size.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 82 insertions(+)
create mode 100644 scripts/fix_size.c
diff --git a/scripts/Makefile b/scripts/Makefile
index 307dc3d..61f31db 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -7,6 +7,7 @@
hostprogs-$(CONFIG_KALLSYMS) += kallsyms
hostprogs-y += bin2c
hostprogs-y += mkimage
+hostprogs-y += fix_size
hostprogs-y += bareboxenv
hostprogs-$(CONFIG_ARCH_MVEBU) += kwbimage kwboot
hostprogs-$(CONFIG_ARCH_NETX) += gen_netx_image
diff --git a/scripts/fix_size.c b/scripts/fix_size.c
new file mode 100644
index 0000000..869ae7e
--- /dev/null
+++ b/scripts/fix_size.c
@@ -0,0 +1,81 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <fcntl.h>
+#ifndef _BSD_SOURCE
+#define _BSD_SOURCE /* See feature_test_macros(7) */
+#endif
+#include <endian.h>
+
+int main(int argc, char**argv)
+{
+ struct stat s;
+ int c;
+ int fd;
+ uint64_t offset = 0;
+ uint32_t size = 0;
+ char *file = NULL;
+ int ret = 1;
+ int is_bigendian = 0;
+
+ while ((c = getopt (argc, argv, "hf:o:b")) != -1) {
+ switch (c) {
+ case 'f':
+ file = optarg;
+ break;
+ case 'o':
+ offset = strtoul(optarg, NULL, 16);
+ break;
+ case 'b':
+ is_bigendian = 1;
+ break;
+ }
+ }
+
+ if (!file) {
+ fprintf(stderr, "missing file\n");
+ return 1;
+ }
+
+ if (stat(file, &s)) {
+ perror("stat");
+ return 1;
+ }
+
+ fd = open(file, O_WRONLY);
+ if (fd < 0) {
+ perror("open");
+ return 1;
+ }
+
+ ret = lseek(fd, offset, SEEK_SET);
+ if (ret < 0) {
+ perror("lseek");
+ ret = 1;
+ goto err;
+ }
+
+ size = s.st_size;
+
+ if (is_bigendian)
+ size = htobe32(size);
+ else
+ size = htole32(size);
+
+ ret = write(fd, &size, 4);
+ if (ret != 4) {
+ perror("write");
+ ret = 1;
+ goto err;
+ }
+
+ ret = 0;
+err:
+
+ close(fd);
+
+ return ret;
+}
--
1.8.4.rc1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2013-09-14 12:26 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-14 12:07 [RFC] [PATCH 0/2] fix barebox size when using a relocated pbl Jean-Christophe PLAGNIOL-VILLARD
2013-09-14 12:27 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2013-09-14 12:27 ` [PATCH 2/2] ARM: PBL: fix binary size Jean-Christophe PLAGNIOL-VILLARD
2013-09-16 8:56 ` [RFC] [PATCH 0/2] fix barebox size when using a relocated pbl Sascha Hauer
2013-09-16 14:35 ` Jean-Christophe PLAGNIOL-VILLARD
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=1379161639-27488-1-git-send-email-plagnioj@jcrosoft.com \
--to=plagnioj@jcrosoft.com \
--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