All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <xypron.glpk@gmx.de>
To: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>,
	Patrick Rudolph <patrick.rudolph@9elements.com>,
	Tom Rini <trini@konsulko.com>,
	U-Boot Mailing List <u-boot@lists.denx.de>
Subject: Re: [PATCH v5 45/46] acpi: Support checking checksums
Date: Fri, 21 Mar 2025 13:24:42 +0100	[thread overview]
Message-ID: <448d550b-1a2b-4fbe-a24a-292ba1037b44@gmx.de> (raw)
In-Reply-To: <0fd6b834-9e74-4919-9d62-19ec6cdcba69@gmx.de>

On 21.03.25 11:49, Heinrich Schuchardt wrote:
> On 15.03.25 15:26, Simon Glass wrote:
>> When the ACPI tables come from an earlier bootloader it is helpful to
>> see whether the checksums are correct or not. Add a -c flag to the
>> 'acpi list' command to support that.
>>
>> Signed-off-by: Simon Glass <sjg@chromium.org>
>> ---
>>
>> (no changes since v3)
>>
>> Changes in v3:
>> - Add new patch to support checking checksums with ACPI command
>>
>>   cmd/acpi.c             | 57 +++++++++++++++++++++++++++---------------
>>   doc/usage/cmd/acpi.rst | 20 ++++++++++++++-
>>   test/dm/acpi.c         | 46 ++++++++++++++++++++++++++++++++++
>>   3 files changed, 102 insertions(+), 21 deletions(-)
>>
>> diff --git a/cmd/acpi.c b/cmd/acpi.c
>> index 2273176f106..bb243202009 100644
>> --- a/cmd/acpi.c
>> +++ b/cmd/acpi.c
>> @@ -7,6 +7,7 @@
>>   #include <display_options.h>
>>   #include <log.h>
>>   #include <mapmem.h>
>> +#include <tables_csum.h>
>>   #include <acpi/acpi_table.h>
>>   #include <asm/acpi_table.h>
>>   #include <asm/global_data.h>
>> @@ -15,6 +16,17 @@
>>
>>   DECLARE_GLOBAL_DATA_PTR;
>>
>> +static const char *show_checksum(void *ptr, uint size, bool chksums)
>> +{
>> +    uint checksum;
>> +
>> +    if (!chksums)
>> +        return "";
>> +    checksum = table_compute_checksum(ptr, size);
>> +
>> +    return checksum ? "  bad" : "  OK";
> 
> Please, move the leading spaces to the printf statements below.
> 
>> +}
>> +
>>   /**
>>    * dump_hdr() - Dump an ACPI header
>>    *
>> @@ -23,16 +35,17 @@ DECLARE_GLOBAL_DATA_PTR;
>>    *
>>    * @hdr: ACPI header to dump
>>    */
>> -static void dump_hdr(struct acpi_table_header *hdr)
>> +static void dump_hdr(struct acpi_table_header *hdr, bool chksums)
>>   {
>>       bool has_hdr = memcmp(hdr->signature, "FACS", ACPI_NAME_LEN);
>>
>>       printf("%.*s  %16lx  %5x", ACPI_NAME_LEN, hdr->signature,
>>              (ulong)map_to_sysmem(hdr), hdr->length);
>>       if (has_hdr) {
>> -        printf("  v%02d %.6s %.8s %x %.4s %x\n", hdr->revision,
>> +        printf("  v%02d %.6s %.8s %x %.4s %x%s\n", hdr->revision,
> 
> %x results in variable length output. To avoid ragged layout, please,
> define the output length.
> 
> Best regards
> 
> Heinrich
> 
>>                  hdr->oem_id, hdr->oem_table_id, hdr->oem_revision,
>> -               hdr->creator_id, hdr->creator_revision);
>> +               hdr->creator_id, hdr->creator_revision,
>> +               show_checksum(hdr, hdr->length, chksums));
>>       } else {
>>           printf("\n");
>>       }
>> @@ -52,22 +65,22 @@ static int dump_table_name(const char *sig)
>>       return 0;
>>   }
>>
>> -static void list_fadt(struct acpi_fadt *fadt)
>> +static void list_fadt(struct acpi_fadt *fadt, bool chksums)
>>   {
>>       if (fadt->header.revision >= 3 && fadt->x_dsdt)
>> -        dump_hdr(nomap_sysmem(fadt->x_dsdt, 0));
>> +        dump_hdr(nomap_sysmem(fadt->x_dsdt, 0), chksums);
>>       else if (fadt->dsdt)
>> -        dump_hdr(nomap_sysmem(fadt->dsdt, 0));
>> +        dump_hdr(nomap_sysmem(fadt->dsdt, 0), chksums);
>>       if (!IS_ENABLED(CONFIG_X86) && !IS_ENABLED(CONFIG_SANDBOX) &&
>>           !(fadt->flags & ACPI_FADT_HW_REDUCED_ACPI))
>>           log_err("FADT not ACPI-hardware-reduced-compliant\n");
>>       if (fadt->header.revision >= 3 && fadt->x_firmware_ctrl)
>> -        dump_hdr(nomap_sysmem(fadt->x_firmware_ctrl, 0));
>> +        dump_hdr(nomap_sysmem(fadt->x_firmware_ctrl, 0), chksums);
>>       else if (fadt->firmware_ctrl)
>> -        dump_hdr(nomap_sysmem(fadt->firmware_ctrl, 0));
>> +        dump_hdr(nomap_sysmem(fadt->firmware_ctrl, 0), chksums);
>>   }
>>
>> -static void list_rsdt(struct acpi_rsdp *rsdp)
>> +static void list_rsdt(struct acpi_rsdp *rsdp, bool chksums)
>>   {
>>       int len, i, count;
>>       struct acpi_rsdt *rsdt;
>> @@ -75,11 +88,11 @@ static void list_rsdt(struct acpi_rsdp *rsdp)
>>
>>       if (rsdp->rsdt_address) {
>>           rsdt = nomap_sysmem(rsdp->rsdt_address, 0);
>> -        dump_hdr(&rsdt->header);
>> +        dump_hdr(&rsdt->header, chksums);
>>       }
>>       if (rsdp->xsdt_address) {
>>           xsdt = nomap_sysmem(rsdp->xsdt_address, 0);
>> -        dump_hdr(&xsdt->header);
>> +        dump_hdr(&xsdt->header, chksums);
>>           len = xsdt->header.length - sizeof(xsdt->header);
>>           count = len / sizeof(u64);
>>       } else if (rsdp->rsdt_address) {
>> @@ -100,24 +113,28 @@ static void list_rsdt(struct acpi_rsdp *rsdp)
>>           if (!entry)
>>               break;
>>           hdr = nomap_sysmem(entry, 0);
>> -        dump_hdr(hdr);
>> +        dump_hdr(hdr, chksums);
>>           if (!memcmp(hdr->signature, "FACP", ACPI_NAME_LEN))
>> -            list_fadt((struct acpi_fadt *)hdr);
>> +            list_fadt((struct acpi_fadt *)hdr, chksums);
>>       }
>>   }
>>
>> -static void list_rsdp(struct acpi_rsdp *rsdp)
>> +static void list_rsdp(struct acpi_rsdp *rsdp, bool chksums)
>>   {
>> -    printf("RSDP  %16lx  %5x  v%02d %.6s\n", (ulong)map_to_sysmem(rsdp),
>> -           rsdp->length, rsdp->revision, rsdp->oem_id);
>> -    list_rsdt(rsdp);
>> +    printf("RSDP  %16lx  %5x  v%02d %.6s%s%s\n",
>> +           (ulong)map_to_sysmem(rsdp), rsdp->length, rsdp->revision,
>> +           rsdp->oem_id, show_checksum(rsdp, 0x14, chksums),
>> +           show_checksum(rsdp, rsdp->length, chksums));
>> +    list_rsdt(rsdp, chksums);
>>   }
>>
>>   static int do_acpi_list(struct cmd_tbl *cmdtp, int flag, int argc,
>>               char *const argv[])
>>   {
>>       struct acpi_rsdp *rsdp;
>> +    bool chksums;
>>
>> +    chksums = argc >= 2 && !strcmp("-c", argv[1]);
>>       rsdp = map_sysmem(gd_acpi_start(), 0);
>>       if (!rsdp) {
>>           printf("No ACPI tables present\n");
>> @@ -125,7 +142,7 @@ static int do_acpi_list(struct cmd_tbl *cmdtp, int 
>> flag, int argc,
>>       }
>>       printf("Name              Base   Size  Detail\n"
>>              "----  ----------------  -----  
>> ----------------------------\n");
>> -    list_rsdp(rsdp);
>> +    list_rsdp(rsdp, chksums);
>>
>>       return 0;
>>   }
>> @@ -187,13 +204,13 @@ static int do_acpi_dump(struct cmd_tbl *cmdtp, 
>> int flag, int argc,
>>   }
>>
>>   U_BOOT_LONGHELP(acpi,
>> -    "list  - list ACPI tables\n"
>> +    "list [-c] - list ACPI tables [check checksums]\n"

Let's keep things simple for the user:

Always check the checksums.
Only print a notice if a checksum is wrong.

Best regards

Heinrich

>>       "acpi items [-d]   - List/dump each piece of ACPI data from 
>> devices\n"
>>       "acpi set [<addr>] - Set or show address of ACPI tables\n"
>>       "acpi dump <name>  - Dump ACPI table");
>>
>>   U_BOOT_CMD_WITH_SUBCMDS(acpi, "ACPI tables", acpi_help_text,
>> -    U_BOOT_SUBCMD_MKENT(list, 1, 1, do_acpi_list),
>> +    U_BOOT_SUBCMD_MKENT(list, 2, 1, do_acpi_list),
>>       U_BOOT_SUBCMD_MKENT(items, 2, 1, do_acpi_items),
>>       U_BOOT_SUBCMD_MKENT(set, 2, 1, do_acpi_set),
>>       U_BOOT_SUBCMD_MKENT(dump, 2, 1, do_acpi_dump));
>> diff --git a/doc/usage/cmd/acpi.rst b/doc/usage/cmd/acpi.rst
>> index 9f30972fe53..e652968d584 100644
>> --- a/doc/usage/cmd/acpi.rst
>> +++ b/doc/usage/cmd/acpi.rst
>> @@ -11,7 +11,7 @@ Synopsis
>>
>>   ::
>>
>> -    acpi list
>> +    acpi list [-c]
>>       acpi items [-d]
>>       acpi dump <name>
>>       acpi set <address>
>> @@ -38,6 +38,9 @@ List the ACPI tables that have been generated. Each 
>> table has a 4-character
>>   table name (e.g. SSDT, FACS) and has a format defined by the
>>   `ACPI specification`_.
>>
>> +The `-c` flag tells U-Boot to verify the checksums and print 'OK' or 
>> 'BAD' next
>> +to each table.
>> +
>>   U-Boot does not currently support decoding the tables. Unlike 
>> devicetree, ACPI
>>   tables have no regular schema and also some include bytecode, so 
>> decoding the
>>   tables requires a lot of code.
>> @@ -259,5 +262,20 @@ pointer::
>>       WAET  bff76a3b     28  v01 BOCHS  BXPC     1 BXPC 1
>>       SSDT  bff95040     c5  v02 COREv4 COREBOOT 2a CORE 20221020
>>
>> +This shows checking that the checksums are correct for each table::
>> +
>> +    => acpi list -c
>> +    Name              Base   Size  Detail
>> +    ----  ----------------  -----  ----------------------------
>> +    RSDP          bec9a000     24  v00 BOCHS   OK OK
>> +    RSDT          bec9bd4a     38  v01 BOCHS  BXPC     1 BXPC 1  OK
>> +    FACP          bec9bb46     74  v01 BOCHS  BXPC     1 BXPC 1  OK
>> +    DSDT          bec9a080   1ac6  v01 BOCHS  BXPC     1 BXPC 1  OK
>> +    FACS          bec9a040     40
>> +    APIC          bec9bbba     78  v03 BOCHS  BXPC     1 BXPC 1  OK
>> +    HPET          bec9bc32     38  v01 BOCHS  BXPC     1 BXPC 1  OK
>> +    SRAT          bec9bc6a     b8  v01 BOCHS  BXPC     1 BXPC 1  OK
>> +    WAET          bec9bd22     28  v01 BOCHS  BXPC     1 BXPC 1  OK
>> +
>>
>>   .. _`ACPI specification`: https://uefi.org/sites/default/files/ 
>> resources/ACPI_6_3_final_Jan30.pdf
>> diff --git a/test/dm/acpi.c b/test/dm/acpi.c
>> index f98f9d1e74b..db012b6d2f1 100644
>> --- a/test/dm/acpi.c
>> +++ b/test/dm/acpi.c
>> @@ -439,6 +439,52 @@ static int dm_test_acpi_cmd_list(struct 
>> unit_test_state *uts)
>>   }
>>   DM_TEST(dm_test_acpi_cmd_list, UTF_SCAN_PDATA | UTF_SCAN_FDT | 
>> UTF_CONSOLE);
>>
>> +/* Test 'acpi list -c' command */
>> +static int dm_test_acpi_cmd_list_chksum(struct unit_test_state *uts)
>> +{
>> +    struct acpi_ctx ctx;
>> +    ulong addr;
>> +    void *buf;
>> +
>> +    buf = memalign(16, BUF_SIZE);
>> +    ut_assertnonnull(buf);
>> +    addr = map_to_sysmem(buf);
>> +    ut_assertok(setup_ctx_and_base_tables(uts, &ctx, addr));
>> +
>> +    ut_assertok(acpi_write_dev_tables(&ctx));
>> +
>> +    run_command("acpi list -c", 0);
>> +    ut_assert_nextline("Name              Base   Size  Detail");
>> +    ut_assert_nextline("----  ----------------  -----  
>> ----------------------------");
>> +    ut_assert_nextline("RSDP  %16lx  %5zx  v02 U-BOOT  OK  OK", addr,
>> +               sizeof(struct acpi_rsdp));
>> +    addr = ALIGN(addr + sizeof(struct acpi_rsdp), 16);
>> +    ut_assert_nextline("RSDT  %16lx  %5zx  v01 U-BOOT U-BOOTBL %x 
>> INTL 0  OK",
>> +               addr, sizeof(struct acpi_table_header) +
>> +               3 * sizeof(u32), OEM_REVISION);
>> +    addr = ALIGN(addr + sizeof(struct acpi_rsdt), 16);
>> +    ut_assert_nextline("XSDT  %16lx  %5zx  v01 U-BOOT U-BOOTBL %x 
>> INTL 0  OK",
>> +               addr, sizeof(struct acpi_table_header) +
>> +               3 * sizeof(u64), OEM_REVISION);
>> +    addr = ALIGN(addr + sizeof(struct acpi_xsdt), 64);
>> +    ut_assert_nextline("DMAR  %16lx  %5zx  v01 U-BOOT U-BOOTBL %x 
>> INTL 0  OK",
>> +               addr, sizeof(struct acpi_dmar), OEM_REVISION);
>> +    addr = ALIGN(addr + sizeof(struct acpi_dmar), 16);
>> +    ut_assert_nextline("DMAR  %16lx  %5zx  v01 U-BOOT U-BOOTBL %x 
>> INTL 0  OK",
>> +               addr, sizeof(struct acpi_dmar), OEM_REVISION);
>> +    addr = ALIGN(addr + sizeof(struct acpi_dmar), 16);
>> +    ut_assert_nextline("DMAR  %16lx  %5zx  v01 U-BOOT U-BOOTBL %x 
>> INTL 0  OK",
>> +               addr, sizeof(struct acpi_dmar), OEM_REVISION);
>> +    ut_assert_console_end();
>> +    ut_assert_console_end();
>> +    unmap_sysmem(buf);
>> +    free(buf);
>> +
>> +    return 0;
>> +}
>> +DM_TEST(dm_test_acpi_cmd_list_chksum,
>> +    UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_CONSOLE);
>> +
>>   /* Test 'acpi dump' command */
>>   static int dm_test_acpi_cmd_dump(struct unit_test_state *uts)
>>   {
> 


  reply	other threads:[~2025-03-21 12:24 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-15 14:25 [PATCH v5 00/46] x86: Improve operation under QEMU Simon Glass
2025-03-15 14:25 ` [PATCH v5 01/46] boot: Correct ramdisk address Simon Glass
2025-03-15 14:25 ` [PATCH v5 02/46] sandbox: Correct a typo in mapmem Simon Glass
2025-03-15 14:25 ` [PATCH v5 03/46] x86: Expand x86_64 early memory Simon Glass
2025-03-15 14:25 ` [PATCH v5 04/46] x86: qemu: Switch to bochs display Simon Glass
2025-03-15 14:25 ` [PATCH v5 05/46] x86: qemu: Enable dhrystone Simon Glass
2025-03-15 14:25 ` [PATCH v5 06/46] x86: qemu: Avoid accessing BSS too early Simon Glass
2025-03-15 14:25 ` [PATCH v5 07/46] x86: Drop mpspec from the SPL build Simon Glass
2025-03-17 14:31   ` Tom Rini
2025-03-18  8:32     ` Simon Glass
2025-03-15 14:25 ` [PATCH v5 08/46] x86: Add some log categories Simon Glass
2025-03-15 14:25 ` [PATCH v5 09/46] x86: Drop use of CONFIG_REALMODE_DEBUG Simon Glass
2025-03-17 14:32   ` Tom Rini
2025-03-15 14:25 ` [PATCH v5 10/46] x86: Avoid clearing the VESA display Simon Glass
2025-03-15 14:25 ` [PATCH v5 11/46] x86: Add 64-bit entries to the GDT Simon Glass
2025-03-15 14:25 ` [PATCH v5 12/46] x86: Use defines for the cache flags Simon Glass
2025-03-15 14:25 ` [PATCH v5 13/46] x86: spl: Drop duplicate CPU init Simon Glass
2025-03-15 14:25 ` [PATCH v5 14/46] x86: Drop the message about features missing in 64-bit Simon Glass
2025-03-15 14:25 ` [PATCH v5 15/46] x86: Include stdbool.h in interrupt header Simon Glass
2025-03-15 14:25 ` [PATCH v5 16/46] x86: Tidy up the GDT size in start/16.S Simon Glass
2025-03-15 14:25 ` [PATCH v5 17/46] x86: Disable paging before changing to long mode Simon Glass
2025-03-15 14:25 ` [PATCH v5 18/46] x86: Use the same GDT when jumping " Simon Glass
2025-03-15 14:25 ` [PATCH v5 19/46] x86: Use a simple jump into " Simon Glass
2025-03-15 14:25 ` [PATCH v5 20/46] x86: Rename the _D dirty flag Simon Glass
2025-03-15 14:25 ` [PATCH v5 21/46] x86: Support CPU functions in long mode Simon Glass
2025-03-15 14:25 ` [PATCH v5 22/46] x86: Add functions to convert between mtrr size and mask Simon Glass
2025-03-15 14:25 ` [PATCH v5 23/46] x86: Update mtrr command to support 64-bit values Simon Glass
2025-03-15 14:25 ` [PATCH v5 24/46] x86: Update cpuid_eax et al to work on amd64 Simon Glass
2025-03-15 14:25 ` [PATCH v5 25/46] x86: Correct msr operation " Simon Glass
2025-03-15 14:25 ` [PATCH v5 26/46] x86: Allow adding non-aligned size for MTRR Simon Glass
2025-03-15 14:25 ` [PATCH v5 27/46] x86: emulation: Set an MTRR for the RAM Simon Glass
2025-03-15 14:25 ` [PATCH v5 28/46] x86: qemu: Support environment and cat command Simon Glass
2025-03-15 14:25 ` [PATCH v5 29/46] test/py: Correct sizing of created disks Simon Glass
2025-03-15 14:25 ` [PATCH v5 30/46] test/py: Add a helper to send characters Simon Glass
2025-03-15 14:25 ` [PATCH v5 31/46] test/py: Allow tests to be filtered by role Simon Glass
2025-03-15 14:25 ` [PATCH v5 32/46] x86: e820: Add a function to dump the e820 table Simon Glass
2025-03-15 14:25 ` [PATCH v5 33/46] x86: Add a new API for e820 Simon Glass
2025-03-15 14:25 ` [PATCH v5 34/46] x86: qemu: Use the new e820 API Simon Glass
2025-03-15 14:25 ` [PATCH v5 35/46] x86: emulation: Support BLOBLIST_TABLES properly Simon Glass
2025-03-15 14:25 ` [PATCH v5 36/46] x86: Support a 64-bit ramdisk address Simon Glass
2025-03-15 14:25 ` [PATCH v5 37/46] acpi: Mark struct acpi_rsdp as packed Simon Glass
2025-03-15 14:25 ` [PATCH v5 38/46] boot: Consider non-bootable partitions Simon Glass
2025-03-18 14:04   ` Tom Rini
2025-03-18 15:24     ` Simon Glass
2025-03-18 15:52       ` Tom Rini
2025-03-19 15:03         ` Simon Glass
2025-03-19 15:40           ` Tom Rini
2025-03-20  3:43             ` Simon Glass
2025-03-20 14:22               ` Tom Rini
2025-03-21 18:38                 ` Simon Glass
2025-03-28 16:29                   ` Tom Rini
2025-03-28 23:41                     ` Simon Glass
2025-04-02 14:28   ` Tom Rini
2025-04-02 19:22     ` Simon Glass
2025-04-03 17:43       ` Tom Rini
2025-03-15 14:25 ` [PATCH v5 39/46] boot: Handle running out of labels Simon Glass
2025-03-15 14:26 ` [PATCH v5 40/46] boot: Support IO UARTs for earlycon and console Simon Glass
2025-04-02 14:28   ` Tom Rini
2025-04-02 19:22     ` Simon Glass
2025-04-02 19:50       ` Tom Rini
2025-04-02 19:56         ` Tom Rini
2025-04-02 23:54           ` Simon Glass
2025-04-03  0:26             ` Tom Rini
2025-04-03 17:57               ` Simon Glass
2025-03-15 14:26 ` [PATCH v5 41/46] sandbox: acpi: Avoid a warning about FADT Simon Glass
2025-03-15 14:26 ` [PATCH v5 42/46] sandbox: acpi: Correct mapping in FADT Simon Glass
2025-03-15 14:26 ` [PATCH v5 43/46] acpi: Add a checksum to the DMAR table Simon Glass
2025-03-21 11:47   ` Heinrich Schuchardt
2025-03-15 14:26 ` [PATCH v5 44/46] test: acpi: Correct memory leaks Simon Glass
2025-03-21 11:34   ` Heinrich Schuchardt
2025-03-15 14:26 ` [PATCH v5 45/46] acpi: Support checking checksums Simon Glass
2025-03-21 10:49   ` Heinrich Schuchardt
2025-03-21 12:24     ` Heinrich Schuchardt [this message]
2025-03-28 12:01       ` Simon Glass
2025-03-15 14:26 ` [PATCH v5 46/46] test: Add a test for booting Ubuntu 24.04 Simon Glass
2025-04-05 14:31 ` [PATCH v5 00/46] x86: Improve operation under QEMU Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=448d550b-1a2b-4fbe-a24a-292ba1037b44@gmx.de \
    --to=xypron.glpk@gmx.de \
    --cc=bmeng.cn@gmail.com \
    --cc=patrick.rudolph@9elements.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.