avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Home of avr-mem.sh?


From: Eric Weddington
Subject: Re: [avr-gcc-list] Home of avr-mem.sh?
Date: Fri, 30 Dec 2005 13:42:37 -0700
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

Eric Weddington wrote:

Eventually I would like to change this. Ideally, I would like to have a patch for avr-size where it can be given a parameter to produce this output on it's own. It would also have to have another parameter to give the processor type, just as in the script. Another ideal, would be for the toolchain to embed the *exact* processor type within the ELF file itself (right now the ELF file just reports that it's an AVR, not the exact type). That way avr-size can get this information from the file.

Ok, so I decided to take a quick crack at it.

Attached is a draft patch to binutils 2.16.1 to implement part of it. This patch will allow avr-size to report the memory sizes in the same kind of format as the avr-mem.sh script. You can use either -C, or --format=avr. Also, this is set to the default format. Note that the patch also generates 3 warnings that, so far, seem to be benign. But I eventually want to get rid of them.

However, this will not yet report percentage used. It does not accept an additional parameter for specifying the device. This is next.

Setting the device type in the ELF file is a little more complicated. It looks like the infrastructure should already be in place; it looks like it can set the base architecture (avr1,avr2,avr3,avr4,avr5), but it doesn't yet set the device. I'll have to talk to either Denis Chertykov or Marek Michalkiewicz (AVR port maintainers) on what would be the best way to go about doing this. But this part will have to be done later.

Eric
--- binutils-2.16.1/binutils/size.c     Thu Mar  3 04:46:12 2005
+++ binutils-2.16.1-new/binutils/size.c Fri Dec 30 13:07:47 2005
@@ -33,9 +33,18 @@
 #include "libiberty.h"
 #include "getopt.h"
 
-#ifndef BSD_DEFAULT
-#define BSD_DEFAULT 1
-#endif
+typedef enum
+{
+    format_sysv = 0,
+    format_bsd = 1,
+    format_avr = 2,
+} format_type_t;
+
+
+#define FORMAT_DEFAULT_SYSV 0
+#define FORMAT_DEFAULT_BSD 0
+#define FORMAT_DEFAULT_AVR 1
+
 
 /* Program options.  */
 
@@ -45,7 +54,8 @@ enum
   }
 radix = decimal;
 
-int berkeley_format = BSD_DEFAULT;     /* 0 means use AT&T-style output.  */
+/* Set default format. */
+format_type_t format = format_avr;
 int show_version = 0;
 int show_help = 0;
 int show_totals = 0;
