From patchwork Mon Mar 18 23:51:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 228853 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id A755E2C00B1 for ; Tue, 19 Mar 2013 10:57:58 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BD3C64A203; Tue, 19 Mar 2013 00:56:20 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DJfzUJgYTMnD; Tue, 19 Mar 2013 00:56:20 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CE45F4A100; Tue, 19 Mar 2013 00:54:09 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8E2E44A03C for ; Tue, 19 Mar 2013 00:53:35 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kZuvjJvF-rel for ; Tue, 19 Mar 2013 00:53:34 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-ye0-f201.google.com (mail-ye0-f201.google.com [209.85.213.201]) by theia.denx.de (Postfix) with ESMTPS id DD4894A051 for ; Tue, 19 Mar 2013 00:53:21 +0100 (CET) Received: by mail-ye0-f201.google.com with SMTP id m12so638545yen.2 for ; Mon, 18 Mar 2013 16:53:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=A2lp/W/kuBPhMds1TepUDQ5s2mz4WeDfYqOXW5H6Ggc=; b=i6nhSmljkJs/k1qDy7P2/BSgeWSe4hIdug3QDg+EKy3HrwpB6w/KmIKw6uX+pLvhvC LvOsy4lGuG30hp0TgZyJmlrIATDPCXPhC79SiCX5vBMbdkeNRKzr2FFSFDiWxSc8WKB4 pb0hiOlJLXl9hPApeLnsEENl5JIzRROR4KETEgDYCAEWQ4dkjDHNyox9F75LuVMfauRd A/ceyCNfn2uK1I337igmgFfVuKb2dY32XiqbpcFlmfMmlqV2WuBcOhyvWWpqPRU8Gh6j 7dno0VSC0KXVkJMno/j9c0GcbP+NdteANwBFs2Tv5/hY7zH/0h93/D4F+Mw3hVCED6tp dzyQ== X-Received: by 10.58.154.194 with SMTP id vq2mr13914300veb.17.1363650800083; Mon, 18 Mar 2013 16:53:20 -0700 (PDT) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id t30si2188025yhi.6.2013.03.18.16.53.20 (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Mon, 18 Mar 2013 16:53:20 -0700 (PDT) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.73.79]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id CBCB731C00F; Mon, 18 Mar 2013 16:53:19 -0700 (PDT) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id ACCEC160341; Mon, 18 Mar 2013 16:53:19 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 18 Mar 2013 16:51:38 -0700 Message-Id: <1363650725-30459-19-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.8.1.3 In-Reply-To: <1363650725-30459-1-git-send-email-sjg@chromium.org> References: <1363650725-30459-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQlCNFTVzuhWKtgn5stHgdt3CnQxuKvhmtIhWpUHdBduZnZlN9aZ3wt2Jrwrslr0pks7oN7gOtkVR03rtIAF8BK7463jGgGMxz8LncOft+IVmPX9UB4Kjx57yWYZramZlslVr00LrrUo9+WVyLjCNllWm80Thr8tut4yuL6jMaNM1+MFG7cTqPSieWGsM8GXRdMQpTce Cc: Joel A Fernandes , Will Drewry , u-boot-review@google.com, Bill Richardson , Randall Spangler , Jerry Van Baren , Tom Rini , Vadim Bendebury , =?UTF-8?q?Andreas=20B=C3=A4ck?= , Kees Cook Subject: [U-Boot] [PATCH v2 18/45] fdt: Add a parameter to fdt_valid() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de At present this only checks working_fdt, but we want to check other FDTs also. So add the FDT to check as a parameter to fdt_valid(). Signed-off-by: Simon Glass --- Changes in v2: - Allow the control FDT to be set even if there is currently no control FDT - fdt_valid() sets the FDT pointer to NULL on error, to simplify callers common/cmd_fdt.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/common/cmd_fdt.c b/common/cmd_fdt.c index ac77a08..07072f3 100644 --- a/common/cmd_fdt.c +++ b/common/cmd_fdt.c @@ -43,7 +43,7 @@ */ DECLARE_GLOBAL_DATA_PTR; -static int fdt_valid(void); +static int fdt_valid(struct fdt_header **blobp); static int fdt_parse_prop(char *const*newval, int count, char *data, int *len); static int fdt_print(const char *pathp, char *prop, int depth); static int is_printable_string(const void *data, int len); @@ -104,9 +104,8 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) * Set the address [and length] of the fdt. */ if (argc == 2) { - if (!fdt_valid()) { + if (!fdt_valid(&working_fdt)) return 1; - } printf("The address of the fdt is %p\n", working_fdt); return 0; } @@ -114,9 +113,8 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) addr = simple_strtoul(argv[2], NULL, 16); set_working_fdt_addr((void *)addr); - if (!fdt_valid()) { + if (!fdt_valid(&working_fdt)) return 1; - } if (argc >= 4) { int len; @@ -167,9 +165,8 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) * Set the address and length of the fdt. */ working_fdt = (struct fdt_header *)simple_strtoul(argv[2], NULL, 16); - if (!fdt_valid()) { + if (!fdt_valid(&working_fdt)) return 1; - } newaddr = (struct fdt_header *)simple_strtoul(argv[3],NULL,16); @@ -592,16 +589,23 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) /****************************************************************************/ -static int fdt_valid(void) +/** + * fdt_valid() - Check if an FDT is valid. If not, change it to NULL + * + * @blobp: Pointer to FDT pointer + * @return 1 if OK, 0 if bad (in which case *blobp is set to NULL) + */ +static int fdt_valid(struct fdt_header **blobp) { - int err; + const void *blob = *blobp; + int err; - if (working_fdt == NULL) { + if (blob == NULL) { printf ("The address of the fdt is invalid (NULL).\n"); return 0; } - err = fdt_check_header(working_fdt); + err = fdt_check_header(blob); if (err == 0) return 1; /* valid */ @@ -611,23 +615,21 @@ static int fdt_valid(void) * Be more informative on bad version. */ if (err == -FDT_ERR_BADVERSION) { - if (fdt_version(working_fdt) < + if (fdt_version(blob) < FDT_FIRST_SUPPORTED_VERSION) { printf (" - too old, fdt %d < %d", - fdt_version(working_fdt), + fdt_version(blob), FDT_FIRST_SUPPORTED_VERSION); - working_fdt = NULL; } - if (fdt_last_comp_version(working_fdt) > + if (fdt_last_comp_version(blob) > FDT_LAST_SUPPORTED_VERSION) { printf (" - too new, fdt %d > %d", - fdt_version(working_fdt), + fdt_version(blob), FDT_LAST_SUPPORTED_VERSION); - working_fdt = NULL; } - return 0; } printf("\n"); + *blobp = NULL; return 0; } return 1;