This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

objcopy option forces byte ordering for ROM programmers / weird targets


Yet another option. sigh...

This patch solves problems trying to use the existing tools, 
to generate a ROM images for certain target systems where the
byte order implemented in hardware did not match the endian
the processor used. The ROM programmer did not have this
functionality built in unfortunately and we were stuck...


tom
Yet another option. sigh...

This patch solves problems trying to use the existing tools, 
to generate a ROM images for certain target systems where the
byte order implemented in hardware did not match the endian
the processor used. The ROM programmer did not have this
functionality built in unfortunately.

A new option "--reverse" has been added swap bytes within
an output section... Given bytes in the order:
01 02 03 04 05 06 07 08

Allows users to re-order them as:
02 01 04 03 06 05 08 07 (2 byte reversal)
04 03 02 01 08 07 06 05 (4 byte reversal)
03 04 01 02 07 08 05 06 (combination 2 & 4 byte reversal)
=======================================================================
2000-03-17  Thomas de Lellis  <tdel@windriver.com>

        * objcopy.c (copy_section):  Added new command line
        option "--reverse={2,4}" to reverve the "endianness"
        in an output section. Needed for generating ROMs
        for some targets, where the user's ROM burner had no
        capability of doing this operation itself. The
        particular target that prompted this required ROMs in
        one endian regardless of what the processor
        was set to use...  Pretty weird!
        * objcopy.1: Docs for --reverse.
        * binutils.texi: Docs for --reverse.
        
=======================================================================
*** objcopy.c@@/main/14	Fri Jan 28 11:08:09 2000
--- objcopy.c	Mon Mar 20 11:45:32 2000
*************** static bfd_byte gap_fill = 0;
*** 170,175 ****
--- 170,179 ----
  static boolean pad_to_set = false;
  static bfd_vma pad_to;
  
+ /* Reverse byte ordering.  */
+ static boolean reversedat_set = false;
+ static int reversedat = 0;
+ 
  /* List of sections to add.  */
  
  struct section_add
*************** static boolean weaken = false;
*** 239,244 ****
--- 243,249 ----
  #define OPTION_BIOS_ROM (OPTION_IGNORE_VMA + 1)
  #define OPTION_EXTRACT_SYMBOL (OPTION_BIOS_ROM + 1)
  #define OPTION_BINARY_WITHOUT_BSS (OPTION_EXTRACT_SYMBOL + 1)
+ #define OPTION_REVERSE (OPTION_BINARY_WITHOUT_BSS + 1)
  
  /* Options to handle if running as "strip".  */
  
*************** static struct option copy_options[] =
*** 317,322 ****
--- 322,328 ----
    {"strip-debug", no_argument, 0, 'g'},
    {"strip-unneeded", no_argument, 0, OPTION_STRIP_UNNEEDED},
    {"strip-symbol", required_argument, 0, 'N'},
+   {"reverse", required_argument, 0, OPTION_REVERSE},
    {"target", required_argument, 0, 'F'},
    {"verbose", no_argument, 0, 'v'},
    {"version", no_argument, 0, 'V'},
*************** copy_usage (stream, exit_status)
*** 342,347 ****
--- 348,354 ----
    fprintf (stream, _("\
  Usage: %s [-vVSpgxXr] [-I bfdname] [-O bfdname] [-F bfdname] [-b byte]\n\
         [-j section] [-R section]\n\
+        [--reverse={2,4}]\n\
         [-i interleave] [--interleave=interleave] [--byte=byte]\n\
         [--input-target=bfdname] [--output-target=bfdname] [--target=bfdname]\n\
         [--relocateable]\n\
*************** copy_section (ibfd, isection, obfdarg)
*** 1581,1586 ****
--- 1588,1620 ----
  				     size))
  	RETURN_NONFATAL (bfd_get_filename (ibfd));
  
+       if (reversedat_set)
+ 	{
+ 	  /* If section length is a multiple of the bytes to swap...  */
+ 	  if  ((size % reversedat) == 0)
+ 	    {
+ 	      long i;
+ 	      long j;
+ 	      bfd_byte b;
+ 	      
+ 	      /* Reverse the bytes.  */
+ 	      for (i = 0; i < size; i += reversedat)
+ 		{
+ 		  for (j = 0; j < (reversedat / 2); j++)
+ 		    {
+ 		      b = ((bfd_byte *) memhunk)[i + j];
+ 		      ((bfd_byte *) memhunk)[i + j]
+ 			= ((bfd_byte *) memhunk)[(i + reversedat) - (j + 1)];
+ 		      ((bfd_byte *) memhunk)[(i + reversedat) - (j + 1)] = b;
+ 		    }
+ 		}
+ 	    }
+ 	  else
+ 	    /* Sorry, but the poor user must pad the section up a bit.  */
+ 	    fatal (_("cannot reverse - length of section %s must be evenly divisible by %d"),
+ 		   bfd_section_name (ibfd, isection), reversedat);
+ 	}
+ 
        if (copy_byte >= 0) 
  	filter_bytes (memhunk, &size);
  
*************** copy_main (argc, argv)
*** 2269,2274 ****
--- 2303,2316 ----
            /* Check if --output-vector-pc=PC is set */
  	  set_pc = parse_vma (optarg, "--output-vector-pc");
  	  set_pc_set = true;