@@ -81,15 +91,17 @@ usage (FILE *stream, int status)
   fprintf (stream, _(" Displays the sizes of sections inside binary files\n"));
   fprintf (stream, _(" If no input file(s) are specified, a.out is 
assumed\n"));
   fprintf (stream, _(" The options are:\n\
-  -A|-B     --format={sysv|berkeley}  Select output style (default is %s)\n\
+  -A|-B|-C  --format={sysv|berkeley|avr}  Select output style (default is 
%s)\n\
   -o|-d|-x  --radix={8|10|16}         Display numbers in octal, decimal or 
hex\n\
   -t        --totals                  Display the total sizes (Berkeley 
only)\n\
             --target=<bfdname>        Set the binary file format\n\
   -h        --help                    Display this information\n\
   -v        --version                 Display the program's version\n\
 \n"),
-#if BSD_DEFAULT
+#if FORMAT_DEFAULT_BSD
   "berkeley"
+#elif FORMAT_DEFAULT_AVR
+  "avr"
 #else
   "sysv"
 #endif
@@ -134,7 +146,7 @@ main (int argc, char **argv)
   bfd_init ();
   set_default_bfd_target ();
 
-  while ((c = getopt_long (argc, argv, "ABHhVvdfotx", long_options,
+  while ((c = getopt_long (argc, argv, "ABCHhVvdfotx", long_options,
                           (int *) 0)) != EOF)
     switch (c)
       {
@@ -143,12 +155,16 @@ main (int argc, char **argv)
          {
          case 'B':
          case 'b':
-           berkeley_format = 1;
+           format = format_bsd;
            break;
          case 'S':
          case 's':
-           berkeley_format = 0;
+           format = format_sysv;
            break;
+      case 'A':
+      case 'a':
+        format = format_avr;
+        break;
          default:
            non_fatal (_("invalid argument to --format: %s"), optarg);
            usage (stderr, 1);
@@ -183,11 +199,14 @@ main (int argc, char **argv)
        break;
 
       case 'A':
-       berkeley_format = 0;
+       format = format_sysv;
        break;
       case 'B':
-       berkeley_format = 1;
+       format = format_bsd;
        break;
+      case 'C':
+    format = format_avr;
+    break;
       case 'v':
       case 'V':
        show_version = 1;
@@ -233,7 +252,7 @@ main (int argc, char **argv)
     for (; optind < argc;)
       display_file (argv[optind++]);
 
-  if (show_totals && berkeley_format)
+  if (show_totals && format == format_bsd)
     {
       bfd_size_type total = total_textsize + total_datasize + total_bsssize;
 
@@ -537,11 +556,87 @@ print_sysv_format (bfd *file)
   printf ("\n\n");
 }
 
+
+static void
+print_avr_format (bfd *file)
+{
+  char avr_device[20] = "Unknown";
+  int progmax = 0;
+  int datamax = 0;
+  int eeprommax = 0;
+  asection *section; 
+  bfd_size_type datasize = 0;
+  bfd_size_type textsize = 0;
+  bfd_size_type bsssize = 0;
+  bfd_size_type bootloadersize = 0;
+  bfd_size_type noinitsize = 0;
+  bfd_size_type eepromsize = 0;
+  
+  
+  if ((section = bfd_get_section_by_name (file, ".data")) != NULL)
+    datasize = bfd_section_size (file, section);
+  if ((section = bfd_get_section_by_name (file, ".text")) != NULL)
+    textsize = bfd_section_size (file, section);
+  if ((section = bfd_get_section_by_name (file, ".bss")) != NULL)
+    bsssize = bfd_section_size (file, section);
+  if ((section = bfd_get_section_by_name (file, ".bootloader")) != NULL)
+    bootloadersize = bfd_section_size (file, section);
+  if ((section = bfd_get_section_by_name (file, ".noinit")) != NULL)
+    noinitsize = bfd_section_size (file, section);
+  if ((section = bfd_get_section_by_name (file, ".eeprom")) != NULL)
+    eepromsize = bfd_section_size (file, section);
+  
+  bfd_size_type text = textsize + datasize + bootloadersize;
+  bfd_size_type data = datasize + bsssize + noinitsize;
+  bfd_size_type eeprom = eepromsize;
+  
+  printf ("AVR Memory Usage\n"
+          "----------------\n"
+          "Device: %s\n\n", avr_device);
+  
+  /* Text size */
+  printf ("Program:%8ld bytes", text);
+  if (progmax > 0)
+  {
+    printf (" (%2.1lf%% Full)", (text / progmax) * 100);
+  }
+  printf ("\n(.text + .data + .bootloader)\n\n");
+  
+  /* Data size */
+  printf ("Data:   %8ld bytes", data);
+  if (datamax > 0)
+  {
+    printf (" (%2.1lf%% Full)", (data / datamax) * 100);
+  }
+  printf ("\n(.data + .bss + .noinit)\n\n");
+  
+  /* EEPROM size */
+  if (eeprom > 0) 
+  { 
+    printf ("EEPROM: %8ld bytes", eeprom);
+    if (eeprommax > 0)
+    {
+      printf (" (%2.1lf%% Full)", (eeprom / eeprommax) * 100);
+    }
+    printf ("\n(.eeprom)\n\n");
+  }
+}
+
+
 static void
 print_sizes (bfd *file)
 {
-  if (berkeley_format)
-    print_berkeley_format (file);
-  else
-    print_sysv_format (file);
+  switch (format)
+  {
+    case format_sysv:
+      print_sysv_format (file);
+      break;
+    case format_bsd:
+      print_berkeley_format (file);
+      break;
+    case format_avr:
+    default:
+      print_avr_format (file);
+      break;
+  }
 }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]