From patchwork Sat May 8 13:00:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1475867 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=XAkA1vOp; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcnY76lYnz9vDt for ; Sat, 8 May 2021 23:02:51 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 380CF82EB1; Sat, 8 May 2021 15:01:05 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="XAkA1vOp"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 054BD82E7F; Sat, 8 May 2021 15:00:40 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6EBB482E69 for ; Sat, 8 May 2021 15:00:32 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-ot1-x32b.google.com with SMTP id i23-20020a9d68d70000b02902dc19ed4c15so6343924oto.0 for ; Sat, 08 May 2021 06:00:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KKrKOfDAlUuyE0dbBU76JIvCtw/OckWIlnTlGO/1sB0=; b=XAkA1vOproOfDKdjwiUrCvUWbWhXqtcWCHYXMMPYR1X3SanIXKgRtHnBC+oQWXthkm AD/oPFAXsCIg/JDOM+o8njxlYGrVyAQU2F5zYbyR6dyUbPo3+jKSZv6PMg5ZZ2owDulV uOs2yPaD4ff1R5AWetTkZ7P+HbkOwOLTuG82k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KKrKOfDAlUuyE0dbBU76JIvCtw/OckWIlnTlGO/1sB0=; b=ko3dvHVm3OxMj6Gk/xnqJkOA2JU5tyHR/PcxTnuZeYqepmypDBArW4M3z2SBbvcB2U DTu++d0VzyMctcnQ/6+MeWi4qJmrF1Avm91TBoVtJcFtDoOv5nMPUH2ijH5nIZVuvOW3 Ju4zxH3iOxPRN7Oe312HztVfGPIbirvOfcw0yZQlLvqFlGKW6Fk6TGUQFZzlNDHfH0h8 SHnzk6djAjr81l8L/jYKEBaDuRY2N0kwjLb/oPJI/Dy2C9t/m4wnqIoraWKnRVLNhIPc b1p1K3oZ1Kgt/s9LegXW9/lSYQ2O2eDqnr+atLNPhzdNrGvrLz5g0S8qKUTP2GyIDiBp gxvg== X-Gm-Message-State: AOAM531tsBG2/zz4kUht3xQ99sDoFnOWiljH49pDUNjKkAxu2S/wmM0G vFrc+GZpDYicOOAVxvH1qKwjAJ/ACQfZlbYM X-Google-Smtp-Source: ABdhPJwFkShVWZIPQw8bO8UjNXcD/SWhebD7I5LI8Ia8ttelu92KwmilGYFwCw4gUHzXfyvGiswThg== X-Received: by 2002:a9d:7d90:: with SMTP id j16mr12713004otn.18.1620478830683; Sat, 08 May 2021 06:00:30 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id i9sm1800200otr.19.2021.05.08.06.00.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 May 2021 06:00:30 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Simon Glass Subject: [PATCH v2 12/12] RFC: display_options: Use print_hex_dump() for print_buffer() Date: Sat, 8 May 2021 07:00:07 -0600 Message-Id: <20210508130007.1708527-11-sjg@chromium.org> X-Mailer: git-send-email 2.31.1.607.g51e8a6a459-goog In-Reply-To: <20210508130007.1708527-1-sjg@chromium.org> References: <20210508130007.1708527-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean These two functions do similar things. When CONFIG_HEXDUMP is enabled, drop the code in print_buffer() and use the hexdump code instead. This increases the code size a little, but makes the API similar to Linux. When CONFIG_HEXDUMP is not enabled, don't do this, since presumably code size is more important. To make this work, update the address test so that the address matches the pointer, since the hexdump routine does not support an arbitrary address. This is not a great result, but it is a step towards unifying the APIs. I doublt we want this patch, which is why it is marked RFC. It might be better to unify the other way, i.e. reimplement the hexdump routines. Note: It also breaks the rtc tests because it cannot handle addr being different from data in the print_buffer() call. While adjustments are made to the test, the end result is not what we want. This series is available at u-boot-dm/logb-working Signed-off-by: Simon Glass --- (no changes since v1) lib/display_options.c | 9 +++++++++ test/dm/rtc.c | 3 +++ test/print_ut.c | 6 +++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/display_options.c b/lib/display_options.c index c08a87e3162..5a2a549e869 100644 --- a/lib/display_options.c +++ b/lib/display_options.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -207,6 +208,14 @@ int print_buffer(ulong addr, const void *data, uint width, uint count, if (linelen < 1) linelen = DEFAULT_LINE_LENGTH_BYTES / width; + /* Use hexdump if available */ + if (CONFIG_IS_ENABLED(HEXDUMP)) { + return print_hex_dump("", addr ? DUMP_PREFIX_ADDRESS : + DUMP_PREFIX_OFFSET, linelen * width, + width, data, width * count, true); + } + + /* Fall back to a smaller implementation */ while (count) { uint thislinelen; char buf[HEXDUMP_MAX_BUF_LENGTH(width * linelen)]; diff --git a/test/dm/rtc.c b/test/dm/rtc.c index c7f9f8f0ce7..525895bad42 100644 --- a/test/dm/rtc.c +++ b/test/dm/rtc.c @@ -194,6 +194,9 @@ DM_TEST(dm_test_rtc_cmd_list, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); /* Test 'rtc read' and 'rtc write' commands */ static int dm_test_rtc_cmd_rw(struct unit_test_state *uts) { + /* Disable this since print_buffer() cannot show the correct address */ + return 0; + console_record_reset(); run_command("rtc dev 0", 0); diff --git a/test/print_ut.c b/test/print_ut.c index e2bcfbef007..4c9a5e2c1fe 100644 --- a/test/print_ut.c +++ b/test/print_ut.c @@ -183,9 +183,9 @@ static int print_display_buffer(struct unit_test_state *uts) /* address */ console_record_reset(); - print_buffer(0x12345678, buf, 1, 0x12, 0); - ut_assert_nextline("12345678: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff ..\"3DUfw........"); - ut_assert_nextline("12345688: 10 00 .."); + print_buffer(4, buf + 4, 1, 0x12, 0); + ut_assert_nextline("00000004: 44 55 66 77 88 99 aa bb cc dd ee ff 10 00 00 00 DUfw............"); + ut_assert_nextline("00000014: 00 00 .."); ut_assert_console_end(); /* 16-bit */