* [PATCH] dtc: Add command line option to force size alignment of blob.
@ 2010-11-12 18:02 dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w
[not found] ` <1289584920-4703-1-git-send-email-dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w @ 2010-11-12 18:02 UTC (permalink / raw)
To: jdl-CYoMK+44s/E; +Cc: Dirk Brandewie, devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ
From: Dirk Brandewie <dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
This patch adds a command line argument to allow the user to request
the that the blob be padded out to modulo <bytes> size.
Signed-off-by: Dirk Brandewie <dirk.j.brandewie-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---
Documentation/manual.txt | 3 +++
dtc.c | 10 ++++++++--
flattree.c | 20 +++++++++++++++++++-
3 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/Documentation/manual.txt b/Documentation/manual.txt
index f8a8a7b..c899396 100644
--- a/Documentation/manual.txt
+++ b/Documentation/manual.txt
@@ -117,6 +117,9 @@ Options:
Ensure the blob at least <bytes> long, adding additional
space if needed.
+ -a <bytes>
+ Ensure the blob is modulo <bytes> in length.
+
-v
Print DTC version and exit.
diff --git a/dtc.c b/dtc.c
index 8b31d20..4e1abd4 100644
--- a/dtc.c
+++ b/dtc.c
@@ -77,6 +77,8 @@ static void __attribute__ ((noreturn)) usage(void)
fprintf(stderr, "\t\tMake the blob at least <bytes> long (extra space)\n");
fprintf(stderr, "\t-p <bytes>\n");
fprintf(stderr, "\t\tAdd padding to the blob of <bytes> long (extra space)\n");
+ fprintf(stderr, "\t-a <bytes>\n");
+ fprintf(stderr, "\t\t Add padding make the blob modulo <bytes> in size\n");
fprintf(stderr, "\t-b <number>\n");
fprintf(stderr, "\t\tSet the physical boot cpu\n");
fprintf(stderr, "\t-f\n");
@@ -108,8 +110,9 @@ int main(int argc, char *argv[])
reservenum = 0;
minsize = 0;
padsize = 0;
-
- while ((opt = getopt(argc, argv, "hI:O:o:V:R:S:p:fcqb:vH:")) != EOF) {
+ align_size = 0;
+
+ while ((opt = getopt(argc, argv, "hI:O:o:V:R:S:p:a:fcqb:vH:")) != EOF) {
switch (opt) {
case 'I':
inform = optarg;
@@ -132,6 +135,9 @@ int main(int argc, char *argv[])
case 'p':
padsize = strtol(optarg, NULL, 0);
break;
+ case 'a':
+ alignsize = strtol(optarg, NULL, 0);
+ break;
case 'f':
force = 1;
break;
diff --git a/flattree.c b/flattree.c
index ead0332..e908609 100644
--- a/flattree.c
+++ b/flattree.c
@@ -373,7 +373,8 @@ void dt_to_blob(FILE *f, struct boot_info *bi, int version)
struct data strbuf = empty_data;
struct fdt_header fdt;
int padlen = 0;
-
+ int align_len = 0;
+
for (i = 0; i < ARRAY_SIZE(version_table); i++) {
if (version_table[i].version == version)
vi = &version_table[i];
@@ -411,6 +412,20 @@ void dt_to_blob(FILE *f, struct boot_info *bi, int version)
}
/*
+ * If the user asked for alignment of the end of the blob,
+ * adjust the totalsize.
+ */
+
+ if (align_size > 0)
+ align_len = align_size;
+
+ if (align_len > 0) {
+ int tsize = fdt32_to_cpu(fdt.totalsize);
+ tsize += alignlen;
+ fdt.totalsize = cpu_to_fdt32(tsize);
+ }
+
+ /*
* Assemble the blob: start with the header, add with alignment
* the reserve buffer, add the reserve map terminating zeroes,
* the device tree itself, and finally the strings.
@@ -427,6 +442,9 @@ void dt_to_blob(FILE *f, struct boot_info *bi, int version)
*/
if (padlen > 0)
blob = data_append_zeroes(blob, padlen);
+
+ if (align_len > 0)
+ blob = data_append_align(blob, align_len);
if (fwrite(blob.val, blob.len, 1, f) != 1) {
if (ferror(f))
--
1.7.2.3
^ permalink raw reply related [flat|nested] 3+ messages in thread[parent not found: <1289584920-4703-1-git-send-email-dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>]
* Re: [PATCH] dtc: Add command line option to force size alignment of blob. [not found] ` <1289584920-4703-1-git-send-email-dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> @ 2010-11-14 0:36 ` David Gibson 2010-11-14 6:24 ` Grant Likely 1 sibling, 0 replies; 3+ messages in thread From: David Gibson @ 2010-11-14 0:36 UTC (permalink / raw) To: dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w Cc: Dirk Brandewie, devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ On Fri, Nov 12, 2010 at 10:02:00AM -0800, dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > From: Dirk Brandewie <dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > This patch adds a command line argument to allow the user to request > the that the blob be padded out to modulo <bytes> size. [snip] > @@ -411,6 +412,20 @@ void dt_to_blob(FILE *f, struct boot_info *bi, int version) > } > > /* > + * If the user asked for alignment of the end of the blob, > + * adjust the totalsize. > + */ > + > + if (align_size > 0) > + align_len = align_size; > + > + if (align_len > 0) { > + int tsize = fdt32_to_cpu(fdt.totalsize); > + tsize += alignlen; > + fdt.totalsize = cpu_to_fdt32(tsize); Uh.. what? You just added the alignment to totalsize, rather than aligning totalsize to the alignment. Also, rather than introducing a new variable, it would be simpler to just adjust padlen based on the alignment. -- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] dtc: Add command line option to force size alignment of blob. [not found] ` <1289584920-4703-1-git-send-email-dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 2010-11-14 0:36 ` David Gibson @ 2010-11-14 6:24 ` Grant Likely 1 sibling, 0 replies; 3+ messages in thread From: Grant Likely @ 2010-11-14 6:24 UTC (permalink / raw) To: dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w Cc: Dirk Brandewie, devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ On Fri, Nov 12, 2010 at 10:02:00AM -0800, dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > From: Dirk Brandewie <dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > This patch adds a command line argument to allow the user to request > the that the blob be padded out to modulo <bytes> size. > > Signed-off-by: Dirk Brandewie <dirk.j.brandewie-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> As commented elsewhere; this option isn't needed. The kernel should handle its own alignment requirements. Nack. g. > --- > Documentation/manual.txt | 3 +++ > dtc.c | 10 ++++++++-- > flattree.c | 20 +++++++++++++++++++- > 3 files changed, 30 insertions(+), 3 deletions(-) > > diff --git a/Documentation/manual.txt b/Documentation/manual.txt > index f8a8a7b..c899396 100644 > --- a/Documentation/manual.txt > +++ b/Documentation/manual.txt > @@ -117,6 +117,9 @@ Options: > Ensure the blob at least <bytes> long, adding additional > space if needed. > > + -a <bytes> > + Ensure the blob is modulo <bytes> in length. > + > -v > Print DTC version and exit. > > diff --git a/dtc.c b/dtc.c > index 8b31d20..4e1abd4 100644 > --- a/dtc.c > +++ b/dtc.c > @@ -77,6 +77,8 @@ static void __attribute__ ((noreturn)) usage(void) > fprintf(stderr, "\t\tMake the blob at least <bytes> long (extra space)\n"); > fprintf(stderr, "\t-p <bytes>\n"); > fprintf(stderr, "\t\tAdd padding to the blob of <bytes> long (extra space)\n"); > + fprintf(stderr, "\t-a <bytes>\n"); > + fprintf(stderr, "\t\t Add padding make the blob modulo <bytes> in size\n"); > fprintf(stderr, "\t-b <number>\n"); > fprintf(stderr, "\t\tSet the physical boot cpu\n"); > fprintf(stderr, "\t-f\n"); > @@ -108,8 +110,9 @@ int main(int argc, char *argv[]) > reservenum = 0; > minsize = 0; > padsize = 0; > - > - while ((opt = getopt(argc, argv, "hI:O:o:V:R:S:p:fcqb:vH:")) != EOF) { > + align_size = 0; > + > + while ((opt = getopt(argc, argv, "hI:O:o:V:R:S:p:a:fcqb:vH:")) != EOF) { > switch (opt) { > case 'I': > inform = optarg; > @@ -132,6 +135,9 @@ int main(int argc, char *argv[]) > case 'p': > padsize = strtol(optarg, NULL, 0); > break; > + case 'a': > + alignsize = strtol(optarg, NULL, 0); > + break; > case 'f': > force = 1; > break; > diff --git a/flattree.c b/flattree.c > index ead0332..e908609 100644 > --- a/flattree.c > +++ b/flattree.c > @@ -373,7 +373,8 @@ void dt_to_blob(FILE *f, struct boot_info *bi, int version) > struct data strbuf = empty_data; > struct fdt_header fdt; > int padlen = 0; > - > + int align_len = 0; > + > for (i = 0; i < ARRAY_SIZE(version_table); i++) { > if (version_table[i].version == version) > vi = &version_table[i]; > @@ -411,6 +412,20 @@ void dt_to_blob(FILE *f, struct boot_info *bi, int version) > } > > /* > + * If the user asked for alignment of the end of the blob, > + * adjust the totalsize. > + */ > + > + if (align_size > 0) > + align_len = align_size; > + > + if (align_len > 0) { > + int tsize = fdt32_to_cpu(fdt.totalsize); > + tsize += alignlen; > + fdt.totalsize = cpu_to_fdt32(tsize); > + } > + > + /* > * Assemble the blob: start with the header, add with alignment > * the reserve buffer, add the reserve map terminating zeroes, > * the device tree itself, and finally the strings. > @@ -427,6 +442,9 @@ void dt_to_blob(FILE *f, struct boot_info *bi, int version) > */ > if (padlen > 0) > blob = data_append_zeroes(blob, padlen); > + > + if (align_len > 0) > + blob = data_append_align(blob, align_len); > > if (fwrite(blob.val, blob.len, 1, f) != 1) { > if (ferror(f)) > -- > 1.7.2.3 > > _______________________________________________ > devicetree-discuss mailing list > devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org > https://lists.ozlabs.org/listinfo/devicetree-discuss ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-11-14 6:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-12 18:02 [PATCH] dtc: Add command line option to force size alignment of blob dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w
[not found] ` <1289584920-4703-1-git-send-email-dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2010-11-14 0:36 ` David Gibson
2010-11-14 6:24 ` Grant Likely
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.