From patchwork Fri Dec 29 11:55:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rudolf Marek X-Patchwork-Id: 853878 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=flashrom.org (client-ip=80.81.252.135; helo=mail.coreboot.org; envelope-from=flashrom-bounces@flashrom.org; receiver=) Received: from mail.coreboot.org (mail.coreboot.org [80.81.252.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3z7Q7B65jVz9s7G for ; Fri, 29 Dec 2017 22:57:09 +1100 (AEDT) Received: from [127.0.0.1] (helo=ra.coreboot.org) by mail.coreboot.org with esmtp (Exim 4.86_2) (envelope-from ) id 1eUtGU-0007fx-4p; Fri, 29 Dec 2017 12:55:54 +0100 Received: from mail.medvecky.net ([85.118.132.146]) by mail.coreboot.org with esmtp (Exim 4.86_2) (envelope-from ) id 1eUtGF-0007XC-Oi for flashrom@flashrom.org; Fri, 29 Dec 2017 12:55:52 +0100 Received: from localhost (localhost [127.0.0.1]) by mail.medvecky.net (Postfix) with ESMTP id 8ACD25E2002; Fri, 29 Dec 2017 12:54:34 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at medvecky.net X-Spam-Flag: NO X-Spam-Score: -0.715 X-Spam-Level: X-Spam-Status: No, score=-0.715 tagged_above=-999 required=3.8 tests=[ALL_TRUSTED=-1, BAYES_00=-1.9, J_CHICKENPOX_32=0.6, J_CHICKENPOX_42=0.6, J_CHICKENPOX_65=0.6, TW_CR=0.077, TW_DJ=0.077, TW_GP=0.077, TW_JG=0.077, TW_SD=0.077] autolearn=no Received: from mail.medvecky.net ([127.0.0.1]) by localhost (slovakia.medvecky.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id da-6-yCcOOhu; Fri, 29 Dec 2017 12:54:06 +0100 (CET) Received: from [192.168.88.62] (56.32.broadband3.iol.cz [85.70.32.56]) by mail.medvecky.net (Postfix) with ESMTPSA id B9AD25E2001; Fri, 29 Dec 2017 12:54:05 +0100 (CET) To: flashrom From: Rudolf Marek Message-ID: <3669ee86-d690-d905-0ea5-803de68aaeb8@assembler.cz> Date: Fri, 29 Dec 2017 12:55:38 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Score: -3.0 (---) Subject: [flashrom] [PATCH] fix the DOS port problems X-BeenThere: flashrom@flashrom.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: flashrom discussion and development mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: RayeR Errors-To: flashrom-bounces@flashrom.org Sender: "flashrom" X-Duff: Orig. Duff, Duff Lite, Duff Dry, Duff Dark, Raspberry Duff, Lady Duff, Red Duff, Tartar Control Duff Hi, Attaching a patch which works around the valloc() issue in the DJGPP. Please apply before the flashrom 1.0. In the meanwhile, it would be great if someone could test it too, if needed I will distribute the executable for a test to Rayer (on CC). I will also try to get some help on DJGPP list, as this issue happens even with the official RPMs of DJGPP 2.05. Signed-off-by: Rudolf Marek Fix the documentation and DOS port. Update the DOS cross-compile documentation, and workaround issue with valloc() with the latest DJGPP. Thanks Rudolf Signed-off-by: Rudolf Marek Signed-off-by: Rudolf Marek diff --git a/README b/README index ab761f7..b23b315 100644 --- a/README +++ b/README @@ -95,30 +95,47 @@ To cross-compile on Linux for DOS: Get packages of the DJGPP cross compiler and install them: djgpp-filesystem djgpp-gcc djgpp-cpp djgpp-runtime djgpp-binutils As an alternative, the DJGPP web site offers packages for download as well: - djcross-binutils-2.19.1-10ap.i386.rpm - djcross-gcc-4.3.2-8ap.i686.rpm - djcrx-2.04pre_20090725-13ap.i386.rpm + djcross-binutils-2.29.1-1ap.x86_64.rpm + djcross-gcc-7.2.0-1ap.x86_64.rpm + djcrx-2.05-5.x86_64.rpm The cross toolchain packages for your distribution may have slightly different names (look for packages named *djgpp*). - You will need the following library source trees containing their compiled - static libraries either in the parent directory of the flashrom source or - specify the base folder on compile time with the LIBS_BASE parameter. - The default as described above is equal to calling - 'make djgpp-dos LIBS_BASE=..' + Alternatively, you could use a script to build it from scratch: + https://github.com/andrewwutw/build-djgpp + + You will need the libpci and libgetopt library source trees containing + their compiled static libraries and header files installed in some + directory say libpci-libgetopt/, which will be later specified with + LIBS_BASE parameter during flashrom compilation. Easiest way to + handle it is to put pciutils, libgetopt and flashrom directories + in one subdirectory. There will be extra subdirectory libpci-libgetopt + created, which will contain compiled libpci and libgetopt. - To get and build said libraries... Download pciutils 3.1.5 and apply http://flashrom.org/File:Pciutils.patch.gz - Compile pciutils, see README.DJGPP for instructions. - Download and compile http://flashrom.org/File:Libgetopt.tar.gz + Compile pciutils, using following command line: + + make ZLIB=no DNS=no HOST=i386-djgpp-djgpp CROSS_COMPILE=i586-pc-msdosdjgpp- \ + PREFIX=/ DESTDIR=$PWD/../libpci-libgetopt \ + STRIP="--strip-program=i586-pc-msdosdjgpp-strip -s" install install-lib + + Download and compile with 'make' http://flashrom.org/File:Libgetopt.tar.gz + + Copy the libgetopt.a to ../libpci-libgetopt/lib and + getopt.h to ../libpci-libgetopt/include + Enter the flashrom directory. - Run either (change settings where appropriate) - make CC=i586-pc-msdosdjgpp-gcc STRIP=i586-pc-msdosdjgpp-strip - or (above settings hardcoded) - make djgpp-dos + + make CC=i586-pc-msdosdjgpp-gcc STRIP=i586-pc-msdosdjgpp-strip LIBS_BASE=../libpci-libgetopt/ strip + + If you like can compress the resulting executable with UPX: + + upx -9 flashrom.exe + To run flashrom.exe, download http://flashrom.org/File:Csdpmi7b.zip and unpack CWSDPMI.EXE into the current directory or one in PATH. + To cross-compile on Linux for Windows: Get packages of the MinGW cross compiler and install them: diff --git a/physmap.c b/physmap.c index a261ccd..3338b62 100644 --- a/physmap.c +++ b/physmap.c @@ -38,29 +38,40 @@ #ifdef __DJGPP__ #include +#include #include +#define ONE_MEGABYTE (1024 * 1024) #define MEM_DEV "dpmi" -static void *realmem_map; +static void *realmem_map_aligned; static void *map_first_meg(uintptr_t phys_addr, size_t len) { - if (realmem_map) - return realmem_map + phys_addr; + void *realmem_map; + size_t pagesize; - realmem_map = valloc(1024 * 1024); + if (realmem_map_aligned) + return realmem_map_aligned + phys_addr; + + /* valloc() from DJGPP 2.05 does not work properly */ + pagesize = getpagesize(); + + realmem_map = malloc(ONE_MEGABYTE + pagesize); if (!realmem_map) return ERROR_PTR; - if (__djgpp_map_physical_memory(realmem_map, (1024 * 1024), 0)) { + realmem_map_aligned = (void *)(((size_t) realmem_map + + (pagesize - 1)) & ~(pagesize - 1)); + + if (__djgpp_map_physical_memory(realmem_map_aligned, ONE_MEGABYTE, 0)) { free(realmem_map); - realmem_map = NULL; + realmem_map_aligned = NULL; return ERROR_PTR; } - return realmem_map + phys_addr; + return realmem_map_aligned + phys_addr; } static void *sys_physmap(uintptr_t phys_addr, size_t len) @@ -72,7 +83,7 @@ static void *sys_physmap(uintptr_t phys_addr, size_t len) if (!__djgpp_nearptr_enable()) return ERROR_PTR; - if ((phys_addr + len - 1) < (1024 * 1024)) { + if ((phys_addr + len - 1) < ONE_MEGABYTE) { /* We need to use another method to map first 1MB. */ return map_first_meg(phys_addr, len); } @@ -97,8 +108,8 @@ void sys_physunmap_unaligned(void *virt_addr, size_t len) /* There is no known way to unmap the first 1 MB. The DPMI server will * do this for us on exit. */ - if ((virt_addr >= realmem_map) && - ((virt_addr + len) <= (realmem_map + (1024 * 1024)))) { + if ((virt_addr >= realmem_map_aligned) && + ((virt_addr + len) <= (realmem_map_aligned + ONE_MEGABYTE))) { return; }