From patchwork Mon Jan 23 13:46:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 718573 X-Patchwork-Delegate: jagannadh.teki@gmail.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 3v6Xh24syxz9sDF for ; Tue, 24 Jan 2017 00:48:02 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 882854B5A1; Mon, 23 Jan 2017 14:47:51 +0100 (CET) X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" 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 kfIBfOeNKmoA; Mon, 23 Jan 2017 14:47:51 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 517ED4B55F; Mon, 23 Jan 2017 14:47:23 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6B5504AAA7 for ; Mon, 23 Jan 2017 14:47:12 +0100 (CET) X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" 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 VCL93-8jwAwr for ; Mon, 23 Jan 2017 14:47:12 +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.free-electrons.com (mail.free-electrons.com [62.4.15.54]) by theia.denx.de (Postfix) with ESMTP id 2A3464A997 for ; Mon, 23 Jan 2017 14:47:09 +0100 (CET) Received: by mail.free-electrons.com (Postfix, from userid 110) id 7CD8820C00; Mon, 23 Jan 2017 14:47:13 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id 510AD20BA0; Mon, 23 Jan 2017 14:47:13 +0100 (CET) From: Maxime Ripard To: Jagan Teki , Scott Wood Date: Mon, 23 Jan 2017 14:46:44 +0100 Message-Id: <53f1f7ee56756fc2e8a90ff347d0cde691103f10.1485179128.git-series.maxime.ripard@free-electrons.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Cc: Thomas Petazzoni , Alexander Kaplan , Maxime Ripard , u-boot@lists.denx.de Subject: [U-Boot] [PATCH v4 2/16] bch: Allow to build for the host X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" We will need the bch functions in the tool to generate the SPL images for the Allwinner SoCs. Do the needed adjustments so that we can use it on the host. Signed-off-by: Maxime Ripard Reviewed-by: Tom Rini --- lib/bch.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+), 0 deletions(-) diff --git a/lib/bch.c b/lib/bch.c index 147715afd06a..ec53483774b5 100644 --- a/lib/bch.c +++ b/lib/bch.c @@ -54,10 +54,27 @@ * finite fields GF(2^q). In Rapport de recherche INRIA no 2829, 1996. */ +#ifndef USE_HOSTCC #include #include #include +#else +#include +#include +#include +#include +#include + +#undef cpu_to_be32 +#define cpu_to_be32 htobe32 +#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) +#define kmalloc(size, flags) malloc(size) +#define kzalloc(size, flags) calloc(1, size) +#define kfree free +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) +#endif + #include #include @@ -95,6 +112,37 @@ struct gf_poly_deg1 { unsigned int c[2]; }; +#ifdef USE_HOSTCC +static int fls(int x) +{ + int r = 32; + + if (!x) + return 0; + if (!(x & 0xffff0000u)) { + x <<= 16; + r -= 16; + } + if (!(x & 0xff000000u)) { + x <<= 8; + r -= 8; + } + if (!(x & 0xf0000000u)) { + x <<= 4; + r -= 4; + } + if (!(x & 0xc0000000u)) { + x <<= 2; + r -= 2; + } + if (!(x & 0x80000000u)) { + x <<= 1; + r -= 1; + } + return r; +} +#endif + /* * same as encode_bch(), but process input data one byte at a time */