From patchwork Mon May 6 12:24:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georg-Johann Lay X-Patchwork-Id: 89556 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A866E3858417 for ; Mon, 6 May 2024 12:25:32 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [81.169.146.163]) by sourceware.org (Postfix) with ESMTPS id D13543858D35 for ; Mon, 6 May 2024 12:24:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D13543858D35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gjlay.de Authentication-Results: sourceware.org; spf=none smtp.mailfrom=gjlay.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D13543858D35 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=81.169.146.163 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714998301; cv=pass; b=AYhH/q4nK5NsvSnKCi8NcvdI5eMv/ctUAhI5IZ27MEft6EX4sV/670d96CJDpYypCEMv11iOUzE82sqg7rrDmwEoEG1/B3+Mp5sNaOcUHPJ0rrqhVSmIcvD0boVui8YUJxQi2zI2vt+XSHzv4hbh12LSLnryJpuwni2OCLxX6W8= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714998301; c=relaxed/simple; bh=5QcoptujYRsb0gnWHHoF87hYhlqz3KFf2ScUcErEcPA=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:MIME-Version:From: To:Subject; b=U5ttDH7G4XTrrkaSHWWTOh6rXkwtqiqPKZq95R0bjNLldjoSf9PAIxZNt9/hP0x3fADVn0LP/xrxecgwttEuJSI4y1++LGz+xI9+ZH3AfWz7mFH+LmW2mRLWL3QjbC0zineROev8FXne45sJkrJWRdwaTXlmusGfpuP60Pz5DpM= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; t=1714998293; cv=none; d=strato.com; s=strato-dkim-0002; b=eaSf29o4gmshTpl85c/zLFYl9mmAv1+podrj9DXCrPjv5ovIL14BNuPszcyFCoK1CG sEcCszCqjjiyAE6WjO/0HPcAdORqk7lBptpzfqg1Znn0O2XX74iEHjjYP3B4+OXNmRpg VGl/KxNI1f5JI237jyfs+hwJVe9dXfU7qZJreUNf+EWwkwfD92Q2FBB18oYp/5EA+ghS 0XyOK+jwTYTUdnJE4Ym85TqZA9dGWhnAQN97zJCC/zsEXgv9WMqP3CLNgea30OqU8TCF H9p+Rom1/h+7AbPqqrKmi3MMk8zKNakqie69PJSuZSI/5jIvzQgwq1Aghh6Scc97J8vg yLsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1714998293; s=strato-dkim-0002; d=strato.com; h=Subject:To:From:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=S1KP4oAVjZduk3v/ms/HYOjzJCUOuc/FrePvH71bFV4=; b=eBgAGYRhO0aepWP8J6hljcy/R1XYHzSuqyQu8nQ9nZocwX5DBWH2ZlzRlXYRBY8PN3 AjC0kfriCitImFA8SqFDbzVIe6pZ4tK0Ff59PHpjAWA7L8gOVm94Q9nKLztUJkqOYg5y yxnSKrz+0r3XFTvLRV5sAqwzcjktH64+x30bnOHTVLzXcknuiihl0O7kNeLY0n34ZyOY ZY+WNaL4uAGsJ8j69piMUQi4KK2EhIaFftS+9QCaQpjwX3kMeHFI5qZZIdxG5pEgAY1z 5R9ODzN/S+UznzdAREd+5w/sR5zWQ3ua5b2kwRWEACTZpaK1lwF44REMXFSkwWMFjjTr IMaA== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1714998293; s=strato-dkim-0002; d=gjlay.de; h=Subject:To:From:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=S1KP4oAVjZduk3v/ms/HYOjzJCUOuc/FrePvH71bFV4=; b=dg1V4qjUQwJAD7gajGoS+h/4JVBtxw2YqKFaz3HLO0ybgq2Sb60jiuLktcYHY2yw/e uzX4VAbZx6gHfKD+L4p9KeuPK6jkvyAG2p8iYn6ZZO0Jmc/ZEmZIlff9dMdIJZAh15lS xL/h7E4AJQtLnIo0RI2Hynw2MQrwy9uhcu2FqR6ab99C8Ydv09dhhJHC0qWwTNiKQHMT KaITqNlNmA929zzINxM1qo9Oyem79lVt3H26BxIwuzpBK2siSdiJmExlvYyB30GnzHHv 18YhiRDRhK90SM7qvWYFtqNqi6FH/l1SiwF6+5y0Mg+JDHA4m6bdgWBMf/UfkhjbeLMV kbEg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1714998293; s=strato-dkim-0003; d=gjlay.de; h=Subject:To:From:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=S1KP4oAVjZduk3v/ms/HYOjzJCUOuc/FrePvH71bFV4=; b=qreQC8uEA7OqbH2l3EFPZhApbKYJA/t4BxnHlvZ1xLLp6nSTy6fzYrZJfcxZzNl+N9 jZIR8SYtSZnCuAWPp6DA== X-RZG-AUTH: ":LXoWVUeid/7A29J/hMvvT3koxZnKT7Qq0xotTetVnKkbgtK4q2y4KBIJzcU=" Received: from [192.168.2.102] by smtp.strato.de (RZmta 50.5.0 DYNA|AUTH) with ESMTPSA id xcdf44046COqli1 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Mon, 6 May 2024 14:24:52 +0200 (CEST) Message-ID: Date: Mon, 6 May 2024 14:24:52 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Georg-Johann Lay Content-Language: en-US To: binutils@sourceware.org, Nick Clifton Subject: [patch,avr] PR31704: Let avr-objdump show .note.gnu.avr.deviceinfo X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+patchwork=sourceware.org@sourceware.org AVR: binutils/31704 - Let avr-objdump show .note.gnu.avr.deviceinfo This patch supports avr-objdump -P avr-deviceinfo which displays the contents of the .note.gnu.avr.deviceinfo section, which is added by the startup code from AVR-LibC in crt.o. binutils/ PR binutils/31704 * od-elf32_avr.c (OPT_AVRDEVICEINFO): New macro. (objdump_private_option options): Set [2] to "avr-deviceinfo". (elf32_avr_help): Help on new -P avr-deviceinfo. (elf32_avr_dump) [OPT_AVRDEVICEINFO]: Run... (elf32_avr_dump_avr_deviceinfo): ...this new static function. diff --git a/binutils/od-elf32_avr.c b/binutils/od-elf32_avr.c index 1e7a8b49935..c495fc973fe 100644 --- a/binutils/od-elf32_avr.c +++ b/binutils/od-elf32_avr.c @@ -36,12 +36,14 @@ /* Index of the options in the options[] array. */ #define OPT_MEMUSAGE 0 #define OPT_AVRPROP 1 +#define OPT_AVRDEVICEINFO 2 /* List of actions. */ static struct objdump_private_option options[] = { { "mem-usage", 0 }, { "avr-prop", 0}, + { "avr-deviceinfo", 0}, { NULL, 0 } }; @@ -52,8 +54,9 @@ elf32_avr_help (FILE *stream) { fprintf (stream, _("\ For AVR ELF files:\n\ - mem-usage Display memory usage\n\ - avr-prop Display contents of .avr.prop section\n\ + mem-usage Display memory usage\n\ + avr-prop Display contents of .avr.prop section\n\ + avr-deviceinfo Display contents of .note.gnu.avr.deviceinfo section\n\ ")); } @@ -323,6 +326,55 @@ elf32_avr_dump_avr_prop (bfd *abfd) free (r_list); } + +static void +elf32_avr_dump_avr_deviceinfo (bfd *abfd) +{ + char *description = NULL; + bfd_size_type sec_size, desc_size; + + deviceinfo dinfo = { 0, 0, 0, 0, 0, 0, NULL }; + dinfo.name = "Unknown"; + + char *contents = elf32_avr_get_note_section_contents (abfd, &sec_size); + + if (contents == NULL) + return; + + description = elf32_avr_get_note_desc (abfd, contents, sec_size, &desc_size); + elf32_avr_get_device_info (abfd, description, desc_size, &dinfo); + + printf ("AVR Device Info\n" + "----------------\n" + "Device: %s\n\n", dinfo.name); + + printf ("Memory Start Size Start Size\n"); + + printf ("Flash %9" PRIu32 " %9" PRIu32 " %#9" PRIx32 " %#9" PRIx32 "\n", + dinfo.flash_start, dinfo.flash_size, + dinfo.flash_start, dinfo.flash_size); + + /* FIXME: There are devices like ATtiny11 without RAM, and where the + avr/io*.h header has defines like + #define RAMSTART 0x60 + // Last memory addresses + #define RAMEND 0x1F + which results in a negative RAM size. The correct display would be to + show a size of 0, however we also want to show what's actually in the + note section as precise as possible. Hence, display the decimal size + as %d, not as %u. */ + printf ("RAM %9" PRIu32 " %9" PRId32 " %#9" PRIx32 " %#9" PRIx32 "\n", + dinfo.ram_start, dinfo.ram_size, + dinfo.ram_start, dinfo.ram_size); + + printf ("EEPROM %9" PRIu32 " %9" PRIu32 " %#9" PRIx32 " %#9" PRIx32 "\n", + dinfo.eeprom_start, dinfo.eeprom_size, + dinfo.eeprom_start, dinfo.eeprom_size); + + free (contents); +} + + static void elf32_avr_dump (bfd *abfd) { @@ -330,6 +382,8 @@ elf32_avr_dump (bfd *abfd) elf32_avr_dump_mem_usage (abfd); if (options[OPT_AVRPROP].selected) elf32_avr_dump_avr_prop (abfd); + if (options[OPT_AVRDEVICEINFO].selected) + elf32_avr_dump_avr_deviceinfo (abfd); } const struct objdump_private_desc objdump_private_desc_elf32_avr =