Project

General

Profile

Bug #407

Updated by Anastasia Klimchuk almost 2 years ago

Reported by nyanpasu64 on #flashrom channel 

 ``` 
 $ ninja 
 [75/146] Compiling C object tests/flashrom_unit_tests.p/linux_spi.c.o 
 FAILED: tests/flashrom_unit_tests.p/linux_spi.c.o 
 cc -Itests/flashrom_unit_tests.p -Itests -I../tests -Isubprojects -I../subprojects -I../subprojects/cmocka-1.1.5/include -I../include -I/usr/include/libusb-1.0 -I/usr/include/arm-linux-gnueabihf -I/usr/include/libftdi1 -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Werror -std=c99 -Os -Wshadow -Wmissing-prototypes -Wwrite-strings -Wno-unused-parameter -Wno-address-of-packed-member -Wno-enum-conversion -Wno-missing-braces -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L -D_BSD_SOURCE '-DFLASHROM_VERSION="v1.2-803-g7b82b51"' -D__FLASHROM_LITTLE_ENDIAN__=1 -DHAVE_CLOCK_GETTIME=1 -DHAVE_STRNLEN=1 -DHAVE_UTSNAME=1 -DIS_WINDOWS=0 -includestdlib.h -includeunittest_env.h -DCONFIG_BUSPIRATE_SPI=1 -DCONFIG_CH341A_SPI=1 -DCONFIG_DEDIPROG=1 -DCONFIG_DEVELOPERBOX_SPI=1 -DCONFIG_DIGILENT_SPI=1 -DCONFIG_DUMMY=1 -DCONFIG_FT2232_SPI=1 -DHAVE_FT232H=1 -DCONFIG_RAIDEN_DEBUG_SPI=1 -DCONFIG_LINUX_MTD=1 -DCONFIG_LINUX_SPI=1 -DCONFIG_PICKIT2_SPI=1 -DCONFIG_PONY_SPI=1 -DCONFIG_SERPROG=1 -DCONFIG_USBBLASTER_SPI=1 -DCONFIG_STLINKV3_SPI=1 -DCONFIG_REALTEK_MST_I2C_SPI=1 -DCONFIG_BITBANG_SPI=1 -DCONFIG_PRINT_WIKI=1 -DCONFIG_DEFAULT_PROGRAMMER_NAME=NULL '-DCONFIG_DEFAULT_PROGRAMMER_ARGS=""' -ffunction-sections -fdata-sections -MD -MQ tests/flashrom_unit_tests.p/linux_spi.c.o -MF tests/flashrom_unit_tests.p/linux_spi.c.o.d -o tests/flashrom_unit_tests.p/linux_spi.c.o -c ../tests/linux_spi.c 
 ../tests/linux_spi.c: In function ‘linux_spi_ioctl’: 
 ../tests/linux_spi.c:26:29: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast] 
    26 |     unsigned char *writearr = (unsigned char *)msg[0].tx_buf; 
       |                               ^ 
 ../tests/linux_spi.c:33:29: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast] 
    33 |      unsigned char *readarr = (unsigned char *)msg[1].rx_buf; 
       |                               ^ 
 cc1: all warnings being treated as errors 
 [80/146] Compiling C object subprojects/cmocka-1.1.5/src/libcmocka.so.0.5.0.p/cmocka.c.o 
 ninja: build stopped: subcommand failed. 
 ``` 

 Potential fix suggested by the reporter nyanpasu64 on #flashrom channel 

 ``` 
     

     Fix build error on 32-bit Linux 

 diff --git a/tests/linux_spi.c b/tests/linux_spi.c 
 index 2e3dc95..d71e5b4 100644 
 --- a/tests/linux_spi.c 
 +++ b/tests/linux_spi.c 
 @@ -23,14 +23,14 @@ static int linux_spi_ioctl(void *state, int fd, unsigned long request, va_list a 
 
 		 /* First message has write array and write count */ 
 		 unsigned int writecnt = msg[0].len; 
 - 		 unsigned char *writearr = (unsigned char *)msg[0].tx_buf; 
 + 		 unsigned char *writearr = (unsigned char *)(uintptr_t)msg[0].tx_buf; 
 		 /* Second message has read array and read count */ 
 		 unsigned int readcnt = msg[1].len; 
 
 		 /* Detect probing */ 
 		 if (writecnt == 1 && writearr[0] == JEDEC_RDID && readcnt == 3) { 
 			 /* We need to populate read array. */ 
 - 			 unsigned char *readarr = (unsigned char *)msg[1].rx_buf; 
 + 			 unsigned char *readarr = (unsigned char *)(uintptr_t)msg[1].rx_buf; 
 			 readarr[0] = 0xEF; /* WINBOND_NEX_ID */ 
 			 readarr[1] = 0x40; /* WINBOND_NEX_W25Q128_V left byte */ 
 			 readarr[2] = 0x18; /* WINBOND_NEX_W25Q128_V right byte */ 
 ```

Back