1 diff --git a/binutils/size.c b/binutils/size.c
2 index 3697087714..f99d45a6bf 100644
5 @@ -51,7 +51,8 @@ enum output_format
13 static enum output_format selected_output_format =
15 @@ -74,6 +75,246 @@ static bfd_size_type total_textsize;
16 /* Program exit status. */
17 static int return_code = 0;
20 +/* AVR Size specific stuff */
30 +#define AVR16K 16384UL
31 +#define AVR20K 20480UL
32 +#define AVR24K 24576UL
33 +#define AVR32K 32768UL
34 +#define AVR36K 36864UL
35 +#define AVR40K 40960UL
36 +#define AVR64K 65536UL
37 +#define AVR68K 69632UL
38 +#define AVR128K 131072UL
39 +#define AVR136K 139264UL
40 +#define AVR200K 204800UL
41 +#define AVR256K 262144UL
42 +#define AVR264K 270336UL
54 + {"atxmega256a3", AVR264K, AVR16K, AVR4K},
55 + {"atxmega256a3b", AVR264K, AVR16K, AVR4K},
56 + {"atxmega256d3", AVR264K, AVR16K, AVR4K},
58 + {"atmega2560", AVR256K, AVR8K, AVR4K},
59 + {"atmega2561", AVR256K, AVR8K, AVR4K},
61 + {"atxmega192a3", AVR200K, AVR16K, AVR2K},
62 + {"atxmega192d3", AVR200K, AVR16K, AVR2K},
64 + {"atxmega128a1", AVR136K, AVR8K, AVR2K},
65 + {"atxmega128a1u", AVR136K, AVR8K, AVR2K},
66 + {"atxmega128a3", AVR136K, AVR8K, AVR2K},
67 + {"atxmega128d3", AVR136K, AVR8K, AVR2K},
69 + {"at43usb320", AVR128K, 608UL, 0UL},
70 + {"at90can128", AVR128K, AVR4K, AVR4K},
71 + {"at90usb1286", AVR128K, AVR8K, AVR4K},
72 + {"at90usb1287", AVR128K, AVR8K, AVR4K},
73 + {"atmega128", AVR128K, AVR4K, AVR4K},
74 + {"atmega1280", AVR128K, AVR8K, AVR4K},
75 + {"atmega1281", AVR128K, AVR8K, AVR4K},
76 + {"atmega1284p", AVR128K, AVR16K, AVR4K},
77 + {"atmega128rfa1", AVR128K, AVR16K, AVR4K},
78 + {"atmega103", AVR128K, 4000UL, AVR4K},
80 + {"atxmega64a1", AVR68K, AVR4K, AVR2K},
81 + {"atxmega64a1u", AVR68K, AVR4K, AVR2K},
82 + {"atxmega64a3", AVR68K, AVR4K, AVR2K},
83 + {"atxmega64d3", AVR68K, AVR4K, AVR2K},
85 + {"at90can64", AVR64K, AVR4K, AVR2K},
86 + {"at90scr100", AVR64K, AVR4K, AVR2K},
87 + {"at90usb646", AVR64K, AVR4K, AVR2K},
88 + {"at90usb647", AVR64K, AVR4K, AVR2K},
89 + {"atmega64", AVR64K, AVR4K, AVR2K},
90 + {"atmega640", AVR64K, AVR8K, AVR4K},
91 + {"atmega644", AVR64K, AVR4K, AVR2K},
92 + {"atmega644a", AVR64K, AVR4K, AVR2K},
93 + {"atmega644p", AVR64K, AVR4K, AVR2K},
94 + {"atmega644pa", AVR64K, AVR4K, AVR2K},
95 + {"atmega645", AVR64K, AVR4K, AVR2K},
96 + {"atmega645a", AVR64K, AVR4K, AVR2K},
97 + {"atmega645p", AVR64K, AVR4K, AVR2K},
98 + {"atmega6450", AVR64K, AVR4K, AVR2K},
99 + {"atmega6450a", AVR64K, AVR4K, AVR2K},
100 + {"atmega6450p", AVR64K, AVR4K, AVR2K},
101 + {"atmega649", AVR64K, AVR4K, AVR2K},
102 + {"atmega649a", AVR64K, AVR4K, AVR2K},
103 + {"atmega649p", AVR64K, AVR4K, AVR2K},
104 + {"atmega6490", AVR64K, AVR4K, AVR2K},
105 + {"atmega6490a", AVR64K, AVR4K, AVR2K},
106 + {"atmega6490p", AVR64K, AVR4K, AVR2K},
107 + {"atmega64c1", AVR64K, AVR4K, AVR2K},
108 + {"atmega64hve", AVR64K, AVR4K, AVR1K},
109 + {"atmega64m1", AVR64K, AVR4K, AVR2K},
110 + {"m3000", AVR64K, AVR4K, 0UL},
112 + {"atmega406", AVR40K, AVR2K, AVR512},
114 + {"atxmega32a4", AVR36K, AVR4K, AVR1K},
115 + {"atxmega32d4", AVR36K, AVR4K, AVR1K},
117 + {"at90can32", AVR32K, AVR2K, AVR1K},
118 + {"at94k", AVR32K, AVR4K, 0UL},
119 + {"atmega32", AVR32K, AVR2K, AVR1K},
120 + {"atmega323", AVR32K, AVR2K, AVR1K},
121 + {"atmega324a", AVR32K, AVR2K, AVR1K},
122 + {"atmega324p", AVR32K, AVR2K, AVR1K},
123 + {"atmega324pa", AVR32K, AVR2K, AVR1K},
124 + {"atmega325", AVR32K, AVR2K, AVR1K},
125 + {"atmega325a", AVR32K, AVR2K, AVR1K},
126 + {"atmega325p", AVR32K, AVR2K, AVR1K},
127 + {"atmega3250", AVR32K, AVR2K, AVR1K},
128 + {"atmega3250a", AVR32K, AVR2K, AVR1K},
129 + {"atmega3250p", AVR32K, AVR2K, AVR1K},
130 + {"atmega328", AVR32K, AVR2K, AVR1K},
131 + {"atmega328p", AVR32K, AVR2K, AVR1K},
132 + {"atmega329", AVR32K, AVR2K, AVR1K},
133 + {"atmega329a", AVR32K, AVR2K, AVR1K},
134 + {"atmega329p", AVR32K, AVR2K, AVR1K},
135 + {"atmega329pa", AVR32K, AVR2K, AVR1K},
136 + {"atmega3290", AVR32K, AVR2K, AVR1K},
137 + {"atmega3290a", AVR32K, AVR2K, AVR1K},
138 + {"atmega3290p", AVR32K, AVR2K, AVR1K},
139 + {"atmega32hvb", AVR32K, AVR2K, AVR1K},
140 + {"atmega32c1", AVR32K, AVR2K, AVR1K},
141 + {"atmega32hvb", AVR32K, AVR2K, AVR1K},
142 + {"atmega32m1", AVR32K, AVR2K, AVR1K},
143 + {"atmega32u2", AVR32K, AVR1K, AVR1K},
144 + {"atmega32u4", AVR32K, 2560UL, AVR1K},
145 + {"atmega32u6", AVR32K, 2560UL, AVR1K},
147 + {"at43usb355", AVR24K, 1120UL, 0UL},
149 + {"atxmega16a4", AVR20K, AVR2K, AVR1K},
150 + {"atxmega16d4", AVR20K, AVR2K, AVR1K},
152 + {"at76c711", AVR16K, AVR2K, 0UL},
153 + {"at90pwm216", AVR16K, AVR1K, AVR512},
154 + {"at90pwm316", AVR16K, AVR1K, AVR512},
155 + {"at90usb162", AVR16K, AVR512, AVR512},
156 + {"atmega16", AVR16K, AVR1K, AVR512},
157 + {"atmega16a", AVR16K, AVR1K, AVR512},
158 + {"atmega161", AVR16K, AVR1K, AVR512},
159 + {"atmega162", AVR16K, AVR1K, AVR512},
160 + {"atmega163", AVR16K, AVR1K, AVR512},
161 + {"atmega164", AVR16K, AVR1K, AVR512},
162 + {"atmega164a", AVR16K, AVR1K, AVR512},
163 + {"atmega164p", AVR16K, AVR1K, AVR512},
164 + {"atmega165a", AVR16K, AVR1K, AVR512},
165 + {"atmega165", AVR16K, AVR1K, AVR512},
166 + {"atmega165p", AVR16K, AVR1K, AVR512},
167 + {"atmega168", AVR16K, AVR1K, AVR512},
168 + {"atmega168a", AVR16K, AVR1K, AVR512},
169 + {"atmega168p", AVR16K, AVR1K, AVR512},
170 + {"atmega169", AVR16K, AVR1K, AVR512},
171 + {"atmega169a", AVR16K, AVR1K, AVR512},
172 + {"atmega169p", AVR16K, AVR1K, AVR512},
173 + {"atmega169pa", AVR16K, AVR1K, AVR512},
174 + {"atmega16hva", AVR16K, 768UL, AVR256},
175 + {"atmega16hva2", AVR16K, AVR1K, AVR256},
176 + {"atmega16hvb", AVR16K, AVR1K, AVR512},
177 + {"atmega16m1", AVR16K, AVR1K, AVR512},
178 + {"atmega16u2", AVR16K, AVR512, AVR512},
179 + {"atmega16u4", AVR16K, 1280UL, AVR512},
180 + {"attiny167", AVR16K, AVR512, AVR512},
182 + {"at90c8534", AVR8K, 352UL, AVR512},
183 + {"at90pwm1", AVR8K, AVR512, AVR512},
184 + {"at90pwm2", AVR8K, AVR512, AVR512},
185 + {"at90pwm2b", AVR8K, AVR512, AVR512},
186 + {"at90pwm3", AVR8K, AVR512, AVR512},
187 + {"at90pwm3b", AVR8K, AVR512, AVR512},
188 + {"at90pwm81", AVR8K, AVR256, AVR512},
189 + {"at90s8515", AVR8K, AVR512, AVR512},
190 + {"at90s8535", AVR8K, AVR512, AVR512},
191 + {"at90usb82", AVR8K, AVR512, AVR512},
192 + {"ata6289", AVR8K, AVR512, 320UL},
193 + {"atmega8", AVR8K, AVR1K, AVR512},
194 + {"atmega8515", AVR8K, AVR512, AVR512},
195 + {"atmega8535", AVR8K, AVR512, AVR512},
196 + {"atmega88", AVR8K, AVR1K, AVR512},
197 + {"atmega88a", AVR8K, AVR1K, AVR512},
198 + {"atmega88p", AVR8K, AVR1K, AVR512},
199 + {"atmega88pa", AVR8K, AVR1K, AVR512},
200 + {"atmega8hva", AVR8K, 768UL, AVR256},
201 + {"atmega8u2", AVR8K, AVR512, AVR512},
202 + {"attiny84", AVR8K, AVR512, AVR512},
203 + {"attiny84a", AVR8K, AVR512, AVR512},
204 + {"attiny85", AVR8K, AVR512, AVR512},
205 + {"attiny861", AVR8K, AVR512, AVR512},
206 + {"attiny861a", AVR8K, AVR512, AVR512},
207 + {"attiny87", AVR8K, AVR512, AVR512},
208 + {"attiny88", AVR8K, AVR512, AVR64},
210 + {"at90s4414", AVR4K, 352UL, AVR256},
211 + {"at90s4433", AVR4K, AVR128, AVR256},
212 + {"at90s4434", AVR4K, 352UL, AVR256},
213 + {"atmega48", AVR4K, AVR512, AVR256},
214 + {"atmega48a", AVR4K, AVR512, AVR256},
215 + {"atmega48p", AVR4K, AVR512, AVR256},
216 + {"attiny4313", AVR4K, AVR256, AVR256},
217 + {"attiny43u", AVR4K, AVR256, AVR64},
218 + {"attiny44", AVR4K, AVR256, AVR256},
219 + {"attiny44a", AVR4K, AVR256, AVR256},
220 + {"attiny45", AVR4K, AVR256, AVR256},
221 + {"attiny461", AVR4K, AVR256, AVR256},
222 + {"attiny461a", AVR4K, AVR256, AVR256},
223 + {"attiny48", AVR4K, AVR256, AVR64},
225 + {"at86rf401", AVR2K, 224UL, AVR128},
226 + {"at90s2313", AVR2K, AVR128, AVR128},
227 + {"at90s2323", AVR2K, AVR128, AVR128},
228 + {"at90s2333", AVR2K, 224UL, AVR128},
229 + {"at90s2343", AVR2K, AVR128, AVR128},
230 + {"attiny20", AVR2K, AVR128, 0UL},
231 + {"attiny22", AVR2K, 224UL, AVR128},
232 + {"attiny2313", AVR2K, AVR128, AVR128},
233 + {"attiny2313a", AVR2K, AVR128, AVR128},
234 + {"attiny24", AVR2K, AVR128, AVR128},
235 + {"attiny24a", AVR2K, AVR128, AVR128},
236 + {"attiny25", AVR2K, AVR128, AVR128},
237 + {"attiny26", AVR2K, AVR128, AVR128},
238 + {"attiny261", AVR2K, AVR128, AVR128},
239 + {"attiny261a", AVR2K, AVR128, AVR128},
240 + {"attiny28", AVR2K, 0UL, 0UL},
241 + {"attiny40", AVR2K, AVR256, 0UL},
243 + {"at90s1200", AVR1K, 0UL, AVR64},
244 + {"attiny9", AVR1K, 32UL, 0UL},
245 + {"attiny10", AVR1K, 32UL, 0UL},
246 + {"attiny11", AVR1K, 0UL, AVR64},
247 + {"attiny12", AVR1K, 0UL, AVR64},
248 + {"attiny13", AVR1K, AVR64, AVR64},
249 + {"attiny13a", AVR1K, AVR64, AVR64},
250 + {"attiny15", AVR1K, 0UL, AVR64},
252 + {"attiny4", AVR512, 32UL, 0UL},
253 + {"attiny5", AVR512, 32UL, 0UL},
256 +static char *avrmcu = NULL;
259 static char *target = NULL;
261 /* Forward declarations. */
262 @@ -89,7 +330,8 @@ usage (FILE *stream, int status)
263 fprintf (stream, _(" Displays the sizes of sections inside binary files\n"));
264 fprintf (stream, _(" If no input file(s) are specified, a.out is assumed\n"));
265 fprintf (stream, _(" The options are:\n\
266 - -A|-B|-G --format={sysv|berkeley|gnu} Select output style (default is %s)\n\
267 + -A|-B|-G|-C --format={sysv|berkeley|gnu|avr} Select output style (default is %s)\n\
268 + --mcu=<avrmcu> MCU name for AVR format only\n\
269 -o|-d|-x --radix={8|10|16} Display numbers in octal, decimal or hex\n\
270 -t --totals Display the total sizes (Berkeley only)\n\
271 --common Display total size for *COM* syms\n\
272 @@ -113,6 +355,7 @@ usage (FILE *stream, int status)
273 #define OPTION_FORMAT (200)
274 #define OPTION_RADIX (OPTION_FORMAT + 1)
275 #define OPTION_TARGET (OPTION_RADIX + 1)
276 +#define OPTION_MCU (OPTION_TARGET + 1)
278 static struct option long_options[] =
280 @@ -120,6 +363,7 @@ static struct option long_options[] =
281 {"format", required_argument, 0, OPTION_FORMAT},
282 {"radix", required_argument, 0, OPTION_RADIX},
283 {"target", required_argument, 0, OPTION_TARGET},
284 + {"mcu", required_argument, 0, 203},
285 {"totals", no_argument, &show_totals, 1},
286 {"version", no_argument, &show_version, 1},
287 {"help", no_argument, &show_help, 1},
288 @@ -153,7 +397,7 @@ main (int argc, char **argv)
289 fatal (_("fatal error: libbfd ABI mismatch"));
290 set_default_bfd_target ();
292 - while ((c = getopt_long (argc, argv, "ABGHhVvdfotx", long_options,
293 + while ((c = getopt_long (argc, argv, "ABCGHhVvdfotx", long_options,
297 @@ -172,12 +416,20 @@ main (int argc, char **argv)
299 selected_output_format = FORMAT_GNU;
303 + selected_output_format = FORMAT_AVR;
306 non_fatal (_("invalid argument to --format: %s"), optarg);
318 @@ -214,6 +466,9 @@ main (int argc, char **argv)
320 selected_output_format = FORMAT_GNU;
323 + selected_output_format = FORMAT_AVR;
328 @@ -656,6 +911,98 @@ print_sysv_format (bfd *file)
332 +static avr_device_t *
333 +avr_find_device (void)
336 + if (avrmcu != NULL)
338 + for (i = 0; i < sizeof(avr) / sizeof(avr[0]); i++)
340 + if (strcmp(avr[i].name, avrmcu) == 0)
351 +print_avr_format (bfd *file)
353 + char *avr_name = "Unknown";
358 + bfd_size_type my_datasize = 0;
359 + bfd_size_type my_textsize = 0;
360 + bfd_size_type my_bsssize = 0;
361 + bfd_size_type bootloadersize = 0;
362 + bfd_size_type noinitsize = 0;
363 + bfd_size_type eepromsize = 0;
365 + avr_device_t *avrdevice = avr_find_device();
366 + if (avrdevice != NULL)
368 + avr_name = avrdevice->name;
369 + flashmax = avrdevice->flash;
370 + rammax = avrdevice->ram;
371 + eeprommax = avrdevice->eeprom;
374 + if ((section = bfd_get_section_by_name (file, ".data")) != NULL)
375 + my_datasize = bfd_section_size (section);
376 + if ((section = bfd_get_section_by_name (file, ".text")) != NULL)
377 + my_textsize = bfd_section_size (section);
378 + if ((section = bfd_get_section_by_name (file, ".bss")) != NULL)
379 + my_bsssize = bfd_section_size (section);
380 + if ((section = bfd_get_section_by_name (file, ".bootloader")) != NULL)
381 + bootloadersize = bfd_section_size (section);
382 + if ((section = bfd_get_section_by_name (file, ".noinit")) != NULL)
383 + noinitsize = bfd_section_size (section);
384 + if ((section = bfd_get_section_by_name (file, ".eeprom")) != NULL)
385 + eepromsize = bfd_section_size (section);
387 + bfd_size_type text = my_textsize + my_datasize + bootloadersize;
388 + bfd_size_type data = my_datasize + my_bsssize + noinitsize;
389 + bfd_size_type eeprom = eepromsize;
391 + printf ("AVR Memory Usage\n"
392 + "----------------\n"
393 + "Device: %s\n\n", avr_name);
396 + printf ("Program:%8ld bytes", text);
399 + printf (" (%2.1f%% Full)", ((float)text / flashmax) * 100);
401 + printf ("\n(.text + .data + .bootloader)\n\n");
404 + printf ("Data: %8ld bytes", data);
407 + printf (" (%2.1f%% Full)", ((float)data / rammax) * 100);
409 + printf ("\n(.data + .bss + .noinit)\n\n");
414 + printf ("EEPROM: %8ld bytes", eeprom);
417 + printf (" (%2.1f%% Full)", ((float)eeprom / eeprommax) * 100);
419 + printf ("\n(.eeprom)\n\n");
425 print_sizes (bfd *file)
427 @@ -663,6 +1010,8 @@ print_sizes (bfd *file)
428 calculate_common_size (file);
429 if (selected_output_format == FORMAT_SYSV)
430 print_sysv_format (file);
431 + else if (selected_output_format == FORMAT_AVR)
432 + print_avr_format (file);
434 print_berkeley_or_gnu_format (file);