* [PATCH v4] Implement the -a option to pad dtb aligned @ 2016-07-01 9:30 Tim Wang [not found] ` <1467365408-923-1-git-send-email-timwang-XOWFcpiLszpWk0Htik3J/w@public.gmane.org> 0 siblings, 1 reply; 3+ messages in thread From: Tim Wang @ 2016-07-01 9:30 UTC (permalink / raw) To: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA Cc: wtt_usst-9Onoh4P/yGk, timwang-XOWFcpiLszpWk0Htik3J/w There is one condition that need cat the dtb files into one dtb.img which can support several boards use same SoC platform. And the original dtb file size is not aligned to any base. This may cause "Synchronous Abort" when load from a unligned address on some SoC machine, such as ARM. So this patch implement the -a <aligned number> option to pad zero at the end of dtb files and make the dtb size aligned to <aligned number>. Then, the aligned dtbs can cat together and load without "Synchronous Abort". Signed-off-by: Tim Wang <timwang-XOWFcpiLszpWk0Htik3J/w@public.gmane.org> --- dtc.c | 17 ++++++++++++++++- dtc.h | 1 + flattree.c | 10 +++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/dtc.c b/dtc.c index 5fa23c4..d47089e 100644 --- a/dtc.c +++ b/dtc.c @@ -30,8 +30,14 @@ int quiet; /* Level of quietness */ int reservenum; /* Number of memory reservation slots */ int minsize; /* Minimum blob size */ int padsize; /* Additional padding to blob */ +int alignsize; /* Additional padding to blob accroding to the alignsize */ int phandle_format = PHANDLE_BOTH; /* Use linux,phandle or phandle properties */ +static int is_power_of_2(int x) +{ + return (x > 0) && ((x & (x - 1)) == 0); +} + static void fill_fullpaths(struct node *tree, const char *prefix) { struct node *child; @@ -53,7 +59,7 @@ static void fill_fullpaths(struct node *tree, const char *prefix) #define FDT_VERSION(version) _FDT_VERSION(version) #define _FDT_VERSION(version) #version static const char usage_synopsis[] = "dtc [options] <input file>"; -static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:fb:i:H:sW:E:hv"; +static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:a:fb:i:H:sW:E:hv"; static struct option const usage_long_opts[] = { {"quiet", no_argument, NULL, 'q'}, {"in-format", a_argument, NULL, 'I'}, @@ -64,6 +70,7 @@ static struct option const usage_long_opts[] = { {"reserve", a_argument, NULL, 'R'}, {"space", a_argument, NULL, 'S'}, {"pad", a_argument, NULL, 'p'}, + {"align", a_argument, NULL, 'a'}, {"boot-cpu", a_argument, NULL, 'b'}, {"force", no_argument, NULL, 'f'}, {"include", a_argument, NULL, 'i'}, @@ -91,6 +98,7 @@ static const char * const usage_opts_help[] = { "\n\tMake space for <number> reserve map entries (for dtb and asm output)", "\n\tMake the blob at least <bytes> long (extra space)", "\n\tAdd padding to the blob of <bytes> long (extra space)", + "\n\tMake the blob align to the <bytes> (extra space)", "\n\tSet the physical boot cpu", "\n\tTry to produce output even if the input tree has errors", "\n\tAdd a path to search for include files", @@ -169,6 +177,7 @@ int main(int argc, char *argv[]) reservenum = 0; minsize = 0; padsize = 0; + alignsize = 0; while ((opt = util_getopt_long()) != EOF) { switch (opt) { @@ -196,6 +205,12 @@ int main(int argc, char *argv[]) case 'p': padsize = strtol(optarg, NULL, 0); break; + case 'a': + alignsize = strtol(optarg, NULL, 0); + if (!is_power_of_2(alignsize)) + die("Invalid argument \"%s\" to -H option\n", + optarg); + break; case 'f': force = true; break; diff --git a/dtc.h b/dtc.h index 56212c8..32009bc 100644 --- a/dtc.h +++ b/dtc.h @@ -53,6 +53,7 @@ extern int quiet; /* Level of quietness */ extern int reservenum; /* Number of memory reservation slots */ extern int minsize; /* Minimum blob size */ extern int padsize; /* Additional padding to blob */ +extern int alignsize; /* Additional padding to blob accroding to the alignsize */ extern int phandle_format; /* Use linux,phandle or phandle properties */ #define PHANDLE_LEGACY 0x1 diff --git a/flattree.c b/flattree.c index ec14954..1cdd426 100644 --- a/flattree.c +++ b/flattree.c @@ -398,15 +398,21 @@ void dt_to_blob(FILE *f, struct boot_info *bi, int version) */ if (minsize > 0) { padlen = minsize - fdt32_to_cpu(fdt.totalsize); - if ((padlen < 0) && (quiet < 1)) + if ((padlen < 0) && (quiet < 1)) { fprintf(stderr, "Warning: blob size %d >= minimum size %d\n", fdt32_to_cpu(fdt.totalsize), minsize); + padlen = 0; + } } if (padsize > 0) padlen = padsize; + if (alignsize > 0) + padlen = ALIGN(fdt32_to_cpu(fdt.totalsize) + padlen, alignsize) + - fdt32_to_cpu(fdt.totalsize); + if (padlen > 0) { int tsize = fdt32_to_cpu(fdt.totalsize); tsize += padlen; @@ -572,6 +578,8 @@ void dt_to_asm(FILE *f, struct boot_info *bi, int version) if (padsize > 0) { fprintf(f, "\t.space\t%d, 0\n", padsize); } + if (alignsize > 0) + asm_emit_align(f, alignsize); emit_label(f, symprefix, "blob_abs_end"); data_free(strbuf); -- 1.9.1 ^ permalink raw reply related [flat|nested] 3+ messages in thread
[parent not found: <1467365408-923-1-git-send-email-timwang-XOWFcpiLszpWk0Htik3J/w@public.gmane.org>]
* Re: [PATCH v4] Implement the -a option to pad dtb aligned [not found] ` <1467365408-923-1-git-send-email-timwang-XOWFcpiLszpWk0Htik3J/w@public.gmane.org> @ 2016-07-07 4:45 ` David Gibson [not found] ` <20160707044512.GS14675-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org> 0 siblings, 1 reply; 3+ messages in thread From: David Gibson @ 2016-07-07 4:45 UTC (permalink / raw) To: Tim Wang; +Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA, wtt_usst-9Onoh4P/yGk [-- Attachment #1: Type: text/plain, Size: 5700 bytes --] On Fri, Jul 01, 2016 at 05:30:08PM +0800, Tim Wang wrote: > There is one condition that need cat the dtb files > into one dtb.img which can support several boards > use same SoC platform. > > And the original dtb file size is not aligned to any base. > This may cause "Synchronous Abort" when load from a unligned > address on some SoC machine, such as ARM. > > So this patch implement the -a <aligned number> option to > pad zero at the end of dtb files and make the dtb size aligned > to <aligned number>. > > Then, the aligned dtbs can cat together and load without "Synchronous > Abort". > > Signed-off-by: Tim Wang <timwang-XOWFcpiLszpWk0Htik3J/w@public.gmane.org> > --- > dtc.c | 17 ++++++++++++++++- > dtc.h | 1 + > flattree.c | 10 +++++++++- > 3 files changed, 26 insertions(+), 2 deletions(-) > > diff --git a/dtc.c b/dtc.c > index 5fa23c4..d47089e 100644 > --- a/dtc.c > +++ b/dtc.c > @@ -30,8 +30,14 @@ int quiet; /* Level of quietness */ > int reservenum; /* Number of memory reservation slots */ > int minsize; /* Minimum blob size */ > int padsize; /* Additional padding to blob */ > +int alignsize; /* Additional padding to blob accroding to the alignsize */ > int phandle_format = PHANDLE_BOTH; /* Use linux,phandle or phandle properties */ > > +static int is_power_of_2(int x) > +{ > + return (x > 0) && ((x & (x - 1)) == 0); > +} > + > static void fill_fullpaths(struct node *tree, const char *prefix) > { > struct node *child; > @@ -53,7 +59,7 @@ static void fill_fullpaths(struct node *tree, const char *prefix) > #define FDT_VERSION(version) _FDT_VERSION(version) > #define _FDT_VERSION(version) #version > static const char usage_synopsis[] = "dtc [options] <input file>"; > -static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:fb:i:H:sW:E:hv"; > +static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:a:fb:i:H:sW:E:hv"; > static struct option const usage_long_opts[] = { > {"quiet", no_argument, NULL, 'q'}, > {"in-format", a_argument, NULL, 'I'}, > @@ -64,6 +70,7 @@ static struct option const usage_long_opts[] = { > {"reserve", a_argument, NULL, 'R'}, > {"space", a_argument, NULL, 'S'}, > {"pad", a_argument, NULL, 'p'}, > + {"align", a_argument, NULL, 'a'}, > {"boot-cpu", a_argument, NULL, 'b'}, > {"force", no_argument, NULL, 'f'}, > {"include", a_argument, NULL, 'i'}, > @@ -91,6 +98,7 @@ static const char * const usage_opts_help[] = { > "\n\tMake space for <number> reserve map entries (for dtb and asm output)", > "\n\tMake the blob at least <bytes> long (extra space)", > "\n\tAdd padding to the blob of <bytes> long (extra space)", > + "\n\tMake the blob align to the <bytes> (extra space)", > "\n\tSet the physical boot cpu", > "\n\tTry to produce output even if the input tree has errors", > "\n\tAdd a path to search for include files", > @@ -169,6 +177,7 @@ int main(int argc, char *argv[]) > reservenum = 0; > minsize = 0; > padsize = 0; > + alignsize = 0; > > while ((opt = util_getopt_long()) != EOF) { > switch (opt) { > @@ -196,6 +205,12 @@ int main(int argc, char *argv[]) > case 'p': > padsize = strtol(optarg, NULL, 0); > break; > + case 'a': > + alignsize = strtol(optarg, NULL, 0); > + if (!is_power_of_2(alignsize)) > + die("Invalid argument \"%s\" to -H option\n", You have the wrong option name here. Also, since the argument isn't a string, I wouldn't suggest the \"s. > + optarg); > + break; > case 'f': > force = true; > break; > diff --git a/dtc.h b/dtc.h > index 56212c8..32009bc 100644 > --- a/dtc.h > +++ b/dtc.h > @@ -53,6 +53,7 @@ extern int quiet; /* Level of quietness */ > extern int reservenum; /* Number of memory reservation slots */ > extern int minsize; /* Minimum blob size */ > extern int padsize; /* Additional padding to blob */ > +extern int alignsize; /* Additional padding to blob accroding to the alignsize */ > extern int phandle_format; /* Use linux,phandle or phandle properties */ > > #define PHANDLE_LEGACY 0x1 > diff --git a/flattree.c b/flattree.c > index ec14954..1cdd426 100644 > --- a/flattree.c > +++ b/flattree.c > @@ -398,15 +398,21 @@ void dt_to_blob(FILE *f, struct boot_info *bi, int version) > */ > if (minsize > 0) { > padlen = minsize - fdt32_to_cpu(fdt.totalsize); > - if ((padlen < 0) && (quiet < 1)) > + if ((padlen < 0) && (quiet < 1)) { > fprintf(stderr, > "Warning: blob size %d >= minimum size %d\n", > fdt32_to_cpu(fdt.totalsize), minsize); > + padlen = 0; Here, your behaviour will change if you add the -q option, which is incorrect. You'll need to split the if condition. > + } > } > > if (padsize > 0) > padlen = padsize; > > + if (alignsize > 0) > + padlen = ALIGN(fdt32_to_cpu(fdt.totalsize) + padlen, alignsize) > + - fdt32_to_cpu(fdt.totalsize); > + This looks correct now. > if (padlen > 0) { > int tsize = fdt32_to_cpu(fdt.totalsize); > tsize += padlen; > @@ -572,6 +578,8 @@ void dt_to_asm(FILE *f, struct boot_info *bi, int version) > if (padsize > 0) { > fprintf(f, "\t.space\t%d, 0\n", padsize); > } > + if (alignsize > 0) > + asm_emit_align(f, alignsize); > emit_label(f, symprefix, "blob_abs_end"); > > data_free(strbuf); -- 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 [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 819 bytes --] ^ permalink raw reply [flat|nested] 3+ messages in thread
[parent not found: <20160707044512.GS14675-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>]
* RE: [PATCH v4] Implement the -a option to pad dtb aligned [not found] ` <20160707044512.GS14675-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org> @ 2016-07-07 9:56 ` Wang Tim(王艇艇) 0 siblings, 0 replies; 3+ messages in thread From: Wang Tim(王艇艇) @ 2016-07-07 9:56 UTC (permalink / raw) To: David Gibson Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, wtt_usst-9Onoh4P/yGk@public.gmane.org Hi David, Thanks for your carefully review! I'll refine my patch in next patch version according your suggestions. Best Regards Tim Wang(王艇艇) -----Original Message----- From: David Gibson [mailto:david@gibson.dropbear.id.au] Sent: Thursday, July 07, 2016 12:45 PM To: Wang Tim(王艇艇) Cc: devicetree-compiler@vger.kernel.org; wtt_usst@163.com Subject: Re: [PATCH v4] Implement the -a option to pad dtb aligned On Fri, Jul 01, 2016 at 05:30:08PM +0800, Tim Wang wrote: > There is one condition that need cat the dtb files > into one dtb.img which can support several boards > use same SoC platform. > > And the original dtb file size is not aligned to any base. > This may cause "Synchronous Abort" when load from a unligned > address on some SoC machine, such as ARM. > > So this patch implement the -a <aligned number> option to > pad zero at the end of dtb files and make the dtb size aligned > to <aligned number>. > > Then, the aligned dtbs can cat together and load without "Synchronous > Abort". > > Signed-off-by: Tim Wang <timwang@asrmicro.com> > --- > dtc.c | 17 ++++++++++++++++- > dtc.h | 1 + > flattree.c | 10 +++++++++- > 3 files changed, 26 insertions(+), 2 deletions(-) > > diff --git a/dtc.c b/dtc.c > index 5fa23c4..d47089e 100644 > --- a/dtc.c > +++ b/dtc.c > @@ -30,8 +30,14 @@ int quiet; /* Level of quietness */ > int reservenum; /* Number of memory reservation slots */ > int minsize; /* Minimum blob size */ > int padsize; /* Additional padding to blob */ > +int alignsize; /* Additional padding to blob accroding to the alignsize */ > int phandle_format = PHANDLE_BOTH; /* Use linux,phandle or phandle properties */ > > +static int is_power_of_2(int x) > +{ > + return (x > 0) && ((x & (x - 1)) == 0); > +} > + > static void fill_fullpaths(struct node *tree, const char *prefix) > { > struct node *child; > @@ -53,7 +59,7 @@ static void fill_fullpaths(struct node *tree, const char *prefix) > #define FDT_VERSION(version) _FDT_VERSION(version) > #define _FDT_VERSION(version) #version > static const char usage_synopsis[] = "dtc [options] <input file>"; > -static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:fb:i:H:sW:E:hv"; > +static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:a:fb:i:H:sW:E:hv"; > static struct option const usage_long_opts[] = { > {"quiet", no_argument, NULL, 'q'}, > {"in-format", a_argument, NULL, 'I'}, > @@ -64,6 +70,7 @@ static struct option const usage_long_opts[] = { > {"reserve", a_argument, NULL, 'R'}, > {"space", a_argument, NULL, 'S'}, > {"pad", a_argument, NULL, 'p'}, > + {"align", a_argument, NULL, 'a'}, > {"boot-cpu", a_argument, NULL, 'b'}, > {"force", no_argument, NULL, 'f'}, > {"include", a_argument, NULL, 'i'}, > @@ -91,6 +98,7 @@ static const char * const usage_opts_help[] = { > "\n\tMake space for <number> reserve map entries (for dtb and asm output)", > "\n\tMake the blob at least <bytes> long (extra space)", > "\n\tAdd padding to the blob of <bytes> long (extra space)", > + "\n\tMake the blob align to the <bytes> (extra space)", > "\n\tSet the physical boot cpu", > "\n\tTry to produce output even if the input tree has errors", > "\n\tAdd a path to search for include files", > @@ -169,6 +177,7 @@ int main(int argc, char *argv[]) > reservenum = 0; > minsize = 0; > padsize = 0; > + alignsize = 0; > > while ((opt = util_getopt_long()) != EOF) { > switch (opt) { > @@ -196,6 +205,12 @@ int main(int argc, char *argv[]) > case 'p': > padsize = strtol(optarg, NULL, 0); > break; > + case 'a': > + alignsize = strtol(optarg, NULL, 0); > + if (!is_power_of_2(alignsize)) > + die("Invalid argument \"%s\" to -H option\n", You have the wrong option name here. Also, since the argument isn't a string, I wouldn't suggest the \"s. > + optarg); > + break; > case 'f': > force = true; > break; > diff --git a/dtc.h b/dtc.h > index 56212c8..32009bc 100644 > --- a/dtc.h > +++ b/dtc.h > @@ -53,6 +53,7 @@ extern int quiet; /* Level of quietness */ > extern int reservenum; /* Number of memory reservation slots */ > extern int minsize; /* Minimum blob size */ > extern int padsize; /* Additional padding to blob */ > +extern int alignsize; /* Additional padding to blob accroding to the alignsize */ > extern int phandle_format; /* Use linux,phandle or phandle properties */ > > #define PHANDLE_LEGACY 0x1 > diff --git a/flattree.c b/flattree.c > index ec14954..1cdd426 100644 > --- a/flattree.c > +++ b/flattree.c > @@ -398,15 +398,21 @@ void dt_to_blob(FILE *f, struct boot_info *bi, int version) > */ > if (minsize > 0) { > padlen = minsize - fdt32_to_cpu(fdt.totalsize); > - if ((padlen < 0) && (quiet < 1)) > + if ((padlen < 0) && (quiet < 1)) { > fprintf(stderr, > "Warning: blob size %d >= minimum size %d\n", > fdt32_to_cpu(fdt.totalsize), minsize); > + padlen = 0; Here, your behaviour will change if you add the -q option, which is incorrect. You'll need to split the if condition. > + } > } > > if (padsize > 0) > padlen = padsize; > > + if (alignsize > 0) > + padlen = ALIGN(fdt32_to_cpu(fdt.totalsize) + padlen, alignsize) > + - fdt32_to_cpu(fdt.totalsize); > + This looks correct now. > if (padlen > 0) { > int tsize = fdt32_to_cpu(fdt.totalsize); > tsize += padlen; > @@ -572,6 +578,8 @@ void dt_to_asm(FILE *f, struct boot_info *bi, int version) > if (padsize > 0) { > fprintf(f, "\t.space\t%d, 0\n", padsize); > } > + if (alignsize > 0) > + asm_emit_align(f, alignsize); > emit_label(f, symprefix, "blob_abs_end"); > > data_free(strbuf); -- 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
end of thread, other threads:[~2016-07-07 9:56 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-07-01 9:30 [PATCH v4] Implement the -a option to pad dtb aligned Tim Wang [not found] ` <1467365408-923-1-git-send-email-timwang-XOWFcpiLszpWk0Htik3J/w@public.gmane.org> 2016-07-07 4:45 ` David Gibson [not found] ` <20160707044512.GS14675-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org> 2016-07-07 9:56 ` Wang Tim(王艇艇)
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).