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
10 -#define BSD_DEFAULT 1
19 +/* Set the default format. */
20 +#define FORMAT_DEFAULT_SYSV 0
21 +#define FORMAT_DEFAULT_BSD 1
22 +#define FORMAT_DEFAULT_AVR 0
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"
36 /* Program options. */
39 @@ -47,9 +68,8 @@ static enum
43 -/* 0 means use AT&T-style output. */
44 -static int berkeley_format = BSD_DEFAULT;
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,163 @@ static bfd_size_type total_textsize;
51 /* Program exit status. */
52 static int return_code = 0;
55 +/* AVR Size specific stuff */
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
83 + {"atmega2560", AVR256K, AVR8K, AVR4K},
84 + {"atmega2561", AVR256K, AVR8K, AVR4K},
85 + {"atxmega256a3", AVR256K, AVR8K, AVR4K},
86 + {"atxmega256a3b", AVR256K, AVR8K, AVR4K},
87 + {"atxmega256a3v", AVR256K, AVR8K, AVR4K},
89 + {"at43usb320", AVR128K, 608UL, 0},
90 + {"at90can128", AVR128K, AVR4K, AVR4K},
91 + {"at90usb1286", AVR128K, AVR8K, AVR4K},
92 + {"at90usb1287", AVR128K, AVR8K, AVR4K},
93 + {"atmega128", AVR128K, AVR4K, AVR4K},
94 + {"atmega1280", AVR128K, AVR8K, AVR4K},
95 + {"atmega1281", AVR128K, AVR8K, AVR4K},
96 + {"atmega1284P", AVR128K, AVR16K, AVR4K},
97 + {"atmega103", AVR128K, 4000UL, AVR4K},
98 + {"atxmega128a1", AVR128K, AVR8K, AVR2K},
99 + {"atxmega128a3", AVR128K, AVR16K, AVR2K},
101 + {"at90can64", AVR64K, AVR4K, AVR2K},
102 + {"at90usb646", AVR64K, AVR4K, AVR2K},
103 + {"at90usb647", AVR64K, AVR4K, AVR2K},
104 + {"atmega64", AVR64K, AVR4K, AVR2K},
105 + {"atmega640", AVR64K, AVR8K, AVR4K},
106 + {"atmega644", AVR64K, AVR4K, AVR2K},
107 + {"atmega644p", AVR64K, AVR4K, AVR2K},
108 + {"atmega645", AVR64K, AVR4K, AVR2K},
109 + {"atmega6450", AVR64K, AVR4K, AVR2K},
110 + {"atmega649", AVR64K, AVR4K, AVR2K},
111 + {"atmega6490", AVR64K, AVR4K, AVR2K},
112 + {"atxmega64a1", AVR64K, AVR4K, AVR2K},
113 + {"atxmega64a3", AVR64K, AVR4K, AVR2K},
115 + {"atmega406", AVR40K, AVR2K, AVR512},
117 + {"at90can32", AVR32K, AVR2K, AVR1K},
118 + {"at94k", AVR32K, AVR4K, 0},
119 + {"atmega32", AVR32K, AVR2K, AVR1K},
120 + {"atmega323", AVR32K, AVR2K, AVR1K},
121 + {"atmega324p", AVR32K, AVR2K, AVR1K},
122 + {"atmega325", AVR32K, AVR2K, AVR1K},
123 + {"atmega325p", AVR32K, AVR2K, AVR1K},
124 + {"atmega3250", AVR32K, AVR2K, AVR1K},
125 + {"atmega3250p", AVR32K, AVR2K, AVR1K},
126 + {"atmega328p", AVR32K, AVR2K, AVR1K},
127 + {"atmega329", AVR32K, AVR2K, AVR1K},
128 + {"atmega329p", AVR32K, AVR2K, AVR1K},
129 + {"atmega3290", AVR32K, AVR2K, AVR1K},
130 + {"atmega3290p", AVR32K, AVR2K, AVR1K},
131 + {"atmega32hvb", AVR32K, AVR2K, AVR1K},
132 + {"atmega32c1", AVR32K, AVR2K, AVR1K},
133 + {"atmega32m1", AVR32K, AVR2K, AVR1K},
134 + {"atmega32u4", AVR32K, 2560UL, AVR1K},
135 + {"atmega32u6", AVR32K, 2560UL, AVR1K},
137 + {"at43usb355", AVR24K, 1120, 0},
139 + {"at76c711", AVR16K, AVR2K, 0},
140 + {"at90pwm216", AVR16K, AVR1K, AVR512},
141 + {"at90pwm316", AVR16K, AVR1K, AVR512},
142 + {"at90usb162", AVR16K, AVR512, AVR512},
143 + {"atmega16", AVR16K, AVR1K, AVR512},
144 + {"atmega161", AVR16K, AVR1K, AVR512},
145 + {"atmega162", AVR16K, AVR1K, AVR512},
146 + {"atmega163", AVR16K, AVR1K, AVR512},
147 + {"atmega164", AVR16K, AVR1K, AVR512},
148 + {"atmega164p", AVR16K, AVR1K, AVR512},
149 + {"atmega165", AVR16K, AVR1K, AVR512},
150 + {"atmega165p", AVR16K, AVR1K, AVR512},
151 + {"atmega168", AVR16K, AVR1K, AVR512},
152 + {"atmega168p", AVR16K, AVR1K, AVR512},
153 + {"atmega169", AVR16K, AVR1K, AVR512},
154 + {"atmega169p", AVR16K, AVR1K, AVR512},
155 + {"atmega16u4", AVR16K, 1280UL, AVR512},
156 + {"attiny167", AVR16K, AVR512, AVR512},
158 + {"at90c8534", AVR8K, 352, AVR512},
159 + {"at90pwm1", AVR8K, AVR512, AVR512},
160 + {"at90pwm2", AVR8K, AVR512, AVR512},
161 + {"at90pwm2b", AVR8K, AVR512, AVR512},
162 + {"at90pwm3", AVR8K, AVR512, AVR512},
163 + {"at90pwm3b", AVR8K, AVR512, AVR512},
164 + {"at90s8515", AVR8K, AVR512, AVR512},
165 + {"at90s8535", AVR8K, AVR512, AVR512},
166 + {"at90usb82", AVR8K, AVR512, AVR512},
167 + {"atmega8", AVR8K, AVR1K, AVR512},
168 + {"atmega8515", AVR8K, AVR512, AVR512},
169 + {"atmega8535", AVR8K, AVR512, AVR512},
170 + {"atmega88", AVR8K, AVR1K, AVR512},
171 + {"atmega88p", AVR8K, AVR1K, AVR512},
172 + {"attiny84", AVR8K, AVR512, AVR512},
173 + {"attiny85", AVR8K, AVR512, AVR512},
174 + {"attiny861", AVR8K, AVR512, AVR512},
175 + {"attiny88", AVR8K, AVR256, AVR64},
177 + {"at90s4414", AVR4K, 352, AVR256},
178 + {"at90s4433", AVR4K, AVR128, AVR256},
179 + {"at90s4434", AVR4K, 352, AVR256},
180 + {"atmega48", AVR4K, AVR512, AVR256},
181 + {"atmega48p", AVR4K, AVR512, AVR256},
182 + {"attiny43u", AVR4K, AVR256, AVR64},
183 + {"attiny44", AVR4K, AVR256, AVR256},
184 + {"attiny45", AVR4K, AVR256, AVR256},
185 + {"attiny461", AVR4K, AVR256, AVR256},
186 + {"attiny48", AVR4K, AVR256, AVR64},
188 + {"at86rf401", AVR2K, 224, AVR128},
189 + {"at90s2313", AVR2K, AVR128, AVR128},
190 + {"at90s2323", AVR2K, AVR128, AVR128},
191 + {"at90s2333", AVR2K, 224, AVR128},
192 + {"at90s2343", AVR2K, AVR128, AVR128},
193 + {"attiny22", AVR2K, 224, AVR128},
194 + {"attiny2313", AVR2K, AVR128, AVR128},
195 + {"attiny24", AVR2K, AVR128, AVR128},
196 + {"attiny25", AVR2K, AVR128, AVR128},
197 + {"attiny26", AVR2K, AVR128, AVR128},
198 + {"attiny261", AVR2K, AVR128, AVR128},
199 + {"attiny28", AVR2K, 0, 0},
201 + {"at90s1200", AVR1K, 0, AVR64},
202 + {"attiny11", AVR1K, 0, AVR64},
203 + {"attiny12", AVR1K, 0, AVR64},
204 + {"attiny13", AVR1K, AVR64, AVR64},
205 + {"attiny15", AVR1K, 0, AVR64},
208 +static char *avrmcu = NULL;
211 static char *target = NULL;
213 /* Forward declarations. */
214 @@ -78,7 +247,8 @@ usage (FILE *stream, int status)
215 fprintf (stream, _(" Displays the sizes of sections inside binary files\n"));
216 fprintf (stream, _(" If no input file(s) are specified, a.out is assumed\n"));
217 fprintf (stream, _(" The options are:\n\
218 - -A|-B --format={sysv|berkeley} Select output style (default is %s)\n\
219 + -A|-B|-C --format={sysv|berkeley|avr} Select output style (default is %s)\n\
220 + --mcu=<avrmcu> MCU name for AVR format only\n\
221 -o|-d|-x --radix={8|10|16} Display numbers in octal, decimal or hex\n\
222 -t --totals Display the total sizes (Berkeley only)\n\
223 --common Display total size for *COM* syms\n\
224 @@ -87,11 +257,7 @@ usage (FILE *stream, int status)
225 -h --help Display this information\n\
226 -v --version Display the program's version\n\
235 list_supported_targets (program_name, stream);
236 if (REPORT_BUGS_TO[0] && status == 0)
237 @@ -102,6 +268,7 @@ usage (FILE *stream, int status)
238 #define OPTION_FORMAT (200)
239 #define OPTION_RADIX (OPTION_FORMAT + 1)
240 #define OPTION_TARGET (OPTION_RADIX + 1)
241 +#define OPTION_MCU (OPTION_TARGET + 1)
243 static struct option long_options[] =
245 @@ -109,6 +276,7 @@ static struct option long_options[] =
246 {"format", required_argument, 0, OPTION_FORMAT},
247 {"radix", required_argument, 0, OPTION_RADIX},
248 {"target", required_argument, 0, OPTION_TARGET},
249 + {"mcu", required_argument, 0, 203},
250 {"totals", no_argument, &show_totals, 1},
251 {"version", no_argument, &show_version, 1},
252 {"help", no_argument, &show_help, 1},
253 @@ -140,7 +308,7 @@ main (int argc, char **argv)
255 set_default_bfd_target ();
257 - while ((c = getopt_long (argc, argv, "ABHhVvdfotx", long_options,
258 + while ((c = getopt_long (argc, argv, "ABCHhVvdfotx", long_options,
262 @@ -149,11 +317,15 @@ main (int argc, char **argv)
266 - berkeley_format = 1;
267 + format = format_bsd;
271 - berkeley_format = 0;
272 + format = format_sysv;
276 + format = format_avr;
279 non_fatal (_("invalid argument to --format: %s"), optarg);
280 @@ -161,6 +333,10 @@ main (int argc, char **argv)
291 @@ -189,11 +365,14 @@ main (int argc, char **argv)
295 - berkeley_format = 0;
296 + format = format_sysv;
299 - berkeley_format = 1;
300 + format = format_bsd;
303 + format = format_avr;
308 @@ -239,7 +418,7 @@ main (int argc, char **argv)
309 for (; optind < argc;)
310 display_file (argv[optind++]);
312 - if (show_totals && berkeley_format)
313 + if (show_totals && format == format_bsd)
315 bfd_size_type total = total_textsize + total_datasize + total_bsssize;
317 @@ -600,13 +779,117 @@ print_sysv_format (bfd *file)
322 +static avr_device_t *
323 +avr_find_device (void)
326 + if (avrmcu != NULL)
328 + for (i = 0; i < sizeof(avr) / sizeof(avr[0]); i++)
330 + if (strcmp(avr[i].name, avrmcu) == 0)
343 +print_avr_format (bfd *file)
345 + char *avr_name = "Unknown";
350 + bfd_size_type datasize = 0;
351 + bfd_size_type textsize = 0;
352 + bfd_size_type bsssize = 0;
353 + bfd_size_type bootloadersize = 0;
354 + bfd_size_type noinitsize = 0;
355 + bfd_size_type eepromsize = 0;
357 + avr_device_t *avrdevice = avr_find_device();
358 + if (avrdevice != NULL)
360 + avr_name = avrdevice->name;
361 + flashmax = avrdevice->flash;
362 + rammax = avrdevice->ram;
363 + eeprommax = avrdevice->eeprom;
366 + if ((section = bfd_get_section_by_name (file, ".data")) != NULL)
367 + datasize = bfd_section_size (file, section);
368 + if ((section = bfd_get_section_by_name (file, ".text")) != NULL)
369 + textsize = bfd_section_size (file, section);
370 + if ((section = bfd_get_section_by_name (file, ".bss")) != NULL)
371 + bsssize = bfd_section_size (file, section);
372 + if ((section = bfd_get_section_by_name (file, ".bootloader")) != NULL)
373 + bootloadersize = bfd_section_size (file, section);
374 + if ((section = bfd_get_section_by_name (file, ".noinit")) != NULL)
375 + noinitsize = bfd_section_size (file, section);
376 + if ((section = bfd_get_section_by_name (file, ".eeprom")) != NULL)
377 + eepromsize = bfd_section_size (file, section);
379 + bfd_size_type text = textsize + datasize + bootloadersize;
380 + bfd_size_type data = datasize + bsssize + noinitsize;
381 + bfd_size_type eeprom = eepromsize;
383 + printf ("AVR Memory Usage\n"
384 + "----------------\n"
385 + "Device: %s\n\n", avr_name);
388 + printf ("Program:%8ld bytes", text);
391 + printf (" (%2.1f%% Full)", ((float)text / flashmax) * 100);
393 + printf ("\n(.text + .data + .bootloader)\n\n");
396 + printf ("Data: %8ld bytes", data);
399 + printf (" (%2.1f%% Full)", ((float)data / rammax) * 100);
401 + printf ("\n(.data + .bss + .noinit)\n\n");
406 + printf ("EEPROM: %8ld bytes", eeprom);
409 + printf (" (%2.1f%% Full)", ((float)eeprom / eeprommax) * 100);
411 + printf ("\n(.eeprom)\n\n");
417 print_sizes (bfd *file)
420 calculate_common_size (file);
421 - if (berkeley_format)
422 - print_berkeley_format (file);
424 - print_sysv_format (file);
428 + print_sysv_format (file);
431 + print_berkeley_format (file);
435 + print_avr_format (file);