]> git.pld-linux.org Git - packages/crossavr-binutils.git/blob - crossavr-binutils-avr-size.patch
- patch adds pretty print format, known from WinAVR project:
[packages/crossavr-binutils.git] / crossavr-binutils-avr-size.patch
1 AVR specific only
2 --------------------------------------------------------------------------------
3 --- binutils/size.c     2007-08-06 13:56:14.000000000 -0600
4 +++ binutils/size.c     2007-09-13 09:13:10.281250000 -0600
5 @@ -35,10 +35,31 @@
6  #include "getopt.h"
7  #include "bucomm.h"
8  
9 -#ifndef BSD_DEFAULT
10 -#define BSD_DEFAULT 1
11 +typedef enum
12 +{
13 +    format_sysv = 0,
14 +    format_bsd = 1,
15 +    format_avr = 2,
16 +} format_type_t;
17 +
18 +
19 +/* Set the default format. */
20 +#define FORMAT_DEFAULT_SYSV 0
21 +#define FORMAT_DEFAULT_BSD 1
22 +#define FORMAT_DEFAULT_AVR 0
23 +
24 +#if FORMAT_DEFAULT_SYSV
25 +    #define FORMAT_DEFAULT format_sysv
26 +    #define FORMAT_NAME "sysv"
27 +#elif FORMAT_DEFAULT_BSD
28 +    #define FORMAT_DEFAULT format_bsd
29 +    #define FORMAT_NAME "berkeley"
30 +#elif FORMAT_DEFAULT_AVR
31 +    #define FORMAT_DEFAULT format_avr
32 +    #define FORMAT_NAME "avr"
33  #endif
34  
35 +
36  /* Program options.  */
37  
38  static enum
39 @@ -47,9 +68,8 @@ static enum
40    }
41  radix = decimal;
42  
43 -/* 0 means use AT&T-style output.  */
44 -static int berkeley_format = BSD_DEFAULT;
45  
46 +format_type_t format = FORMAT_DEFAULT;
47  static int show_version = 0;
48  static int show_help = 0;
49  static int show_totals = 0;
50 @@ -63,6 +83,156 @@ static bfd_size_type total_textsize;
51  /* Program exit status.  */
52  static int return_code = 0;
53  
54 +
55 +/* AVR Size specific stuff */
56 +
57 +#define AVR64 64UL
58 +#define AVR128 128UL
59 +#define AVR256 256UL
60 +#define AVR512 512UL
61 +#define AVR1K 1024UL
62 +#define AVR2K 2048UL
63 +#define AVR4K 4096UL
64 +#define AVR8K 8192UL
65 +#define AVR16K 16384UL
66 +#define AVR24K 24576UL
67 +#define AVR32K 32768UL
68 +#define AVR40K 40960UL
69 +#define AVR64K 65536UL
70 +#define AVR128K 131072UL
71 +#define AVR256K 262144UL
72 +
73 +typedef struct
74 +{
75 +    char *name;
76 +       long flash;
77 +       long ram;
78 +       long eeprom;
79 +} avr_device_t;
80 +
81 +avr_device_t avr[] =
82 +{
83 +       {"atmega2560",  AVR256K, AVR8K,  AVR4K},
84 +       {"atmega2561",  AVR256K, AVR8K,  AVR4K},
85 +
86 +       {"at43usb320",  AVR128K, 608UL,    0},
87 +       {"at90can128",  AVR128K, AVR4K,  AVR4K},
88 +       {"at90usb1286", AVR128K, AVR8K,  AVR4K},
89 +       {"at90usb1287", AVR128K, AVR8K,  AVR4K},
90 +       {"atmega128",   AVR128K, AVR4K,  AVR4K},
91 +       {"atmega1280",  AVR128K, AVR8K,  AVR4K},
92 +       {"atmega1281",  AVR128K, AVR8K,  AVR4K},
93 +       {"atmega1284P", AVR128K, AVR16K, AVR4K},
94 +       {"atmega103",   AVR128K, 4000UL,   AVR4K},
95 +       {"atxmega128a1",AVR128K, AVR8K,  AVR2K},
96 +
97 +       {"at90can64",   AVR64K,  AVR4K,  AVR2K},
98 +       {"at90usb646",  AVR64K,  AVR4K,  AVR2K},
99 +       {"at90usb647",  AVR64K,  AVR4K,  AVR2K},
100 +       {"atmega64",    AVR64K,  AVR4K,  AVR2K},
101 +       {"atmega640",   AVR64K,  AVR8K,  AVR4K},
102 +       {"atmega644",   AVR64K,  AVR4K,  AVR2K},
103 +       {"atmega644p",  AVR64K,  AVR4K,  AVR2K},
104 +       {"atmega645",   AVR64K,  AVR4K,  AVR2K},
105 +       {"atmega6450",  AVR64K,  AVR4K,  AVR2K},
106 +       {"atmega649",   AVR64K,  AVR4K,  AVR2K},
107 +       {"atmega6490",  AVR64K,  AVR4K,  AVR2K},
108 +       {"atxmega64a1", AVR64K,  AVR4K,  AVR2K},
109 +
110 +       {"atmega406",   AVR40K,  AVR512, AVR2K},
111 +
112 +       {"at90can32",   AVR32K,  AVR2K,  AVR1K},
113 +       {"at94k",       AVR32K,  AVR4K,  0},
114 +       {"atmega32",    AVR32K,  AVR2K,  AVR1K},
115 +       {"atmega323",   AVR32K,  AVR2K,  AVR1K},
116 +       {"atmega324p",  AVR32K,  AVR2K,  AVR1K},
117 +       {"atmega325",   AVR32K,  AVR2K,  AVR1K},
118 +       {"atmega325p",  AVR32K,  AVR2K,  AVR1K},
119 +       {"atmega3250",  AVR32K,  AVR2K,  AVR1K},
120 +       {"atmega3250p", AVR32K,  AVR2K,  AVR1K},
121 +       {"atmega328p",  AVR32K,  AVR2K,  AVR1K},
122 +       {"atmega329",   AVR32K,  AVR2K,  AVR1K},
123 +       {"atmega329p",  AVR32K,  AVR2K,  AVR1K},
124 +       {"atmega3290",  AVR32K,  AVR2K,  AVR1K},
125 +       {"atmega3290p", AVR32K,  AVR2K,  AVR1K},
126 +       {"atmega32hvb", AVR32K,  AVR2K,  AVR1K},
127 +       {"atmega32c1",  AVR32K,  AVR2K,  AVR1K},
128 +       {"atmega32m1",  AVR32K,  AVR2K,  AVR1K},
129 +       {"atmega32u4",  AVR32K,  2560UL, AVR1K},
130 +
131 +       {"at43usb355",  AVR24K,  1120,   0},
132 +
133 +       {"at76c711",    AVR16K,  AVR2K,  0},
134 +       {"at90pwm216",  AVR16K,  AVR1K,  AVR512},
135 +       {"at90pwm316",  AVR16K,  AVR1K,  AVR512},
136 +       {"at90usb162",  AVR16K,  AVR512, AVR512},
137 +       {"atmega16",    AVR16K,  AVR1K,  AVR512},
138 +       {"atmega161",   AVR16K,  AVR1K,  AVR512},
139 +       {"atmega162",   AVR16K,  AVR1K,  AVR512},
140 +       {"atmega163",   AVR16K,  AVR1K,  AVR512},
141 +       {"atmega164",   AVR16K,  AVR1K,  AVR512},
142 +       {"atmega164p",  AVR16K,  AVR1K,  AVR512},
143 +       {"atmega165",   AVR16K,  AVR1K,  AVR512},
144 +       {"atmega165p",  AVR16K,  AVR1K,  AVR512},
145 +       {"atmega168",   AVR16K,  AVR1K,  AVR512},
146 +       {"atmega168p",  AVR16K,  AVR1K,  AVR512},
147 +       {"atmega169",   AVR16K,  AVR1K,  AVR512},
148 +       {"atmega169p",  AVR16K,  AVR1K,  AVR512},
149 +       {"attiny167",   AVR16K,  AVR512, AVR512},
150 +
151 +       {"at90c8534",   AVR8K,   352,    AVR512},
152 +       {"at90pwm1",    AVR8K,   AVR512, AVR512},
153 +       {"at90pwm2",    AVR8K,   AVR512, AVR512},
154 +       {"at90pwm2b",   AVR8K,   AVR512, AVR512},
155 +       {"at90pwm3",    AVR8K,   AVR512, AVR512},
156 +       {"at90pwm3b",   AVR8K,   AVR512, AVR512},
157 +       {"at90s8515",   AVR8K,   AVR512, AVR512},
158 +       {"at90s8535",   AVR8K,   AVR512, AVR512},
159 +       {"at90usb82",   AVR8K,   AVR512, AVR512},
160 +       {"atmega8",     AVR8K,   AVR1K,  AVR512},
161 +       {"atmega8515",  AVR8K,   AVR512, AVR512},
162 +       {"atmega8535",  AVR8K,   AVR512, AVR512},
163 +       {"atmega88",    AVR8K,   AVR1K,  AVR512},
164 +       {"atmega88p",   AVR8K,   AVR1K,  AVR512},
165 +       {"attiny84",    AVR8K,   AVR512, AVR512},
166 +       {"attiny85",    AVR8K,   AVR512, AVR512},
167 +       {"attiny861",   AVR8K,   AVR512, AVR512},
168 +       {"attiny88",    AVR8K,   AVR256, AVR64},
169 +
170 +       {"at90s4414",   AVR4K,   352,    AVR256},
171 +       {"at90s4433",   AVR4K,   AVR128, AVR256},
172 +       {"at90s4434",   AVR4K,   352,    AVR256},
173 +       {"atmega48",    AVR4K,   AVR512, AVR256},
174 +       {"atmega48p",   AVR4K,   AVR512, AVR256},
175 +       {"attiny43u",   AVR4K,   AVR256, AVR64},
176 +       {"attiny44",    AVR4K,   AVR256, AVR256},
177 +       {"attiny45",    AVR4K,   AVR256, AVR256},
178 +       {"attiny461",   AVR4K,   AVR256, AVR256},
179 +       {"attiny48",    AVR4K,   AVR256, AVR64},
180 +
181 +       {"at86rf401",   AVR2K,   224,    AVR128},
182 +       {"at90s2313",   AVR2K,   AVR128, AVR128},
183 +       {"at90s2323",   AVR2K,   AVR128, AVR128},
184 +       {"at90s2333",   AVR2K,   224,    AVR128},
185 +       {"at90s2343",   AVR2K,   AVR128, AVR128},
186 +       {"attiny22",    AVR2K,   224,    AVR128},
187 +       {"attiny2313",  AVR2K,   AVR128, AVR128},
188 +       {"attiny24",    AVR2K,   AVR128, AVR128},
189 +       {"attiny25",    AVR2K,   AVR128, AVR128},
190 +       {"attiny26",    AVR2K,   AVR128, AVR128},
191 +       {"attiny261",   AVR2K,   AVR128, AVR128},
192 +       {"attiny28",    AVR2K,   0,      0},
193 +
194 +       {"at90s1200",   AVR1K,   0,      AVR64},
195 +       {"attiny11",    AVR1K,   0,      AVR64},
196 +       {"attiny12",    AVR1K,   0,      AVR64},
197 +       {"attiny13",    AVR1K,   AVR64,  AVR64},
198 +       {"attiny15",    AVR1K,   0,      AVR64},
199 +};
200 +
201 +static char *avrmcu = NULL;
202 +
203 +
204  static char *target = NULL;
205  
206  /* Forward declarations.  */
207 @@ -78,7 +240,8 @@ usage (FILE *stream, int status)
208    fprintf (stream, _(" Displays the sizes of sections inside binary files\n"));
209    fprintf (stream, _(" If no input file(s) are specified, a.out is assumed\n"));
210    fprintf (stream, _(" The options are:\n\
211 -  -A|-B     --format={sysv|berkeley}  Select output style (default is %s)\n\
212 +  -A|-B|-C  --format={sysv|berkeley|avr}  Select output style (default is %s)\n\
213 +            --mcu=<avrmcu>            MCU name for AVR format only\n\
214    -o|-d|-x  --radix={8|10|16}         Display numbers in octal, decimal or hex\n\
215    -t        --totals                  Display the total sizes (Berkeley only)\n\
216              --common                  Display total size for *COM* syms\n\
217 @@ -87,11 +250,7 @@ usage (FILE *stream, int status)
218    -h        --help                    Display this information\n\
219    -v        --version                 Display the program's version\n\
220  \n"),
221 -#if BSD_DEFAULT
222 -  "berkeley"
223 -#else
224 -  "sysv"
225 -#endif
226 +FORMAT_NAME
227  );
228    list_supported_targets (program_name, stream);
229    if (REPORT_BUGS_TO[0] && status == 0)
230 @@ -102,6 +261,7 @@ usage (FILE *stream, int status)
231  #define OPTION_FORMAT (200)
232  #define OPTION_RADIX (OPTION_FORMAT + 1)
233  #define OPTION_TARGET (OPTION_RADIX + 1)
234 +#define OPTION_MCU (OPTION_TARGET + 1) 
235  
236  static struct option long_options[] =
237  {
238 @@ -109,6 +269,7 @@ static struct option long_options[] =
239    {"format", required_argument, 0, OPTION_FORMAT},
240    {"radix", required_argument, 0, OPTION_RADIX},
241    {"target", required_argument, 0, OPTION_TARGET},
242 +  {"mcu", required_argument, 0, 203},
243    {"totals", no_argument, &show_totals, 1},
244    {"version", no_argument, &show_version, 1},
245    {"help", no_argument, &show_help, 1},
246 @@ -140,7 +301,7 @@ main (int argc, char **argv)
247    bfd_init ();
248    set_default_bfd_target ();
249  
250 -  while ((c = getopt_long (argc, argv, "ABHhVvdfotx", long_options,
251 +  while ((c = getopt_long (argc, argv, "ABCHhVvdfotx", long_options,
252                            (int *) 0)) != EOF)
253      switch (c)
254        {
255 @@ -149,11 +310,15 @@ main (int argc, char **argv)
256           {
257           case 'B':
258           case 'b':
259 -           berkeley_format = 1;
260 +           format = format_bsd;
261             break;
262           case 'S':
263           case 's':
264 -           berkeley_format = 0;
265 +           format = format_sysv;
266 +           break;
267 +         case 'A':
268 +         case 'a':
269 +           format = format_avr;
270             break;
271           default:
272             non_fatal (_("invalid argument to --format: %s"), optarg);
273 @@ -161,6 +326,10 @@ main (int argc, char **argv)
274           }
275         break;
276  
277 +      case OPTION_MCU:
278 +       avrmcu = optarg;
279 +       break;
280 +
281        case OPTION_TARGET:
282         target = optarg;
283         break;
284 @@ -189,11 +358,14 @@ main (int argc, char **argv)
285         break;
286  
287        case 'A':
288 -       berkeley_format = 0;
289 +       format = format_sysv;
290         break;
291        case 'B':
292 -       berkeley_format = 1;
293 +       format = format_bsd;
294         break;
295 +      case 'C':
296 +    format = format_avr;
297 +    break;
298        case 'v':
299        case 'V':
300         show_version = 1;
301 @@ -239,7 +411,7 @@ main (int argc, char **argv)
302      for (; optind < argc;)
303        display_file (argv[optind++]);
304  
305 -  if (show_totals && berkeley_format)
306 +  if (show_totals && format == format_bsd)
307      {
308        bfd_size_type total = total_textsize + total_datasize + total_bsssize;
309  
310 @@ -600,13 +772,117 @@ print_sysv_format (bfd *file)
311    printf ("\n\n");
312  }
313  
314 +
315 +static avr_device_t *
316 +avr_find_device (void)
317 +{
318 +  unsigned int i;
319 +  if (avrmcu != NULL)
320 +  {
321 +    for (i = 0; i < sizeof(avr) / sizeof(avr[0]); i++)
322 +    {
323 +      if (strcmp(avr[i].name, avrmcu) == 0)
324 +      {
325 +        /* Match found */
326 +        return (&avr[i]);
327 +      }
328 +    }
329 +  }
330 +  return (NULL);
331 +}
332 +
333 +
334 +
335 +static void
336 +print_avr_format (bfd *file)
337 +{
338 +  char *avr_name = "Unknown";
339 +  int flashmax = 0;
340 +  int rammax = 0;
341 +  int eeprommax = 0;
342 +  asection *section; 
343 +  bfd_size_type datasize = 0;
344 +  bfd_size_type textsize = 0;
345 +  bfd_size_type bsssize = 0;
346 +  bfd_size_type bootloadersize = 0;
347 +  bfd_size_type noinitsize = 0;
348 +  bfd_size_type eepromsize = 0;
349 +
350 +  avr_device_t *avrdevice = avr_find_device();
351 +  if (avrdevice != NULL)
352 +  {
353 +    avr_name = avrdevice->name;
354 +    flashmax = avrdevice->flash;
355 +    rammax = avrdevice->ram;
356 +    eeprommax = avrdevice->eeprom;
357 +  }
358 +
359 +  if ((section = bfd_get_section_by_name (file, ".data")) != NULL)
360 +    datasize = bfd_section_size (file, section);
361 +  if ((section = bfd_get_section_by_name (file, ".text")) != NULL)
362 +    textsize = bfd_section_size (file, section);
363 +  if ((section = bfd_get_section_by_name (file, ".bss")) != NULL)
364 +    bsssize = bfd_section_size (file, section);
365 +  if ((section = bfd_get_section_by_name (file, ".bootloader")) != NULL)
366 +    bootloadersize = bfd_section_size (file, section);
367 +  if ((section = bfd_get_section_by_name (file, ".noinit")) != NULL)
368 +    noinitsize = bfd_section_size (file, section);
369 +  if ((section = bfd_get_section_by_name (file, ".eeprom")) != NULL)
370 +    eepromsize = bfd_section_size (file, section);
371 +  
372 +  bfd_size_type text = textsize + datasize + bootloadersize;
373 +  bfd_size_type data = datasize + bsssize + noinitsize;
374 +  bfd_size_type eeprom = eepromsize;
375 +  
376 +  printf ("AVR Memory Usage\n"
377 +          "----------------\n"
378 +          "Device: %s\n\n", avr_name);
379 +  
380 +  /* Text size */
381 +  printf ("Program:%8ld bytes", text);
382 +  if (flashmax > 0)
383 +  {
384 +    printf (" (%2.1f%% Full)", ((float)text / flashmax) * 100);
385 +  }
386 +  printf ("\n(.text + .data + .bootloader)\n\n");
387 +  
388 +  /* Data size */
389 +  printf ("Data:   %8ld bytes", data);
390 +  if (rammax > 0)
391 +  {
392 +    printf (" (%2.1f%% Full)", ((float)data / rammax) * 100);
393 +  }
394 +  printf ("\n(.data + .bss + .noinit)\n\n");
395 +  
396 +  /* EEPROM size */
397 +  if (eeprom > 0) 
398 +  { 
399 +    printf ("EEPROM: %8ld bytes", eeprom);
400 +    if (eeprommax > 0)
401 +    {
402 +      printf (" (%2.1f%% Full)", ((float)eeprom / eeprommax) * 100);
403 +    }
404 +    printf ("\n(.eeprom)\n\n");
405 +  }
406 +}
407 +
408 +
409  static void
410  print_sizes (bfd *file)
411  {
412    if (show_common)
413      calculate_common_size (file);
414 -  if (berkeley_format)
415 -    print_berkeley_format (file);
416 -  else
417 -    print_sysv_format (file);
418 +  switch (format)
419 +  {
420 +    case format_sysv:
421 +      print_sysv_format (file);
422 +      break;
423 +    case format_bsd:
424 +      print_berkeley_format (file);
425 +      break;
426 +    case format_avr:
427 +    default:
428 +      print_avr_format (file);
429 +      break;
430 +  }
431  }
This page took 0.153482 seconds and 4 git commands to generate.