+ 	  break;
+ 
+ 	case OPTION_REVERSE:
+ 	  reversedat = parse_vma (optarg, "--reverse");
+ 	  /* Actually, any value would work.  */
+ 	  reversedat_set = (reversedat == 2) || (reversedat == 4);
+ 	  if (! reversedat_set)
+ 	    fatal (_("reverse must be set to either 2 or 4"));
  	  break;
  
  	case 0:
=======================================================================
*** objcopy.1@@/main/5	Mon Oct  4 13:17:18 1999
--- objcopy.1	Fri Mar 17 20:28:10 2000
*************** objcopy \- copy and translate object fil
*** 37,42 ****
--- 37,43 ----
  .RB "[\|" \-\-output\-vector\-pc=PC "\|]"
  .RB "[\|" \-\-bios\-rom "\|]"
  .RB "[\|" \-\-binary\-without\-bss "\|]"
+ .RB "[\|" \-\-reverse={2,4} "\|]"
  .RB "[\|" \-\-extract\-symbol "\|]"
  .RB "[\|" \-\-add\-imi\-section\ \\fIfilename\fR "\|]"
  .RB "[\|" \-\-ignore\-vma "\|]"
*************** object module.
*** 320,325 ****
--- 321,349 ----
  Translate only .text & .data sections of an input file. The output file is
  the binary image of the input file without the .bss section. We only
  keep the .text and the .data sections. This option must be given with
+ .TP
+ .B \-\-reverse={2,4}
+ Reverse bytes in a section with output contents. A section length must
+ be evenly divisible by the value given in order for the swap to be able
+ to take place. Reversing takes place before the interleaving is performed.
+ .PP
+ This option is used typically in generating ROM images for problematic
+ target systems. With some target boards, the 32-bit words fetched from
+ 8-bit ROMs are re-assembled in little-endian byte order regardless of the
+ CPU byte order. Depending on the programming model, the endianness of the
+ ROM may need to be modified.
+ .PP
+ Consider a simple file with a section containing the
+ following eight bytes 12345678.
+ .PP
+ Using "\-\-reverse=2" for the above example, bytes in the output file
+ would be ordered 21436587.
+ .PP
+ Using "\-\-reverse=4" for the above example, bytes in the output file
+ would be ordered 43218765.
+ .PP
+ Or by combining a "\-\-reverse=2"-run followed by a "\-\-reverse=4"-run
+ bytes ordered 34127856 would be generated.
  -O binary.
  .TP
  .B \-\-weaken
=======================================================================
*** binutils.texi@@/main/5	Tue Jan 25 15:53:33 2000
--- binutils.texi	Fri Mar 17 20:28:06 2000
*************** objcopy [ -F @var{bfdname} | --target=@v
*** 894,899 ****
--- 894,900 ----
   	[ --bios-rom ]
   	[ --extract-symbol ]
   	[ --binary-without-bss ]
+  	[ --reverse={2,4} ]
          [ --gap-fill=@var{val} ] [ --pad-to=@var{address} ]
          [ --set-start=@var{val} ] [ --adjust-start=@var{incr} ]
          [ --change-addresses=@var{incr} ]
*************** the binary image of the input file witho
*** 1195,1200 ****
--- 1196,1224 ----
  keep the .text and the .data sections. This option requires the -O binary
  option.
    
+ @item --reverse={2,4}
+ Reverse bytes in a section with output contents. A section length must
+ be evenly divisible by the value given in order for the swap to be able
+ to take place. Reversing takes place before the interleaving is performed.
+ 
+ This option is used typically in generating ROM images for problematic
+ target systems. For example, on some target boards, the 32-bit words fetched
+ from 8-bit ROMs are re-assembled in little-endian byte order regardless of the
+ CPU byte order. Depending on the programming model, the endianness of the
+ ROM may need to be modified.
+ 
+ Consider a simple file with a section containing the
+ following eight bytes 12345678.
+ 
+ Using "--reverse=2" for the above example, bytes in the output file
+ would be ordered 21436587.
+ 
+ Using "--reverse=4" for the above example, bytes in the output file
+ would be ordered 43218765.
+ 
+ Or by combining a "--reverse=2"-run followed by a "--reverse=4"-run
+ bytes ordered 34127856 would be generated.
+ 
  @item -V
  @itemx --version
  Show the version number of @code{objcopy}.
TESTCASE ==============================================================
> ./test
# note: although just binary shown here, also works for other modes, like
# srec, ihex, etc....
+ cat 1 
12345678
+ objcopymips -I binary 1 2 --reverse 2 
objcopymips: Warning: Output file cannot represent architecture UNKNOWN!
+ cat 2 
21436587
+ objcopymips -I binary 1 4 --reverse 4 
objcopymips: Warning: Output file cannot represent architecture UNKNOWN!
+ cat 4 
43218765
+ objcopymips -I binary 2 24 --reverse 4 
objcopymips: Warning: Output file cannot represent architecture UNKNOWN!
+ cat 24 
34127856
# and now a few error cases, odd lengthed file & incorrect values...
+ cat 11 
123456789
+ objcopymips -I binary 11 2 --reverse 2 
objcopymips: Warning: Output file cannot represent architecture UNKNOWN!
objcopymips: cannot reverse - length of section .data must be evenly divisible by 2
+ objcopymips -I binary 11 4 --reverse 4 
objcopymips: Warning: Output file cannot represent architecture UNKNOWN!
objcopymips: cannot reverse - length of section .data must be evenly divisible by 4
+ objcopymips -I binary 11 2 --reverse 3 
objcopymips: reverse must be set to either 2 or 4

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]