From patchwork Mon Oct 1 18:22:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 977369 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 42P9jL2yN4z9s3l for ; Tue, 2 Oct 2018 04:26:46 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id B6195C21FAD; Mon, 1 Oct 2018 18:25:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id AD533C21E16; Mon, 1 Oct 2018 18:23:24 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 2E52DC21FB1; Mon, 1 Oct 2018 18:23:23 +0000 (UTC) Received: from mail-io1-f74.google.com (mail-io1-f74.google.com [209.85.166.74]) by lists.denx.de (Postfix) with ESMTPS id 34CF3C21F9C for ; Mon, 1 Oct 2018 18:23:12 +0000 (UTC) Received: by mail-io1-f74.google.com with SMTP id s15-v6so14054742iob.11 for ; Mon, 01 Oct 2018 11:23:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=m+DKHR4+ZEUA8iZvdZC33BnqcioDx8ru4de6ICrWpuY=; b=IHV5jMTO7F7qF1ucEgVM+/YfD08LjmFgVD1WKF7t/CcZmOYKanCRTE1W9xCaxWhE/D 39HnhD0B4it7j3Froj7JWu/FmrZh8SKOh78bD33lBZnf8V5NJi/rNuXZ3MiTlXLsPCKB C/xisKzNxnWj2xvCSS+puk0vk6HOKt0sgRhtqWdfst8yM12WYWRsQZQ2mjjnr6nf0QfH u5/MSsAIbGd9uxuYIbD9R3lH7EXpyBM5iLFc9JpPv70D9eIsxHqhlCCp4+qm2Syw2Eog 0mYhkaj2KKcZMc8wKZV0rLiWxpIXlwqSE0dr5gRPYyFEVYVSVOeUFn0Eg02cGNA2CjUj go/w== X-Gm-Message-State: ABuFfohL6TAv8kAiPLoqsYSMlsWBK8uVh8Q7kr86YtfxoM+NgFDGcnRZ k8B3HCsZIDQFXd5UTSR9Id8ZDgE= X-Google-Smtp-Source: ACcGV61/oSX0aT6Kuw/rAfQKw9XGDX9Hv/tRG31GgFSWnmhBsiVhraP09JncdGS9OOCa2Ihod/zE8TY= X-Received: by 2002:a24:2414:: with SMTP id f20-v6mr11751522ita.0.1538418191225; Mon, 01 Oct 2018 11:23:11 -0700 (PDT) Date: Mon, 1 Oct 2018 12:22:08 -0600 In-Reply-To: <20181001182249.129565-1-sjg@chromium.org> Message-Id: <20181001182249.129565-5-sjg@chromium.org> Mime-Version: 1.0 References: <20181001182249.129565-1-sjg@chromium.org> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog From: Simon Glass To: U-Boot Mailing List Subject: [U-Boot] [PATCH 04/45] dm: core: Update ofnode to read binman-style flash entry X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" At present ofnode_read_fmap_entry() reads a flash map entry in a format which is not supported by binman. To allow use to use binman-format descriptions, update this function. Also add a simple test. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- arch/sandbox/dts/sandbox.dts | 20 ++++++++++---------- arch/sandbox/dts/sandbox64.dts | 20 ++++++++++---------- drivers/core/of_extra.c | 27 +++++++++++++++++++-------- drivers/misc/cros_ec.c | 33 +++++++++++++++++---------------- include/dm/of_extra.h | 3 ++- test/dm/ofnode.c | 16 ++++++++++++++++ 6 files changed, 74 insertions(+), 45 deletions(-) diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts index 1aa0f8eef53..1b00fbebd78 100644 --- a/arch/sandbox/dts/sandbox.dts +++ b/arch/sandbox/dts/sandbox.dts @@ -18,7 +18,7 @@ stdout-path = "/serial"; }; - cros_ec: cros-ec@0 { + cros_ec: cros-ec { reg = <0 0>; compatible = "google,cros-ec-sandbox"; @@ -26,23 +26,23 @@ * This describes the flash memory within the EC. Note * that the STM32L flash erases to 0, not 0xff. */ - #address-cells = <1>; - #size-cells = <1>; - flash@8000000 { - reg = <0x08000000 0x20000>; + flash { + image-pos = <0x08000000>; + size = <0x20000>; erase-value = <0>; - #address-cells = <1>; - #size-cells = <1>; /* Information for sandbox */ ro { - reg = <0 0xf000>; + image-pos = <0>; + size = <0xf000>; }; wp-ro { - reg = <0xf000 0x1000>; + image-pos = <0xf000>; + size = <0x1000>; }; rw { - reg = <0x10000 0x10000>; + image-pos = <0x10000>; + size = <0x10000>; }; }; }; diff --git a/arch/sandbox/dts/sandbox64.dts b/arch/sandbox/dts/sandbox64.dts index 9e65d2fda3d..6ecaaad13d8 100644 --- a/arch/sandbox/dts/sandbox64.dts +++ b/arch/sandbox/dts/sandbox64.dts @@ -17,7 +17,7 @@ stdout-path = "/serial"; }; - cros_ec: cros-ec@0 { + cros_ec: cros-ec { reg = <0 0 0 0>; compatible = "google,cros-ec-sandbox"; @@ -25,23 +25,23 @@ * This describes the flash memory within the EC. Note * that the STM32L flash erases to 0, not 0xff. */ - #address-cells = <1>; - #size-cells = <1>; - flash@8000000 { - reg = <0x08000000 0x20000>; + flash { + image-pos = <0x08000000>; + size = <0x20000>; erase-value = <0>; - #address-cells = <1>; - #size-cells = <1>; /* Information for sandbox */ ro { - reg = <0 0xf000>; + image-pos = <0>; + size = <0xf000>; }; wp-ro { - reg = <0xf000 0x1000>; + image-pos = <0xf000>; + size = <0x1000>; }; rw { - reg = <0x10000 0x10000>; + image-pos = <0x10000>; + size = <0x10000>; }; }; }; diff --git a/drivers/core/of_extra.c b/drivers/core/of_extra.c index aa48917dddf..f1f393c3598 100644 --- a/drivers/core/of_extra.c +++ b/drivers/core/of_extra.c @@ -13,19 +13,30 @@ int ofnode_read_fmap_entry(ofnode node, struct fmap_entry *entry) { const char *prop; - u32 reg[2]; - if (ofnode_read_u32_array(node, "reg", reg, 2)) { - debug("Node '%s' has bad/missing 'reg' property\n", + if (ofnode_read_u32(node, "image-pos", &entry->offset)) { + debug("Node '%s' has bad/missing 'image-pos' property\n", ofnode_get_name(node)); - return -log_ret(ENOENT); + return log_ret(-ENOENT); + } + if (ofnode_read_u32(node, "size", &entry->length)) { + debug("Node '%s' has bad/missing 'size' property\n", + ofnode_get_name(node)); + return log_ret(-ENOENT); } - entry->offset = reg[0]; - entry->length = reg[1]; entry->used = ofnode_read_s32_default(node, "used", entry->length); prop = ofnode_read_string(node, "compress"); - entry->compress_algo = prop && !strcmp(prop, "lzo") ? - FMAP_COMPRESS_LZO : FMAP_COMPRESS_NONE; + if (prop) { + if (!strcmp(prop, "lz4")) + entry->compress_algo = FMAP_COMPRESS_LZ4; + else + return log_msg_ret("Unknown compression algo", + -EINVAL); + } else { + entry->compress_algo = FMAP_COMPRESS_NONE; + } + entry->unc_length = ofnode_read_s32_default(node, "uncomp-size", + entry->length); prop = ofnode_read_string(node, "hash"); if (prop) entry->hash_size = strlen(prop); diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c index 6f299d407a4..c5ac03d027d 100644 --- a/drivers/misc/cros_ec.c +++ b/drivers/misc/cros_ec.c @@ -263,8 +263,8 @@ static int send_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version, * @return number of bytes in response, or -ve on error */ static int ec_command_inptr(struct cros_ec_dev *dev, uint8_t cmd, - int cmd_version, const void *dout, int dout_len, uint8_t **dinp, - int din_len) + int cmd_version, const void *dout, int dout_len, + uint8_t **dinp, int din_len) { uint8_t *din = NULL; int len; @@ -409,7 +409,7 @@ int cros_ec_read_build_info(struct cros_ec_dev *dev, char **strp) } int cros_ec_read_current_image(struct cros_ec_dev *dev, - enum ec_current_image *image) + enum ec_current_image *image) { struct ec_response_get_version *r; @@ -422,7 +422,7 @@ int cros_ec_read_current_image(struct cros_ec_dev *dev, } static int cros_ec_wait_on_hash_done(struct cros_ec_dev *dev, - struct ec_response_vboot_hash *hash) + struct ec_response_vboot_hash *hash) { struct ec_params_vboot_hash p; ulong start; @@ -446,7 +446,7 @@ static int cros_ec_wait_on_hash_done(struct cros_ec_dev *dev, int cros_ec_read_hash(struct cros_ec_dev *dev, - struct ec_response_vboot_hash *hash) + struct ec_response_vboot_hash *hash) { struct ec_params_vboot_hash p; int rv; @@ -515,7 +515,7 @@ static int cros_ec_invalidate_hash(struct cros_ec_dev *dev) } int cros_ec_reboot(struct cros_ec_dev *dev, enum ec_reboot_cmd cmd, - uint8_t flags) + uint8_t flags) { struct ec_params_reboot_ec p; @@ -601,8 +601,8 @@ int cros_ec_clear_host_events(struct cros_ec_dev *dev, uint32_t events) } int cros_ec_flash_protect(struct cros_ec_dev *dev, - uint32_t set_mask, uint32_t set_flags, - struct ec_response_flash_protect *resp) + uint32_t set_mask, uint32_t set_flags, + struct ec_response_flash_protect *resp) { struct ec_params_flash_protect params; @@ -742,7 +742,8 @@ int cros_ec_flash_erase(struct cros_ec_dev *dev, uint32_t offset, uint32_t size) * @return 0 if ok, -1 on error */ static int cros_ec_flash_write_block(struct cros_ec_dev *dev, - const uint8_t *data, uint32_t offset, uint32_t size) + const uint8_t *data, uint32_t offset, + uint32_t size) { struct ec_params_flash_write *p; int ret; @@ -802,7 +803,7 @@ static int cros_ec_data_is_erased(const uint32_t *data, int size) * @param info Pointer to output flash info struct */ int cros_ec_read_flashinfo(struct cros_ec_dev *dev, - struct ec_response_flash_info *info) + struct ec_response_flash_info *info) { int ret; @@ -815,7 +816,7 @@ int cros_ec_read_flashinfo(struct cros_ec_dev *dev, } int cros_ec_flash_write(struct cros_ec_dev *dev, const uint8_t *data, - uint32_t offset, uint32_t size) + uint32_t offset, uint32_t size) { uint32_t burst = cros_ec_flash_write_burst_size(dev); uint32_t end, off; @@ -832,7 +833,7 @@ int cros_ec_flash_write(struct cros_ec_dev *dev, const uint8_t *data, /* If the data is empty, there is no point in programming it */ todo = min(end - off, burst); if (dev->optimise_flash_write && - cros_ec_data_is_erased((uint32_t *)data, todo)) + cros_ec_data_is_erased((uint32_t *)data, todo)) continue; ret = cros_ec_flash_write_block(dev, data, off, todo); @@ -859,7 +860,7 @@ int cros_ec_flash_write(struct cros_ec_dev *dev, const uint8_t *data, * @return 0 if ok, -1 on error */ static int cros_ec_flash_read_block(struct cros_ec_dev *dev, uint8_t *data, - uint32_t offset, uint32_t size) + uint32_t offset, uint32_t size) { struct ec_params_flash_read p; @@ -871,7 +872,7 @@ static int cros_ec_flash_read_block(struct cros_ec_dev *dev, uint8_t *data, } int cros_ec_flash_read(struct cros_ec_dev *dev, uint8_t *data, uint32_t offset, - uint32_t size) + uint32_t size) { uint32_t burst = cros_ec_flash_write_burst_size(dev); uint32_t end, off; @@ -888,8 +889,8 @@ int cros_ec_flash_read(struct cros_ec_dev *dev, uint8_t *data, uint32_t offset, return 0; } -int cros_ec_flash_update_rw(struct cros_ec_dev *dev, - const uint8_t *image, int image_size) +int cros_ec_flash_update_rw(struct cros_ec_dev *dev, const uint8_t *image, + int image_size) { uint32_t rw_offset, rw_size; int ret; diff --git a/include/dm/of_extra.h b/include/dm/of_extra.h index 97988b66632..ca15df21b06 100644 --- a/include/dm/of_extra.h +++ b/include/dm/of_extra.h @@ -11,7 +11,7 @@ enum fmap_compress_t { FMAP_COMPRESS_NONE, - FMAP_COMPRESS_LZO, + FMAP_COMPRESS_LZ4, }; enum fmap_hash_t { @@ -26,6 +26,7 @@ struct fmap_entry { uint32_t length; uint32_t used; /* Number of bytes used in region */ enum fmap_compress_t compress_algo; /* Compression type */ + uint32_t unc_length; /* Uncompressed length */ enum fmap_hash_t hash_algo; /* Hash algorithm */ const uint8_t *hash; /* Hash value */ int hash_size; /* Hash size */ diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index 907d1ddbdb6..745de50c7ba 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -42,3 +43,18 @@ static int dm_test_ofnode_by_prop_value(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_ofnode_by_prop_value, DM_TESTF_SCAN_FDT); + +static int dm_test_ofnode_fmap(struct unit_test_state *uts) +{ + struct fmap_entry entry; + ofnode node; + + node = ofnode_path("/cros-ec/flash"); + ut_assert(ofnode_valid(node)); + ut_assertok(ofnode_read_fmap_entry(node, &entry)); + ut_asserteq(0x08000000, entry.offset); + ut_asserteq(0x20000, entry.length); + + return 0; +} +DM_TEST(dm_test_ofnode_fmap, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);