From fc61cc2ca3bab8fdf38572eb1ccfa6674999c8b8 Mon Sep 17 00:00:00 2001
From: Peng Fan <peng.fan@nxp.com>
Date: Mon, 5 Nov 2018 09:53:22 +0000
Subject: [PATCH 1/7] tools: imx8image: check lseek return value

Check lseek return value.

Fix Coverity CID: 184236 184235 184232

Reported-by: Coverity
Signed-off-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Fabio Estevam <festevam@gmail.com>
---
 tools/imx8image.c | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/tools/imx8image.c b/tools/imx8image.c
index e6b0a146b6..03debe547e 100644
--- a/tools/imx8image.c
+++ b/tools/imx8image.c
@@ -301,6 +301,7 @@ static void copy_file_aligned(int ifd, const char *datafile, int offset,
 	unsigned char *ptr;
 	uint8_t zeros[0x4000];
 	int size;
+	int ret;
 
 	if (align > 0x4000) {
 		fprintf(stderr, "Wrong alignment requested %d\n", align);
@@ -333,7 +334,13 @@ static void copy_file_aligned(int ifd, const char *datafile, int offset,
 	}
 
 	size = sbuf.st_size;
-	lseek(ifd, offset, SEEK_SET);
+	ret = lseek(ifd, offset, SEEK_SET);
+	if (ret < 0) {
+		fprintf(stderr, "%s: lseek error %s\n",
+			__func__, strerror(errno));
+		exit(EXIT_FAILURE);
+	}
+
 	if (write(ifd, ptr, size) != size) {
 		fprintf(stderr, "Write error %s\n", strerror(errno));
 		exit(EXIT_FAILURE);
@@ -359,7 +366,7 @@ static void copy_file (int ifd, const char *datafile, int pad, int offset)
 	int tail;
 	int zero = 0;
 	uint8_t zeros[4096];
-	int size;
+	int size, ret;
 
 	memset(zeros, 0, sizeof(zeros));
 
@@ -387,7 +394,13 @@ static void copy_file (int ifd, const char *datafile, int pad, int offset)
 	}
 
 	size = sbuf.st_size;
-	lseek(ifd, offset, SEEK_SET);
+	ret = lseek(ifd, offset, SEEK_SET);
+	if (ret < 0) {
+		fprintf(stderr, "%s: lseek error %s\n",
+			__func__, strerror(errno));
+		exit(EXIT_FAILURE);
+	}
+
 	if (write(ifd, ptr, size) != size) {
 		fprintf(stderr, "Write error %s\n",
 			strerror(errno));
@@ -762,6 +775,7 @@ static int build_container(soc_type_t soc, uint32_t sector_size,
 	char *tmp_filename = NULL;
 	uint32_t size = 0;
 	uint32_t file_padding = 0;
+	int ret;
 
 	int container = -1;
 	int cont_img_count = 0; /* indexes to arrange the container */
@@ -883,7 +897,12 @@ static int build_container(soc_type_t soc, uint32_t sector_size,
 	} while (img_sp->option != NO_IMG);
 
 	/* Add padding or skip appended container */
-	lseek(ofd, file_padding, SEEK_SET);
+	ret = lseek(ofd, file_padding, SEEK_SET);
+	if (ret < 0) {
+		fprintf(stderr, "%s: lseek error %s\n",
+			__func__, strerror(errno));
+		exit(EXIT_FAILURE);
+	}
 
 	/* Note: Image offset are not contained in the image */
 	tmp = flatten_container_header(&imx_header, container + 1, &size,

From df439e938ceb5165297c3e34b6485af0238608ef Mon Sep 17 00:00:00 2001
From: Peng Fan <peng.fan@nxp.com>
Date: Mon, 5 Nov 2018 09:53:25 +0000
Subject: [PATCH 2/7] tools: imx8image: fix coverity CID 184234

Fix:
CID 184234:    (TAINTED_SCALAR)
Using tainted variable "header.num_images - 1" as an index into an array "header.img".

Reported-by: Coverity
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 tools/imx8image.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/imx8image.c b/tools/imx8image.c
index 03debe547e..019b875773 100644
--- a/tools/imx8image.c
+++ b/tools/imx8image.c
@@ -666,8 +666,10 @@ static int get_container_image_start_pos(image_t *image_stack, uint32_t align)
 			}
 
 			ret = fread(&header, sizeof(header), 1, fd);
-			if (ret != 1)
+			if (ret != 1) {
 				printf("Failure Read header %d\n", ret);
+				exit(EXIT_FAILURE);
+			}
 
 			fclose(fd);
 

From a9f7f1c58535af68efda0127322de30a33dd31b7 Mon Sep 17 00:00:00 2001
From: Peng Fan <peng.fan@nxp.com>
Date: Mon, 5 Nov 2018 09:53:28 +0000
Subject: [PATCH 3/7] tools: imx8image: fix coverity CID 184233

Fix:
CID 184233:    (NEGATIVE_RETURNS)
Using variable "container" as an index to array "imx_header.fhdr".

Reported-by: Coverity
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 tools/imx8image.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/tools/imx8image.c b/tools/imx8image.c
index 019b875773..ac89c821c9 100644
--- a/tools/imx8image.c
+++ b/tools/imx8image.c
@@ -812,6 +812,10 @@ static int build_container(soc_type_t soc, uint32_t sector_size,
 		case SCFW:
 		case DATA:
 		case MSG_BLOCK:
+			if (container < 0) {
+				fprintf(stderr, "No container found\n");
+				exit(EXIT_FAILURE);
+			}
 			check_file(&sbuf, img_sp->filename);
 			tmp_filename = img_sp->filename;
 			set_image_array_entry(&imx_header.fhdr[container],
@@ -825,6 +829,10 @@ static int build_container(soc_type_t soc, uint32_t sector_size,
 			break;
 
 		case SECO:
+			if (container < 0) {
+				fprintf(stderr, "No container found\n");
+				exit(EXIT_FAILURE);
+			}
 			check_file(&sbuf, img_sp->filename);
 			tmp_filename = img_sp->filename;
 			set_image_array_entry(&imx_header.fhdr[container],

From 47f7a9def781c46a956366dc40a6674ea0609c59 Mon Sep 17 00:00:00 2001
From: Peng Fan <peng.fan@nxp.com>
Date: Mon, 5 Nov 2018 09:53:31 +0000
Subject: [PATCH 4/7] tools: imx8image: flatten container header only when
 creating container

If there is no CONTAINER entry, there is no need to flatten container
header.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 tools/imx8image.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/tools/imx8image.c b/tools/imx8image.c
index ac89c821c9..6e8ac464e7 100644
--- a/tools/imx8image.c
+++ b/tools/imx8image.c
@@ -914,17 +914,19 @@ static int build_container(soc_type_t soc, uint32_t sector_size,
 		exit(EXIT_FAILURE);
 	}
 
-	/* Note: Image offset are not contained in the image */
-	tmp = flatten_container_header(&imx_header, container + 1, &size,
-				       file_padding);
-	/* Write image header */
-	if (write(ofd, tmp, size) != size) {
-		fprintf(stderr, "error writing image hdr\n");
-		exit(EXIT_FAILURE);
-	}
+	if (container >= 0) {
+		/* Note: Image offset are not contained in the image */
+		tmp = flatten_container_header(&imx_header, container + 1,
+					       &size, file_padding);
+		/* Write image header */
+		if (write(ofd, tmp, size) != size) {
+			fprintf(stderr, "error writing image hdr\n");
+			exit(EXIT_FAILURE);
+		}
 
-	/* Clean-up memory used by the headers */
-	free(tmp);
+		/* Clean-up memory used by the headers */
+		free(tmp);
+	}
 
 	/*
 	 * step through the image stack again this time copying

From 664fa567eff9f7b5e20cc2fee494f27a0979dcf7 Mon Sep 17 00:00:00 2001
From: Fabio Estevam <festevam@gmail.com>
Date: Thu, 25 Oct 2018 21:23:07 -0300
Subject: [PATCH 5/7] mx8mq_evk: README: Delete file introduced by mistake

board/freescale/mx8mq_evk/README has been introduced by mistake
in commit d0dd73974c61 ("imx: add i.MX8QXP MEK board support")

Remove it for now as this should be introduced when mx8mq_evk
support is in place.

Reported-by: Tim Harvey <tharvey@gateworks.com>
Signed-off-by: Fabio Estevam <festevam@gmail.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
---
 board/freescale/mx8mq_evk/README | 81 --------------------------------
 1 file changed, 81 deletions(-)
 delete mode 100644 board/freescale/mx8mq_evk/README

diff --git a/board/freescale/mx8mq_evk/README b/board/freescale/mx8mq_evk/README
deleted file mode 100644
index cd7e67eec5..0000000000
--- a/board/freescale/mx8mq_evk/README
+++ /dev/null
@@ -1,81 +0,0 @@
-U-Boot for the NXP i.MX8MQ EVK board
-
-Quick Start
-===========
-
-- Build U-Boot
-- Build the ARM Trusted firmware binary
-- Get DDR firmware and mkimage tool
-- Generate flash.bin using imx-mkimage
-- Flash the binary into the SD card
-- Boot
-
-Build U-Boot
-============
-
-$ make mx8mq_evk_defconfig
-$ make
-
-Get and Build the ARM Trusted firmware
-======================================
-
-$ git clone https://source.codeaurora.org/external/imx/imx-atf
-$ cd imx-atf/
-$ git checkout origin/imx_4.9.51_imx8m_beta
-$ make PLAT=imx8mq bl31
-
-Get the DDR firmware and mkimage tool
-==============================
-
-$ wget https://www.nxp.com/lgfiles/NMG/MAD/YOCTO/firmware-imx-7.2.bin
-$ chmod +x firmware-imx-7.2.bin
-$ ./firmware-imx-7.2.bin
-
-Download the imx-mkimage tool:
-
-$ git clone https://source.codeaurora.org/external/imx/imx-mkimage/
-$ cd imx-mkimage/
-$ git checkout origin/imx_4.9.51_imx8m_beta
-
-
-Generate flash.bin using imx-mkimage
-====================================
-
-Copy the following binaries to imx-mkimage/iMX8M folder:
-
-$ cp imx-atf/build/imx8mq/release/bl31.bin imx-mkimage/iMX8M/
-$ cp u-boot/u-boot-nodtb.bin imx-mkimage/iMX8M/
-$ cp u-boot/spl/u-boot-spl.bin imx-mkimage/iMX8M/
-$ cp u-boot/arch/arm/dts/fsl-imx8mq-evk.dtb imx-mkimage/iMX8M/
-
-Copy the following firmwares to imx-mkimage/iMX8 folder :
-
-$ cp firmware-imx-7.2/firmware/ddr/synopsys/lpddr4_pmu_train_1d_dmem.bin imx-mkimage/iMX8M/
-$ cp firmware-imx-7.2/firmware/ddr/synopsys/lpddr4_pmu_train_1d_imem.bin imx-mkimage/iMX8M/
-$ cp firmware-imx-7.2/firmware/ddr/synopsys/lpddr4_pmu_train_2d_dmem.bin imx-mkimage/iMX8M/
-$ cp firmware-imx-7.2/firmware/ddr/synopsys/lpddr4_pmu_train_2d_imem.bin imx-mkimage/iMX8M/
-
-If you want to run with HDMI, copy signed_hdmi_imx8m.bin to imx-mkimage/iMX8M.
-
-Before generating the flash.bin, transfer the mkimage generated by U-Boot to iMX8M folder:
-
-$ cp u-boot/tools/mkimage imx-mkimage/iMX8M/
-$ mv imx-mkimage/iMX8M/mkimage imx-mkimage/iMX8M/mkimage_uboot
-
-$ cd imx-mkimage/
-$ make SOC=iMX8M flash_spl_uboot
-
-Or for using HDMI:
-
-$ make SOC=iMX8M flash_hdmi_spl_uboot
-
-Flash the binary into the SD card
-=================================
-
-Burn the flash.bin binary to SD card offset 33KB:
-
-$ sudo dd if=iMX8M/flash.bin of=/dev/sd[x] bs=1024 seek=33
-
-Boot
-====
-Set Boot switch SW801: 1100 and Bmode: 10 to boot from Micro SD.

From 78c640fed6a4b2cccc74ca052fb8a2193499ac56 Mon Sep 17 00:00:00 2001
From: Fabio Estevam <festevam@gmail.com>
Date: Thu, 25 Oct 2018 21:49:31 -0300
Subject: [PATCH 6/7] ARM: dts: fsl-imx8qxp-mek: Move regulator outside
 "simple-bus"

Commit 3c28576bb0f0 ("arm: dts: imx8qxp: fix build warining")
fixed the dts warning by removing the unnecessary
#address-cells/#size-cells, but the recommendation for regulators is not
to place them under "simple-bus", so move the reg_usdhc2_vmmc regulator
accordingly.

Signed-off-by: Fabio Estevam <festevam@gmail.com>
---
 arch/arm/dts/fsl-imx8qxp-mek.dts | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/arch/arm/dts/fsl-imx8qxp-mek.dts b/arch/arm/dts/fsl-imx8qxp-mek.dts
index c14e1845a1..adab494cdf 100644
--- a/arch/arm/dts/fsl-imx8qxp-mek.dts
+++ b/arch/arm/dts/fsl-imx8qxp-mek.dts
@@ -16,18 +16,14 @@
 		stdout-path = &lpuart0;
 	};
 
-	regulators {
-		compatible = "simple-bus";
-
-		reg_usdhc2_vmmc: usdhc2-vmmc {
-			compatible = "regulator-fixed";
-			regulator-name = "SD1_SPWR";
-			regulator-min-microvolt = <3000000>;
-			regulator-max-microvolt = <3000000>;
-			gpio = <&gpio4 19 GPIO_ACTIVE_HIGH>;
-			off-on-delay = <3480>;
-			enable-active-high;
-		};
+	reg_usdhc2_vmmc: regulator-usdhc2-vmmc {
+		compatible = "regulator-fixed";
+		regulator-name = "SD1_SPWR";
+		regulator-min-microvolt = <3000000>;
+		regulator-max-microvolt = <3000000>;
+		gpio = <&gpio4 19 GPIO_ACTIVE_HIGH>;
+		off-on-delay = <3480>;
+		enable-active-high;
 	};
 };
 

From 0ea82ba2b082475090e11872ec11409a9fc8d486 Mon Sep 17 00:00:00 2001
From: Peng Fan <peng.fan@nxp.com>
Date: Fri, 26 Oct 2018 02:11:42 +0000
Subject: [PATCH 7/7] MAINTAINERS: add NXP linux team maillist as i.MX reviewer

Add NXP linux team upstream maillist as reviewer

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index cf8f73f200..b39b6fc739 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -121,6 +121,7 @@ F:	drivers/spi/bcmstb_spi.c
 ARM FREESCALE IMX
 M:	Stefano Babic <sbabic@denx.de>
 M:	Fabio Estevam <fabio.estevam@nxp.com>
+R:	NXP Linux Team <linux-imx@nxp.com>
 S:	Maintained
 T:	git git://git.denx.de/u-boot-imx.git
 F:	arch/arm/cpu/arm1136/mx*/