From patchwork Wed May 1 08:59:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 240749 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 27D0B2C00C2 for ; Wed, 1 May 2013 19:00:53 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 106334A2E1; Wed, 1 May 2013 11:00:42 +0200 (CEST) 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 uhsLeNEqr03v; Wed, 1 May 2013 11:00:41 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 177E44A2E3; Wed, 1 May 2013 11:00:09 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A73944A2C3 for ; Wed, 1 May 2013 11:00:01 +0200 (CEST) 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 eFfePO9m0Byf for ; Wed, 1 May 2013 10:59:59 +0200 (CEST) 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-ea0-f173.google.com (mail-ea0-f173.google.com [209.85.215.173]) by theia.denx.de (Postfix) with ESMTPS id 5A3334A2A3 for ; Wed, 1 May 2013 10:59:54 +0200 (CEST) Received: by mail-ea0-f173.google.com with SMTP id m14so604942eaj.32 for ; Wed, 01 May 2013 01:59:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:in-reply-to:references:content-type :x-gm-message-state; bh=uLIp4jKDhTaaJFUrrGKmhz9fgNhlF5s1zuVycUcCCVg=; b=FiuPy1b9PcCBjPmpwszC+6JzPgZWPPZtwvHj9cOO//L0cie2w86jc51LM9MyoDIFHG PnU/vNP6d7/gImw3z9NILdopFTd2c2I+y0dubvnD+r9hisZ0KC0Mg2Qs+Xy06GFjAitU OMBHhJOYVtNcKd7GdsKa138ICDPwpLG9/sKviP94Y4nqJvhOp7h43CAv7T1/1bCEyzZS MMaKRi6IIkt6ognG4Ul9vXWJGTqpOEwW44gJeQ09WhKhNx8666eibd682rIXYSwQT8ke DlOR38QcozdlyPnTGzUo+8VMDnGcigssWGD8rXfM8WNu1bsMjWKQjX/O6djlj3CjrQgD rXlQ== X-Received: by 10.14.202.201 with SMTP id d49mr5812665eeo.1.1367398793884; Wed, 01 May 2013 01:59:53 -0700 (PDT) Received: from localhost (nat-63.starnet.cz. [178.255.168.63]) by mx.google.com with ESMTPSA id bp51sm626315eeb.5.2013.05.01.01.59.52 for (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Wed, 01 May 2013 01:59:53 -0700 (PDT) From: Michal Simek To: u-boot@lists.denx.de, Joe Hershberger , Albert Aribaud , Tom Rini Date: Wed, 1 May 2013 10:59:23 +0200 Message-Id: <7e911578f6251419d83604a8256eae32ea4677b1.1367398749.git.michal.simek@xilinx.com> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: References: In-Reply-To: References: X-Gm-Message-State: ALoCoQl50RkcJw8cpaXZW4G79rsP3U1fXruwX77nXmu7WetCP29EBNNR1RS5dfIbWRYZLu3+3E4M Cc: Peter Crosthwaite , Jagannadha Sutradharudu Teki Subject: [U-Boot] [PATCH v2 7/7] fpga: Check device name against bitstream name 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 Ensure that wrong bitstream won't be loaded to current device. Signed-off-by: Michal Simek --- Changes in v2: - New patch in this series drivers/fpga/fpga.c | 20 ++++++++++++++++++++ drivers/fpga/xilinx.c | 2 ++ include/xilinx.h | 1 + include/zynqpl.h | 8 ++++---- 4 files changed, 27 insertions(+), 4 deletions(-) -- 1.8.2.1 diff --git a/drivers/fpga/fpga.c b/drivers/fpga/fpga.c index b74c84f..5ba8cf0 100644 --- a/drivers/fpga/fpga.c +++ b/drivers/fpga/fpga.c @@ -197,8 +197,14 @@ int fpga_loadbitstream(unsigned long dev, char *fpgadata, size_t size) unsigned char *dataptr; unsigned int i; int rc; + const fpga_desc *desc; + Xilinx_desc *xdesc; dataptr = (unsigned char *)fpgadata; + /* Find out fpga_description */ + desc = fpga_validate(dev, dataptr, 0, (char *)__func__); + /* Assign xilinx device description */ + xdesc = desc->devdesc; /* skip the first bytes of the bitsteam, their meaning is unknown */ length = (*dataptr << 8) + *(dataptr + 1); @@ -232,6 +238,20 @@ int fpga_loadbitstream(unsigned long dev, char *fpgadata, size_t size) dataptr += 2; for (i = 0; i < length; i++) buffer[i] = *dataptr++; + + if (xdesc->name) { + i = strncmp(buffer, xdesc->name, strlen(xdesc->name)); + if (i) { + printf("%s: Wrong bitstream ID for this device\n", + __func__); + printf("%s: Bitstream ID %s, current device ID %d/%s\n", + __func__, dev, xdesc->name, buffer); + return FPGA_FAIL; + } + } else { + printf("%s: Please fill correct device ID to Xilinx_desc\n", + __func__); + } printf(" part number = \"%s\"\n", buffer); /* get date (identifier, length, string) */ diff --git a/drivers/fpga/xilinx.c b/drivers/fpga/xilinx.c index fe324ab..bd740c2 100644 --- a/drivers/fpga/xilinx.c +++ b/drivers/fpga/xilinx.c @@ -220,6 +220,8 @@ int xilinx_info (Xilinx_desc * desc) printf ("Device Size: \t%d bytes\n" "Cookie: \t0x%x (%d)\n", desc->size, desc->cookie, desc->cookie); + if (desc->name) + printf("Device name: \t%s\n", desc->name); if (desc->iface_fns) { printf ("Device Function Table @ 0x%p\n", desc->iface_fns); diff --git a/include/xilinx.h b/include/xilinx.h index 592cbea..bcfe76d 100644 --- a/include/xilinx.h +++ b/include/xilinx.h @@ -81,6 +81,7 @@ typedef struct { /* typedef Xilinx_desc */ size_t size; /* bytes of data part can accept */ void *iface_fns; /* interface function table */ int cookie; /* implementation specific cookie */ + char *name; /* device name in bitstream */ } Xilinx_desc; /* end, typedef Xilinx_desc */ /* Generic Xilinx Functions diff --git a/include/zynqpl.h b/include/zynqpl.h index bc9b948..0247ef6 100644 --- a/include/zynqpl.h +++ b/include/zynqpl.h @@ -45,15 +45,15 @@ extern int zynq_info(Xilinx_desc *desc); /* Descriptor Macros */ #define XILINX_XC7Z010_DESC(cookie) \ -{ xilinx_zynq, devcfg, XILINX_XC7Z010_SIZE, NULL, cookie } +{ xilinx_zynq, devcfg, XILINX_XC7Z010_SIZE, NULL, cookie, "7z010" } #define XILINX_XC7Z020_DESC(cookie) \ -{ xilinx_zynq, devcfg, XILINX_XC7Z020_SIZE, NULL, cookie } +{ xilinx_zynq, devcfg, XILINX_XC7Z020_SIZE, NULL, cookie, "7z020" } #define XILINX_XC7Z030_DESC(cookie) \ -{ xilinx_zynq, devcfg, XILINX_XC7Z030_SIZE, NULL, cookie } +{ xilinx_zynq, devcfg, XILINX_XC7Z030_SIZE, NULL, cookie, "7z030" } #define XILINX_XC7Z045_DESC(cookie) \ -{ xilinx_zynq, devcfg, XILINX_XC7Z045_SIZE, NULL, cookie } +{ xilinx_zynq, devcfg, XILINX_XC7Z045_SIZE, NULL, cookie, "7z045" } #endif /* _ZYNQPL_H_ */