From patchwork Fri May 3 07:14:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 241229 X-Patchwork-Delegate: albert.aribaud@free.fr 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 9BF382C00C4 for ; Fri, 3 May 2013 17:15:44 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 193C04A385; Fri, 3 May 2013 09:15:40 +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 noN8jbCkKmEt; Fri, 3 May 2013 09:15:39 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6BE7C4A395; Fri, 3 May 2013 09:14:48 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3C1734A380 for ; Fri, 3 May 2013 09:14:41 +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 yEzuXAys0r2P for ; Fri, 3 May 2013 09:14:36 +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-ee0-f51.google.com (mail-ee0-f51.google.com [74.125.83.51]) by theia.denx.de (Postfix) with ESMTPS id 4193A4A344 for ; Fri, 3 May 2013 09:14:26 +0200 (CEST) Received: by mail-ee0-f51.google.com with SMTP id c1so605934eek.24 for ; Fri, 03 May 2013 00:14:25 -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=R9Fqa8LBB7pc5xSibnmQkrykQpXQkrZmlQQ3nLdfsF0=; b=odEbqg7OsKYUg3VGFc2KtqRTOZuPW+gy/iCYvm3yClv+jM+1ZyGtL5YCz5SPKujEN2 PHVaDk3owq0qcI4zQ/8ucqAVu+WuUdUE4ZmsadEH0DL7FX4xbOFC5iXJ/sv3dsvNOHmw z+N6D6WjqhWTwnvR4GYDLGDehCayD9Erz406bqEadwfoDVDXcorD5Kob0Zv5SzYzMdZr K9hZozrbtF+TAySbdd7I9y4KtisGA8n4UtAXmsoaH21mrfHEdxNbsJOHQiigxC2lclhq R+winVpCin5UZuG9IqBmI7hrK5ZtA4FRI7yAgh1plQlRps5/+wD/aR2oWLzPsTXdY0DA /stA== X-Received: by 10.14.111.129 with SMTP id w1mr25045832eeg.13.1367565265625; Fri, 03 May 2013 00:14:25 -0700 (PDT) Received: from localhost (nat-63.starnet.cz. [178.255.168.63]) by mx.google.com with ESMTPSA id l6sm13990559eem.9.2013.05.03.00.14.24 for (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Fri, 03 May 2013 00:14:25 -0700 (PDT) From: Michal Simek To: u-boot@lists.denx.de, Albert Aribaud , Tom Rini , Michal Simek , Joe Hershberger Date: Fri, 3 May 2013 09:14:11 +0200 Message-Id: X-Mailer: git-send-email 1.8.2.1 In-Reply-To: References: In-Reply-To: References: X-Gm-Message-State: ALoCoQkJGeeMDTjVCGh0EkMPIQlwnDoP07jER5s4R0dDcb4V5RYXK/A3V9UJZaGJCaEE67quKz7s Cc: Peter Crosthwaite , Jagannadha Sutradharudu Teki Subject: [U-Boot] [PATCH v3 4/9] cmd: fpga: Move fpga_loadbitstream to fpga.c 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 In bitstream decoding you can directly check device which you want to load and in fpga.c are fpga_validate and fpga_dev_info functions which should be used for it. Signed-off-by: Michal Simek --- Changes in v3: - Setup fpga_loadbitstream as weak function Changes in v2: None common/cmd_fpga.c | 94 --------------------------------------------------- drivers/fpga/fpga.c | 9 +++++ drivers/fpga/xilinx.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++ include/fpga.h | 1 + 4 files changed, 96 insertions(+), 94 deletions(-) -- 1.8.2.1 diff --git a/common/cmd_fpga.c b/common/cmd_fpga.c index f3579bb..aa14ceb 100644 --- a/common/cmd_fpga.c +++ b/common/cmd_fpga.c @@ -44,100 +44,6 @@ static int fpga_get_op(char *opstr); #define FPGA_DUMP 3 #define FPGA_LOADMK 4 -/* Convert bitstream data and load into the fpga */ -int fpga_loadbitstream(unsigned long dev, char *fpgadata, size_t size) -{ -#if defined(CONFIG_FPGA_XILINX) - unsigned int length; - unsigned int swapsize; - char buffer[80]; - unsigned char *dataptr; - unsigned int i; - int rc; - - dataptr = (unsigned char *)fpgadata; - - /* skip the first bytes of the bitsteam, their meaning is unknown */ - length = (*dataptr << 8) + *(dataptr + 1); - dataptr += 2; - dataptr += length; - - /* get design name (identifier, length, string) */ - length = (*dataptr << 8) + *(dataptr + 1); - dataptr += 2; - if (*dataptr++ != 0x61) { - debug("%s: Design name id not recognized in bitstream\n", - __func__); - return FPGA_FAIL; - } - - length = (*dataptr << 8) + *(dataptr + 1); - dataptr += 2; - for (i = 0; i < length; i++) - buffer[i] = *dataptr++; - - printf(" design filename = \"%s\"\n", buffer); - - /* get part number (identifier, length, string) */ - if (*dataptr++ != 0x62) { - printf("%s: Part number id not recognized in bitstream\n", - __func__); - return FPGA_FAIL; - } - - length = (*dataptr << 8) + *(dataptr + 1); - dataptr += 2; - for (i = 0; i < length; i++) - buffer[i] = *dataptr++; - printf(" part number = \"%s\"\n", buffer); - - /* get date (identifier, length, string) */ - if (*dataptr++ != 0x63) { - printf("%s: Date identifier not recognized in bitstream\n", - __func__); - return FPGA_FAIL; - } - - length = (*dataptr << 8) + *(dataptr+1); - dataptr += 2; - for (i = 0; i < length; i++) - buffer[i] = *dataptr++; - printf(" date = \"%s\"\n", buffer); - - /* get time (identifier, length, string) */ - if (*dataptr++ != 0x64) { - printf("%s: Time identifier not recognized in bitstream\n", - __func__); - return FPGA_FAIL; - } - - length = (*dataptr << 8) + *(dataptr+1); - dataptr += 2; - for (i = 0; i < length; i++) - buffer[i] = *dataptr++; - printf(" time = \"%s\"\n", buffer); - - /* get fpga data length (identifier, length) */ - if (*dataptr++ != 0x65) { - printf("%s: Data length id not recognized in bitstream\n", - __func__); - return FPGA_FAIL; - } - swapsize = ((unsigned int) *dataptr << 24) + - ((unsigned int) *(dataptr + 1) << 16) + - ((unsigned int) *(dataptr + 2) << 8) + - ((unsigned int) *(dataptr + 3)); - dataptr += 4; - printf(" bytes in bitstream = %d\n", swapsize); - - rc = fpga_load(dev, dataptr, swapsize); - return rc; -#else - printf("Bitstream support only for Xilinx devices\n"); - return FPGA_FAIL; -#endif -} - /* ------------------------------------------------------------------------- */ /* command form: * fpga diff --git a/drivers/fpga/fpga.c b/drivers/fpga/fpga.c index 43bdf4f..f0253bf 100644 --- a/drivers/fpga/fpga.c +++ b/drivers/fpga/fpga.c @@ -188,6 +188,15 @@ int fpga_add(fpga_type devtype, void *desc) } /* + * Convert bitstream data and load into the fpga + */ +int __weak fpga_loadbitstream(unsigned long dev, char *fpgadata, size_t size) +{ + printf("Bitstream support not implemented for this FPGA device\n"); + return FPGA_FAIL; +} + +/* * Generic multiplexing code */ int fpga_load(int devnum, const void *buf, size_t bsize) diff --git a/drivers/fpga/xilinx.c b/drivers/fpga/xilinx.c index 32787b2..7d0342a 100644 --- a/drivers/fpga/xilinx.c +++ b/drivers/fpga/xilinx.c @@ -48,6 +48,92 @@ static int xilinx_validate (Xilinx_desc * desc, char *fn); /* ------------------------------------------------------------------------- */ +int fpga_loadbitstream(unsigned long dev, char *fpgadata, size_t size) +{ + unsigned int length; + unsigned int swapsize; + char buffer[80]; + unsigned char *dataptr; + unsigned int i; + + dataptr = (unsigned char *)fpgadata; + + /* skip the first bytes of the bitsteam, their meaning is unknown */ + length = (*dataptr << 8) + *(dataptr + 1); + dataptr += 2; + dataptr += length; + + /* get design name (identifier, length, string) */ + length = (*dataptr << 8) + *(dataptr + 1); + dataptr += 2; + if (*dataptr++ != 0x61) { + debug("%s: Design name id not recognized in bitstream\n", + __func__); + return FPGA_FAIL; + } + + length = (*dataptr << 8) + *(dataptr + 1); + dataptr += 2; + for (i = 0; i < length; i++) + buffer[i] = *dataptr++; + + printf(" design filename = \"%s\"\n", buffer); + + /* get part number (identifier, length, string) */ + if (*dataptr++ != 0x62) { + printf("%s: Part number id not recognized in bitstream\n", + __func__); + return FPGA_FAIL; + } + + length = (*dataptr << 8) + *(dataptr + 1); + dataptr += 2; + for (i = 0; i < length; i++) + buffer[i] = *dataptr++; + printf(" part number = \"%s\"\n", buffer); + + /* get date (identifier, length, string) */ + if (*dataptr++ != 0x63) { + printf("%s: Date identifier not recognized in bitstream\n", + __func__); + return FPGA_FAIL; + } + + length = (*dataptr << 8) + *(dataptr+1); + dataptr += 2; + for (i = 0; i < length; i++) + buffer[i] = *dataptr++; + printf(" date = \"%s\"\n", buffer); + + /* get time (identifier, length, string) */ + if (*dataptr++ != 0x64) { + printf("%s: Time identifier not recognized in bitstream\n", + __func__); + return FPGA_FAIL; + } + + length = (*dataptr << 8) + *(dataptr+1); + dataptr += 2; + for (i = 0; i < length; i++) + buffer[i] = *dataptr++; + printf(" time = \"%s\"\n", buffer); + + /* get fpga data length (identifier, length) */ + if (*dataptr++ != 0x65) { + printf("%s: Data length id not recognized in bitstream\n", + __func__); + return FPGA_FAIL; + } + swapsize = ((unsigned int) *dataptr << 24) + + ((unsigned int) *(dataptr + 1) << 16) + + ((unsigned int) *(dataptr + 2) << 8) + + ((unsigned int) *(dataptr + 3)); + dataptr += 4; + printf(" bytes in bitstream = %d\n", swapsize); + + return fpga_load(dev, dataptr, swapsize); +} + int xilinx_load(Xilinx_desc *desc, const void *buf, size_t bsize) { int ret_val = FPGA_FAIL; /* assume a failure */ diff --git a/include/fpga.h b/include/fpga.h index 30a4e6a..0d01e04 100644 --- a/include/fpga.h +++ b/include/fpga.h @@ -68,6 +68,7 @@ extern void fpga_init(void); extern int fpga_add(fpga_type devtype, void *desc); extern int fpga_count(void); extern int fpga_load(int devnum, const void *buf, size_t bsize); +extern int fpga_loadbitstream(unsigned long dev, char *fpgadata, size_t size); extern int fpga_dump(int devnum, const void *buf, size_t bsize); extern int fpga_info(int devnum);