[PATCH] Fix out of bound access of ep array.

2022-09-22 Thread Alison Huffman
When processing USB_REQ_CLEAR_FEATURE, USB_REQ_SET_FEATURE, and
USB_REQ_GET_STATUS packets in dwc2_ep0_setup an out of bounds access
can occur. This is caused by the wIndex field of the usb control packet
being used as an index into an array whose size is DWC2_MAX_ENDPOINTS (4).

Signed-off-by: Alison Huffman 
---

 drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c 
b/drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c
index f17009a29e..1c34b75351 100644
--- a/drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c
+++ b/drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c
@@ -890,7 +890,7 @@ static int dwc2_ep0_write(struct dwc2_udc *dev)
 static int dwc2_udc_get_status(struct dwc2_udc *dev,
struct usb_ctrlrequest *crq)
 {
-   u8 ep_num = crq->wIndex & 0x7F;
+   u8 ep_num = crq->wIndex & 0x3;
u16 g_status = 0;
u32 ep_ctrl;
 
@@ -1418,7 +1418,7 @@ static void dwc2_ep0_setup(struct dwc2_udc *dev)
break;
 
case USB_REQ_CLEAR_FEATURE:
-   ep_num = usb_ctrl->wIndex & 0x7f;
+   ep_num = usb_ctrl->wIndex & 0x3;
 
if (!dwc2_udc_clear_feature(>ep[ep_num].ep))
return;
@@ -1426,7 +1426,7 @@ static void dwc2_ep0_setup(struct dwc2_udc *dev)
break;
 
case USB_REQ_SET_FEATURE:
-   ep_num = usb_ctrl->wIndex & 0x7f;
+   ep_num = usb_ctrl->wIndex & 0x3;
 
if (!dwc2_udc_set_feature(>ep[ep_num].ep))
return;
-- 
2.37.3.968.ga6b4b080e4-goog



RE: [PATCH] configs: ls1021a: Append CMA configuration to bootargs

2020-04-23 Thread Alison Wang
Hi, Priyanka,

> -Original Message-
> From: Priyanka Jain 
> Sent: Thursday, April 23, 2020 6:32 PM
> To: Alison Wang ; u-boot@lists.denx.de; Jagdish
> Gediya 
> Cc: Shengzhou Liu 
> Subject: RE: [PATCH] configs: ls1021a: Append CMA configuration to bootargs
> 
> >-Original Message-
> >From: Alison Wang 
> >Sent: Thursday, April 23, 2020 6:12 AM
> >To: u-boot@lists.denx.de; Priyanka Jain ;
> >Jagdish Gediya 
> >Cc: Shengzhou Liu 
> >Subject: [PATCH] configs: ls1021a: Append CMA configuration to bootargs
> >
> >According to commit , this patch appends CMA
> >configuration to bootargs for LS1021ATWR.
> >
> Please mention what this patch is doing (as a fresh patch).
> No need to mention relation with previous commit.
[Alison] Update the comment in v2.

Best Regards,
Alison Wang



[PATCH v2] configs: ls1021a: Append CMA configuration to bootargs

2020-04-23 Thread Alison Wang
The default reserved memory for CMA is high memory. If LPAE is enabled,
highmem pages are non-remapped and can not be used with
dma_alloc_coherent. Reserving low memory for CMA is needed for LS1021A.
This patch appends the related CMA configuration to bootargs.

Signed-off-by: Shengzhou Liu 
Signed-off-by: Alison Wang 
---
Change in v2:
   - Update the comment.

 include/configs/ls1021atwr.h | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/configs/ls1021atwr.h b/include/configs/ls1021atwr.h
index a6289850ca..45ce460dca 100644
--- a/include/configs/ls1021atwr.h
+++ b/include/configs/ls1021atwr.h
@@ -297,7 +297,8 @@
 
 #ifdef CONFIG_LPUART
 #define CONFIG_EXTRA_ENV_SETTINGS   \
-   "bootargs=root=/dev/ram0 rw console=ttyLP0,115200 $othbootargs\0" \
+   "bootargs=root=/dev/ram0 rw console=ttyLP0,115200 " \
+   "cma=64M@0x0-0xb000\0" \
"initrd_high=0x\0"  \
"fdt_addr=0x64f0\0" \
"kernel_addr=0x6500\0"  \
@@ -353,7 +354,8 @@
"$kernel_size && bootm $load_addr#$board\0"
 #else
 #define CONFIG_EXTRA_ENV_SETTINGS  \
-   "bootargs=root=/dev/ram0 rw console=ttyS0,115200 $othbootargs\0" \
+   "bootargs=root=/dev/ram0 rw console=ttyS0,115200 "  \
+   "cma=64M@0x0-0xb000\0" \
"initrd_high=0x\0"  \
"fdt_addr=0x64f0\0" \
"kernel_addr=0x6100\0"  \
-- 
2.17.1



[PATCH] configs: ls1021a: Append CMA configuration to bootargs

2020-04-22 Thread Alison Wang
According to commit , this patch appends CMA configuration
to bootargs for LS1021ATWR.

Signed-off-by: Shengzhou Liu 
Signed-off-by: Alison Wang 
---
 include/configs/ls1021atwr.h | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/configs/ls1021atwr.h b/include/configs/ls1021atwr.h
index a6289850ca..45ce460dca 100644
--- a/include/configs/ls1021atwr.h
+++ b/include/configs/ls1021atwr.h
@@ -297,7 +297,8 @@
 
 #ifdef CONFIG_LPUART
 #define CONFIG_EXTRA_ENV_SETTINGS   \
-   "bootargs=root=/dev/ram0 rw console=ttyLP0,115200 $othbootargs\0" \
+   "bootargs=root=/dev/ram0 rw console=ttyLP0,115200 " \
+   "cma=64M@0x0-0xb000\0" \
"initrd_high=0x\0"  \
"fdt_addr=0x64f0\0" \
"kernel_addr=0x6500\0"  \
@@ -353,7 +354,8 @@
"$kernel_size && bootm $load_addr#$board\0"
 #else
 #define CONFIG_EXTRA_ENV_SETTINGS  \
-   "bootargs=root=/dev/ram0 rw console=ttyS0,115200 $othbootargs\0" \
+   "bootargs=root=/dev/ram0 rw console=ttyS0,115200 "  \
+   "cma=64M@0x0-0xb000\0" \
"initrd_high=0x\0"  \
"fdt_addr=0x64f0\0" \
"kernel_addr=0x6100\0"  \
-- 
2.17.1



[PATCH v2] configs: ls1021a: Append othbootargs to bootargs

2020-03-24 Thread Alison Wang
This patch appends CMA configuration to bootargs for LS1021ATWR board.

Signed-off-by: Shengzhou Liu 
Signed-off-by: Alison Wang 
---
Changes for v2:
- Append CMA configuration to bootargs directly

 include/configs/ls1021atwr.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/configs/ls1021atwr.h b/include/configs/ls1021atwr.h
index 8e2784b..5f73821 100644
--- a/include/configs/ls1021atwr.h
+++ b/include/configs/ls1021atwr.h
@@ -297,7 +297,8 @@
 
 #ifdef CONFIG_LPUART
 #define CONFIG_EXTRA_ENV_SETTINGS   \
-   "bootargs=root=/dev/ram0 rw console=ttyLP0,115200\0" \
+   "bootargs=root=/dev/ram0 rw console=ttyLP0,115200 " \
+   "cma=64M@0x0-0xb000\0" \
"initrd_high=0x\0"  \
"fdt_high=0x\0" \
"fdt_addr=0x64f0\0" \
@@ -313,7 +314,6 @@
"kernel_size=0x280\0"   \
"kernel_addr_sd=0x8000\0"   \
"kernel_size_sd=0x14000\0"  \
-   "$othbootargs\0"\
"othbootargs=cma=64M@0x0-0xb000\0"  \
BOOTENV \
"boot_scripts=ls1021atwr_boot.scr\0"\
@@ -355,7 +355,8 @@
"$kernel_size && bootm $load_addr#$board\0"
 #else
 #define CONFIG_EXTRA_ENV_SETTINGS  \
-   "bootargs=root=/dev/ram0 rw console=ttyS0,115200\0" \
+   "bootargs=root=/dev/ram0 rw console=ttyS0,115200 "  \
+   "cma=64M@0x0-0xb000\0" \
"initrd_high=0x\0"  \
"fdt_high=0x\0" \
"fdt_addr=0x64f0\0" \
@@ -375,7 +376,6 @@
"kernel_size_sd=0x14000\0"  \
"kernelhdr_addr_sd=0x4000\0"\
"kernelhdr_size_sd=0x10\0"  \
-   "$othbootargs\0"\
"othbootargs=cma=64M@0x0-0xb000\0"  \
BOOTENV \
"boot_scripts=ls1021atwr_boot.scr\0"\
-- 
2.9.5



[PATCH] configs: ls1021a: Append othbootargs to bootargs

2020-03-16 Thread Alison Wang
This patch appends othbootargs to bootargs for LS1021ATWR board.

Signed-off-by: Alison Wang 
---
 include/configs/ls1021atwr.h | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/include/configs/ls1021atwr.h b/include/configs/ls1021atwr.h
index 8e2784b..266107c 100644
--- a/include/configs/ls1021atwr.h
+++ b/include/configs/ls1021atwr.h
@@ -297,7 +297,7 @@
 
 #ifdef CONFIG_LPUART
 #define CONFIG_EXTRA_ENV_SETTINGS   \
-   "bootargs=root=/dev/ram0 rw console=ttyLP0,115200\0" \
+   "bootargs=root=/dev/ram0 rw console=ttyLP0,115200 $othbootargs\0" \
"initrd_high=0x\0"  \
"fdt_high=0x\0" \
"fdt_addr=0x64f0\0" \
@@ -313,7 +313,6 @@
"kernel_size=0x280\0"   \
"kernel_addr_sd=0x8000\0"   \
"kernel_size_sd=0x14000\0"  \
-   "$othbootargs\0"\
"othbootargs=cma=64M@0x0-0xb000\0"  \
BOOTENV \
"boot_scripts=ls1021atwr_boot.scr\0"\
@@ -355,7 +354,7 @@
"$kernel_size && bootm $load_addr#$board\0"
 #else
 #define CONFIG_EXTRA_ENV_SETTINGS  \
-   "bootargs=root=/dev/ram0 rw console=ttyS0,115200\0" \
+   "bootargs=root=/dev/ram0 rw console=ttyS0,115200 $othbootargs\0" \
"initrd_high=0x\0"  \
"fdt_high=0x\0" \
"fdt_addr=0x64f0\0" \
@@ -375,7 +374,6 @@
"kernel_size_sd=0x14000\0"  \
"kernelhdr_addr_sd=0x4000\0"\
"kernelhdr_size_sd=0x10\0"  \
-   "$othbootargs\0"\
"othbootargs=cma=64M@0x0-0xb000\0"  \
BOOTENV \
"boot_scripts=ls1021atwr_boot.scr\0"\
-- 
2.9.5



[PATCH] ls1021a: Set CONFIG_SYS_BOOTMAPSZ to the memory for relocation

2020-02-02 Thread Alison Wang
This patch sets CONFIG_SYS_BOOTMAPSZ to the amount of memory available
to safely contain a kernel, device tree and initrd for relocation. The
way to set fdt_high as 0x to disable device tree relocation is
removed.

Signed-off-by: Alison Wang 
---
 include/configs/ls1021aiot.h | 5 +++--
 include/configs/ls1021aqds.h | 3 +--
 include/configs/ls1021atsn.h | 3 ++-
 include/configs/ls1021atwr.h | 3 +--
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/include/configs/ls1021aiot.h b/include/configs/ls1021aiot.h
index 769a7e2..4e3d818 100644
--- a/include/configs/ls1021aiot.h
+++ b/include/configs/ls1021aiot.h
@@ -207,12 +207,13 @@
 
 #define CONFIG_EXTRA_ENV_SETTINGS  \
"bootargs=root=/dev/ram0 rw console=ttyS0,115200\0" \
-"initrd_high=0x\0" \
-"fdt_high=0x\0"
+"initrd_high=0x\0"
 
 /*
  * Miscellaneous configurable options
  */
+#define CONFIG_SYS_BOOTMAPSZ   (256 << 20)
+
 #define CONFIG_CMD_GREPENV
 #define CONFIG_CMD_MEMINFO
 
diff --git a/include/configs/ls1021aqds.h b/include/configs/ls1021aqds.h
index 6f1c0d4..5345e8f 100644
--- a/include/configs/ls1021aqds.h
+++ b/include/configs/ls1021aqds.h
@@ -460,13 +460,11 @@ unsigned long get_board_ddr_clk(void);
 #ifdef CONFIG_LPUART
 #define CONFIG_EXTRA_ENV_SETTINGS   \
"bootargs=root=/dev/ram0 rw console=ttyLP0,115200\0" \
-   "fdt_high=0x\0" \
"initrd_high=0x\0"  \
"hwconfig=fsl_ddr:ctlr_intlv=null,bank_intlv=null\0"
 #else
 #define CONFIG_EXTRA_ENV_SETTINGS  \
"bootargs=root=/dev/ram0 rw console=ttyS0,115200\0" \
-   "fdt_high=0x\0" \
"initrd_high=0x\0"  \
"hwconfig=fsl_ddr:ctlr_intlv=null,bank_intlv=null\0"
 #endif
@@ -474,6 +472,7 @@ unsigned long get_board_ddr_clk(void);
 /*
  * Miscellaneous configurable options
  */
+#define CONFIG_SYS_BOOTMAPSZ   (256 << 20)
 
 #define CONFIG_SYS_MEMTEST_START   0x8000
 #define CONFIG_SYS_MEMTEST_END 0x9fff
diff --git a/include/configs/ls1021atsn.h b/include/configs/ls1021atsn.h
index 84fdfce..039c794 100644
--- a/include/configs/ls1021atsn.h
+++ b/include/configs/ls1021atsn.h
@@ -154,7 +154,6 @@
 #define CONFIG_EXTRA_ENV_SETTINGS  \
"bootargs=root=/dev/ram0 rw console=ttyS0,115200\0" \
"initrd_high=0x\0"  \
-   "fdt_high=0x\0" \
"fdt_addr=0x64f0\0" \
"kernel_addr=0x6100\0"  \
"kernelheader_addr=0x6080\0"\
@@ -216,6 +215,8 @@
"bootm $load_addr#$board\0"
 
 /* Miscellaneous configurable options */
+#define CONFIG_SYS_BOOTMAPSZ   (256 << 20)
+
 #define CONFIG_SYS_CBSIZE  256 /* Console I/O Buffer Size */
 #define CONFIG_SYS_PBSIZE  \
(CONFIG_SYS_CBSIZE + sizeof(CONFIG_SYS_PROMPT) + 16)
diff --git a/include/configs/ls1021atwr.h b/include/configs/ls1021atwr.h
index e845232..511d10a 100644
--- a/include/configs/ls1021atwr.h
+++ b/include/configs/ls1021atwr.h
@@ -299,7 +299,6 @@
 #define CONFIG_EXTRA_ENV_SETTINGS   \
"bootargs=root=/dev/ram0 rw console=ttyLP0,115200\0" \
"initrd_high=0x\0"  \
-   "fdt_high=0x\0" \
"fdt_addr=0x64f0\0" \
"kernel_addr=0x6500\0"  \
"scriptaddr=0x8000\0"   \
@@ -357,7 +356,6 @@
 #define CONFIG_EXTRA_ENV_SETTINGS  \
"bootargs=root=/dev/ram0 rw console=ttyS0,115200\0" \
"initrd_high=0x\0"  \
-   "fdt_high=0x\0" \
"fdt_addr=0x64f0\0" \
"kernel_addr=0x6100\0"  \
"kernelheader_addr=0x6080\0"\
@@ -441,6 +439,7 @@
 /*
  * Miscellaneous configurable options
  */
+#define CONFIG_SYS_BOOTMAPSZ   (256 << 20)
 
 #define CONFIG_SYS_MEMTEST_START   0x8000
 #define CONFIG_SYS_MEMTEST_END 0x9fff
-- 
2.9.5



[PATCH] configs: ls1021a: Reserve low memory for CMA

2020-01-20 Thread Alison Wang
The default reserved memory for CMA is high memory. If LPAE is enabled,
highmem pages are non-remapped and can not be used with
dma_alloc_coherent. This patch will reserve low memory for CMA and fix
the issue on LS1021A.

Signed-off-by: Peng Ma 
Signed-off-by: Shengzhou Liu 
Signed-off-by: Alison Wang 
---
 include/configs/ls1021atwr.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/include/configs/ls1021atwr.h b/include/configs/ls1021atwr.h
index 46c372a..6aa7154 100644
--- a/include/configs/ls1021atwr.h
+++ b/include/configs/ls1021atwr.h
@@ -310,6 +310,8 @@
"kernel_size=0x280\0"   \
"kernel_addr_sd=0x8000\0"   \
"kernel_size_sd=0x14000\0"  \
+   "$othbootargs\0"\
+   "othbootargs=cma=64M@0x0-0xb000\0"  \
BOOTENV \
"boot_scripts=ls1021atwr_boot.scr\0"\
"boot_script_hdr=hdr_ls1021atwr_bs.out\0"   \
@@ -370,6 +372,8 @@
"kernel_size_sd=0x14000\0"  \
"kernelhdr_addr_sd=0x4000\0"\
"kernelhdr_size_sd=0x10\0"  \
+   "$othbootargs\0"\
+   "othbootargs=cma=64M@0x0-0xb000\0"  \
BOOTENV \
"boot_scripts=ls1021atwr_boot.scr\0"\
"boot_script_hdr=hdr_ls1021atwr_bs.out\0"   \
-- 
2.9.5



[PATCH] configs: Enable SPL_FSL_PBL for some LayerScape platforms

2019-12-03 Thread Alison Wang
In commit , SPL_FSL_PBL is removed from the configs of
some LayerScape platforms. Actually, SPL_FSL_PBL is needed for SD/NAND
boot on LS1021A/LS1043A/LS1046A to create boot binary having SPL binary
in PBI format concatenated with u-boot binary. SPL_FRAMEWORK is used on
these platforms too.

Signed-off-by: Alison Wang 
---
 common/spl/Kconfig  | 8 ++--
 configs/ls1021aiot_sdcard_defconfig | 1 +
 configs/ls1021aqds_nand_defconfig   | 1 +
 configs/ls1021aqds_sdcard_ifc_defconfig | 1 +
 configs/ls1021aqds_sdcard_qspi_defconfig| 1 +
 configs/ls1021atwr_sdcard_ifc_SECURE_BOOT_defconfig | 1 +
 configs/ls1021atwr_sdcard_ifc_defconfig | 1 +
 configs/ls1021atwr_sdcard_qspi_defconfig| 1 +
 configs/ls1043aqds_nand_defconfig   | 1 +
 configs/ls1043aqds_sdcard_ifc_defconfig | 1 +
 configs/ls1043aqds_sdcard_qspi_defconfig| 1 +
 configs/ls1043ardb_nand_SECURE_BOOT_defconfig   | 1 +
 configs/ls1043ardb_nand_defconfig   | 1 +
 configs/ls1043ardb_sdcard_SECURE_BOOT_defconfig | 1 +
 configs/ls1043ardb_sdcard_defconfig | 1 +
 configs/ls1046aqds_nand_defconfig   | 1 +
 configs/ls1046aqds_sdcard_ifc_defconfig | 1 +
 configs/ls1046aqds_sdcard_qspi_defconfig| 1 +
 configs/ls1046ardb_emmc_defconfig   | 1 +
 configs/ls1046ardb_sdcard_SECURE_BOOT_defconfig | 1 +
 configs/ls1046ardb_sdcard_defconfig | 1 +
 21 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index 1f12283..43f1a9c 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -91,20 +91,24 @@ config SPL_SYS_REPORT_STACK_F_USAGE
  occurrence of non 0xaa bytes.
  This default implementation works for stacks growing down only.
 
-menu "PowerPC SPL Boot options"
-   depends on PPC && (SUPPORT_SPL && !SPL_FRAMEWORK)
+menu "PowerPC and LayerScape SPL Boot options"
 
 config SPL_NAND_BOOT
bool "Load SPL from NAND flash"
+   depends on PPC && (SUPPORT_SPL && !SPL_FRAMEWORK)
 
 config SPL_MMC_BOOT
bool "Load SPL from SD Card / eMMC"
+   depends on PPC && (SUPPORT_SPL && !SPL_FRAMEWORK)
 
 config SPL_SPI_BOOT
bool "Load SPL from SPI flash"
+   depends on PPC && (SUPPORT_SPL && !SPL_FRAMEWORK)
 
 config SPL_FSL_PBL
bool "Create SPL in Freescale PBI format"
+   depends on (PPC || ARCH_LS1021A || ARCH_LS1043A || ARCH_LS1046A) && \
+   SUPPORT_SPL
help
  Create boot binary having SPL binary in PBI format concatenated with
  u-boot binary.
diff --git a/configs/ls1021aiot_sdcard_defconfig 
b/configs/ls1021aiot_sdcard_defconfig
index 55a17f0..0b10e11 100644
--- a/configs/ls1021aiot_sdcard_defconfig
+++ b/configs/ls1021aiot_sdcard_defconfig
@@ -7,6 +7,7 @@ CONFIG_ENV_OFFSET=0x10
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_SPL=y
 CONFIG_AHCI=y
+CONFIG_SPL_FSL_PBL=y
 CONFIG_SPL_TEXT_BASE=0x1000
 CONFIG_SYS_EXTRA_OPTIONS="RAMBOOT_PBL,SD_BOOT,SD_BOOT_QSPI"
 CONFIG_MISC_INIT_R=y
diff --git a/configs/ls1021aqds_nand_defconfig 
b/configs/ls1021aqds_nand_defconfig
index a7f3fd1..767f4fd 100644
--- a/configs/ls1021aqds_nand_defconfig
+++ b/configs/ls1021aqds_nand_defconfig
@@ -10,6 +10,7 @@ CONFIG_ENV_OFFSET=0x14
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_SPL=y
 CONFIG_AHCI=y
+CONFIG_SPL_FSL_PBL=y
 CONFIG_SPL_TEXT_BASE=0x1000
 CONFIG_FIT=y
 CONFIG_FIT_VERBOSE=y
diff --git a/configs/ls1021aqds_sdcard_ifc_defconfig 
b/configs/ls1021aqds_sdcard_ifc_defconfig
index b005aff..5071dd5 100644
--- a/configs/ls1021aqds_sdcard_ifc_defconfig
+++ b/configs/ls1021aqds_sdcard_ifc_defconfig
@@ -11,6 +11,7 @@ CONFIG_ENV_OFFSET=0x30
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_SPL=y
 CONFIG_AHCI=y
+CONFIG_SPL_FSL_PBL=y
 CONFIG_SPL_TEXT_BASE=0x1000
 CONFIG_FIT=y
 CONFIG_FIT_VERBOSE=y
diff --git a/configs/ls1021aqds_sdcard_qspi_defconfig 
b/configs/ls1021aqds_sdcard_qspi_defconfig
index 811694f..9469c1c 100644
--- a/configs/ls1021aqds_sdcard_qspi_defconfig
+++ b/configs/ls1021aqds_sdcard_qspi_defconfig
@@ -11,6 +11,7 @@ CONFIG_ENV_OFFSET=0x30
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_SPL=y
 CONFIG_AHCI=y
+CONFIG_SPL_FSL_PBL=y
 CONFIG_SPL_TEXT_BASE=0x1000
 CONFIG_FIT=y
 CONFIG_FIT_VERBOSE=y
diff --git a/configs/ls1021atwr_sdcard_ifc_SECURE_BOOT_defconfig 
b/configs/ls1021atwr_sdcard_ifc_SECURE_BOOT_defconfig
index 2098a7f..3f03424 100644
--- a/configs/ls1021atwr_sdcard_ifc_SECURE_BOOT_defconfig
+++ b/configs/ls1021atwr_sdcard_ifc_SECURE_BOOT_defconfig
@@ -10,6 +10,7 @@ CONFIG_SPL_DRIVERS_MISC_SUPPORT=y
 CONFIG_ENV_SIZE=0x2
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_SPL=y
+CONFIG_SPL_FSL_PBL=y
 CONFIG_SPL_TEXT_BASE=0x1000
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_FIT

[U-Boot] [PATCH] armv8: ls1046afrwy: Define CONFIG_ENV_ADDR for QSPI Boot

2019-07-22 Thread Alison Wang
This patch defines CONFIG_ENV_ADDR for QSPI Boot which specifies the
start address of the flash sector containing the environment. It fixes
the issue that bootcmd is always set as default at bootup.

Signed-off-by: Alison Wang 
---
 include/configs/ls1046afrwy.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/configs/ls1046afrwy.h b/include/configs/ls1046afrwy.h
index 791bb8dc47..8609ebfecc 100644
--- a/include/configs/ls1046afrwy.h
+++ b/include/configs/ls1046afrwy.h
@@ -103,6 +103,9 @@
 #define CONFIG_ENV_SIZE0x2000  /* 8KB */
 #define CONFIG_ENV_OFFSET  0x50/* 5MB */
 #define CONFIG_ENV_SECT_SIZE   0x4 /* 256KB */
+#define CONFIG_SYS_FSL_QSPI_BASE   0x4000
+#define CONFIG_ENV_ADDR(CONFIG_SYS_FSL_QSPI_BASE + \
+CONFIG_ENV_OFFSET)
 
 /* FMan */
 #ifdef CONFIG_SYS_DPAA_FMAN
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] video: Add dependency for VIDEO_IMX_HDP_LOAD

2019-05-21 Thread Alison Wang
As VIDEO_IMX_HDP_LOAD is supported on LS1028A, this patch adds
ARCH_LS1028A dependency for VIDEO_IMX_HDP_LOAD.

Signed-off-by: Alison Wang 
---
 drivers/video/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 7aa1727e5b..f1fa25a49e 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -552,7 +552,7 @@ config VIDEO
 config VIDEO_IMX_HDP_LOAD
bool "i.MX8 HDMI/DP firmware loading"
default y
-   depends on VIDEO
+   depends on VIDEO && ARCH_LS1028A
help
  Support for HDMI/DP firmware loading for i.MX8QM and LS1028A
  processors. The firmware is copied from system memory to the
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] armv7: ls102xa: Add workaround for DDR erratum A-008850

2019-03-05 Thread Alison Wang
Barrier transactions from CCI400 need to be disabled till
the DDR is configured, otherwise it may lead to system hang.
The patch adds workaround to fix the erratum.

Signed-off-by: Shengzhou Liu 
Signed-off-by: Alison Wang 
---
 arch/arm/cpu/armv7/ls102xa/Kconfig|  6 +++
 arch/arm/cpu/armv7/ls102xa/soc.c  | 44 ---
 .../include/asm/arch-ls102xa/ls102xa_soc.h|  2 +
 board/freescale/ls1021aiot/ls1021aiot.c   |  2 +
 board/freescale/ls1021aqds/ddr.c  |  2 +
 board/freescale/ls1021aqds/ddr.h  |  3 ++
 board/freescale/ls1021aqds/ls1021aqds.c   | 30 -
 board/freescale/ls1021atwr/ls1021atwr.c   |  2 +
 include/configs/ls1021aiot.h  |  2 +
 include/configs/ls1021atwr.h  |  2 +
 10 files changed, 58 insertions(+), 37 deletions(-)

diff --git a/arch/arm/cpu/armv7/ls102xa/Kconfig 
b/arch/arm/cpu/armv7/ls102xa/Kconfig
index 5d6a711c14..94fa68250d 100644
--- a/arch/arm/cpu/armv7/ls102xa/Kconfig
+++ b/arch/arm/cpu/armv7/ls102xa/Kconfig
@@ -4,6 +4,7 @@ config ARCH_LS1021A
select SYS_FSL_DDR_VER_50 if SYS_FSL_DDR
select SYS_FSL_ERRATUM_A008378
select SYS_FSL_ERRATUM_A008407
+   select SYS_FSL_ERRATUM_A008850
select SYS_FSL_ERRATUM_A008997
select SYS_FSL_ERRATUM_A009007
select SYS_FSL_ERRATUM_A009008
@@ -63,6 +64,11 @@ config SYS_CCI400_OFFSET
  Offset for CCI400 base.
  CCI400 base addr = CCSRBAR + CCI400_OFFSET
 
+config SYS_FSL_ERRATUM_A008850
+   bool
+   help
+ Workaround for DDR erratum A008850
+
 config SYS_FSL_ERRATUM_A008997
bool
help
diff --git a/arch/arm/cpu/armv7/ls102xa/soc.c b/arch/arm/cpu/armv7/ls102xa/soc.c
index 448d951c36..a779d33739 100644
--- a/arch/arm/cpu/armv7/ls102xa/soc.c
+++ b/arch/arm/cpu/armv7/ls102xa/soc.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct liodn_id_table sec_liodn_tbl[] = {
SET_SEC_JR_LIODN_ENTRY(0, 0x10, 0x10),
@@ -103,6 +104,41 @@ static void erratum_a009007(void)
 #endif /* CONFIG_SYS_FSL_ERRATUM_A009007 */
 }
 
+static void erratum_a008850_early(void)
+{
+#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
+   /* part 1 of 2 */
+   struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
+   CONFIG_SYS_CCI400_OFFSET);
+   struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
+
+   /* disables propagation of barrier transactions to DDRC from CCI400 */
+   out_le32(>ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
+
+   /* disable the re-ordering in DDRC */
+   out_be32(>eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
+#endif
+}
+
+void erratum_a008850_post(void)
+{
+#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
+   /* part 2 of 2 */
+   struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
+   CONFIG_SYS_CCI400_OFFSET);
+   struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
+   u32 tmp;
+
+   /* enable propagation of barrier transactions to DDRC from CCI400 */
+   out_le32(>ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
+
+   /* enable the re-ordering in DDRC */
+   tmp = in_be32(>eor);
+   tmp &= ~(DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
+   out_be32(>eor, tmp);
+#endif
+}
+
 void s_init(void)
 {
 }
@@ -163,13 +199,6 @@ int arch_soc_init(void)
 */
out_le32(>slave[1].sha_ord, CCI400_SHAORD_NON_SHAREABLE);
out_le32(>slave[2].sha_ord, CCI400_SHAORD_NON_SHAREABLE);
-
-   /* Workaround for the issue that DDR could not respond to
-* barrier transaction which is generated by executing DSB/ISB
-* instruction. Set CCI-400 control override register to
-* terminate the barrier transaction. After DDR is initialized,
-* allow barrier transaction to DDR again */
-   out_le32(>ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
}
 
/* Enable all the snoop signal for various masters */
@@ -191,6 +220,7 @@ int arch_soc_init(void)
out_be32(>eddrtqcfg, 0x63b20042);
 
/* Erratum */
+   erratum_a008850_early();
erratum_a009008();
erratum_a009798();
erratum_a008997();
diff --git a/arch/arm/include/asm/arch-ls102xa/ls102xa_soc.h 
b/arch/arm/include/asm/arch-ls102xa/ls102xa_soc.h
index 05e8b49c2d..1fde8bce5d 100644
--- a/arch/arm/include/asm/arch-ls102xa/ls102xa_soc.h
+++ b/arch/arm/include/asm/arch-ls102xa/ls102xa_soc.h
@@ -10,6 +10,8 @@ unsigned int get_soc_major_rev(void);
 int arch_soc_init(void);
 int ls102xa_smmu_stream_id_init(void);
 
+void erratum_a008850_post(void);
+
 #ifdef CONFIG_SYS_FSL_ERRATUM_A010315
 void erratum_a010315(void);
 #endif
diff --git a/board/freescale/ls1021aiot/ls1021aiot.c 
b/board/freescale/ls1021aiot/ls1021aiot.c
index fb05b55b5c..70992a5ce4 100644
-

Re: [U-Boot] Regression: vf610twr build error

2018-10-23 Thread Alison Wang
Hi, Stefano,

I don't have vf610 boards now. I am afraid I could not verify it too.


Best Regards,
Alison Wang

>-Original Message-
>From: Stefano Babic 
>Sent: 2018年10月23日 0:05
>To: Alison Wang 
>Cc: U-Boot@lists.denx.de
>Subject: Regression: vf610twr build error
>
>Hi Alison,
>
>I get a build error when I try to build the vf610 boards. This is not due to 
>recent
>patches for the board, but it is implicitly done on the current tree after 
>other
>branches were merged, because the resulting binary becomes bigger.
>
>In fact, it exceeds the maximum size:
>
>arm:  +   vf610twr_nand
>+u-boot-nodtb.bin exceeds file size limit:
>+  limit:  520192 bytes
>+  actual: 521316 bytes
>+  excess: 1124 bytes
>+make[1]: *** [u-boot-nodtb.bin] Error 1
>+make: *** [sub-make] Error 2
>   arm:  +   vf610twr
>+u-boot-nodtb.bin exceeds file size limit:
>+  limit:  520192 bytes
>+  actual: 521492 bytes
>+  excess: 1300 bytes
>+make[1]: *** [u-boot-nodtb.bin] Error 1
>+make: *** [sub-make] Error 2
>
>Anyway, colibry_vf has already set CONFIG_SYS_THUMB_BUILD to optimize the
>footprint. I can confirm that setting this to vf610twr fixes the build - 
>anyway, I
>have no way to test.
>
>Can you take a look ? If it is ok, CONFIG_SYS_THUMB_BUILD should be added to
>both vf610twr_defconfig and vf610twr_nand_defconfig.
>
>Best regards,
>Stefano
>
>--
>=
>
>DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
>HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
>Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sba...@denx.de
>=
>
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] arm: ls1021a: Add timer_init() in board_init_f for SPL

2018-10-16 Thread Alison Wang
I2C is used to access DDR SPD in the DDR initialization for SPL. In
i2c_write process, get_timer() will be called. In board_init_f for SPL,
timer_init() is not called before. The system counter is not enabled and
the counter frequency is not set to 12.5MHz in SPL. The parameters for
do_div() are zero too.

It could not be found until CONFIG_USE_PRIVATE_LIBGCC is enabled in
default. When CONFIG_USE_PRIVATE_LIBGCC is enabled, U-Boot will use its
own set of libgcc functions. As the parameters for do_div() are zero,
__div0 will be called. Then the processor will stay in an endless loop
after calling hang().

This patch will add timer_init() in board_init_f for SPL and fix a
series of issues it caused.

Signed-off-by: Alison Wang 
---
 board/freescale/ls1021aqds/ls1021aqds.c |1 +
 board/freescale/ls1021atwr/ls1021atwr.c |1 +
 2 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/board/freescale/ls1021aqds/ls1021aqds.c 
b/board/freescale/ls1021aqds/ls1021aqds.c
index c828dac..c08be1e 100644
--- a/board/freescale/ls1021aqds/ls1021aqds.c
+++ b/board/freescale/ls1021aqds/ls1021aqds.c
@@ -244,6 +244,7 @@ void board_init_f(ulong dummy)
if (major == SOC_MAJOR_VER_1_0)
out_le32(>ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
 
+   timer_init();
dram_init();
 
/* Allow OCRAM access permission as R/W */
diff --git a/board/freescale/ls1021atwr/ls1021atwr.c 
b/board/freescale/ls1021atwr/ls1021atwr.c
index dcd6d93..beb82ce 100644
--- a/board/freescale/ls1021atwr/ls1021atwr.c
+++ b/board/freescale/ls1021atwr/ls1021atwr.c
@@ -467,6 +467,7 @@ void board_init_f(ulong dummy)
 
preloader_console_init();
 
+   timer_init();
dram_init();
 
/* Allow OCRAM access permission as R/W */
-- 
1.7.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] armv8: ls2080ardb: update copyright claim

2018-06-18 Thread Alison Wang
This patch updates the copyright claim for the issues reported by Legal
Review.

Signed-off-by: Alison Wang 
---
 board/freescale/ls2080ardb/ls2080ardb.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/board/freescale/ls2080ardb/ls2080ardb.c 
b/board/freescale/ls2080ardb/ls2080ardb.c
index 683fe44..46b18cf 100644
--- a/board/freescale/ls2080ardb/ls2080ardb.c
+++ b/board/freescale/ls2080ardb/ls2080ardb.c
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Copyright (C) 2017 NXP Semiconductors
  * Copyright 2015 Freescale Semiconductor
+ * Copyright 2017 NXP
  */
 #include 
 #include 
-- 
1.7.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH] arm: ls1021atwr: Rework local commands to not be included in SPL

2018-01-04 Thread Alison Wang

On Wed, Jan 3, 2018 at 10:02 PM, Tom Rini <tr...@konsulko.com> wrote:
> 
> Move some of the code for the "lane_bank" and "cpld" code local commands
> so that they are not built for SPL as they can only be used in full
> U-Boot.  This means we can mark a few functions as static as well now.
> 
> Cc: Alison Wang <alison.w...@freescale.com>
> Cc: Sumit Garg <sumit.g...@nxp.com>
> Cc: York Sun <york@nxp.com>
> Signed-off-by: Tom Rini <tr...@konsulko.com>

Reviewed-by: Alison Wang <alison.w...@nxp.com>
Tested-by: Alison Wang <alison.w...@nxp.com>


Best Regards,
Alison Wang
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3] armv8: errata: Implement workaround for Cortex-A53 Erratum 855873

2017-12-27 Thread Alison Wang
855873: An eviction might overtake a cache clean operation
Workaround: The erratum can be avoided by upgrading cache clean by
address operations to cache clean and invalidate operations. For
Cortex-A53 r0p3 and later release, this can be achieved by setting
CPUACTLR.ENDCCASCI to 1.

This patch is to implement the workaround for this erratum.

Signed-off-by: Alison Wang <alison.w...@nxp.com>
---
Changes in v3:
- Check the major revision of Cortex-A53.

Changes in v2:
- Check the revision of Cortex-A53 and apply the erratum to r0p3 and later 
release.
- Fix the mistake in the commit description.

 arch/arm/Kconfig  |3 +++
 arch/arm/cpu/armv8/fsl-layerscape/Kconfig |3 +++
 arch/arm/cpu/armv8/start.S|   24 +++-
 3 files changed, 29 insertions(+), 1 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index f2c35e3..de323bf 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -122,6 +122,9 @@ config ARM_ERRATA_852421
 config ARM_ERRATA_852423
bool
 
+config ARM_ERRATA_855873
+   bool
+
 config CPU_ARM720T
bool
select SYS_CACHE_SHIFT_5
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig 
b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
index 66bc32c..76a4d8b 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
+++ b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
@@ -1,6 +1,7 @@
 config ARCH_LS1012A
bool
select ARMV8_SET_SMPEN
+   select ARM_ERRATA_855873
select FSL_LSCH2
select SYS_FSL_DDR_BE
select SYS_FSL_MMDC
@@ -15,6 +16,7 @@ config ARCH_LS1012A
 config ARCH_LS1043A
bool
select ARMV8_SET_SMPEN
+   select ARM_ERRATA_855873
select FSL_LSCH2
select SYS_FSL_DDR
select SYS_FSL_DDR_BE
@@ -67,6 +69,7 @@ config ARCH_LS1046A
 config ARCH_LS1088A
bool
select ARMV8_SET_SMPEN
+   select ARM_ERRATA_855873
select FSL_LSCH3
select SYS_FSL_DDR
select SYS_FSL_DDR_LE
diff --git a/arch/arm/cpu/armv8/start.S b/arch/arm/cpu/armv8/start.S
index 03e744e..f385ed4 100644
--- a/arch/arm/cpu/armv8/start.S
+++ b/arch/arm/cpu/armv8/start.S
@@ -196,7 +196,10 @@ reset_sctrl:
 WEAK(apply_core_errata)
 
mov x29, lr /* Save LR */
-   /* For now, we support Cortex-A57 specific errata only */
+   /* For now, we support Cortex-A53, Cortex-A57 specific errata */
+
+   /* Check if we are running on a Cortex-A53 core */
+   branch_if_a53_core x0, apply_a53_core_errata
 
/* Check if we are running on a Cortex-A57 core */
branch_if_a57_core x0, apply_a57_core_errata
@@ -204,6 +207,25 @@ WEAK(apply_core_errata)
mov lr, x29 /* Restore LR */
ret
 
+apply_a53_core_errata:
+
+#ifdef CONFIG_ARM_ERRATA_855873
+   mrs x0, midr_el1
+   tst x0, #(0xf << 20)
+   b.ne0b
+
+   mrs x0, midr_el1
+   and x0, x0, #0xf
+   cmp x0, #3
+   b.lt0b
+
+   mrs x0, S3_1_c15_c2_0   /* cpuactlr_el1 */
+   /* Enable data cache clean as data cache clean/invalidate */
+   orr x0, x0, #1 << 44
+   msr S3_1_c15_c2_0, x0   /* cpuactlr_el1 */
+#endif
+   b 0b
+
 apply_a57_core_errata:
 
 #ifdef CONFIG_ARM_ERRATA_828024
-- 
1.7.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCHv2] GPT: fix memory leaks identified by Coverity

2017-09-26 Thread alison
From: Alison Chaiken <ali...@she-devel.com>

Create a common exit for most of the error handling code in
do_rename_gpt_parts.   Delete the list elements in disk_partitions
before calling INIT_LIST_HEAD from get_gpt_info() a second time.

The SIZEOF_MISMATCH error is not addressed, since that problem was
already fixed by "GPT: incomplete initialization in
allocate_disk_part".

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>

---

 v2: Fix comment-formatting problems in v1.

 cmd/gpt.c | 87 ++-
 1 file changed, 69 insertions(+), 18 deletions(-)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index d4406e3120..9e04affc06 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -633,6 +633,21 @@ static int do_disk_guid(struct blk_desc *dev_desc, char * 
const namestr)
 }
 
 #ifdef CONFIG_CMD_GPT_RENAME
+/*
+ * There are 3 malloc() calls in set_gpt_info() and there is no info about 
which
+ * failed.
+ */
+static void set_gpt_cleanup(char **str_disk_guid,
+   disk_partition_t **partitions)
+{
+#ifdef CONFIG_RANDOM_UUID
+   if (str_disk_guid)
+   free(str_disk_guid);
+#endif
+   if (partitions)
+   free(partitions);
+}
+
 static int do_rename_gpt_parts(struct blk_desc *dev_desc, char *subcomm,
   char *name1, char *name2)
 {
@@ -651,19 +666,27 @@ static int do_rename_gpt_parts(struct blk_desc *dev_desc, 
char *subcomm,
ret = get_disk_guid(dev_desc, disk_guid);
if (ret < 0)
return ret;
+   /*
+* Allocates disk_partitions, requiring matching call to del_gpt_info()
+* if successful.
+*/
numparts = get_gpt_info(dev_desc);
if (numparts <=  0)
return numparts ? numparts : -ENODEV;
 
partlistlen = calc_parts_list_len(numparts);
partitions_list = malloc(partlistlen);
-   if (partitions_list == NULL)
+   if (!partitions_list) {
+   del_gpt_info();
return -ENOMEM;
+   }
memset(partitions_list, '\0', partlistlen);
 
ret = create_gpt_partitions_list(numparts, disk_guid, partitions_list);
-   if (ret < 0)
+   if (ret < 0) {
+   free(partitions_list);
return ret;
+   }
/*
 * Uncomment the following line to print a string that 'gpt write'
 * or 'gpt verify' will accept as input.
@@ -671,15 +694,23 @@ static int do_rename_gpt_parts(struct blk_desc *dev_desc, 
char *subcomm,
debug("OLD partitions_list is %s with %u chars\n", partitions_list,
  (unsigned)strlen(partitions_list));
 
+   /* set_gpt_info allocates new_partitions and str_disk_guid */
ret = set_gpt_info(dev_desc, partitions_list, _disk_guid,
   _partitions, _count);
-   if (ret < 0)
-   return ret;
+   if (ret < 0) {
+   del_gpt_info();
+   free(partitions_list);
+   if (ret == -ENOMEM)
+   set_gpt_cleanup(_disk_guid, _partitions);
+   else
+   goto out;
+   }
 
if (!strcmp(subcomm, "swap")) {
if ((strlen(name1) > PART_NAME_LEN) || (strlen(name2) > 
PART_NAME_LEN)) {
printf("Names longer than %d characters are 
truncated.\n", PART_NAME_LEN);
-   return -EINVAL;
+   ret = -EINVAL;
+   goto out;
}
list_for_each(pos, _partitions) {
curr = list_entry(pos, struct disk_part, list);
@@ -693,21 +724,24 @@ static int do_rename_gpt_parts(struct blk_desc *dev_desc, 
char *subcomm,
}
if ((ctr1 + ctr2 < 2) || (ctr1 != ctr2)) {
printf("Cannot swap partition names except in 
pairs.\n");
-   return -EINVAL;
+   ret = -EINVAL;
+   goto out;
}
} else { /* rename */
if (strlen(name2) > PART_NAME_LEN) {
printf("Names longer than %d characters are 
truncated.\n", PART_NAME_LEN);
-   return -EINVAL;
+   ret = -EINVAL;
+   goto out;
}
partnum = (int)simple_strtol(name1, NULL, 10);
if ((partnum < 0) || (partnum > numparts)) {
printf("Illegal partition number %s\n", name1);
-   return -EINVAL;
+   ret = -EINVAL;
+   goto out;
}
ret = part_get_info(dev_desc, partnum, new_partitions);
if (ret < 0)
-   return ret;
+   goto out;
 
/* U-B

[U-Boot] [PATCHv2] GPT: fix memory leaks identified by Coverity

2017-09-26 Thread alison
From: Alison Chaiken <ali...@she-devel.com>

Create a common exit for most of the error handling code in
do_rename_gpt_parts.   Delete the list elements in disk_partitions
before calling INIT_LIST_HEAD from get_gpt_info() a second time.

The SIZEOF_MISMATCH error is not addressed, since that problem was
already fixed by "GPT: incomplete initialization in
allocate_disk_part".

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>

v2: Fix comment-formatting problems in v1.

---
 cmd/gpt.c | 87 ++-
 1 file changed, 69 insertions(+), 18 deletions(-)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index d4406e3120..9e04affc06 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -633,6 +633,21 @@ static int do_disk_guid(struct blk_desc *dev_desc, char * 
const namestr)
 }
 
 #ifdef CONFIG_CMD_GPT_RENAME
+/*
+ * There are 3 malloc() calls in set_gpt_info() and there is no info about 
which
+ * failed.
+ */
+static void set_gpt_cleanup(char **str_disk_guid,
+   disk_partition_t **partitions)
+{
+#ifdef CONFIG_RANDOM_UUID
+   if (str_disk_guid)
+   free(str_disk_guid);
+#endif
+   if (partitions)
+   free(partitions);
+}
+
 static int do_rename_gpt_parts(struct blk_desc *dev_desc, char *subcomm,
   char *name1, char *name2)
 {
@@ -651,19 +666,27 @@ static int do_rename_gpt_parts(struct blk_desc *dev_desc, 
char *subcomm,
ret = get_disk_guid(dev_desc, disk_guid);
if (ret < 0)
return ret;
+   /*
+* Allocates disk_partitions, requiring matching call to del_gpt_info()
+* if successful.
+*/
numparts = get_gpt_info(dev_desc);
if (numparts <=  0)
return numparts ? numparts : -ENODEV;
 
partlistlen = calc_parts_list_len(numparts);
partitions_list = malloc(partlistlen);
-   if (partitions_list == NULL)
+   if (!partitions_list) {
+   del_gpt_info();
return -ENOMEM;
+   }
memset(partitions_list, '\0', partlistlen);
 
ret = create_gpt_partitions_list(numparts, disk_guid, partitions_list);
-   if (ret < 0)
+   if (ret < 0) {
+   free(partitions_list);
return ret;
+   }
/*
 * Uncomment the following line to print a string that 'gpt write'
 * or 'gpt verify' will accept as input.
@@ -671,15 +694,23 @@ static int do_rename_gpt_parts(struct blk_desc *dev_desc, 
char *subcomm,
debug("OLD partitions_list is %s with %u chars\n", partitions_list,
  (unsigned)strlen(partitions_list));
 
+   /* set_gpt_info allocates new_partitions and str_disk_guid */
ret = set_gpt_info(dev_desc, partitions_list, _disk_guid,
   _partitions, _count);
-   if (ret < 0)
-   return ret;
+   if (ret < 0) {
+   del_gpt_info();
+   free(partitions_list);
+   if (ret == -ENOMEM)
+   set_gpt_cleanup(_disk_guid, _partitions);
+   else
+   goto out;
+   }
 
if (!strcmp(subcomm, "swap")) {
if ((strlen(name1) > PART_NAME_LEN) || (strlen(name2) > 
PART_NAME_LEN)) {
printf("Names longer than %d characters are 
truncated.\n", PART_NAME_LEN);
-   return -EINVAL;
+   ret = -EINVAL;
+   goto out;
}
list_for_each(pos, _partitions) {
curr = list_entry(pos, struct disk_part, list);
@@ -693,21 +724,24 @@ static int do_rename_gpt_parts(struct blk_desc *dev_desc, 
char *subcomm,
}
if ((ctr1 + ctr2 < 2) || (ctr1 != ctr2)) {
printf("Cannot swap partition names except in 
pairs.\n");
-   return -EINVAL;
+   ret = -EINVAL;
+   goto out;
}
} else { /* rename */
if (strlen(name2) > PART_NAME_LEN) {
printf("Names longer than %d characters are 
truncated.\n", PART_NAME_LEN);
-   return -EINVAL;
+   ret = -EINVAL;
+   goto out;
}
partnum = (int)simple_strtol(name1, NULL, 10);
if ((partnum < 0) || (partnum > numparts)) {
printf("Illegal partition number %s\n", name1);
-   return -EINVAL;
+   ret = -EINVAL;
+   goto out;
}
ret = part_get_info(dev_desc, partnum, new_partitions);
if (ret < 0)
-   return ret;
+   goto out;
 
/* U-B

[U-Boot] [PATCH] GPT: fix memory leaks identified by Coverity

2017-09-24 Thread alison
From: Alison Chaiken <ali...@she-devel.com>

Create a common exit for most of the error handling code in
do_rename_gpt_parts.   Delete the list elements in disk_partitions
before calling INIT_LIST_HEAD from get_gpt_info() a second time.

The SIZEOF_MISMATCH error is not addressed, since that problem was
already fixed by "GPT: incomplete initialization in
allocate_disk_part".

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 cmd/gpt.c | 84 +--
 1 file changed, 66 insertions(+), 18 deletions(-)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index d4406e3120..dfa41947e1 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -633,6 +633,21 @@ static int do_disk_guid(struct blk_desc *dev_desc, char * 
const namestr)
 }
 
 #ifdef CONFIG_CMD_GPT_RENAME
+
+/* There are 3 malloc() calls in set_gpt_info() and there is no info about 
which
+ * failed.
+ */
+static void set_gpt_cleanup(char **str_disk_guid,
+   disk_partition_t **partitions)
+{
+#ifdef CONFIG_RANDOM_UUID
+   if (str_disk_guid)
+   free(str_disk_guid);
+#endif
+   if (partitions)
+   free(partitions);
+}
+
 static int do_rename_gpt_parts(struct blk_desc *dev_desc, char *subcomm,
   char *name1, char *name2)
 {
@@ -651,19 +666,26 @@ static int do_rename_gpt_parts(struct blk_desc *dev_desc, 
char *subcomm,
ret = get_disk_guid(dev_desc, disk_guid);
if (ret < 0)
return ret;
+   /* Allocates disk_partitions, requiring matching call to del_gpt_info()
+* if successful.
+*/
numparts = get_gpt_info(dev_desc);
if (numparts <=  0)
return numparts ? numparts : -ENODEV;
 
partlistlen = calc_parts_list_len(numparts);
partitions_list = malloc(partlistlen);
-   if (partitions_list == NULL)
+   if (!partitions_list) {
+   del_gpt_info();
return -ENOMEM;
+   }
memset(partitions_list, '\0', partlistlen);
 
ret = create_gpt_partitions_list(numparts, disk_guid, partitions_list);
-   if (ret < 0)
+   if (ret < 0) {
+   free(partitions_list);
return ret;
+   }
/*
 * Uncomment the following line to print a string that 'gpt write'
 * or 'gpt verify' will accept as input.
@@ -671,15 +693,23 @@ static int do_rename_gpt_parts(struct blk_desc *dev_desc, 
char *subcomm,
debug("OLD partitions_list is %s with %u chars\n", partitions_list,
  (unsigned)strlen(partitions_list));
 
+   /* set_gpt_info allocates new_partitions and str_disk_guid */
ret = set_gpt_info(dev_desc, partitions_list, _disk_guid,
   _partitions, _count);
-   if (ret < 0)
-   return ret;
+   if (ret < 0) {
+   del_gpt_info();
+   free(partitions_list);
+   if (ret == -ENOMEM)
+   set_gpt_cleanup(_disk_guid, _partitions);
+   else
+   goto out;
+   }
 
if (!strcmp(subcomm, "swap")) {
if ((strlen(name1) > PART_NAME_LEN) || (strlen(name2) > 
PART_NAME_LEN)) {
printf("Names longer than %d characters are 
truncated.\n", PART_NAME_LEN);
-   return -EINVAL;
+   ret = -EINVAL;
+   goto out;
}
list_for_each(pos, _partitions) {
curr = list_entry(pos, struct disk_part, list);
@@ -693,21 +723,24 @@ static int do_rename_gpt_parts(struct blk_desc *dev_desc, 
char *subcomm,
}
if ((ctr1 + ctr2 < 2) || (ctr1 != ctr2)) {
printf("Cannot swap partition names except in 
pairs.\n");
-   return -EINVAL;
+   ret = -EINVAL;
+   goto out;
}
} else { /* rename */
if (strlen(name2) > PART_NAME_LEN) {
printf("Names longer than %d characters are 
truncated.\n", PART_NAME_LEN);
-   return -EINVAL;
+   ret = -EINVAL;
+   goto out;
}
partnum = (int)simple_strtol(name1, NULL, 10);
if ((partnum < 0) || (partnum > numparts)) {
printf("Illegal partition number %s\n", name1);
-   return -EINVAL;
+   ret = -EINVAL;
+   goto out;
}
ret = part_get_info(dev_desc, partnum, new_partitions);
if (ret < 0)
-   return ret;
+   goto out;
 
/* U-Boot partition numbering starts at 1 */
  

Re: [U-Boot] [PATCH] test/py: gpt: make use of infra-structure

2017-09-16 Thread Alison Chaiken
I suggest that while we're cleaning this test up, that we add
something like this to each of the tests:

diff --git a/test/py/tests/test_gpt.py b/test/py/tests/test_gpt.py
index e2bbd08e6d..485d092371 100644
--- a/test/py/tests/test_gpt.py
+++ b/test/py/tests/test_gpt.py
@@ -67,6 +67,8 @@ def state_disk_image(u_boot_console):
def test_gpt_guid(state_disk_image, u_boot_console):
"""Test the gpt guid command."""

+if not os.path.exists('/sbin/sgdisk'):
+pytest.skip('install gdisk package to test gpt commands')


Otherwise, the tests will all fail if the gdisk package is not
installed.   Assuredly anyone who does not have gdisk installed does
not care about these tests anyway.   If people agree, I can submit a
patch, or perhaps Stephen could just add it to his.

Best wishes,
Alison Chaiken
Peloton Technology

On Fri, Sep 15, 2017 at 10:54 AM, Tom Rini <tr...@konsulko.com> wrote:
>
> On Fri, Sep 15, 2017 at 11:25:51AM -0600, Stephen Warren wrote:
>
> > From: Stephen Warren <swar...@nvidia.com>
> >
> > Make various changes to the GPT test:
> >
> > 1) Reference the disk image using an absolute path in all cases. This
> > allows test/py to operate correctly if it's run from a directory other
> > than the root of the U-Boot source tree.
> >
> > 2) Store the disk image in the teswt/py persistent data directory. This
> > removes the need to re-generate it every time the tests are run.
> >
> > 3) Execute sgdisk using u_boot_utils.run_and_log() so that its output is
> > captured in the test log. This allows debugging any problems running it.
> >
> > 4) Make the disk image a test fixture. This removes the requirement to
> > always run all GPT tests, and run them in order. The current code doesn't
> > create the disk image if e.g. just test_gpt_uuid() is executed via the
> > test.py -k command-line option.
> >
> > 5) Use @pytest.mark.buildconfigspec for all feature dependencies, rather
> > than manually implementing some of them.
> >
> > Fixes: a2f422555fc8 ("add pytests for 'gpt guid' command in sandbox")
> > Fixes: c5772188ede9 ("add pytests for 'gpt rename' and 'gpt swap'")
> > Signed-off-by: Stephen Warren <swar...@nvidia.com>
>
> Having kicked my jenkins (sigh), and then really tried to run these
> tests on hardware, I think we're not quite done:
>
> >  @pytest.mark.buildconfigspec('cmd_gpt')
> > -def test_gpt_guid(u_boot_console):
> > +def test_gpt_guid(state_disk_image, u_boot_console):
> >  """Test the gpt guid command."""
> >
> > -if u_boot_console.config.buildconfig.get('config_cmd_gpt', 'n') != 'y':
> > -pytest.skip('gpt command not supported')
> > -make_test_disk.makeDisk()
> > -u_boot_console.run_command('host bind 0 testdisk.raw')
> > +u_boot_console.run_command('host bind 0 ' + state_disk_image.path)
>
> Here and elsewhere we also need to say it depends on sandbox as that's
> what gives the host command.  Thanks!
>
> --
> Tom
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH] cmd/gpt.c: Fix warning over memset args in allocate_disk_part

2017-09-16 Thread Alison Chaiken
On Fri, Sep 15, 2017 at 5:02 AM, Tom Rini <tr...@konsulko.com> wrote:

> With clang-3.8 we see:
> cmd/gpt.c:196:31: warning: 'memset' call operates on objects
>   of type 'struct disk_part' while the size is based on a different
> type
>   'struct disk_part *' [-Wsizeof-pointer-memaccess]
> memset(newpart, '\0', sizeof(newpart));
>~~~   ^~~
> cmd/gpt.c:196:31: note: did you mean to dereference the
>   argument to 'sizeof' (and multiply it by the number of elements)?
> memset(newpart, '\0', sizeof(newpart));
>  ^~~
>
> As we should have been passing sizeof(*newpart) not sizeof(newpart)
> here.
>
>
Agreed.  I'm happy to have now read how u-boot can be compiled with clang.

-- Alison


> Cc: Lothar Waßmann <l...@karo-electronics.de>
> Cc: Alison Chaiken <ali...@peloton-tech.com>
> Fixes: 09a49930e415 ("GPT: read partition table from device into a data
> structure")
> Signed-off-by: Tom Rini <tr...@konsulko.com>
> ---
>  cmd/gpt.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/cmd/gpt.c b/cmd/gpt.c
> index 638aa198267b..701a1c1d6cd1 100644
> --- a/cmd/gpt.c
> +++ b/cmd/gpt.c
> @@ -193,7 +193,7 @@ static struct disk_part 
> *allocate_disk_part(disk_partition_t
> *info, int partnum)
> newpart = malloc(sizeof(*newpart));
> if (!newpart)
> return ERR_PTR(-ENOMEM);
> -   memset(newpart, '\0', sizeof(newpart));
> +   memset(newpart, '\0', sizeof(*newpart));
>
> newpart->gpt_part_info.start = info->start;
> newpart->gpt_part_info.size = info->size;
> --
> 1.9.1
>
>
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 1/3] add pytests for 'gpt rename' and 'gpt swap'

2017-09-10 Thread alison
From: Alison Chaiken <ali...@she-devel.com>

On Tue, Sep 5, 2017 at 1:55 AM, Simon Glass <s...@chromium.org> wrote:
> How about we add this to sandbox_defconfig instead?

So done.

-- Alison

Alison Chaiken (1):
  add pytests for 'gpt rename' and 'gpt swap'

 configs/sandbox_defconfig |  1 +
 test/py/tests/test_gpt.py | 31 +++
 2 files changed, 32 insertions(+)

-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 1/1] add pytests for 'gpt rename' and 'gpt swap'

2017-09-10 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

Add unit tests for the 'gpt rename' and 'gpt swap' commands that
rely on the block device created by test/py/make_test_disk.py.
Add CONFIG_CMD_GPT_RENAME to the sandbox_defconfig.  Remove the
testdisk.raw test device at the end of the tests.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 configs/sandbox_defconfig |  1 +
 test/py/tests/test_gpt.py | 31 +++
 2 files changed, 32 insertions(+)

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 4c4e4809be..e7a61bd61a 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -34,6 +34,7 @@ CONFIG_CMD_MX_CYCLIC=y
 CONFIG_CMD_DEMO=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
+CONFIG_CMD_GPT_RENAME=y
 CONFIG_CMD_IDE=y
 CONFIG_CMD_I2C=y
 CONFIG_CMD_PCI=y
diff --git a/test/py/tests/test_gpt.py b/test/py/tests/test_gpt.py
index 73f5c50f6c..06f24b66ce 100644
--- a/test/py/tests/test_gpt.py
+++ b/test/py/tests/test_gpt.py
@@ -35,4 +35,35 @@ def test_gpt_save_guid(u_boot_console):
 output = u_boot_console.run_command('gpt guid host 0 newguid')
 output = u_boot_console.run_command('printenv newguid')
 assert '375a56f7-d6c9-4e81-b5f0-09d41ca89efe' in output
+
+@pytest.mark.buildconfigspec('cmd_gpt')
+def test_gpt_rename_partition(u_boot_console):
+"""Test the gpt rename command to write partition names."""
+
+if u_boot_console.config.buildconfig.get('config_cmd_gpt_rename', 'n') != 
'y':
+pytest.skip('gpt rename command not supported')
+u_boot_console.run_command('host bind 0 testdisk.raw')
+u_boot_console.run_command('gpt rename host 0 1 first')
+output = u_boot_console.run_command('gpt read host 0')
+assert 'name first' in output
+u_boot_console.run_command('gpt rename host 0 2 second')
+output = u_boot_console.run_command('gpt read host 0')
+assert 'name second' in output
+
+@pytest.mark.buildconfigspec('cmd_gpt')
+def test_gpt_swap_partitions(u_boot_console):
+"""Test the gpt swap command to exchange two partition names."""
+
+if u_boot_console.config.buildconfig.get('config_cmd_gpt_rename', 'n') != 
'y':
+pytest.skip('gpt rename command not supported')
+if u_boot_console.config.buildconfig.get('config_cmd_part', 'n') != 'y':
+pytest.skip('gpt swap test needs CMD_PART')
+u_boot_console.run_command('host bind 0 testdisk.raw')
+output = u_boot_console.run_command('part list host 0')
+assert '0x07ff "first"' in output
+assert '0x17ff "second"' in output
+u_boot_console.run_command('gpt swap host 0 first second')
+output = u_boot_console.run_command('part list host 0')
+assert '0x07ff "second"' in output
+assert '0x17ff "first"' in output
 os.remove('testdisk.raw')
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 1/2] GPT: create block device for sandbox testing

2017-09-10 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

Provide a Python function that creates a small block device for the
purpose of testing the cmd/gpt.c or cmd/part.c functions in the u-boot
sandbox.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 board/sandbox/README.sandbox |  5 +
 test/py/make_test_disk.py| 19 +++
 2 files changed, 24 insertions(+)
 create mode 100755 test/py/make_test_disk.py

diff --git a/board/sandbox/README.sandbox b/board/sandbox/README.sandbox
index 9dc2eb09d1..947241e3eb 100644
--- a/board/sandbox/README.sandbox
+++ b/board/sandbox/README.sandbox
@@ -338,6 +338,11 @@ $> lodev=`sudo losetup -P -f --show ./disk.raw`
 $> sudo mkfs.vfat -n EFI -v ${lodev}p1
 $> sudo mkfs.ext4 -L ROOT -v ${lodev}p2
 
+or utilize the device described in test/py/make_test_disk.py:
+
+   #!/usr/bin/python
+   import make_test_disk
+   make_test_disk.makeDisk()
 
 Writing Sandbox Drivers
 ---
diff --git a/test/py/make_test_disk.py b/test/py/make_test_disk.py
new file mode 100755
index 00..5288295588
--- /dev/null
+++ b/test/py/make_test_disk.py
@@ -0,0 +1,19 @@
+# Copyright (c) 2017 Alison Chaiken
+#
+# SPDX-License-Identifier: GPL-2.0
+#
+# Create a block device for testing of 'gpt' and 'part' commands.
+
+import os
+
+def makeDisk():
+if (os.path.exists("testdisk.raw")):
+os.remove("testdisk.raw")
+fd = os.open("testdisk.raw", os.O_RDWR|os.O_CREAT )
+os.ftruncate(fd, 4194304)
+os.close(fd)
+os.spawnl(os.P_WAIT, "/sbin/sgdisk", "sgdisk", "-U",
+  "375a56f7-d6c9-4e81-b5f0-09d41ca89efe", "testdisk.raw")
+os.spawnl(os.P_WAIT, "/sbin/sgdisk", "sgdisk", "--new=1:2048:2560", 
"testdisk.raw")
+os.spawnl(os.P_WAIT, "/sbin/sgdisk", "sgdisk", "--new=2:4096:4608", 
"testdisk.raw")
+os.spawnl(os.P_WAIT, "/sbin/gdisk", "sgdisk", "-l", "testdisk.raw")
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 2/2] add pytests for 'gpt guid' command in sandbox

2017-09-10 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

Run unit tests for the 'gpt guid' command, making use of the block
device created by test/py/make_test_disk.py.  Remove this device at
the end of the tests.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 test/py/tests/test_gpt.py | 38 ++
 1 file changed, 38 insertions(+)
 create mode 100644 test/py/tests/test_gpt.py

diff --git a/test/py/tests/test_gpt.py b/test/py/tests/test_gpt.py
new file mode 100644
index 00..73f5c50f6c
--- /dev/null
+++ b/test/py/tests/test_gpt.py
@@ -0,0 +1,38 @@
+# Copyright (c) 2017 Alison Chaiken
+#
+# SPDX-License-Identifier: GPL-2.0
+
+# Test GPT manipulation commands.
+
+import os
+import pytest
+import u_boot_utils
+import make_test_disk
+
+"""
+These tests rely on a 4 MB block device called testdisk.raw
+which is automatically removed at the end of the tests.
+"""
+
+@pytest.mark.buildconfigspec('cmd_gpt')
+def test_gpt_guid(u_boot_console):
+"""Test the gpt guid command."""
+
+if u_boot_console.config.buildconfig.get('config_cmd_gpt', 'n') != 'y':
+pytest.skip('gpt command not supported')
+make_test_disk.makeDisk()
+u_boot_console.run_command('host bind 0 testdisk.raw')
+output = u_boot_console.run_command('gpt guid host 0')
+assert '375a56f7-d6c9-4e81-b5f0-09d41ca89efe' in output
+
+@pytest.mark.buildconfigspec('cmd_gpt')
+def test_gpt_save_guid(u_boot_console):
+"""Test the gpt guid command to save GUID into a string."""
+
+if u_boot_console.config.buildconfig.get('config_cmd_gpt', 'n') != 'y':
+pytest.skip('gpt command not supported')
+u_boot_console.run_command('host bind 0 testdisk.raw')
+output = u_boot_console.run_command('gpt guid host 0 newguid')
+output = u_boot_console.run_command('printenv newguid')
+assert '375a56f7-d6c9-4e81-b5f0-09d41ca89efe' in output
+os.remove('testdisk.raw')
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 0/2] GPT: create block device for guid testing

2017-09-10 Thread alison
From: Alison Chaiken <ali...@she-devel.com>

Simon Glass <s...@chromium.org> asked:
> Can you please move this into the Python script so that it is created
> automatically and deleted at the end.

In this version, the device creation is moved to a Python function
that the pytest framework can invoke, and a description of the
function is added to README.sandbox.  The test of the 'gpt guid'
command now creates the device at the start of the test and removes it
again at the end.

Alison Chaiken (2):
  GPT: create block device for sandbox testing
  add pytests for 'gpt guid' command in sandbox

 board/sandbox/README.sandbox |  5 +
 test/py/make_test_disk.py| 19 +++
 test/py/tests/test_gpt.py| 38 ++
 3 files changed, 62 insertions(+)
 create mode 100755 test/py/make_test_disk.py
 create mode 100644 test/py/tests/test_gpt.py

-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] doc: remove duplicate text in README.gpt

2017-09-04 Thread alison
From: Alison Chaiken <ali...@she-devel.com>

Signed-off-by: Alison Chaiken <ali...@she-devel.com>
---
 doc/README.gpt | 10 --
 1 file changed, 10 deletions(-)

diff --git a/doc/README.gpt b/doc/README.gpt
index 517df551e7..d3db8bce1c 100644
--- a/doc/README.gpt
+++ b/doc/README.gpt
@@ -233,16 +233,6 @@ The GPT functionality may be tested with the 'sandbox' 
board by
 creating a disk image as described under 'Block Device Emulation' in
 board/sandbox/README.sandbox:
 
-=>host bind 0 ./disk.raw
-=> gpt read host 0
-[ . . . ]
-=> gpt flip host 0
-[ . . . ]
-
-The GPT functionality may be tested with the 'sandbox' board by
-creating a disk image as described under 'Block Device Emulation' in
-board/sandbox/README.sandbox:
-
 =>host bind 0 ./disk.raw
 => gpt read host 0
 [ . . . ]
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 3/3] add pytests for 'gpt rename' and 'gpt swap'

2017-09-02 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

Add unit tests for the 'gpt rename' and 'gpt swap' commands that rely
on the block device created by test/gpt/make-test-disk.sh.   Create a
new configs/sandbox_gpt_rename_defconfig file to enable testing with
CONFIG_CMD_GPT_RENAME.  Remove the disk.raw test device at the end of
the tests.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 configs/sandbox_gpt_rename_defconfig | 196 +++
 test/py/tests/test_gpt.py|  31 ++
 2 files changed, 227 insertions(+)
 create mode 100644 configs/sandbox_gpt_rename_defconfig

diff --git a/configs/sandbox_gpt_rename_defconfig 
b/configs/sandbox_gpt_rename_defconfig
new file mode 100644
index 000..e7a61bd
--- /dev/null
+++ b/configs/sandbox_gpt_rename_defconfig
@@ -0,0 +1,196 @@
+CONFIG_SYS_MALLOC_F_LEN=0x2000
+CONFIG_DEFAULT_DEVICE_TREE="sandbox"
+CONFIG_DISTRO_DEFAULTS=y
+CONFIG_ANDROID_BOOT_IMAGE=y
+CONFIG_FIT=y
+CONFIG_FIT_SIGNATURE=y
+CONFIG_FIT_VERBOSE=y
+CONFIG_BOOTSTAGE=y
+CONFIG_BOOTSTAGE_REPORT=y
+CONFIG_BOOTSTAGE_USER_COUNT=32
+CONFIG_BOOTSTAGE_FDT=y
+CONFIG_BOOTSTAGE_STASH=y
+CONFIG_BOOTSTAGE_STASH_ADDR=0x0
+CONFIG_BOOTSTAGE_STASH_SIZE=0x4096
+CONFIG_CONSOLE_RECORD=y
+CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000
+CONFIG_SILENT_CONSOLE=y
+CONFIG_PRE_CONSOLE_BUFFER=y
+CONFIG_PRE_CON_BUF_ADDR=0
+CONFIG_CMD_CPU=y
+CONFIG_CMD_LICENSE=y
+CONFIG_CMD_BOOTZ=y
+# CONFIG_CMD_ELF is not set
+# CONFIG_CMD_IMLS is not set
+CONFIG_CMD_ASKENV=y
+CONFIG_CMD_GREPENV=y
+CONFIG_CMD_ENV_CALLBACK=y
+CONFIG_CMD_ENV_FLAGS=y
+CONFIG_LOOPW=y
+CONFIG_CMD_MD5SUM=y
+CONFIG_CMD_MEMINFO=y
+CONFIG_CMD_MEMTEST=y
+CONFIG_CMD_MX_CYCLIC=y
+CONFIG_CMD_DEMO=y
+CONFIG_CMD_GPIO=y
+CONFIG_CMD_GPT=y
+CONFIG_CMD_GPT_RENAME=y
+CONFIG_CMD_IDE=y
+CONFIG_CMD_I2C=y
+CONFIG_CMD_PCI=y
+CONFIG_CMD_READ=y
+CONFIG_CMD_REMOTEPROC=y
+CONFIG_CMD_SF=y
+CONFIG_CMD_SPI=y
+CONFIG_CMD_USB=y
+CONFIG_CMD_TFTPPUT=y
+CONFIG_CMD_TFTPSRV=y
+CONFIG_CMD_RARP=y
+CONFIG_CMD_CDP=y
+CONFIG_CMD_SNTP=y
+CONFIG_CMD_DNS=y
+CONFIG_CMD_LINK_LOCAL=y
+CONFIG_CMD_ETHSW=y
+CONFIG_CMD_BMP=y
+CONFIG_CMD_TIME=y
+CONFIG_CMD_TIMER=y
+CONFIG_CMD_SOUND=y
+CONFIG_CMD_QFW=y
+CONFIG_CMD_BOOTSTAGE=y
+CONFIG_CMD_PMIC=y
+CONFIG_CMD_REGULATOR=y
+CONFIG_CMD_TPM=y
+CONFIG_CMD_TPM_TEST=y
+CONFIG_CMD_CBFS=y
+CONFIG_CMD_CRAMFS=y
+CONFIG_CMD_EXT4_WRITE=y
+CONFIG_CMD_MTDPARTS=y
+CONFIG_MAC_PARTITION=y
+CONFIG_AMIGA_PARTITION=y
+CONFIG_OF_CONTROL=y
+CONFIG_OF_LIVE=y
+CONFIG_OF_HOSTFILE=y
+CONFIG_NETCONSOLE=y
+CONFIG_REGMAP=y
+CONFIG_SYSCON=y
+CONFIG_DEVRES=y
+CONFIG_DEBUG_DEVRES=y
+CONFIG_ADC=y
+CONFIG_ADC_SANDBOX=y
+CONFIG_CLK=y
+CONFIG_CPU=y
+CONFIG_DM_DEMO=y
+CONFIG_DM_DEMO_SIMPLE=y
+CONFIG_DM_DEMO_SHAPE=y
+CONFIG_PM8916_GPIO=y
+CONFIG_SANDBOX_GPIO=y
+CONFIG_DM_I2C_COMPAT=y
+CONFIG_I2C_CROS_EC_TUNNEL=y
+CONFIG_I2C_CROS_EC_LDO=y
+CONFIG_DM_I2C_GPIO=y
+CONFIG_SYS_I2C_SANDBOX=y
+CONFIG_I2C_MUX=y
+CONFIG_SPL_I2C_MUX=y
+CONFIG_I2C_ARB_GPIO_CHALLENGE=y
+CONFIG_CROS_EC_KEYB=y
+CONFIG_I8042_KEYB=y
+CONFIG_LED=y
+CONFIG_LED_BLINK=y
+CONFIG_LED_GPIO=y
+CONFIG_DM_MAILBOX=y
+CONFIG_SANDBOX_MBOX=y
+CONFIG_MISC=y
+CONFIG_CROS_EC=y
+CONFIG_CROS_EC_I2C=y
+CONFIG_CROS_EC_LPC=y
+CONFIG_CROS_EC_SANDBOX=y
+CONFIG_CROS_EC_SPI=y
+CONFIG_PWRSEQ=y
+CONFIG_SPL_PWRSEQ=y
+CONFIG_I2C_EEPROM=y
+CONFIG_MMC_SANDBOX=y
+CONFIG_SPI_FLASH_SANDBOX=y
+CONFIG_SPI_FLASH=y
+CONFIG_SPI_FLASH_ATMEL=y
+CONFIG_SPI_FLASH_EON=y
+CONFIG_SPI_FLASH_GIGADEVICE=y
+CONFIG_SPI_FLASH_MACRONIX=y
+CONFIG_SPI_FLASH_SPANSION=y
+CONFIG_SPI_FLASH_STMICRO=y
+CONFIG_SPI_FLASH_SST=y
+CONFIG_SPI_FLASH_WINBOND=y
+CONFIG_DM_ETH=y
+CONFIG_NVME=y
+CONFIG_PCI=y
+CONFIG_DM_PCI=y
+CONFIG_DM_PCI_COMPAT=y
+CONFIG_PCI_SANDBOX=y
+CONFIG_PHY=y
+CONFIG_PHY_SANDBOX=y
+CONFIG_PINCTRL=y
+CONFIG_PINCONF=y
+CONFIG_PINCTRL_ROCKCHIP_RK3036=y
+CONFIG_PINCTRL_ROCKCHIP_RK3288=y
+CONFIG_PINCTRL_SANDBOX=y
+CONFIG_POWER_DOMAIN=y
+CONFIG_SANDBOX_POWER_DOMAIN=y
+CONFIG_DM_PMIC=y
+CONFIG_PMIC_ACT8846=y
+CONFIG_DM_PMIC_PFUZE100=y
+CONFIG_DM_PMIC_MAX77686=y
+CONFIG_PMIC_PM8916=y
+CONFIG_PMIC_RK8XX=y
+CONFIG_PMIC_S2MPS11=y
+CONFIG_DM_PMIC_SANDBOX=y
+CONFIG_PMIC_S5M8767=y
+CONFIG_PMIC_TPS65090=y
+CONFIG_DM_REGULATOR=y
+CONFIG_REGULATOR_ACT8846=y
+CONFIG_DM_REGULATOR_PFUZE100=y
+CONFIG_DM_REGULATOR_MAX77686=y
+CONFIG_DM_REGULATOR_FIXED=y
+CONFIG_REGULATOR_RK8XX=y
+CONFIG_REGULATOR_S5M8767=y
+CONFIG_DM_REGULATOR_SANDBOX=y
+CONFIG_REGULATOR_TPS65090=y
+CONFIG_DM_PWM=y
+CONFIG_PWM_SANDBOX=y
+CONFIG_RAM=y
+CONFIG_REMOTEPROC_SANDBOX=y
+CONFIG_DM_RESET=y
+CONFIG_SANDBOX_RESET=y
+CONFIG_DM_RTC=y
+CONFIG_SANDBOX_SERIAL=y
+CONFIG_SOUND=y
+CONFIG_SOUND_SANDBOX=y
+CONFIG_SANDBOX_SPI=y
+CONFIG_SPMI=y
+CONFIG_SPMI_SANDBOX=y
+CONFIG_SYSRESET=y
+CONFIG_TIMER=y
+CONFIG_TIMER_EARLY=y
+CONFIG_SANDBOX_TIMER=y
+CONFIG_TPM_TIS_SANDBOX=y
+CONFIG_USB=y
+CONFIG_DM_USB=y
+CONFIG_USB_EMUL=y
+CONFIG_USB_STORAGE=y
+CONFIG_USB_KEYBOARD=y
+CONFIG_SYS_USB_EVENT_POLL=y
+CONFIG_DM_VIDEO=y
+CONFIG_CONSOLE_ROTATION=y
+CONFIG_CONSOLE_TRUETYPE=y
+CONFIG_CONSOLE

[U-Boot] [PATCH 2/3] add pytest for 'gpt guid' command in sandbox

2017-09-02 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

Run unit tests for the 'gpt guid' command, making use of the disk.raw
block device created by test/gpt/make-test-disk.sh script.  Remove
this device at the end of the tests.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 test/py/tests/test_gpt.py | 39 +++
 1 file changed, 39 insertions(+)
 create mode 100644 test/py/tests/test_gpt.py

diff --git a/test/py/tests/test_gpt.py b/test/py/tests/test_gpt.py
new file mode 100644
index 000..2201f39
--- /dev/null
+++ b/test/py/tests/test_gpt.py
@@ -0,0 +1,39 @@
+# Copyright (c) 2017 Alison Chaiken
+#
+# SPDX-License-Identifier: GPL-2.0
+
+# Test GPT manipulation commands.
+# Before executing the test, please run the test/gpt/make-test-disk.sh script.
+
+import os
+import pytest
+import u_boot_utils
+
+"""
+These tests rely on a 256KB block device called disk.raw.  Run
+test/gpt/make-test-disk.sh
+in order to create this device, which is automatically removed at the end of 
the
+tests.
+"""
+
+@pytest.mark.buildconfigspec('cmd_gpt')
+def test_gpt_guid(u_boot_console):
+"""Test the gpt guid command."""
+
+if u_boot_console.config.buildconfig.get('config_cmd_gpt', 'n') != 'y':
+pytest.skip('gpt command not supported')
+u_boot_console.run_command('host bind 0 disk.raw')
+output = u_boot_console.run_command('gpt guid host 0')
+assert '375a56f7-d6c9-4e81-b5f0-09d41ca89efe' in output
+
+@pytest.mark.buildconfigspec('cmd_gpt')
+def test_gpt_save_guid(u_boot_console):
+"""Test the gpt guid command to save GUID into a string."""
+
+if u_boot_console.config.buildconfig.get('config_cmd_gpt', 'n') != 'y':
+pytest.skip('gpt command not supported')
+u_boot_console.run_command('host bind 0 disk.raw')
+output = u_boot_console.run_command('gpt guid host 0 newguid')
+output = u_boot_console.run_command('printenv newguid')
+assert '375a56f7-d6c9-4e81-b5f0-09d41ca89efe' in output
+os.remove('disk.raw')
-- 
2.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 1/3] GPT: create block device for sandbox testing

2017-09-02 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

Provide a shell script that creates a small block device for the
purpose of testing the cmd/gpt.c functions in the u-boot sandbox.
Running the tests removes the device file.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 test/gpt/make-test-disk.sh | 8 
 1 file changed, 8 insertions(+)
 create mode 100755 test/gpt/make-test-disk.sh

diff --git a/test/gpt/make-test-disk.sh b/test/gpt/make-test-disk.sh
new file mode 100755
index 000..022acba
--- /dev/null
+++ b/test/gpt/make-test-disk.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+/usr/bin/truncate -s 265K disk.raw
+echo -e "label: gpt\n,64K,U\n,,L" | /sbin/sgdisk ./disk.raw
+/sbin/sgdisk --new=1:34:161 ./disk.raw
+/sbin/sgdisk --new=2:162:496 ./disk.raw
+/sbin/sgdisk -U 375a56f7-d6c9-4e81-b5f0-09d41ca89efe ./disk.raw
+/sbin/gdisk -l ./disk.raw
-- 
2.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v2 5/6] rename GPT partitions to detect boot failure

2017-08-27 Thread Chaiken, Alison

On 2017-05-31 01:12, Lukasz Majewski wrote:

[ . . . ]


And another request -> Could you consider adding tests for those new
gpt commands to the 'sandbox' (sandbox_defconfig) ?

Then you can 'mount' some gpt test image ('host' command) and use it
with:
gpt  host X .


The GPT functionality really cannot be tested without a block device.   
We could build the disk.raw described in board/sandbox/README.sandbox 
when (CONFIG_UNIT_TEST && CONFIG_CMD_GPT_RENAME) in imitation of the 
file helloworld.efi.   There would be no reason for the size to be as 
large as 1200M, of course.   256KB appears to be the smallest usable 
size for 4 partitions (although trying to partition a 16 KB raw object 
with gdisk produces entertaining results).


To create this object for testing, we could use a subdirectory like 
lib/efi_loader, but maybe doing so in test/ makes more sense?  If the 
build system did create the object, then we could modify 
board/sandbox/README.sandbox to so indicate.   Then the test should go 
in test/py/tests presumably.


Thanks for feedback,
Alison

---
Alison Chaiken  ali...@she-devel.com
http://{ she-devel.com, exerciseforthereader.org }
"We are giving up our privacy, one convenience at a time." -- Evangelos 
Simoudis

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v2] armv8: errata: Implement workaround for Cortex-A53 Erratum 855873

2017-07-24 Thread Alison Wang
> On 21/07/17 09:00, Alison Wang wrote:
> 
> Hi,
> 
> > 855873: An eviction might overtake a cache clean operation
> > Workaround: The erratum can be avoided by upgrading cache clean by
> > address operations to cache clean and invalidate operations. For
> > Cortex-A53 r0p3 and later release, this can be achieved by setting
> > CPUACTLR.ENDCCASCI to 1.
> >
> > This patch is to implement the workaround for this erratum.
> >
> > Signed-off-by: Alison Wang <alison.w...@nxp.com>
> > ---
> > Changes in v2:
> > - Check the revision of Cortex-A53 and apply the erratum to r0p3 and
> later release.
> > - Fix the mistake in the commit description.
> 
> Thanks for those fixes, this looks much better now.
> One thing below 
> 
> >  arch/arm/Kconfig  |  3 +++
> >  arch/arm/cpu/armv8/fsl-layerscape/Kconfig |  2 ++
> >  arch/arm/cpu/armv8/start.S| 20 +++-
> >  3 files changed, 24 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index
> > d43aaac..4a885a3 100644
> > --- a/arch/arm/Kconfig
> > +++ b/arch/arm/Kconfig
> > @@ -103,6 +103,9 @@ config ARM_ERRATA_852421  config
> ARM_ERRATA_852423
> > bool
> >
> > +config ARM_ERRATA_855873
> > +   bool
> > +
> >  config CPU_ARM720T
> > bool
> > select SYS_CACHE_SHIFT_5
> > diff --git a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
> > b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
> > index 5825f9b..63658b5 100644
> > --- a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
> > +++ b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
> > @@ -1,6 +1,7 @@
> >  config ARCH_LS1012A
> > bool
> > select ARMV8_SET_SMPEN
> > +   select ARM_ERRATA_855873
> > select FSL_LSCH2
> > select SYS_FSL_DDR_BE
> > select SYS_FSL_MMDC
> > @@ -11,6 +12,7 @@ config ARCH_LS1012A
> >  config ARCH_LS1043A
> > bool
> > select ARMV8_SET_SMPEN
> > +   select ARM_ERRATA_855873
> > select FSL_LSCH2
> > select SYS_FSL_DDR
> > select SYS_FSL_DDR_BE
> > diff --git a/arch/arm/cpu/armv8/start.S b/arch/arm/cpu/armv8/start.S
> > index 5c500be..6ca054b 100644
> > --- a/arch/arm/cpu/armv8/start.S
> > +++ b/arch/arm/cpu/armv8/start.S
> > @@ -170,7 +170,10 @@ reset_sctrl:
> >  WEAK(apply_core_errata)
> >
> > mov x29, lr /* Save LR */
> > -   /* For now, we support Cortex-A57 specific errata only */
> > +   /* For now, we support Cortex-A53, Cortex-A57 specific errata */
> > +
> > +   /* Check if we are running on a Cortex-A53 core */
> > +   branch_if_a53_core x0, apply_a53_core_errata
> >
> > /* Check if we are running on a Cortex-A57 core */
> > branch_if_a57_core x0, apply_a57_core_errata @@ -178,6 +181,21 @@
> > WEAK(apply_core_errata)
> > mov lr, x29 /* Restore LR */
> > ret
> >
> > +apply_a53_core_errata:
> > +
> > +#ifdef CONFIG_ARM_ERRATA_855873
> > +   mrs x0, midr_el1
> > +   and x0, x0, #0xf
> > +   cmp x0, #3
> 
> This only checks for the revision field being 3 (which is correct), but
> the condition is really >= r0p3, so you have to check bits 23:20
> ("variant") as well, by concatenating the two fields to end up
> comparing against 0x03. It's a few more instructions only.
> 
> The rest of the patch is fine.
> 
> Thanks,
> Andre.
> 
[Alison Wang] I have checked Revision >=3. Do you mean to check variant 
bit[23:20] >= 0 too?

Best Regards,
Alison Wang

> > +   b.lt0b
> > +
> > +   mrs x0, S3_1_c15_c2_0   /* cpuactlr_el1 */
> > +   /* Enable data cache clean as data cache clean/invalidate */
> > +   orr x0, x0, #1 << 44
> > +   msr S3_1_c15_c2_0, x0   /* cpuactlr_el1 */
> > +#endif
> > +   b 0b
> > +
> >  apply_a57_core_errata:
> >
> >  #ifdef CONFIG_ARM_ERRATA_828024
> >

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2] armv8: errata: Implement workaround for Cortex-A53 Erratum 855873

2017-07-21 Thread Alison Wang
855873: An eviction might overtake a cache clean operation
Workaround: The erratum can be avoided by upgrading cache clean by
address operations to cache clean and invalidate operations. For
Cortex-A53 r0p3 and later release, this can be achieved by setting
CPUACTLR.ENDCCASCI to 1.

This patch is to implement the workaround for this erratum.

Signed-off-by: Alison Wang <alison.w...@nxp.com>
---
Changes in v2:
- Check the revision of Cortex-A53 and apply the erratum to r0p3 and later 
release.
- Fix the mistake in the commit description.

 arch/arm/Kconfig  |  3 +++
 arch/arm/cpu/armv8/fsl-layerscape/Kconfig |  2 ++
 arch/arm/cpu/armv8/start.S| 20 +++-
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index d43aaac..4a885a3 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -103,6 +103,9 @@ config ARM_ERRATA_852421
 config ARM_ERRATA_852423
bool
 
+config ARM_ERRATA_855873
+   bool
+
 config CPU_ARM720T
bool
select SYS_CACHE_SHIFT_5
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig 
b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
index 5825f9b..63658b5 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
+++ b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
@@ -1,6 +1,7 @@
 config ARCH_LS1012A
bool
select ARMV8_SET_SMPEN
+   select ARM_ERRATA_855873
select FSL_LSCH2
select SYS_FSL_DDR_BE
select SYS_FSL_MMDC
@@ -11,6 +12,7 @@ config ARCH_LS1012A
 config ARCH_LS1043A
bool
select ARMV8_SET_SMPEN
+   select ARM_ERRATA_855873
select FSL_LSCH2
select SYS_FSL_DDR
select SYS_FSL_DDR_BE
diff --git a/arch/arm/cpu/armv8/start.S b/arch/arm/cpu/armv8/start.S
index 5c500be..6ca054b 100644
--- a/arch/arm/cpu/armv8/start.S
+++ b/arch/arm/cpu/armv8/start.S
@@ -170,7 +170,10 @@ reset_sctrl:
 WEAK(apply_core_errata)
 
mov x29, lr /* Save LR */
-   /* For now, we support Cortex-A57 specific errata only */
+   /* For now, we support Cortex-A53, Cortex-A57 specific errata */
+
+   /* Check if we are running on a Cortex-A53 core */
+   branch_if_a53_core x0, apply_a53_core_errata
 
/* Check if we are running on a Cortex-A57 core */
branch_if_a57_core x0, apply_a57_core_errata
@@ -178,6 +181,21 @@ WEAK(apply_core_errata)
mov lr, x29 /* Restore LR */
ret
 
+apply_a53_core_errata:
+
+#ifdef CONFIG_ARM_ERRATA_855873
+   mrs x0, midr_el1
+   and x0, x0, #0xf
+   cmp x0, #3
+   b.lt0b
+
+   mrs x0, S3_1_c15_c2_0   /* cpuactlr_el1 */
+   /* Enable data cache clean as data cache clean/invalidate */
+   orr x0, x0, #1 << 44
+   msr S3_1_c15_c2_0, x0   /* cpuactlr_el1 */
+#endif
+   b 0b
+
 apply_a57_core_errata:
 
 #ifdef CONFIG_ARM_ERRATA_828024
-- 
2.1.0.27.g96db324

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH] armv8: errata: Implement workaround for Cortex-A53 Erratum 855873

2017-07-20 Thread Alison Wang
Hi, Andre,

> On 20/07/17 03:09, Alison Wang wrote:
> > 855873: An eviction might overtake a cache clean operation
> > Workaround: The erratum can be avoided by upgrading cache clean by
> > address operations to cache clean and invalidate operations. For
> > Cortex-A53 r0p3 and later release,
> 
> As you mention, this workaround is only viable for r0p3 and above, as
> the chicken bit does not exist in prior versions of the core.
> So I would feel better if we could have an MIDR check just before
> reading CPUACTLR_EL1. This would allow other A53 users to reuse the
> errata fixes more easily.
[Alison Wang] You are right. Revision should be checked through MIDR before 
applying the workaround.
I will add it.
> 
> > this can be achieved by setting CPUACTLR.ENDCASCI to 1.
> 
> I think the name of the bit is ENDCCASCI (with two C's).
[Alison Wang] Yes. It's a slip of the pen. I will correct it.

Thanks for your advices.

Best Regards,
Alison Wang
> 
> Cheers,
> Andre.
> 
> > This patch is to implement the workaround for this erratum.
> >
> > Signed-off-by: Alison Wang <alison.w...@nxp.com>
> > ---
> >  arch/arm/Kconfig  |  3 +++
> >  arch/arm/cpu/armv8/fsl-layerscape/Kconfig |  2 ++
> >  arch/arm/cpu/armv8/start.S| 15 ++-
> >  3 files changed, 19 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index
> > d43aaac..4a885a3 100644
> > --- a/arch/arm/Kconfig
> > +++ b/arch/arm/Kconfig
> > @@ -103,6 +103,9 @@ config ARM_ERRATA_852421  config
> ARM_ERRATA_852423
> > bool
> >
> > +config ARM_ERRATA_855873
> > +   bool
> > +
> >  config CPU_ARM720T
> > bool
> > select SYS_CACHE_SHIFT_5
> > diff --git a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
> > b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
> > index 5825f9b..63658b5 100644
> > --- a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
> > +++ b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
> > @@ -1,6 +1,7 @@
> >  config ARCH_LS1012A
> > bool
> > select ARMV8_SET_SMPEN
> > +   select ARM_ERRATA_855873
> > select FSL_LSCH2
> > select SYS_FSL_DDR_BE
> > select SYS_FSL_MMDC
> > @@ -11,6 +12,7 @@ config ARCH_LS1012A
> >  config ARCH_LS1043A
> > bool
> > select ARMV8_SET_SMPEN
> > +   select ARM_ERRATA_855873
> > select FSL_LSCH2
> > select SYS_FSL_DDR
> > select SYS_FSL_DDR_BE
> > diff --git a/arch/arm/cpu/armv8/start.S b/arch/arm/cpu/armv8/start.S
> > index 5c500be..3484fd8 100644
> > --- a/arch/arm/cpu/armv8/start.S
> > +++ b/arch/arm/cpu/armv8/start.S
> > @@ -170,7 +170,10 @@ reset_sctrl:
> >  WEAK(apply_core_errata)
> >
> > mov x29, lr /* Save LR */
> > -   /* For now, we support Cortex-A57 specific errata only */
> > +   /* For now, we support Cortex-A53, Cortex-A57 specific errata */
> > +
> > +   /* Check if we are running on a Cortex-A53 core */
> > +   branch_if_a53_core x0, apply_a53_core_errata
> >
> > /* Check if we are running on a Cortex-A57 core */
> > branch_if_a57_core x0, apply_a57_core_errata @@ -178,6 +181,16 @@
> > WEAK(apply_core_errata)
> > mov lr, x29 /* Restore LR */
> > ret
> >
> > +apply_a53_core_errata:
> > +
> > +#ifdef CONFIG_ARM_ERRATA_855873
> > +   mrs x0, S3_1_c15_c2_0   /* cpuactlr_el1 */
> > +   /* Enable data cache clean as data cache clean/invalidate */
> > +   orr x0, x0, #1 << 44
> > +   msr S3_1_c15_c2_0, x0   /* cpuactlr_el1 */
> > +#endif
> > +   b 0b
> > +
> >  apply_a57_core_errata:
> >
> >  #ifdef CONFIG_ARM_ERRATA_828024
> >
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] armv8: errata: Implement workaround for Cortex-A53 Erratum 855873

2017-07-19 Thread Alison Wang
855873: An eviction might overtake a cache clean operation
Workaround: The erratum can be avoided by upgrading cache clean by
address operations to cache clean and invalidate operations. For
Cortex-A53 r0p3 and later release, this can be achieved by setting
CPUACTLR.ENDCASCI to 1.

This patch is to implement the workaround for this erratum.

Signed-off-by: Alison Wang <alison.w...@nxp.com>
---
 arch/arm/Kconfig  |  3 +++
 arch/arm/cpu/armv8/fsl-layerscape/Kconfig |  2 ++
 arch/arm/cpu/armv8/start.S| 15 ++-
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index d43aaac..4a885a3 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -103,6 +103,9 @@ config ARM_ERRATA_852421
 config ARM_ERRATA_852423
bool
 
+config ARM_ERRATA_855873
+   bool
+
 config CPU_ARM720T
bool
select SYS_CACHE_SHIFT_5
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig 
b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
index 5825f9b..63658b5 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
+++ b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
@@ -1,6 +1,7 @@
 config ARCH_LS1012A
bool
select ARMV8_SET_SMPEN
+   select ARM_ERRATA_855873
select FSL_LSCH2
select SYS_FSL_DDR_BE
select SYS_FSL_MMDC
@@ -11,6 +12,7 @@ config ARCH_LS1012A
 config ARCH_LS1043A
bool
select ARMV8_SET_SMPEN
+   select ARM_ERRATA_855873
select FSL_LSCH2
select SYS_FSL_DDR
select SYS_FSL_DDR_BE
diff --git a/arch/arm/cpu/armv8/start.S b/arch/arm/cpu/armv8/start.S
index 5c500be..3484fd8 100644
--- a/arch/arm/cpu/armv8/start.S
+++ b/arch/arm/cpu/armv8/start.S
@@ -170,7 +170,10 @@ reset_sctrl:
 WEAK(apply_core_errata)
 
mov x29, lr /* Save LR */
-   /* For now, we support Cortex-A57 specific errata only */
+   /* For now, we support Cortex-A53, Cortex-A57 specific errata */
+
+   /* Check if we are running on a Cortex-A53 core */
+   branch_if_a53_core x0, apply_a53_core_errata
 
/* Check if we are running on a Cortex-A57 core */
branch_if_a57_core x0, apply_a57_core_errata
@@ -178,6 +181,16 @@ WEAK(apply_core_errata)
mov lr, x29 /* Restore LR */
ret
 
+apply_a53_core_errata:
+
+#ifdef CONFIG_ARM_ERRATA_855873
+   mrs x0, S3_1_c15_c2_0   /* cpuactlr_el1 */
+   /* Enable data cache clean as data cache clean/invalidate */
+   orr x0, x0, #1 << 44
+   msr S3_1_c15_c2_0, x0   /* cpuactlr_el1 */
+#endif
+   b 0b
+
 apply_a57_core_errata:
 
 #ifdef CONFIG_ARM_ERRATA_828024
-- 
2.1.0.27.g96db324

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] Targets with xHCI but without DM_USB

2017-07-07 Thread Alison Wang
Hi, Bin,

I have sent a patch to enable driver model for USB for LS1021A boards.

Thanks for reminding.

Best Regards,
Alison Wang

> -Original Message-
> From: Bin Meng [mailto:bmeng...@gmail.com]
> Sent: Tuesday, July 04, 2017 10:16 PM
> To: Vignesh R <vigne...@ti.com>; Alison Wang <alison.w...@nxp.com>;
> York Sun <york@nxp.com>
> Cc: Stefan Roese <s...@denx.de>; U-Boot list <u-boot@lists.denx.de>;
> Marek Vasut <ma...@denx.de>; Prabhakar Kushwaha
> <prabhakar.kushw...@nxp.com>; Sumit Garg <sumit.g...@nxp.com>; Vutla,
> Lokesh <lokeshvu...@ti.com>; Alison Wang <alison.w...@freescale.com>;
> Nikita Kiryanov <nik...@compulab.co.il>; Davis, Andrew <a...@ti.com>;
> Andrianov, Vitaly <vita...@ti.com>; Uri Mashiach
> <uri.mashi...@compulab.co.il>
> Subject: Re: [U-Boot] Targets with xHCI but without DM_USB
> 
> +Alison and York for LS1021A_xxx boards..
> 
> On Tue, Jul 4, 2017 at 12:36 PM, Vignesh R <vigne...@ti.com> wrote:
> > Hi Bin,
> >
> > On Monday 03 July 2017 06:49 PM, Bin Meng wrote:
> >> Hi Vignesh,
> >>
> >> On Thu, Jun 29, 2017 at 2:41 PM, Vignesh R <vigne...@ti.com> wrote:
> >>> Hi Stefan,
> >>>
> >>> On Thursday 29 June 2017 11:15 AM, Stefan Roese wrote:
> >>>> Hi,
> >>>>
> >>>> as you might have noticed, Bin Meng is currently greatly improving
> >>>> the U-Boot xHCI support. While doing this, he noticed that some
> >>>> additions are more complex and especially ugly to add, since some
> >>>> users of the xHCI support have not enabled CONFIG_DM_USB. This
> adds
> >>>> ugly #ifdef's, which we really would like to avoid. Because of
> this
> >>>> we checked, which boards exactly are using xHCI without DM_USB
> >>>> enabled. Here a complete list of all the boards:
> >>>>
> >>>> ls1012ardb_qspi_SECURE_BOOT
> >>>> ls1021atwr_nor_SECURE_BOOT
> >>>> am43xx_hs_evm
> >>>> am57xx_hs_evm
> >>>> ls1021aqds_nand
> >>>> ls1021atwr_nor
> >>>> ls1021atwr_qspi
> >>>> cm_t43
> >>>> ls1021atwr_nor_lpuart
> >>>> ls1021aqds_sdcard_qspi
> >>>> k2hk_hs_evm
> >>>> am43xx_evm
> >>>> ls1021aqds_qspi
> >>>> am57xx_evm_nodt
> >>>> k2g_hs_evm
> >>>> ls1021atwr_sdcard_qspi
> >>>> am43xx_evm_ethboot
> >>>> ls1021aqds_sdcard_ifc
> >>>> k2l_evm
> >>>> am43xx_evm_usbhost_boot
> >>>> am43xx_evm_qspiboot
> >>>> k2g_evm
> >>>> am57xx_evm
> >>>> ls1021atwr_sdcard_ifc
> >>>> cl-som-am57x
> >>>> k2hk_evm
> >>>> k2e_evm
> >>>> ls1021atwr_sdcard_ifc_SECURE_BOOT
> >>>> ls1021aqds_nor_SECURE_BOOT
> >>>> k2e_hs_evm
> >>>
> >>> For TI platforms, there is some work needed to convert xhci-dwc3,
> >>> xhci-omap and xhci-keystone to DM (under drivers/usb/host)
> >>>
> >>> But the bigger concern of enabling DM_USB is with gadget framework,
> >>> which is not DM compliant yet. There is a significant amount
> >>> work[1][2] there before dwc3 gadget can be moved to DM and we can
> enable DM_USB.
> >>>
> >>> [1]https://lists.denx.de/pipermail/u-boot/2017-June/296081.html
> >>> [2]https://lists.denx.de/pipermail/u-boot/2017-June/295370.html
> >>
> >> I thought gadget and host support are separate, so host support like
> >> xHCI can be moved to DM without affecting gadget support, no? Are
> >> they sharing some codes?
> >>
> >
> > Right now, the assumption is if DM_USB is enabled, then both host and
> > gadget frameworks use DM along with DT. If, DM_USB is enabled, then
> > board specific registration of gadget drivers don't happen. Also, I
> > see couple of gadget drivers like ether.c. ci_udc.c (and everything
> > under
> > musb_new) seem use DM_USB already, making it hard for DM based host
> > and non DM gadget to exist.
> >
> > Some work would be needed to remove dependency b/w DM_USB and gadget
> > support.
> >
> 
> Thanks for the clarification!
> 
> Regards,
> Bin
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] dm: arm: ls1021a: Move to driver model for USB

2017-07-07 Thread Alison Wang
This patch enables driver model for USB in defconfigs for LS1021A platforms.

Signed-off-by: Alison Wang <alison.w...@nxp.com>
---
 configs/ls1021aqds_nand_defconfig   | 1 +
 configs/ls1021aqds_nor_SECURE_BOOT_defconfig| 1 +
 configs/ls1021aqds_qspi_defconfig   | 1 +
 configs/ls1021aqds_sdcard_ifc_defconfig | 1 +
 configs/ls1021aqds_sdcard_qspi_defconfig| 1 +
 configs/ls1021atwr_nor_SECURE_BOOT_defconfig| 1 +
 configs/ls1021atwr_nor_defconfig| 1 +
 configs/ls1021atwr_nor_lpuart_defconfig | 1 +
 configs/ls1021atwr_qspi_defconfig   | 1 +
 configs/ls1021atwr_sdcard_ifc_SECURE_BOOT_defconfig | 1 +
 configs/ls1021atwr_sdcard_ifc_defconfig | 1 +
 configs/ls1021atwr_sdcard_qspi_defconfig| 1 +
 12 files changed, 12 insertions(+)

diff --git a/configs/ls1021aqds_nand_defconfig 
b/configs/ls1021aqds_nand_defconfig
index e1ddd29..eff3590 100644
--- a/configs/ls1021aqds_nand_defconfig
+++ b/configs/ls1021aqds_nand_defconfig
@@ -54,6 +54,7 @@ CONFIG_DM_PCI_COMPAT=y
 CONFIG_PCIE_LAYERSCAPE=y
 CONFIG_SYS_NS16550=y
 CONFIG_USB=y
+CONFIG_DM_USB=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_XHCI_DWC3=y
 CONFIG_USB_STORAGE=y
diff --git a/configs/ls1021aqds_nor_SECURE_BOOT_defconfig 
b/configs/ls1021aqds_nor_SECURE_BOOT_defconfig
index 6b5477f..64f8e26 100644
--- a/configs/ls1021aqds_nor_SECURE_BOOT_defconfig
+++ b/configs/ls1021aqds_nor_SECURE_BOOT_defconfig
@@ -40,6 +40,7 @@ CONFIG_DM_PCI_COMPAT=y
 CONFIG_PCIE_LAYERSCAPE=y
 CONFIG_SYS_NS16550=y
 CONFIG_USB=y
+CONFIG_DM_USB=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_XHCI_DWC3=y
 CONFIG_USB_STORAGE=y
diff --git a/configs/ls1021aqds_qspi_defconfig 
b/configs/ls1021aqds_qspi_defconfig
index 7993a69..0f241a8 100644
--- a/configs/ls1021aqds_qspi_defconfig
+++ b/configs/ls1021aqds_qspi_defconfig
@@ -47,6 +47,7 @@ CONFIG_DM_SPI=y
 CONFIG_FSL_DSPI=y
 CONFIG_FSL_QSPI=y
 CONFIG_USB=y
+CONFIG_DM_USB=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_XHCI_DWC3=y
 CONFIG_USB_STORAGE=y
diff --git a/configs/ls1021aqds_sdcard_ifc_defconfig 
b/configs/ls1021aqds_sdcard_ifc_defconfig
index b349fea..ab4af77 100644
--- a/configs/ls1021aqds_sdcard_ifc_defconfig
+++ b/configs/ls1021aqds_sdcard_ifc_defconfig
@@ -52,6 +52,7 @@ CONFIG_DM_PCI_COMPAT=y
 CONFIG_PCIE_LAYERSCAPE=y
 CONFIG_SYS_NS16550=y
 CONFIG_USB=y
+CONFIG_DM_USB=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_XHCI_DWC3=y
 CONFIG_USB_STORAGE=y
diff --git a/configs/ls1021aqds_sdcard_qspi_defconfig 
b/configs/ls1021aqds_sdcard_qspi_defconfig
index ea8738f..9e2cf16 100644
--- a/configs/ls1021aqds_sdcard_qspi_defconfig
+++ b/configs/ls1021aqds_sdcard_qspi_defconfig
@@ -58,6 +58,7 @@ CONFIG_DM_SPI=y
 CONFIG_FSL_DSPI=y
 CONFIG_FSL_QSPI=y
 CONFIG_USB=y
+CONFIG_DM_USB=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_XHCI_DWC3=y
 CONFIG_USB_STORAGE=y
diff --git a/configs/ls1021atwr_nor_SECURE_BOOT_defconfig 
b/configs/ls1021atwr_nor_SECURE_BOOT_defconfig
index cf99770..664e4ca 100644
--- a/configs/ls1021atwr_nor_SECURE_BOOT_defconfig
+++ b/configs/ls1021atwr_nor_SECURE_BOOT_defconfig
@@ -39,6 +39,7 @@ CONFIG_DM_PCI_COMPAT=y
 CONFIG_PCIE_LAYERSCAPE=y
 CONFIG_SYS_NS16550=y
 CONFIG_USB=y
+CONFIG_DM_USB=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_XHCI_DWC3=y
 CONFIG_USB_STORAGE=y
diff --git a/configs/ls1021atwr_nor_defconfig b/configs/ls1021atwr_nor_defconfig
index c56533a..1d82763 100644
--- a/configs/ls1021atwr_nor_defconfig
+++ b/configs/ls1021atwr_nor_defconfig
@@ -39,6 +39,7 @@ CONFIG_PCIE_LAYERSCAPE=y
 CONFIG_DM_SERIAL=y
 CONFIG_SYS_NS16550=y
 CONFIG_USB=y
+CONFIG_DM_USB=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_XHCI_DWC3=y
 CONFIG_USB_STORAGE=y
diff --git a/configs/ls1021atwr_nor_lpuart_defconfig 
b/configs/ls1021atwr_nor_lpuart_defconfig
index 89b89cd..18cd3e8 100644
--- a/configs/ls1021atwr_nor_lpuart_defconfig
+++ b/configs/ls1021atwr_nor_lpuart_defconfig
@@ -40,6 +40,7 @@ CONFIG_PCIE_LAYERSCAPE=y
 CONFIG_DM_SERIAL=y
 CONFIG_FSL_LPUART=y
 CONFIG_USB=y
+CONFIG_DM_USB=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_XHCI_DWC3=y
 CONFIG_USB_STORAGE=y
diff --git a/configs/ls1021atwr_qspi_defconfig 
b/configs/ls1021atwr_qspi_defconfig
index 07a4143..4ff5554 100644
--- a/configs/ls1021atwr_qspi_defconfig
+++ b/configs/ls1021atwr_qspi_defconfig
@@ -47,6 +47,7 @@ CONFIG_DM_SPI=y
 CONFIG_FSL_DSPI=y
 CONFIG_FSL_QSPI=y
 CONFIG_USB=y
+CONFIG_DM_USB=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_XHCI_DWC3=y
 CONFIG_USB_STORAGE=y
diff --git a/configs/ls1021atwr_sdcard_ifc_SECURE_BOOT_defconfig 
b/configs/ls1021atwr_sdcard_ifc_SECURE_BOOT_defconfig
index d13652a..8560132 100644
--- a/configs/ls1021atwr_sdcard_ifc_SECURE_BOOT_defconfig
+++ b/configs/ls1021atwr_sdcard_ifc_SECURE_BOOT_defconfig
@@ -54,6 +54,7 @@ CONFIG_DM_PCI_COMPAT=y
 CONFIG_PCIE_LAYERSCAPE=y
 CONFIG_SYS_NS16550=y
 CONFIG_USB=y
+CONFIG_DM_USB=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_XHCI_DWC3=y
 CONFIG_USB_STORAGE=y
diff --git a/configs/ls1021atwr_sdcard_ifc_defconfig 
b/configs/ls1021atwr_sdcard_ifc_defconfig
index 9809c60..0

[U-Boot] [PATCH v2 10/10] gpt: harden set_gpt_info() against non NULL-terminated strings

2017-07-04 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

Strings read from devices may sometimes fail to be
NULL-terminated.   The functions in lib/string.c are subject to
failure in this case.   Protect against observed failures in
set_gpt_info() by switching to length-checking variants with a length
limit of the maximum possible partition table length.  At the same
time, add a few checks for NULL string pointers.

Here is an example as observed in sandbox under GDB:

=> gpt verify host 0 $partitions
Program received signal SIGSEGV, Segmentation fault.
0x00477747 in strlen (s=0x0) at lib/string.c:267
267 for (sc = s; *sc != '\0'; ++sc)
(gdb) bt
#0  0x00477747 in strlen (s=0x0) at lib/string.c:267
#1  0x004140b2 in set_gpt_info (str_part=,
str_disk_guid=str_disk_guid@entry=0x7fffdbe8, 
partitions=partitions@entry=0x7fffdbd8,
parts_count=parts_count@entry=0x7fffdbcf "", dev_desc=) 
at cmd/gpt.c:415
#2  0x004145b9 in gpt_verify (str_part=, 
blk_dev_desc=0x7fffef09a9d0) at cmd/gpt.c:580
#3  do_gpt (cmdtp=, flag=, argc=, argv=0x7fffef09a8f0)
at cmd/gpt.c:783
#4  0x004295b0 in cmd_call (argv=0x7fffef09a8f0, argc=0x5, 
flag=,
cmdtp=0x714e20 <_u_boot_list_2_cmd_2_gpt>) at common/command.c:500
#5  cmd_process (flag=, argc=0x5, argv=0x7fffef09a8f0,
repeatable=repeatable@entry=0x726c04 , ticks=ticks@entry=0x0) 
at common/command.c:539

Suggested-by: Lothar Waßmann <l...@karo-electronics.de>
Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---

Changes since v1:
  -- Checkpatch cleanups.


 cmd/gpt.c | 28 +++-
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index d703385a24..f8f35c23e0 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -233,7 +233,7 @@ static void print_gpt_info(void)
}
 }
 
-#ifdef CONFIG_CMD_GPT_RENAME
+
 static int calc_parts_list_len(int numparts)
 {
int partlistlen = UUID_STR_LEN + 1 + strlen("uuid_disk=");
@@ -253,6 +253,7 @@ static int calc_parts_list_len(int numparts)
return partlistlen;
 }
 
+#ifdef CONFIG_CMD_GPT_RENAME
 /*
  * create the string that upstream 'gpt write' command will accept as an
  * argument
@@ -385,6 +386,7 @@ static int set_gpt_info(struct blk_desc *dev_desc,
int errno = 0;
uint64_t size_ll, start_ll;
lbaint_t offset = 0;
+   int max_str_part = calc_parts_list_len(MAX_SEARCH_PARTITIONS);
 
debug("%s:  lba num: 0x%x %d\n", __func__,
  (unsigned int)dev_desc->lba, (unsigned int)dev_desc->lba);
@@ -402,6 +404,8 @@ static int set_gpt_info(struct blk_desc *dev_desc,
if (!val) {
 #ifdef CONFIG_RANDOM_UUID
*str_disk_guid = malloc(UUID_STR_LEN + 1);
+   if (str_disk_guid == NULL)
+   return -ENOMEM;
gen_rand_uuid_str(*str_disk_guid, UUID_STR_FORMAT_STD);
 #else
free(str);
@@ -416,10 +420,14 @@ static int set_gpt_info(struct blk_desc *dev_desc,
/* Move s to first partition */
strsep(, ";");
}
-   if (strlen(s) == 0)
+   if (s == NULL) {
+   printf("Error: is the partitions string NULL-terminated?\n");
+   return -EINVAL;
+   }
+   if (strnlen(s, max_str_part) == 0)
return -3;
 
-   i = strlen(s) - 1;
+   i = strnlen(s, max_str_part) - 1;
if (s[i] == ';')
s[i] = '\0';
 
@@ -433,6 +441,8 @@ static int set_gpt_info(struct blk_desc *dev_desc,
 
/* allocate memory for partitions */
parts = calloc(sizeof(disk_partition_t), p_count);
+   if (parts == NULL)
+   return -ENOMEM;
 
/* retrieve partitions data from string */
for (i = 0; i < p_count; i++) {
@@ -454,12 +464,12 @@ static int set_gpt_info(struct blk_desc *dev_desc,
} else {
if (extract_env(val, ))
p = val;
-   if (strlen(p) >= sizeof(parts[i].uuid)) {
+   if (strnlen(p, max_str_part) >= sizeof(parts[i].uuid)) {
printf("Wrong uuid format for partition %d\n", 
i);
errno = -4;
goto err;
}
-   strcpy((char *)parts[i].uuid, p);
+   strncpy((char *)parts[i].uuid, p, max_str_part);
free(val);
}
 #ifdef CONFIG_PARTITION_TYPE_GUID
@@ -469,13 +479,13 @@ static int set_gpt_info(struct blk_desc *dev_desc,
/* 'type' is optional */
if (extract_env(val, ))
p = val;
-   if (strlen(p) >= sizeof(

[U-Boot] [PATCH v8 09/10] GPT: provide commands to selectively rename partitions

2017-07-04 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

This patch provides support in u-boot for renaming GPT
partitions.  The renaming is accomplished via new 'gpt swap'
and 'gpt rename' commands.

The 'swap' mode returns an error if no matching partition names
are found, or if the number of partitions with one name does not equal
the number with the second name.   The 'rename' variant always
succeeds as long as a partition with the provided number exists.

Rewriting the partition table has the side-effect that all partitions
end up with "msftdata" flag set.  The reason is that partition type
PARTITION_BASIC_DATA_GUID is hard-coded in the gpt_fill_pte()
function.  This does not appear to cause any harm.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---

Changes since v7:
  -- Checkpatch cleanups.

 cmd/Kconfig|   8 ++
 cmd/gpt.c  | 241 -
 doc/README.gpt |  20 -
 3 files changed, 264 insertions(+), 5 deletions(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 6758db16f3..8d6fcb576d 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -595,6 +595,14 @@ config CMD_GPT
  Enable the 'gpt' command to ready and write GPT style partition
  tables.
 
+config CMD_GPT_RENAME
+   bool "GPT partition renaming commands"
+   depends on CMD_GPT
+   help
+ Enables the 'gpt' command to interchange names on two GPT
+ partitions via the 'gpt swap' command or to rename single
+ partitions via the 'rename' command.
+
 config CMD_ARMFLASH
#depends on FLASH_CFI_DRIVER
bool "armflash"
diff --git a/cmd/gpt.c b/cmd/gpt.c
index 8457b80757..d703385a24 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -20,6 +20,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 static LIST_HEAD(disk_partitions);
 
@@ -194,16 +196,32 @@ static struct disk_part 
*allocate_disk_part(disk_partition_t *info, int partnum)
return newpart;
 }
 
+static void prettyprint_part_size(char *sizestr, lbaint_t partsize,
+ lbaint_t blksize)
+{
+   unsigned long long partbytes, partmegabytes;
+
+   partbytes = partsize * blksize;
+   partmegabytes = lldiv(partbytes, SZ_1M);
+   snprintf(sizestr, 16, "%lluMiB", partmegabytes);
+}
+
 static void print_gpt_info(void)
 {
struct list_head *pos;
struct disk_part *curr;
+   char partstartstr[16];
+   char partsizestr[16];
 
list_for_each(pos, _partitions) {
curr = list_entry(pos, struct disk_part, list);
+   prettyprint_part_size(partstartstr, curr->gpt_part_info.start,
+ curr->gpt_part_info.blksz);
+   prettyprint_part_size(partsizestr, curr->gpt_part_info.size,
+ curr->gpt_part_info.blksz);
+
printf("Partition %d:\n", curr->partnum);
-   printf("1st block %x, size %x\n", 
(unsigned)curr->gpt_part_info.start,
-  (unsigned)curr->gpt_part_info.size);
+   printf("Start %s, size %s\n", partstartstr, partsizestr);
printf("Block size %lu, name %s\n", curr->gpt_part_info.blksz,
   curr->gpt_part_info.name);
printf("Type %s, bootable %d\n", curr->gpt_part_info.type,
@@ -215,6 +233,75 @@ static void print_gpt_info(void)
}
 }
 
+#ifdef CONFIG_CMD_GPT_RENAME
+static int calc_parts_list_len(int numparts)
+{
+   int partlistlen = UUID_STR_LEN + 1 + strlen("uuid_disk=");
+   /* for the comma */
+   partlistlen++;
+
+   /* per-partition additions; numparts starts at 1, so this should be 
correct */
+   partlistlen += numparts * (strlen("name=,") + PART_NAME_LEN + 1);
+   /* see part.h for definition of struct disk_partition */
+   partlistlen += numparts * (strlen("start=MiB,") + sizeof(lbaint_t) + 1);
+   partlistlen += numparts * (strlen("size=MiB,") + sizeof(lbaint_t) + 1);
+   partlistlen += numparts * (strlen("uuid=;") + UUID_STR_LEN + 1);
+   /* for the terminating null */
+   partlistlen++;
+   debug("Length of partitions_list is %d for %d partitions\n", 
partlistlen,
+ numparts);
+   return partlistlen;
+}
+
+/*
+ * create the string that upstream 'gpt write' command will accept as an
+ * argument
+ *
+ * From doc/README.gpt, Format of partitions layout:
+ *"uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
+ * name=kernel,size=60MiB,uuid=...;"
+ * The fields 'name' and 'size' are mandatory for every partition.
+ * The field 'start' is optional. The fields 'uuid' and 'uuid_disk'
+ * are optional if CONFIG_RANDOM_UUID is enabled.
+ */
+static int create_gpt_partitions_list(int numparts, const char *gu

[U-Boot] [PATCH v8 08/10] GPT: read partition table from device into a data structure

2017-07-04 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

Make the partition table available for modification by reading it from
the user-specified device into a linked list.   Provide an accessor
function for command-line testing.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 cmd/gpt.c  | 121 +
 include/part.h |   7 
 2 files changed, 128 insertions(+)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index 65fb80b3df..8457b80757 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c

Changes since v7:
  -- Made counter in get_gpt_info() start at 0 rather than 1.
  -- Checkpatch cleanup.

@@ -19,6 +19,9 @@
 #include 
 #include 
 #include 
+#include 
+
+static LIST_HEAD(disk_partitions);
 
 /**
  * extract_env(): Expand env name from string format '&{env_name}'
@@ -151,6 +154,120 @@ static bool found_key(const char *str, const char *key)
return result;
 }
 
+static void del_gpt_info(void)
+{
+   struct list_head *pos = _partitions;
+   struct disk_part *curr;
+   while (!list_empty(pos)) {
+   curr = list_entry(pos->next, struct disk_part, list);
+   list_del(pos->next);
+   free(curr);
+   }
+}
+
+static struct disk_part *allocate_disk_part(disk_partition_t *info, int 
partnum)
+{
+   struct disk_part *newpart;
+   newpart = malloc(sizeof(*newpart));
+   if (!newpart)
+   return ERR_PTR(-ENOMEM);
+   memset(newpart, '\0', sizeof(newpart));
+
+   newpart->gpt_part_info.start = info->start;
+   newpart->gpt_part_info.size = info->size;
+   newpart->gpt_part_info.blksz = info->blksz;
+   strncpy((char *)newpart->gpt_part_info.name, (const char *)info->name,
+   PART_NAME_LEN);
+   newpart->gpt_part_info.name[PART_NAME_LEN - 1] = '\0';
+   strncpy((char *)newpart->gpt_part_info.type, (const char *)info->type,
+   PART_TYPE_LEN);
+   newpart->gpt_part_info.type[PART_TYPE_LEN - 1] = '\0';
+   newpart->gpt_part_info.bootable = info->bootable;
+#ifdef CONFIG_PARTITION_UUIDS
+   strncpy(newpart->gpt_part_info.uuid, (const char *)info->uuid,
+   UUID_STR_LEN);
+   /* UUID_STR_LEN is correct, as uuid[]'s length is UUID_STR_LEN+1 chars 
*/
+   newpart->gpt_part_info.uuid[UUID_STR_LEN] = '\0';
+#endif
+   newpart->partnum = partnum;
+
+   return newpart;
+}
+
+static void print_gpt_info(void)
+{
+   struct list_head *pos;
+   struct disk_part *curr;
+
+   list_for_each(pos, _partitions) {
+   curr = list_entry(pos, struct disk_part, list);
+   printf("Partition %d:\n", curr->partnum);
+   printf("1st block %x, size %x\n", 
(unsigned)curr->gpt_part_info.start,
+  (unsigned)curr->gpt_part_info.size);
+   printf("Block size %lu, name %s\n", curr->gpt_part_info.blksz,
+  curr->gpt_part_info.name);
+   printf("Type %s, bootable %d\n", curr->gpt_part_info.type,
+  curr->gpt_part_info.bootable);
+#ifdef CONFIG_PARTITION_UUIDS
+   printf("UUID %s\n", curr->gpt_part_info.uuid);
+#endif
+   printf("\n");
+   }
+}
+
+/*
+ * read partition info into disk_partitions list where
+ * it can be printed or modified
+ */
+static int get_gpt_info(struct blk_desc *dev_desc)
+{
+   /* start partition numbering at 1, as U-Boot does */
+   int valid_parts = 0, p, ret;
+   disk_partition_t info;
+   struct disk_part *new_disk_part;
+
+   if (disk_partitions.next == NULL)
+   INIT_LIST_HEAD(_partitions);
+
+   for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
+   ret = part_get_info(dev_desc, p, );
+   if (ret)
+   continue;
+
+   /* Add 1 here because counter is zero-based but p1 is
+  the first partition */
+   new_disk_part = allocate_disk_part(, valid_parts+1);
+   if (IS_ERR(new_disk_part))
+   goto out;
+
+   list_add_tail(_disk_part->list, _partitions);
+   valid_parts++;
+   }
+   if (valid_parts == 0) {
+   printf("** No valid partitions found **\n");
+   goto out;
+   }
+   return valid_parts;
+ out:
+   if (valid_parts >= 1)
+   del_gpt_info();
+   return -ENODEV;
+}
+
+/* a wrapper to test get_gpt_info */
+static int do_get_gpt_info(struct blk_desc *dev_desc)
+{
+   int ret;
+
+   ret = get_gpt_info(dev_desc);
+   if (ret > 0) {
+   print_gpt_info();
+   del_gpt_info();
+   return 0;
+   }
+   return ret;
+}
+
 /**
  * set_gpt_info(): Fill partition information from string
  *

[U-Boot] [PATCH 10/10] gpt: harden set_gpt_info() against non NULL-terminated strings

2017-07-01 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

Strings read from devices may sometimes fail to be
NULL-terminated.   The functions in lib/string.c are subject to
failure in this case.   Protect against observed failures in
set_gpt_info() by switching to length-checking variants with a length
limit of the maximum possible partition table length.  At the same
time, add a few checks for NULL string pointers.

Here is an example as observed in sandbox under GDB:

=> gpt verify host 0 $partitions
Program received signal SIGSEGV, Segmentation fault.
0x00477747 in strlen (s=0x0) at lib/string.c:267
267 for (sc = s; *sc != '\0'; ++sc)
(gdb) bt
#0  0x00477747 in strlen (s=0x0) at lib/string.c:267
#1  0x004140b2 in set_gpt_info (str_part=,
str_disk_guid=str_disk_guid@entry=0x7fffdbe8, 
partitions=partitions@entry=0x7fffdbd8,
parts_count=parts_count@entry=0x7fffdbcf "", dev_desc=) 
at cmd/gpt.c:415
#2  0x004145b9 in gpt_verify (str_part=, 
blk_dev_desc=0x7fffef09a9d0) at cmd/gpt.c:580
#3  do_gpt (cmdtp=, flag=, argc=, argv=0x7fffef09a8f0)
at cmd/gpt.c:783
#4  0x004295b0 in cmd_call (argv=0x7fffef09a8f0, argc=0x5, 
flag=,
cmdtp=0x714e20 <_u_boot_list_2_cmd_2_gpt>) at common/command.c:500
#5  cmd_process (flag=, argc=0x5, argv=0x7fffef09a8f0,
repeatable=repeatable@entry=0x726c04 , ticks=ticks@entry=0x0) 
at common/command.c:539

Suggested-by: Lothar Waßmann <l...@karo-electronics.de>
Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 cmd/gpt.c | 28 +++-
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index 73bf273..8bd7bdf 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -233,7 +233,7 @@ static void print_gpt_info(void)
}
 }
 
-#ifdef CONFIG_CMD_GPT_RENAME
+
 static int calc_parts_list_len(int numparts)
 {
int partlistlen = UUID_STR_LEN + 1 + strlen("uuid_disk=");
@@ -253,6 +253,7 @@ static int calc_parts_list_len(int numparts)
return partlistlen;
 }
 
+#ifdef CONFIG_CMD_GPT_RENAME
 /*
  * create the string that upstream 'gpt write' command will accept as an
  * argument
@@ -381,6 +382,7 @@ static int set_gpt_info(struct blk_desc *dev_desc,
int errno = 0;
uint64_t size_ll, start_ll;
lbaint_t offset = 0;
+int max_str_part = calc_parts_list_len(MAX_SEARCH_PARTITIONS);
 
debug("%s:  lba num: 0x%x %d\n", __func__,
  (unsigned int)dev_desc->lba, (unsigned int)dev_desc->lba);
@@ -398,6 +400,8 @@ static int set_gpt_info(struct blk_desc *dev_desc,
if (!val) {
 #ifdef CONFIG_RANDOM_UUID
*str_disk_guid = malloc(UUID_STR_LEN + 1);
+   if (str_disk_guid == NULL)
+   return -ENOMEM;
gen_rand_uuid_str(*str_disk_guid, UUID_STR_FORMAT_STD);
 #else
free(str);
@@ -412,10 +416,14 @@ static int set_gpt_info(struct blk_desc *dev_desc,
/* Move s to first partition */
strsep(, ";");
}
-   if (strlen(s) == 0)
+   if (s == NULL) {
+printf("Error: is the partitions string NULL-terminated?\n");
+   return -EINVAL;
+   }
+   if (strnlen(s, max_str_part) == 0)
return -3;
 
-   i = strlen(s) - 1;
+   i = strnlen(s, max_str_part) - 1;
if (s[i] == ';')
s[i] = '\0';
 
@@ -429,6 +437,8 @@ static int set_gpt_info(struct blk_desc *dev_desc,
 
/* allocate memory for partitions */
parts = calloc(sizeof(disk_partition_t), p_count);
+   if (parts == NULL)
+   return -ENOMEM;
 
/* retrieve partitions data from string */
for (i = 0; i < p_count; i++) {
@@ -450,12 +460,12 @@ static int set_gpt_info(struct blk_desc *dev_desc,
} else {
if (extract_env(val, ))
p = val;
-   if (strlen(p) >= sizeof(parts[i].uuid)) {
+   if (strnlen(p, max_str_part) >= sizeof(parts[i].uuid)) {
printf("Wrong uuid format for partition %d\n", 
i);
errno = -4;
goto err;
}
-   strcpy((char *)parts[i].uuid, p);
+   strncpy((char *)parts[i].uuid, p, max_str_part);
free(val);
}
 #ifdef CONFIG_PARTITION_TYPE_GUID
@@ -465,13 +475,13 @@ static int set_gpt_info(struct blk_desc *dev_desc,
/* 'type' is optional */
if (extract_env(val, ))
p = val;
-   if (strlen(p) >= sizeof(parts[i].type_guid)) {
+   if (strnlen(p, max_str_part) >= 
size

[U-Boot] [PATCH 09/10] GPT: provide commands to selectively rename partitions

2017-07-01 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

This patch provides support in u-boot for renaming GPT
partitions.  The renaming is accomplished via new 'gpt swap'
and 'gpt rename' commands.

The 'swap' mode returns an error if no matching partition names
are found, or if the number of partitions with one name does not equal
the number with the second name.   The 'rename' variant always
succeeds as long as a partition with the provided number exists.

Rewriting the partition table has the side-effect that all partitions
end up with "msftdata" flag set.  The reason is that partition type
PARTITION_BASIC_DATA_GUID is hard-coded in the gpt_fill_pte()
function.  This does not appear to cause any harm.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---

Changes since v7:
  This version removes casts to unsigned long where the
  underlying data type is lbaint_t.  I tested this version both
  with and without CONFIG_SYS_64BIT_LBA, and the output is fine
  in either case.  This version also removes unneeded casts to
  const and restores the gpt command's error reporting to its
  earlier state if CONFIG_GPT_RENAME is unset.

  In addition, there is an additional check that a malloc() has
  succeeded.

 cmd/Kconfig|   8 ++
 cmd/gpt.c  | 240 -
 doc/README.gpt |  20 -
 3 files changed, 263 insertions(+), 5 deletions(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 07b0e3b..ae61b96 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -595,6 +595,14 @@ config CMD_GPT
  Enable the 'gpt' command to ready and write GPT style partition
  tables.
 
+config CMD_GPT_RENAME
+   bool "GPT partition renaming commands"
+   depends on CMD_GPT
+   help
+ Enables the 'gpt' command to interchange names on two GPT
+ partitions via the 'gpt swap' command or to rename single
+ partitions via the 'rename' command.
+
 config CMD_ARMFLASH
#depends on FLASH_CFI_DRIVER
bool "armflash"
diff --git a/cmd/gpt.c b/cmd/gpt.c
index dd5f78b..73bf273 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -20,6 +20,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 static LIST_HEAD(disk_partitions);
 
@@ -194,16 +196,32 @@ static struct disk_part 
*allocate_disk_part(disk_partition_t *info, int partnum)
return newpart;
 }
 
+static void prettyprint_part_size(char *sizestr, lbaint_t partsize,
+ lbaint_t blksize)
+{
+   unsigned long long partbytes, partmegabytes;
+
+   partbytes = partsize * blksize;
+   partmegabytes = lldiv(partbytes, SZ_1M);
+   snprintf(sizestr, 16, "%lluMiB", partmegabytes);
+}
+
 static void print_gpt_info(void)
 {
struct list_head *pos;
struct disk_part *curr;
+   char partstartstr[16];
+   char partsizestr[16];
 
list_for_each(pos, _partitions) {
curr = list_entry(pos, struct disk_part, list);
+   prettyprint_part_size(partstartstr, curr->gpt_part_info.start,
+ curr->gpt_part_info.blksz);
+   prettyprint_part_size(partsizestr, curr->gpt_part_info.size,
+  curr->gpt_part_info.blksz);
+
printf("Partition %d:\n", curr->partnum);
-   printf("1st block %x, size %x\n", 
(unsigned)curr->gpt_part_info.start,
-  (unsigned)curr->gpt_part_info.size);
+   printf("Start %s, size %s\n", partstartstr, partsizestr);
printf("Block size %lu, name %s\n", curr->gpt_part_info.blksz,
   curr->gpt_part_info.name);
printf("Type %s, bootable %d\n", curr->gpt_part_info.type,
@@ -215,6 +233,73 @@ static void print_gpt_info(void)
}
 }
 
+#ifdef CONFIG_CMD_GPT_RENAME
+static int calc_parts_list_len(int numparts)
+{
+   int partlistlen = UUID_STR_LEN + 1 + strlen("uuid_disk=");
+   /* for the comma */
+   partlistlen++;
+
+   /* per-partition additions; numparts starts at 1, so this should be 
correct */
+   partlistlen += numparts * (strlen("name=,") + PART_NAME_LEN + 1);
+   /* see part.h for definition of struct disk_partition */
+   partlistlen += numparts * (strlen("start=MiB,") + sizeof(lbaint_t) + 1);
+   partlistlen += numparts * (strlen("size=MiB,") + sizeof(lbaint_t) + 1);
+   partlistlen += numparts * (strlen("uuid=;") + UUID_STR_LEN + 1);
+   /* for the terminating null */
+   partlistlen++;
+   debug("Length of partitions_list is %d for %d partitions\n", 
partlistlen,
+  numparts);
+   return partlistlen;
+}
+
+/*
+ * create the string that upstream 'gpt write' command will accept as an
+ * argument
+ *
+ * From doc/README.gpt, Format of parti

[U-Boot] [PATCH v8 8/10] GPT: read partition table from device into a data structure

2017-07-01 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

Make the partition table available for modification by reading it from
the user-specified device into a linked list.   Provide an accessor
function for command-line testing.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---

Changes since v7:
   The failure-handling logic of get_gpt_info() now is triggered
   properly when valid_part=1.

 cmd/gpt.c  | 119 +
 include/part.h |   7 
 2 files changed, 126 insertions(+)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index 65fb80b..dd5f78b 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -19,6 +19,9 @@
 #include 
 #include 
 #include 
+#include 
+
+static LIST_HEAD(disk_partitions);
 
 /**
  * extract_env(): Expand env name from string format '&{env_name}'
@@ -151,6 +154,118 @@ static bool found_key(const char *str, const char *key)
return result;
 }
 
+static void del_gpt_info(void)
+{
+   struct list_head *pos = _partitions;
+   struct disk_part *curr;
+   while (!list_empty(pos)) {
+   curr = list_entry(pos->next, struct disk_part, list);
+   list_del(pos->next);
+   free(curr);
+   }
+}
+
+static struct disk_part *allocate_disk_part(disk_partition_t *info, int 
partnum)
+{
+   struct disk_part *newpart;
+   newpart = malloc(sizeof(*newpart));
+   if (!newpart)
+   return ERR_PTR(-ENOMEM);
+   memset(newpart, '\0', sizeof(newpart));
+
+   newpart->gpt_part_info.start = info->start;
+   newpart->gpt_part_info.size = info->size;
+   newpart->gpt_part_info.blksz = info->blksz;
+   strncpy((char *)newpart->gpt_part_info.name, (const char *)info->name,
+   PART_NAME_LEN);
+   newpart->gpt_part_info.name[PART_NAME_LEN - 1] = '\0';
+   strncpy((char *)newpart->gpt_part_info.type, (const char *)info->type,
+   PART_TYPE_LEN);
+   newpart->gpt_part_info.type[PART_TYPE_LEN - 1] = '\0';
+   newpart->gpt_part_info.bootable = info->bootable;
+#ifdef CONFIG_PARTITION_UUIDS
+   strncpy(newpart->gpt_part_info.uuid, (const char *)info->uuid,
+   UUID_STR_LEN);
+   /* UUID_STR_LEN is correct, as uuid[]'s length is UUID_STR_LEN+1 chars 
*/
+   newpart->gpt_part_info.uuid[UUID_STR_LEN] = '\0';
+#endif
+   newpart->partnum = partnum;
+
+   return newpart;
+}
+
+static void print_gpt_info(void)
+{
+   struct list_head *pos;
+   struct disk_part *curr;
+
+   list_for_each(pos, _partitions) {
+   curr = list_entry(pos, struct disk_part, list);
+   printf("Partition %d:\n", curr->partnum);
+   printf("1st block %x, size %x\n", 
(unsigned)curr->gpt_part_info.start,
+  (unsigned)curr->gpt_part_info.size);
+   printf("Block size %lu, name %s\n", curr->gpt_part_info.blksz,
+  curr->gpt_part_info.name);
+   printf("Type %s, bootable %d\n", curr->gpt_part_info.type,
+  curr->gpt_part_info.bootable);
+#ifdef CONFIG_PARTITION_UUIDS
+   printf("UUID %s\n", curr->gpt_part_info.uuid);
+#endif
+   printf("\n");
+   }
+}
+
+/*
+ * read partition info into disk_partitions list where
+ * it can be printed or modified
+ */
+static int get_gpt_info(struct blk_desc *dev_desc)
+{
+   /* start partition numbering at 1, as U-Boot does */
+   int valid_parts = 1, p, ret;
+   disk_partition_t info;
+   struct disk_part *new_disk_part;
+
+   if (disk_partitions.next == NULL)
+   INIT_LIST_HEAD(_partitions);
+
+   for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
+   ret = part_get_info(dev_desc, p, );
+   if (ret)
+   continue;
+
+   new_disk_part = allocate_disk_part(, valid_parts);
+   if (IS_ERR(new_disk_part))
+   goto out;
+
+   list_add_tail(_disk_part->list, _partitions);
+   valid_parts++;
+   }
+   if (valid_parts == 1) {
+   printf("** No valid partitions found **\n");
+   goto out;
+   }
+   return --valid_parts;
+ out:
+   if (valid_parts >= 2)
+   del_gpt_info();
+   return -ENODEV;
+}
+
+/* a wrapper to test get_gpt_info */
+static int do_get_gpt_info(struct blk_desc *dev_desc)
+{
+   int ret;
+
+   ret = get_gpt_info(dev_desc);
+   if (ret > 0) {
+   print_gpt_info();
+   del_gpt_info();
+   return 0;
+   }
+   return ret;
+}
+
 /**
  * set_gpt_info(): Fill partition information from string
  * function allocates memory, remember to free!
@@ -455,6 +570,8 @@ static int do_gpt(cmd_tbl_t *cmdtp, int fl

Re: [U-Boot] [PATCH v6 3/3] GPT: provide commands to selectively rename partitions

2017-07-01 Thread Alison Chaiken
On Tue, Jun 27, 2017 at 12:05 AM, Lothar Waßmann <l...@karo-electronics.de> 
wrote:
>
> Hi,
>
> On Sun, 25 Jun 2017 14:54:56 -0700 Alison Chaiken wrote:
> > On Sun, Jun 18, 2017 at 4:03 AM, Wolfgang Denk <w...@denx.de> wrote:
> >
> > > Dear Alison,
> > >
> > > In message 

[U-Boot] [PATCH v7 9/9] GPT: provide commands to selectively rename partitions

2017-06-25 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

This patch provides support in u-boot for renaming GPT
partitions.  The renaming is accomplished via new 'gpt swap'
and 'gpt rename' commands.

The 'swap' mode returns an error if no matching partition names
are found, or if the number of partitions with one name does not equal
the number with the second name.   The 'rename' variant always
succeeds as long as a partition with the provided number exists.

Rewriting the partition table has the side-effect that all partitions
end up with "msftdata" flag set.  The reason is that partition type
PARTITION_BASIC_DATA_GUID is hard-coded in the gpt_fill_pte()
function.  This does not appear to cause any harm.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 cmd/Kconfig|   8 ++
 cmd/gpt.c  | 239 +++--
 doc/README.gpt |  20 -
 3 files changed, 261 insertions(+), 6 deletions(-)

Changes since v7:

-- Removed several casts in create_gpt_partitions_list() and
   do_rename_gpt_parts() as suggested by Lothar Waßmann.  The cast of
   gpt_part_info.name to char* is needed to silence a compiler
   warning.

-- Substituted simple_strtol() for atoi() in do_gpt_rename_parts() as
   suggested by Tom Rini and Wolfgang Denk.

-- Fixed bug in do_rename_gpt_parts() where 0 was returned as a valid
   number of partitions with which to continue.

-- Added a comment to do_rename_gpt_parts() noting that the debug()
   string it optionally prints is useful as input to the pre-existing
   'gpt write' and 'gpt verify' commands.

-- Changed some -1 return values to -ENODEV and -EINVAL as suggested
   by Tom Rini.

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 07b0e3b..ae61b96 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -595,6 +595,14 @@ config CMD_GPT
  Enable the 'gpt' command to ready and write GPT style partition
  tables.
 
+config CMD_GPT_RENAME
+   bool "GPT partition renaming commands"
+   depends on CMD_GPT
+   help
+ Enables the 'gpt' command to interchange names on two GPT
+ partitions via the 'gpt swap' command or to rename single
+ partitions via the 'rename' command.
+
 config CMD_ARMFLASH
#depends on FLASH_CFI_DRIVER
bool "armflash"
diff --git a/cmd/gpt.c b/cmd/gpt.c
index 9934ef4..8c0441f 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -20,6 +20,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 static LIST_HEAD(disk_partitions);
 
@@ -194,16 +196,33 @@ static struct disk_part 
*allocate_disk_part(disk_partition_t *info, int partnum)
return newpart;
 }
 
+static void prettyprint_part_size(char *sizestr, unsigned long partsize,
+ unsigned long blksize)
+{
+   unsigned long long partbytes;
+   unsigned long partmegabytes;
+
+   partbytes = partsize * blksize;
+   partmegabytes = lldiv(partbytes, SZ_1M);
+   snprintf(sizestr, 16, "%luMiB", partmegabytes);
+}
+
 static void print_gpt_info(void)
 {
struct list_head *pos;
struct disk_part *curr;
+   char partstartstr[16];
+   char partsizestr[16];
 
list_for_each(pos, _partitions) {
curr = list_entry(pos, struct disk_part, list);
+   prettyprint_part_size(partstartstr, (unsigned 
long)curr->gpt_part_info.start,
+ (unsigned long) 
curr->gpt_part_info.blksz);
+   prettyprint_part_size(partsizestr, (unsigned 
long)curr->gpt_part_info.size,
+ (unsigned long) 
curr->gpt_part_info.blksz);
+
printf("Partition %d:\n", curr->partnum);
-   printf("1st block %x, size %x\n", 
(unsigned)curr->gpt_part_info.start,
-  (unsigned)curr->gpt_part_info.size);
+   printf("Start %s, size %s\n", partstartstr, partsizestr);
printf("Block size %lu, name %s\n", curr->gpt_part_info.blksz,
   curr->gpt_part_info.name);
printf("Type %s, bootable %d\n", curr->gpt_part_info.type,
@@ -215,6 +234,74 @@ static void print_gpt_info(void)
}
 }
 
+#ifdef CONFIG_CMD_GPT_RENAME
+static int calc_parts_list_len(int numparts)
+{
+   int partlistlen = UUID_STR_LEN + 1 + strlen("uuid_disk=");
+   /* for the comma */
+   partlistlen++;
+
+   /* per-partition additions; numparts starts at 1, so this should be 
correct */
+   partlistlen += numparts * (strlen("name=,") + PART_NAME_LEN + 1);
+   /* see part.h for definition of struct disk_partition */
+   partlistlen += numparts * (strlen("start=MiB,") + sizeof(lbaint_t) + 1);
+   partlistlen += numparts * (strlen("size=MiB,") + sizeof(lbaint_t) + 1);
+   partlistlen += numparts * (strlen(&q

[U-Boot] [PATCH v7 4/9] sandbox: README: fix partition command invocation

2017-06-25 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

The instructions for creating a disk image that are presently in
README.sandbox fail because sfdisk doesn't know about GPT.

Changes since v6: none.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 board/sandbox/README.sandbox | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/board/sandbox/README.sandbox b/board/sandbox/README.sandbox
index 02d8ab3..9dc2eb0 100644
--- a/board/sandbox/README.sandbox
+++ b/board/sandbox/README.sandbox
@@ -333,7 +333,7 @@ the contents of the root directory on the second partion of 
the image
 A disk image can be created using the following commands:
 
 $> truncate -s 1200M ./disk.raw
-$> echo -e "label: gpt\n,64M,U\n,,L" | /usr/sbin/sfdisk  ./disk.raw
+$> echo -e "label: gpt\n,64M,U\n,,L" | /usr/sbin/sgdisk  ./disk.raw
 $> lodev=`sudo losetup -P -f --show ./disk.raw`
 $> sudo mkfs.vfat -n EFI -v ${lodev}p1
 $> sudo mkfs.ext4 -L ROOT -v ${lodev}p2
-- 
2.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v7 5/9] cmd gpt: test in sandbox

2017-06-25 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

Make minor changes to README.gpt and sandbox_defconfig to support
testing of the gpt command's functionality in the sandbox.

Changes since v6: none.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 doc/README.gpt | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/doc/README.gpt b/doc/README.gpt
index 589295b..0a3286f 100644
--- a/doc/README.gpt
+++ b/doc/README.gpt
@@ -210,6 +210,16 @@ U-BOOT> gpt verify mmc 0 $partitions
 U-BOOT> if test $? = 0; then echo "GPT OK"; else echo "GPT ERR"; fi
 
 
+The GPT functionality may be tested with the 'sandbox' board by
+creating a disk image as described under 'Block Device Emulation' in
+board/sandbox/README.sandbox:
+
+=>host bind 0 ./disk.raw
+=> gpt read host 0
+[ . . . ]
+=> gpt flip host 0
+[ . . . ]
+
 Partition type GUID:
 
 
-- 
2.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v7 6/9] partitions: increase MAX_SEARCH_PARTITIONS and move to part.h

2017-06-25 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

Move MAX_SEARCH_PARTITIONS to part.h so that functions in cmd
directory can find it.  At the same time, increase the value to
64 since some operating systems use many, and the resources
consumed by a larger value are minimal.

Changes since v6: none.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 disk/part.c| 1 -
 include/part.h | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/disk/part.c b/disk/part.c
index 491b02d..e640a55 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -388,7 +388,6 @@ cleanup:
 
 #define PART_UNSPECIFIED -2
 #define PART_AUTO -1
-#define MAX_SEARCH_PARTITIONS 16
 int blk_get_device_part_str(const char *ifname, const char *dev_part_str,
 struct blk_desc **dev_desc,
 disk_partition_t *info, int allow_whole_dev)
diff --git a/include/part.h b/include/part.h
index 87b..22da604 100644
--- a/include/part.h
+++ b/include/part.h
@@ -49,6 +49,7 @@ struct block_drvr {
 
 #define PART_NAME_LEN 32
 #define PART_TYPE_LEN 32
+#define MAX_SEARCH_PARTITIONS 64
 
 typedef struct disk_partition {
lbaint_tstart;  /* # of first block in partition*/
-- 
2.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v7 7/9] GPT: add accessor function for disk GUID

2017-06-25 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

In order to read the GPT, modify the partition name strings, and then
write out a new GPT, the disk GUID is needed.  While there is an
existing accessor for the partition UUIDs, there is none yet for the
disk GUID.

Changes since v6: none.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 cmd/gpt.c   | 26 ++
 disk/part_efi.c | 31 +++
 doc/README.gpt  |  3 ++-
 include/part.h  | 15 +++
 4 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index 3e98821..65fb80b 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -398,6 +398,23 @@ static int gpt_verify(struct blk_desc *blk_dev_desc, const 
char *str_part)
return ret;
 }
 
+static int do_disk_guid(struct blk_desc *dev_desc, char * const namestr)
+{
+   int ret;
+   char disk_guid[UUID_STR_LEN + 1];
+
+   ret = get_disk_guid(dev_desc, disk_guid);
+   if (ret < 0)
+   return CMD_RET_FAILURE;
+
+   if (namestr)
+   setenv(namestr, disk_guid);
+   else
+   printf("%s\n", disk_guid);
+
+   return ret;
+}
+
 /**
  * do_gpt(): Perform GPT operations
  *
@@ -436,6 +453,8 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
} else if ((strcmp(argv[1], "verify") == 0)) {
ret = gpt_verify(blk_dev_desc, argv[4]);
printf("Verify GPT: ");
+   } else if (strcmp(argv[1], "guid") == 0) {
+   ret = do_disk_guid(blk_dev_desc, argv[4]);
} else {
return CMD_RET_USAGE;
}
@@ -458,4 +477,11 @@ U_BOOT_CMD(gpt, CONFIG_SYS_MAXARGS, 1, do_gpt,
" Example usage:\n"
" gpt write mmc 0 $partitions\n"
" gpt verify mmc 0 $partitions\n"
+   " guid  \n"
+   "- print disk GUID\n"
+   " guid   \n"
+   "- set environment variable to disk GUID\n"
+   " Example usage:\n"
+   " gpt guid mmc 0\n"
+   " gpt guid mmc 0 varname\n"
 );
diff --git a/disk/part_efi.c b/disk/part_efi.c
index 20d33ef..71c3cb3 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -178,6 +178,37 @@ static void prepare_backup_gpt_header(gpt_header *gpt_h)
  * Public Functions (include/part.h)
  */
 
+/*
+ * UUID is displayed as 32 hexadecimal digits, in 5 groups,
+ * separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters
+ */
+int get_disk_guid(struct blk_desc * dev_desc, char *guid)
+{
+   ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
+   gpt_entry *gpt_pte = NULL;
+   unsigned char *guid_bin;
+
+   /* This function validates AND fills in the GPT header and PTE */
+   if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA,
+gpt_head, _pte) != 1) {
+   printf("%s: *** ERROR: Invalid GPT ***\n", __func__);
+   if (is_gpt_valid(dev_desc, dev_desc->lba - 1,
+gpt_head, _pte) != 1) {
+   printf("%s: *** ERROR: Invalid Backup GPT ***\n",
+  __func__);
+   return -EINVAL;
+   } else {
+   printf("%s: ***Using Backup GPT ***\n",
+  __func__);
+   }
+   }
+
+   guid_bin = gpt_head->disk_guid.b;
+   uuid_bin_to_str(guid_bin, guid, UUID_STR_FORMAT_GUID);
+
+   return 0;
+}
+
 void part_print_efi(struct blk_desc *dev_desc)
 {
ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
diff --git a/doc/README.gpt b/doc/README.gpt
index 0a3286f..6c5ab78 100644
--- a/doc/README.gpt
+++ b/doc/README.gpt
@@ -171,7 +171,8 @@ To restore GUID partition table one needs to:
The fields 'uuid' and 'uuid_disk' are optional if CONFIG_RANDOM_UUID is
enabled. A random uuid will be used if omitted or they point to an empty/
non-existent environment variable. The environment variable will be set to
-   the generated UUID.
+   the generated UUID.  The 'gpt guid' command reads the current value of the
+   uuid_disk from the GPT.
 
The field 'bootable' is optional, it is used to mark the GPT partition
bootable (set attribute flags "Legacy BIOS bootable").
diff --git a/include/part.h b/include/part.h
index 22da604..c41aa6a 100644
--- a/include/part.h
+++ b/include/part.h
@@ -372,6 +372,21 @@ int gpt_verify_headers(struct blk_desc *dev_desc, 
gpt_header *gpt_head,
 int gpt_verify_partitions(struct blk_desc *dev_desc,
  disk_partition_t *partitions, int parts,
  gpt_header *gpt_head, gpt_entry **gpt_pte);
+
+
+/**
+ * get_disk_guid() - Function to read the GUID string from a d

[U-Boot] [PATCH v7 1/9] EFI: replace number with UUID_STR_LEN macro

2017-06-25 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

Changes since v6: none.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 disk/part_efi.c | 2 +-
 include/part.h  | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/disk/part_efi.c b/disk/part_efi.c
index 1b7ba27..20d33ef 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -183,7 +183,7 @@ void part_print_efi(struct blk_desc *dev_desc)
ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
gpt_entry *gpt_pte = NULL;
int i = 0;
-   char uuid[37];
+   char uuid[UUID_STR_LEN + 1];
unsigned char *uuid_bin;
 
/* This function validates AND fills in the GPT header and PTE */
diff --git a/include/part.h b/include/part.h
index 83bce05..6ace09f 100644
--- a/include/part.h
+++ b/include/part.h
@@ -9,6 +9,7 @@
 
 #include 
 #include 
+#include 
 
 struct block_drvr {
char *name;
@@ -54,10 +55,10 @@ typedef struct disk_partition {
uchar   type[32];   /* string type description  */
int bootable;   /* Active/Bootable flag is set  */
 #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
-   charuuid[37];   /* filesystem UUID as string, if exists */
+   charuuid[UUID_STR_LEN + 1]; /* filesystem UUID as string, if exists 
*/
 #endif
 #ifdef CONFIG_PARTITION_TYPE_GUID
-   chartype_guid[37];  /* type GUID as string, if exists   */
+   chartype_guid[UUID_STR_LEN + 1];/* type GUID as string, if 
exists   */
 #endif
 #ifdef CONFIG_DOS_PARTITION
uchar   sys_ind;/* partition type   */
-- 
2.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v7 9/9] GPT: provide commands to selectively rename partitions

2017-06-25 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

This patch provides support in u-boot for renaming GPT
partitions.  The renaming is accomplished via new 'gpt swap'
and 'gpt rename' commands.

The 'swap' mode returns an error if no matching partition names
are found, or if the number of partitions with one name does not equal
the number with the second name.   The 'rename' variant always
succeeds as long as a partition with the provided number exists.

Rewriting the partition table has the side-effect that all partitions
end up with "msftdata" flag set.  The reason is that partition type
PARTITION_BASIC_DATA_GUID is hard-coded in the gpt_fill_pte()
function.  This does not appear to cause any harm.

Changes since v7:

-- Removed several casts in create_gpt_partitions_list() and
   do_rename_gpt_parts() as suggested by Lothar Waßmann.  The cast of
   gpt_part_info.name to char* is needed to silence a compiler
   warning.

-- Substituted simple_strtol() for atoi() in do_gpt_rename_parts() as
   suggested by Tom Rini and Wolfgang Denk.

-- Fixed bug in do_rename_gpt_parts() where 0 was returned as a valid
   number of partitions with which to continue.

-- Added a comment to do_rename_gpt_parts() noting that the debug()
   string it optionally prints is useful as input to the pre-existing
   'gpt write' and 'gpt verify' commands.

-- Changed some -1 return values to -ENODEV and -EINVAL as suggested
   by Tom Rini.


Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 cmd/Kconfig|   8 ++
 cmd/gpt.c  | 239 +++--
 doc/README.gpt |  20 -
 3 files changed, 261 insertions(+), 6 deletions(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 07b0e3b..ae61b96 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -595,6 +595,14 @@ config CMD_GPT
  Enable the 'gpt' command to ready and write GPT style partition
  tables.
 
+config CMD_GPT_RENAME
+   bool "GPT partition renaming commands"
+   depends on CMD_GPT
+   help
+ Enables the 'gpt' command to interchange names on two GPT
+ partitions via the 'gpt swap' command or to rename single
+ partitions via the 'rename' command.
+
 config CMD_ARMFLASH
#depends on FLASH_CFI_DRIVER
bool "armflash"
diff --git a/cmd/gpt.c b/cmd/gpt.c
index 9934ef4..8c0441f 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -20,6 +20,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 static LIST_HEAD(disk_partitions);
 
@@ -194,16 +196,33 @@ static struct disk_part 
*allocate_disk_part(disk_partition_t *info, int partnum)
return newpart;
 }
 
+static void prettyprint_part_size(char *sizestr, unsigned long partsize,
+ unsigned long blksize)
+{
+   unsigned long long partbytes;
+   unsigned long partmegabytes;
+
+   partbytes = partsize * blksize;
+   partmegabytes = lldiv(partbytes, SZ_1M);
+   snprintf(sizestr, 16, "%luMiB", partmegabytes);
+}
+
 static void print_gpt_info(void)
 {
struct list_head *pos;
struct disk_part *curr;
+   char partstartstr[16];
+   char partsizestr[16];
 
list_for_each(pos, _partitions) {
curr = list_entry(pos, struct disk_part, list);
+   prettyprint_part_size(partstartstr, (unsigned 
long)curr->gpt_part_info.start,
+ (unsigned long) 
curr->gpt_part_info.blksz);
+   prettyprint_part_size(partsizestr, (unsigned 
long)curr->gpt_part_info.size,
+ (unsigned long) 
curr->gpt_part_info.blksz);
+
printf("Partition %d:\n", curr->partnum);
-   printf("1st block %x, size %x\n", 
(unsigned)curr->gpt_part_info.start,
-  (unsigned)curr->gpt_part_info.size);
+   printf("Start %s, size %s\n", partstartstr, partsizestr);
printf("Block size %lu, name %s\n", curr->gpt_part_info.blksz,
   curr->gpt_part_info.name);
printf("Type %s, bootable %d\n", curr->gpt_part_info.type,
@@ -215,6 +234,74 @@ static void print_gpt_info(void)
}
 }
 
+#ifdef CONFIG_CMD_GPT_RENAME
+static int calc_parts_list_len(int numparts)
+{
+   int partlistlen = UUID_STR_LEN + 1 + strlen("uuid_disk=");
+   /* for the comma */
+   partlistlen++;
+
+   /* per-partition additions; numparts starts at 1, so this should be 
correct */
+   partlistlen += numparts * (strlen("name=,") + PART_NAME_LEN + 1);
+   /* see part.h for definition of struct disk_partition */
+   partlistlen += numparts * (strlen("start=MiB,") + sizeof(lbaint_t) + 1);
+   partlistlen += numparts * (strlen("size=MiB,") + sizeof(lbaint_t) + 1);
+   partlistlen += numparts * (strlen(&q

[U-Boot] [PATCH v7 2/9] disk_partition: introduce macros for description string lengths

2017-06-25 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

Changes since v6: none.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 include/part.h | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/include/part.h b/include/part.h
index 6ace09f..87b 100644
--- a/include/part.h
+++ b/include/part.h
@@ -47,12 +47,15 @@ struct block_drvr {
 #define DEV_TYPE_CDROM 0x05/* CD-ROM */
 #define DEV_TYPE_OPDISK0x07/* optical disk */
 
+#define PART_NAME_LEN 32
+#define PART_TYPE_LEN 32
+
 typedef struct disk_partition {
lbaint_tstart;  /* # of first block in partition*/
lbaint_tsize;   /* number of blocks in partition*/
ulong   blksz;  /* block size in bytes  */
-   uchar   name[32];   /* partition name   */
-   uchar   type[32];   /* string type description  */
+   uchar   name[PART_NAME_LEN];/* partition name   
*/
+   uchar   type[PART_TYPE_LEN];/* string type description  
*/
int bootable;   /* Active/Bootable flag is set  */
 #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
charuuid[UUID_STR_LEN + 1]; /* filesystem UUID as string, if exists 
*/
-- 
2.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v7 3/9] GPT: fix error in partitions string doc

2017-06-25 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

The existing partitions-list parsing in cmd/gpt.c passes a value
from gpt_default() to set_gpt_info() that README.gpt suggests
should begin with 'partitions='.  Partition-list strings should
in fact begin with 'uuid_disk', as otherwise the call from
set_gpt_info() to extract_val() to find 'uuid_disk' will fail.
Change README.gpt accordingly.

Changes since v6: none.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 doc/README.gpt | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/doc/README.gpt b/doc/README.gpt
index 3fcd835..589295b 100644
--- a/doc/README.gpt
+++ b/doc/README.gpt
@@ -156,10 +156,10 @@ Creating GPT partitions in U-Boot:
 To restore GUID partition table one needs to:
 1. Define partition layout in the environment.
Format of partitions layout:
- "partitions=uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
+ "uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
name=kernel,size=60MiB,uuid=...;"
  or
- "partitions=uuid_disk=${uuid_gpt_disk};name=${uboot_name},
+ "uuid_disk=${uuid_gpt_disk};name=${uboot_name},
size=${uboot_size},uuid=${uboot_uuid};"
 
The fields 'name' and 'size' are mandatory for every partition.
@@ -219,7 +219,7 @@ PARTITION_BASIC_DATA_GUID 
(EBD0A0A2-B9E5-4433-87C0-68B6B72699C7).
 If you define 'CONFIG_PARTITION_TYPE_GUID', a optionnal parameter 'type'
 can specify a other partition type guid:
 
- "partitions=uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
+ "uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
name=kernel,size=60MiB,uuid=...,
type=0FC63DAF-8483-4772-8E79-3D69D8477DE4;"
 
@@ -241,7 +241,7 @@ Some strings can be also used at the place of known GUID :
"lvm"= PARTITION_LINUX_LVM_GUID
   (E6D6D379-F507-44C2-A23C-238F2A3DF928)
 
-"partitions=uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
+"uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
name=kernel,size=60MiB,uuid=...,type=linux;"
 
 They are also used to display the type of partition in "part list" command.
-- 
2.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v7 0/9] add support for GPT partition name manipulation

2017-06-25 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

Here is a resubmission of the 9-part patch series, the first 8 of
which have already been marked 'applied', 'reviewed', or 'ack'ed' by
Lukasz Majewski, Simon Glass or Tom Rini.  I'm reposting them all as a
set at Tom Rini's suggestion.  Those earlier patches are listed here:

  GPT: read partition table from device into a data structure
  Reviewed-by: Tom Rini, Jun 11 in <20170611133854.GS10782@bill-the-cat>

  GPT: add accessor function for disk GUID
  Reviewed-by: Tom Rini, Jun 11 in <20170611133849.GR10782@bill-the-cat>

  partitions: increase MAX_SEARCH_PARTITIONS and move to part.h
  Reviewed-by: Lukasz Majewski, Jun 3 in <20170603135259.6ba67e86@jawa>

  cmd gpt: test in sandbox
  Applied to u-boot-dm by Simon Glass, Jun 15 in 

[U-Boot] [PATCH v7 8/9] GPT: read partition table from device into a data structure

2017-06-25 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

Make the partition table available for modification by reading it from
the user-specified device into a linked list.   Provide an accessor
function for command-line testing.

Change since v6:
-- Removed a cast in allocate_disk_part() as suggested by Lothar.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 cmd/gpt.c  | 119 +
 include/part.h |   7 
 2 files changed, 126 insertions(+)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index 65fb80b..9934ef4 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -19,6 +19,9 @@
 #include 
 #include 
 #include 
+#include 
+
+static LIST_HEAD(disk_partitions);
 
 /**
  * extract_env(): Expand env name from string format '&{env_name}'
@@ -151,6 +154,118 @@ static bool found_key(const char *str, const char *key)
return result;
 }
 
+static void del_gpt_info(void)
+{
+   struct list_head *pos = _partitions;
+   struct disk_part *curr;
+   while (!list_empty(pos)) {
+   curr = list_entry(pos->next, struct disk_part, list);
+   list_del(pos->next);
+   free(curr);
+   }
+}
+
+static struct disk_part *allocate_disk_part(disk_partition_t *info, int 
partnum)
+{
+   struct disk_part *newpart;
+   newpart = malloc(sizeof(*newpart));
+   if (!newpart)
+   return ERR_PTR(-ENOMEM);
+   memset(newpart, '\0', sizeof(newpart));
+
+   newpart->gpt_part_info.start = info->start;
+   newpart->gpt_part_info.size = info->size;
+   newpart->gpt_part_info.blksz = info->blksz;
+   strncpy((char *)newpart->gpt_part_info.name, (const char *)info->name,
+   PART_NAME_LEN);
+   newpart->gpt_part_info.name[PART_NAME_LEN - 1] = '\0';
+   strncpy((char *)newpart->gpt_part_info.type, (const char *)info->type,
+   PART_TYPE_LEN);
+   newpart->gpt_part_info.type[PART_TYPE_LEN - 1] = '\0';
+   newpart->gpt_part_info.bootable = info->bootable;
+#ifdef CONFIG_PARTITION_UUIDS
+   strncpy(newpart->gpt_part_info.uuid, (const char *)info->uuid,
+   UUID_STR_LEN);
+   /* UUID_STR_LEN is correct, as uuid[]'s length is UUID_STR_LEN+1 chars 
*/
+   newpart->gpt_part_info.uuid[UUID_STR_LEN] = '\0';
+#endif
+   newpart->partnum = partnum;
+
+   return newpart;
+}
+
+static void print_gpt_info(void)
+{
+   struct list_head *pos;
+   struct disk_part *curr;
+
+   list_for_each(pos, _partitions) {
+   curr = list_entry(pos, struct disk_part, list);
+   printf("Partition %d:\n", curr->partnum);
+   printf("1st block %x, size %x\n", 
(unsigned)curr->gpt_part_info.start,
+  (unsigned)curr->gpt_part_info.size);
+   printf("Block size %lu, name %s\n", curr->gpt_part_info.blksz,
+  curr->gpt_part_info.name);
+   printf("Type %s, bootable %d\n", curr->gpt_part_info.type,
+  curr->gpt_part_info.bootable);
+#ifdef CONFIG_PARTITION_UUIDS
+   printf("UUID %s\n", curr->gpt_part_info.uuid);
+#endif
+   printf("\n");
+   }
+}
+
+/*
+ * read partition info into disk_partitions list where
+ * it can be printed or modified
+ */
+static int get_gpt_info(struct blk_desc *dev_desc)
+{
+   /* start partition numbering at 1, as U-Boot does */
+   int valid_parts = 1, p, ret;
+   disk_partition_t info;
+   struct disk_part *new_disk_part;
+
+   if (disk_partitions.next == NULL)
+   INIT_LIST_HEAD(_partitions);
+
+   for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
+   ret = part_get_info(dev_desc, p, );
+   if (ret)
+   continue;
+
+   new_disk_part = allocate_disk_part(, valid_parts);
+   if (IS_ERR(new_disk_part))
+   goto out;
+
+   list_add_tail(_disk_part->list, _partitions);
+   valid_parts++;
+   }
+   if (!valid_parts) {
+   printf("** No valid partitions found **\n");
+   goto out;
+   }
+   return --valid_parts;
+ out:
+   if (valid_parts >= 2)
+   del_gpt_info();
+   return -ENODEV;
+}
+
+/* a wrapper to test get_gpt_info */
+static int do_get_gpt_info(struct blk_desc *dev_desc)
+{
+   int ret;
+
+   ret = get_gpt_info(dev_desc);
+   if (ret > 0) {
+   print_gpt_info();
+   del_gpt_info();
+   return 0;
+   }
+   return ret;
+}
+
 /**
  * set_gpt_info(): Fill partition information from string
  * function allocates memory, remember to free!
@@ -455,6 +570,8 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])

Re: [U-Boot] [PATCH v6 3/3] GPT: provide commands to selectively rename partitions

2017-06-25 Thread Alison Chaiken
On Sun, Jun 18, 2017 at 4:03 AM, Wolfgang Denk <w...@denx.de> wrote:

> Dear Alison,
>
> In message 

Re: [U-Boot] [PATCH] arm: ls1021atwr: Add distro boot support

2017-06-14 Thread Alison Wang
Hi, York,

> On 05/26/2017 01:01 AM, Alison Wang wrote:
> > This patch includes common config_distro_defaults.h and
> > config_distro_bootcmd.h for u-boot enviroments to support distro boot
> > which automatically scan boot.scr from storage devices(e.g.
> > SD/USB/SATA/SCSI disk) and execute autoboot script on LS1021ATWR
> board.
> >
> > Signed-off-by: Shengzhou Liu <shengzhou@nxp.com>
> > Signed-off-by: Alison Wang <alison.w...@nxp.com>
> > ---
> 
> Wouldn't it be helpful to document the steps for distro boot in board
> README file?
> 
[Alison Wang] As doc/README.distro gives enough descriptions, I think board 
README file couldn't give more.

Thanks.

Best Regards,
Alison Wang
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v6 3/3] GPT: provide commands to selectively rename partitions

2017-06-12 Thread Alison Chaiken
On Mon, Jun 12, 2017 at 12:45 AM, Wolfgang Denk <w...@denx.de> wrote:

> Dear Alison,
>
> In message <1497137617-772-1-git-send-email-ali...@peloton-tech.com> you
> wrote:
> >
> > This patch provides support in u-boot for renaming GPT
> > partitions.  The renaming is accomplished via new 'gpt swap'
> > and 'gpt rename' commands.
>
> Thanks.
>
> One question: can multiple GPT partitions have the same name?
>


The idea behind the 'swap' mode is that a storage device can have two sets
of partitions, one set all named 'primary' and one set all named 'backup'.
  The software updater in userspace can then simply rename the partitions
with sgdisk in order to pick the new image.   The swap mode changes the
whole set of labels at once, so there's little chance of being interrupted.


>
> > The 'swap' mode prints a warning if no matching partition names
> > are found.  If only one matching name of a provided pair is found, it
> > renames the matching partitions to the new name.
>
> I see a problem here...
>
> > + if (!strcmp(subcomm, "swap")) {
> > + if ((strlen(name1) > PART_NAME_LEN) || (strlen(name2) >
> PART_NAME_LEN)) {
> > + printf("Names longer than %d characters are
> truncated.\n", PART_NAME_LEN);
> > + return -EINVAL;
> > + }
> > + list_for_each(pos, _partitions) {
> > + curr = list_entry(pos, struct disk_part, list);
> > + if (!strcmp((char *)curr->gpt_part_info.name,
> name1)) {
> > + strcpy((char *)curr->gpt_part_info.name,
> name2);
> > + changed++;
> > + }
> > + else if (!strcmp((char *)curr->gpt_part_info.name,
> name2)) {
> > + strcpy((char *)curr->gpt_part_info.name,
> name1);
> > + changed++;
> > + }
> > +
> > + }
> > + if (changed == 0) {
> > + printf("No matching partition names were
> found.\n");
> > + return ret;
> > + }
>
> You will never know if there really was a pair of names that was
> swapped.  Just a single rename of name1->name2 _or_ of name2->name1
> will make the user think everything was fine.
>

Point taken.   The last version I posted has two counters instead of just
changed in order to address this problem.



> [Note: I'm in the process of relocating and will be offline for the
> next 2..3. days.  Don't expect more comments from mee soon.
> Sorry...]
> Best regards,
> Wolfgang Denk



One additional note: the last version I posted worked fine for the sandbox,
but wouldn't link for an ARM target with the Linaro toolchain, as the
linker couldn't find atoi().   I guess the libc for the x86 compiler
includes it.   To test on ARM, I copied in simple_atoi() from
lib/vsprintf.c, but assuredly that is an ugly solution.Does anyone have
a better idea to solve this problem?

Thanks,
Alison Chaiken
Peloton Technology
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v7] GPT: provide commands to selectively rename partitions

2017-06-11 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

This patch provides support in u-boot for renaming GPT
partitions.  The renaming is accomplished via new 'gpt swap'
and 'gpt rename' commands.

The 'swap' mode returns an error if no matching partition names
are found, or if the number of partitions with one name does not equal
the number with the second name.   The 'rename' variant always
succeeds as long as a partition with the provided number exists.

Rewriting the partition table has the side-effect that all partitions
end up with "msftdata" flag set.  The reason is that partition type
PARTITION_BASIC_DATA_GUID is hard-coded in the gpt_fill_pte()
function.  This does not appear to cause any harm.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 cmd/Kconfig|   8 ++
 cmd/gpt.c  | 236 +++--
 doc/README.gpt |  20 -
 3 files changed, 258 insertions(+), 6 deletions(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 412bf24..7b262de 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -595,6 +595,14 @@ config CMD_GPT
  Enable the 'gpt' command to ready and write GPT style partition
  tables.
 
+config CMD_GPT_RENAME
+   bool "GPT partition renaming commands"
+   depends on CMD_GPT
+   help
+ Enables the 'gpt' command to interchange names on two GPT
+ partitions via the 'gpt swap' command or to rename single
+ partitions via the 'rename' command.
+
 config CMD_ARMFLASH
#depends on FLASH_CFI_DRIVER
bool "armflash"
diff --git a/cmd/gpt.c b/cmd/gpt.c
index 669031f8..b0c9623 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -20,6 +20,9 @@
 #include 
 #include 
 #include 
+#include 
+
+extern int atoi(const char *nptr);
 
 static LIST_HEAD(disk_partitions);
 
@@ -194,16 +197,33 @@ static struct disk_part 
*allocate_disk_part(disk_partition_t *info, int partnum)
return newpart;
 }
 
+static void prettyprint_part_size(char *sizestr, unsigned long partsize,
+ unsigned long blksize)
+{
+   unsigned long long partbytes;
+   unsigned long partmegabytes;
+
+   partbytes = partsize * blksize;
+   partmegabytes = lldiv(partbytes, SZ_1M);
+   snprintf(sizestr, 16, "%luMiB", partmegabytes);
+}
+
 static void print_gpt_info(void)
 {
struct list_head *pos;
struct disk_part *curr;
+   char partstartstr[16];
+   char partsizestr[16];
 
list_for_each(pos, _partitions) {
curr = list_entry(pos, struct disk_part, list);
+   prettyprint_part_size(partstartstr, (unsigned 
long)curr->gpt_part_info.start,
+ (unsigned long) 
curr->gpt_part_info.blksz);
+   prettyprint_part_size(partsizestr, (unsigned 
long)curr->gpt_part_info.size,
+ (unsigned long) 
curr->gpt_part_info.blksz);
+
printf("Partition %d:\n", curr->partnum);
-   printf("1st block %x, size %x\n", 
(unsigned)curr->gpt_part_info.start,
-  (unsigned)curr->gpt_part_info.size);
+   printf("Start %s, size %s\n", partstartstr, partsizestr);
printf("Block size %lu, name %s\n", curr->gpt_part_info.blksz,
   curr->gpt_part_info.name);
printf("Type %s, bootable %d\n", curr->gpt_part_info.type,
@@ -215,6 +235,74 @@ static void print_gpt_info(void)
}
 }
 
+#ifdef CONFIG_CMD_GPT_RENAME
+static int calc_parts_list_len(int numparts)
+{
+   int partlistlen = UUID_STR_LEN + 1 + strlen("uuid_disk=");
+   /* for the comma */
+   partlistlen++;
+
+   /* per-partition additions; numparts starts at 1, so this should be 
correct */
+   partlistlen += numparts * (strlen("name=,") + PART_NAME_LEN + 1);
+   /* see part.h for definition of struct disk_partition */
+   partlistlen += numparts * (strlen("start=MiB,") + sizeof(lbaint_t) + 1);
+   partlistlen += numparts * (strlen("size=MiB,") + sizeof(lbaint_t) + 1);
+   partlistlen += numparts * (strlen("uuid=;") + UUID_STR_LEN + 1);
+   /* for the terminating null */
+   partlistlen++;
+   debug("Length of partitions_list is %d for %d partitions\n", 
partlistlen,
+  numparts);
+   return partlistlen;
+}
+
+/*
+ * create the string that upstream 'gpt write' command will accept as an
+ * argument
+ *
+ * From doc/README.gpt, Format of partitions layout:
+ *"uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
+ * name=kernel,size=60MiB,uuid=...;"
+ * The fields 'name' and 'size' are mandatory for every partition.
+ * The field 'start' is optional. The fields 'uuid' and 'uuid_disk'
+ * are optional if CONFIG_RANDOM_UUID is enabled.
+ 

[U-Boot] [PATCH v6 3/3] GPT: provide commands to selectively rename partitions

2017-06-10 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

This patch provides support in u-boot for renaming GPT
partitions.  The renaming is accomplished via new 'gpt swap'
and 'gpt rename' commands.

The 'swap' mode prints a warning if no matching partition names
are found.  If only one matching name of a provided pair is found, it
renames the matching partitions to the new name.

Rewriting the partition table has the side-effect that all partitions
end up with "msftdata" flag set.  The reason is that partition type
PARTITION_BASIC_DATA_GUID is hard-coded in the gpt_fill_pte()
function.  This does not appear to cause any harm.

Changes since v5:
-- The former 'gpt flip' is now 'gpt swap', which takes the two
   arbitrary partition names it exchanges as command-line input.
-- A new command, 'gpt rename', now allows renaming of single,
   specified partitions.
-- Updated README.gpt to reflect the changes.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 cmd/Kconfig|   8 ++
 cmd/gpt.c  | 239 +++--
 doc/README.gpt |  20 -
 3 files changed, 261 insertions(+), 6 deletions(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 412bf24..7b262de 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -595,6 +595,14 @@ config CMD_GPT
  Enable the 'gpt' command to ready and write GPT style partition
  tables.
 
+config CMD_GPT_RENAME
+   bool "GPT partition renaming commands"
+   depends on CMD_GPT
+   help
+ Enables the 'gpt' command to interchange names on two GPT
+ partitions via the 'gpt swap' command or to rename single
+ partitions via the 'rename' command.
+
 config CMD_ARMFLASH
#depends on FLASH_CFI_DRIVER
bool "armflash"
diff --git a/cmd/gpt.c b/cmd/gpt.c
index 669031f8..aa3245a 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -20,6 +20,9 @@
 #include 
 #include 
 #include 
+#include 
+
+extern int atoi(const char *nptr);
 
 static LIST_HEAD(disk_partitions);
 
@@ -194,16 +197,33 @@ static struct disk_part 
*allocate_disk_part(disk_partition_t *info, int partnum)
return newpart;
 }
 
+static void prettyprint_part_size(char *sizestr, unsigned long partsize,
+ unsigned long blksize)
+{
+   unsigned long long partbytes;
+   unsigned long partmegabytes;
+
+   partbytes = partsize * blksize;
+   partmegabytes = lldiv(partbytes, SZ_1M);
+   snprintf(sizestr, 16, "%luMiB", partmegabytes);
+}
+
 static void print_gpt_info(void)
 {
struct list_head *pos;
struct disk_part *curr;
+   char partstartstr[16];
+   char partsizestr[16];
 
list_for_each(pos, _partitions) {
curr = list_entry(pos, struct disk_part, list);
+   prettyprint_part_size(partstartstr, (unsigned 
long)curr->gpt_part_info.start,
+ (unsigned long) 
curr->gpt_part_info.blksz);
+   prettyprint_part_size(partsizestr, (unsigned 
long)curr->gpt_part_info.size,
+ (unsigned long) 
curr->gpt_part_info.blksz);
+
printf("Partition %d:\n", curr->partnum);
-   printf("1st block %x, size %x\n", 
(unsigned)curr->gpt_part_info.start,
-  (unsigned)curr->gpt_part_info.size);
+   printf("Start %s, size %s\n", partstartstr, partsizestr);
printf("Block size %lu, name %s\n", curr->gpt_part_info.blksz,
   curr->gpt_part_info.name);
printf("Type %s, bootable %d\n", curr->gpt_part_info.type,
@@ -215,6 +235,74 @@ static void print_gpt_info(void)
}
 }
 
+#ifdef CONFIG_CMD_GPT_RENAME
+static int calc_parts_list_len(int numparts)
+{
+   int partlistlen = UUID_STR_LEN + 1 + strlen("uuid_disk=");
+   /* for the comma */
+   partlistlen++;
+
+   /* per-partition additions; numparts starts at 1, so this should be 
correct */
+   partlistlen += numparts * (strlen("name=,") + PART_NAME_LEN + 1);
+   /* see part.h for definition of struct disk_partition */
+   partlistlen += numparts * (strlen("start=MiB,") + sizeof(lbaint_t) + 1);
+   partlistlen += numparts * (strlen("size=MiB,") + sizeof(lbaint_t) + 1);
+   partlistlen += numparts * (strlen("uuid=;") + UUID_STR_LEN + 1);
+   /* for the terminating null */
+   partlistlen++;
+   debug("Length of partitions_list is %d for %d partitions\n", 
partlistlen,
+  numparts);
+   return partlistlen;
+}
+
+/*
+ * create the string that upstream 'gpt write' command will accept as an
+ * argument
+ *
+ * From doc/README.gpt, Format of partitions layout:
+ *"uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
+ * name=kernel,size=60MiB,uuid=...;"
+ 

Re: [U-Boot] [PATCH v5 3/3] rename GPT partitions to detect boot failure

2017-06-10 Thread Alison Chaiken
On Fri, Jun 9, 2017 at 11:51 PM, Wolfgang Denk <w...@denx.de> wrote:

> I think you are talking about two parts here, and I strongly feel
> these should be kept separate.
>
> The first part is support for renaming GPT partitions.  The idea is
> clean, but should it not rather be kept general and let the user
> provide the new name as argument, i. e. implement a generic
> "gpt rename" command instead of a hard-wired "gpt flip"?
>
> The second part is the flipping of the partition names.  This is in
> my opinion policy, and should also not be hardwaired into this
> command, but left to the user.  Maybe I do nmot want to fall back to
> the ‘backup’ partition after a single boot attempt, but instead try
> other things first, like booting another kernel or another device
> tree blob?
>
> I feel this should be not so much hardwired, but leave more freedom
> for the user's creativity.
>

Lukasz has already made similar suggestions.   In the following message is
a new version which attempts to implement them.

Thanks to Lothar and Lukasz for all their help.

Best wishes,
Alison Chaiken
Peloton Technology
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 3/3] rename GPT partitions to detect boot failure

2017-06-09 Thread alison
From: Alison Chaiken <ali...@she-devel.com>

This patch provides support in u-boot for renaming GPT
partitions.  The renaming is accomplished via a new 'gpt flip'
command.

The concept for the bootloader state machine is the following:

-- u-boot renames ‘primary’ partitions as ‘candidate’ and tries
   to boot them.
-- Linux, at boot, will rename ‘candidate’ partitions as
   ‘primary’.
-- If u-boot sees a ‘candidate’ partition after a boot attempt,
   it tries to boot the ‘backup’ partition.

Rewriting the partition table has the side-effect that all partitions
end up with "msftdata" flag set.  The reason is that partition type
PARTITION_BASIC_DATA_GUID is hard-coded in the gpt_fill_pte()
function.  This does not appear to cause any harm.

Changes since v4:
-- Changed the erroneous '17' values in calc_parts_list_len() to
   match the definition of struct disk_partition in part.h.
-- Modified do_gpt() so that the 'gpt flip' command prints
   "success!" or "error!" on exit.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 cmd/Kconfig|   7 +++
 cmd/gpt.c  | 190 +++--
 doc/README.gpt |  13 
 3 files changed, 206 insertions(+), 4 deletions(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 270cff6..880ca97 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -593,6 +593,13 @@ config CMD_GPT
  Enable the 'gpt' command to ready and write GPT style partition
  tables.
 
+config CMD_GPT_FLIP
+   bool "GPT flip-partitions command"
+   depends on CMD_GPT
+   help
+ Enables the 'gpt' command to write modified GPT partition
+ tables via the 'gpt flip' command.
+
 config CMD_ARMFLASH
#depends on FLASH_CFI_DRIVER
bool "armflash"
diff --git a/cmd/gpt.c b/cmd/gpt.c
index 669031f8..ad7c7ec 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static LIST_HEAD(disk_partitions);
 
@@ -194,16 +195,33 @@ static struct disk_part 
*allocate_disk_part(disk_partition_t *info, int partnum)
return newpart;
 }
 
+static void prettyprint_part_size(char *sizestr, unsigned long partsize,
+ unsigned long blksize)
+{
+   unsigned long long partbytes;
+   unsigned long partmegabytes;
+
+   partbytes = partsize * blksize;
+   partmegabytes = lldiv(partbytes, SZ_1M);
+   snprintf(sizestr, 16, "%luMiB", partmegabytes);
+}
+
 static void print_gpt_info(void)
 {
struct list_head *pos;
struct disk_part *curr;
+   char partstartstr[16];
+   char partsizestr[16];
 
list_for_each(pos, _partitions) {
curr = list_entry(pos, struct disk_part, list);
+   prettyprint_part_size(partstartstr, (unsigned 
long)curr->gpt_part_info.start,
+ (unsigned long) 
curr->gpt_part_info.blksz);
+   prettyprint_part_size(partsizestr, (unsigned 
long)curr->gpt_part_info.size,
+ (unsigned long) 
curr->gpt_part_info.blksz);
+
printf("Partition %d:\n", curr->partnum);
-   printf("1st block %x, size %x\n", 
(unsigned)curr->gpt_part_info.start,
-  (unsigned)curr->gpt_part_info.size);
+   printf("Start %s, size %s\n", partstartstr, partsizestr);
printf("Block size %lu, name %s\n", curr->gpt_part_info.blksz,
   curr->gpt_part_info.name);
printf("Type %s, bootable %d\n", curr->gpt_part_info.type,
@@ -215,6 +233,74 @@ static void print_gpt_info(void)
}
 }
 
+#ifdef CONFIG_CMD_GPT_FLIP
+static int calc_parts_list_len(int numparts)
+{
+   int partlistlen = UUID_STR_LEN + 1 + strlen("uuid_disk=");
+   /* for the comma */
+   partlistlen++;
+
+   /* per-partition additions; numparts starts at 1, so this should be 
correct */
+   partlistlen += numparts * (strlen("name=,") + PART_NAME_LEN + 1);
+   /* see part.h for definition of struct disk_partition */
+   partlistlen += numparts * (strlen("start=MiB,") + sizeof(lbaint_t) + 1);
+   partlistlen += numparts * (strlen("size=MiB,") + sizeof(lbaint_t) + 1);
+   partlistlen += numparts * (strlen("uuid=;") + UUID_STR_LEN + 1);
+   /* for the terminating null */
+   partlistlen++;
+   debug("Length of partitions_list is %d for %d partitions\n", 
partlistlen,
+  numparts);
+   return partlistlen;
+}
+
+/*
+ * create the string that upstream 'gpt write' command will accept as an
+ * argument
+ *
+ * From doc/README.gpt, Format of partitions layout:
+ *"uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
+ * name=kernel,size=60MiB,uuid=...;"
+ * The fields 'name' 

[U-Boot] [PATCH v5 2/3] GPT: read partition table from device into a data structure

2017-06-09 Thread alison
From: Alison Chaiken <ali...@she-devel.com>

Make the partition table available for modification by reading it from
the user-specified device into a linked list.   Provide an accessor
function for command-line testing.

Changes since v4:
-- Made do_get_gpt_info() return 0 upon success so that now, in the
   sandbox, u-boot prints a "success!" exit message.
-- Created a single exit point for get_gpt_info(), with the
   result that after an error, del_gpt_info() always removes the
   list.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 cmd/gpt.c  | 120 +
 include/part.h |   7 
 2 files changed, 127 insertions(+)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index 65fb80b..669031f8 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -19,6 +19,9 @@
 #include 
 #include 
 #include 
+#include 
+
+static LIST_HEAD(disk_partitions);
 
 /**
  * extract_env(): Expand env name from string format '&{env_name}'
@@ -151,6 +154,119 @@ static bool found_key(const char *str, const char *key)
return result;
 }
 
+static void del_gpt_info(void)
+{
+   struct list_head *pos = _partitions;
+   struct disk_part *curr;
+   while (!list_empty(pos)) {
+   curr = list_entry(pos->next, struct disk_part, list);
+   list_del(pos->next);
+   free(curr);
+   }
+}
+
+static struct disk_part *allocate_disk_part(disk_partition_t *info, int 
partnum)
+{
+   struct disk_part *newpart;
+   newpart = (struct disk_part *)malloc(sizeof(*newpart));
+   if (!newpart)
+   return ERR_PTR(-ENOMEM);
+   memset(newpart, '\0', sizeof(newpart));
+
+   newpart->gpt_part_info.start = info->start;
+   newpart->gpt_part_info.size = info->size;
+   newpart->gpt_part_info.blksz = info->blksz;
+   strncpy((char *)newpart->gpt_part_info.name, (const char *)info->name,
+   PART_NAME_LEN);
+   newpart->gpt_part_info.name[PART_NAME_LEN - 1] = '\0';
+   strncpy((char *)newpart->gpt_part_info.type, (const char *)info->type,
+   PART_TYPE_LEN);
+   newpart->gpt_part_info.type[PART_TYPE_LEN - 1] = '\0';
+   newpart->gpt_part_info.bootable = info->bootable;
+#ifdef CONFIG_PARTITION_UUIDS
+   strncpy(newpart->gpt_part_info.uuid, (const char *)info->uuid,
+   UUID_STR_LEN);
+   /* UUID_STR_LEN is correct, as uuid[]'s length is UUID_STR_LEN+1 chars 
*/
+   newpart->gpt_part_info.uuid[UUID_STR_LEN] = '\0';
+#endif
+   newpart->partnum = partnum;
+
+   return newpart;
+}
+
+static void print_gpt_info(void)
+{
+   struct list_head *pos;
+   struct disk_part *curr;
+
+   list_for_each(pos, _partitions) {
+   curr = list_entry(pos, struct disk_part, list);
+   printf("Partition %d:\n", curr->partnum);
+   printf("1st block %x, size %x\n", 
(unsigned)curr->gpt_part_info.start,
+  (unsigned)curr->gpt_part_info.size);
+   printf("Block size %lu, name %s\n", curr->gpt_part_info.blksz,
+  curr->gpt_part_info.name);
+   printf("Type %s, bootable %d\n", curr->gpt_part_info.type,
+  curr->gpt_part_info.bootable);
+#ifdef CONFIG_PARTITION_UUIDS
+   printf("UUID %s\n", curr->gpt_part_info.uuid);
+#endif
+   printf("\n");
+   }
+}
+
+/*
+ * read partition info into disk_partitions list where
+ * it can be printed or modified
+ */
+static int get_gpt_info(struct blk_desc *dev_desc)
+{
+   /* start partition numbering at 1, as U-Boot does */
+   int valid_parts = 1, p, ret;
+   disk_partition_t info;
+   struct disk_part *new_disk_part;
+
+   if (disk_partitions.next == NULL)
+   INIT_LIST_HEAD(_partitions);
+
+   for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
+   ret = part_get_info(dev_desc, p, );
+   if (ret)
+   continue;
+
+   new_disk_part = allocate_disk_part(, valid_parts);
+   if (IS_ERR(new_disk_part))
+   goto out;
+
+   list_add_tail(_disk_part->list, _partitions);
+   valid_parts++;
+   }
+   if (!valid_parts) {
+   printf("** No valid partitions found **\n");
+   goto out;
+   }
+   return --valid_parts;
+ out:
+   if (valid_parts >= 2)
+   del_gpt_info();
+   return -ENODEV;
+}
+
+/* a wrapper to test get_gpt_info */
+static int do_get_gpt_info(struct blk_desc *dev_desc)
+{
+   int ret;
+
+   ret = get_gpt_info(dev_desc);
+   if (ret > 0) {
+   print_gpt_info();
+   del_gpt_info();
+   return 0;
+   }
+   return ret;
+}
+
+
 /**
  * set_g

[U-Boot] [PATCH v5 1/3] GPT: add accessor function for disk GUID

2017-06-09 Thread alison
From: Alison Chaiken <ali...@she-devel.com>

In order to read the GPT, modify the partition name strings, and then
write out a new GPT, the disk GUID is needed.  While there is an
existing accessor for the partition UUIDs, there is none yet for the
disk GUID.

Changes since v4:
-- Made do_disk_guid() return 0 upon success so that now, in the
   sandbox, u-boot prints a "success!" exit message.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 cmd/gpt.c   | 26 ++
 disk/part_efi.c | 31 +++
 doc/README.gpt  |  3 ++-
 include/part.h  | 15 +++
 4 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index 3e98821..65fb80b 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -398,6 +398,23 @@ static int gpt_verify(struct blk_desc *blk_dev_desc, const 
char *str_part)
return ret;
 }
 
+static int do_disk_guid(struct blk_desc *dev_desc, char * const namestr)
+{
+   int ret;
+   char disk_guid[UUID_STR_LEN + 1];
+
+   ret = get_disk_guid(dev_desc, disk_guid);
+   if (ret < 0)
+   return CMD_RET_FAILURE;
+
+   if (namestr)
+   setenv(namestr, disk_guid);
+   else
+   printf("%s\n", disk_guid);
+
+   return ret;
+}
+
 /**
  * do_gpt(): Perform GPT operations
  *
@@ -436,6 +453,8 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
} else if ((strcmp(argv[1], "verify") == 0)) {
ret = gpt_verify(blk_dev_desc, argv[4]);
printf("Verify GPT: ");
+   } else if (strcmp(argv[1], "guid") == 0) {
+   ret = do_disk_guid(blk_dev_desc, argv[4]);
} else {
return CMD_RET_USAGE;
}
@@ -458,4 +477,11 @@ U_BOOT_CMD(gpt, CONFIG_SYS_MAXARGS, 1, do_gpt,
" Example usage:\n"
" gpt write mmc 0 $partitions\n"
" gpt verify mmc 0 $partitions\n"
+   " guid  \n"
+   "- print disk GUID\n"
+   " guid   \n"
+   "- set environment variable to disk GUID\n"
+   " Example usage:\n"
+   " gpt guid mmc 0\n"
+   " gpt guid mmc 0 varname\n"
 );
diff --git a/disk/part_efi.c b/disk/part_efi.c
index 20d33ef..71c3cb3 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -178,6 +178,37 @@ static void prepare_backup_gpt_header(gpt_header *gpt_h)
  * Public Functions (include/part.h)
  */
 
+/*
+ * UUID is displayed as 32 hexadecimal digits, in 5 groups,
+ * separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters
+ */
+int get_disk_guid(struct blk_desc * dev_desc, char *guid)
+{
+   ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
+   gpt_entry *gpt_pte = NULL;
+   unsigned char *guid_bin;
+
+   /* This function validates AND fills in the GPT header and PTE */
+   if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA,
+gpt_head, _pte) != 1) {
+   printf("%s: *** ERROR: Invalid GPT ***\n", __func__);
+   if (is_gpt_valid(dev_desc, dev_desc->lba - 1,
+gpt_head, _pte) != 1) {
+   printf("%s: *** ERROR: Invalid Backup GPT ***\n",
+  __func__);
+   return -EINVAL;
+   } else {
+   printf("%s: ***Using Backup GPT ***\n",
+  __func__);
+   }
+   }
+
+   guid_bin = gpt_head->disk_guid.b;
+   uuid_bin_to_str(guid_bin, guid, UUID_STR_FORMAT_GUID);
+
+   return 0;
+}
+
 void part_print_efi(struct blk_desc *dev_desc)
 {
ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
diff --git a/doc/README.gpt b/doc/README.gpt
index 3fcd835..c0779a4 100644
--- a/doc/README.gpt
+++ b/doc/README.gpt
@@ -171,7 +171,8 @@ To restore GUID partition table one needs to:
The fields 'uuid' and 'uuid_disk' are optional if CONFIG_RANDOM_UUID is
enabled. A random uuid will be used if omitted or they point to an empty/
non-existent environment variable. The environment variable will be set to
-   the generated UUID.
+   the generated UUID.  The 'gpt guid' command reads the current value of the
+   uuid_disk from the GPT.
 
The field 'bootable' is optional, it is used to mark the GPT partition
bootable (set attribute flags "Legacy BIOS bootable").
diff --git a/include/part.h b/include/part.h
index 87b..16c4a46 100644
--- a/include/part.h
+++ b/include/part.h
@@ -371,6 +371,21 @@ int gpt_verify_headers(struct blk_desc *dev_desc, 
gpt_header *gpt_head,
 int gpt_verify_partitions(struct blk_desc *dev_desc,
  disk_partition_t *partitions, int parts,
 

[U-Boot] [PATCH] armv8: Remove duplicate definition for IH_ARCH_ARM and IH_ARCH_ARM64

2017-06-08 Thread Alison Wang
The duplicate definitions for IH_ARCH_ARM and IH_ARCH_ARM64 are removed.
The definitions in  are used.

According to this modification, the comparison between os arch and cpu
arch is done in C programming instead of ASM programming.

Signed-off-by: Alison Wang <alison.w...@nxp.com>
---
 arch/arm/cpu/armv8/fsl-layerscape/lowlevel.S  |  8 ++--
 arch/arm/cpu/armv8/fsl-layerscape/mp.c| 11 ---
 arch/arm/include/asm/arch-fsl-layerscape/mp.h | 13 -
 3 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/arch/arm/cpu/armv8/fsl-layerscape/lowlevel.S 
b/arch/arm/cpu/armv8/fsl-layerscape/lowlevel.S
index 619d9b7..3136e3f 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/lowlevel.S
+++ b/arch/arm/cpu/armv8/fsl-layerscape/lowlevel.S
@@ -497,9 +497,7 @@ slave_cpu:
rev x0, x0  /* BE to LE conversion */
 cpu_is_le:
ldr x5, [x11, #24]
-   ldr x6, =IH_ARCH_DEFAULT
-   cmp x6, x5
-   b.eq1f
+   cbz x5, 1f
 
 #ifdef CONFIG_ARMV8_SWITCH_TO_EL1
adr x4, secondary_switch_to_el1
@@ -541,9 +539,7 @@ ENTRY(secondary_switch_to_el1)
ldr x4, [x11]
 
ldr x5, [x11, #24]
-   ldr x6, =IH_ARCH_DEFAULT
-   cmp x6, x5
-   b.eq2f
+   cbz x5, 2f
 
ldr x5, =ES_TO_AARCH32
bl  switch_to_el1
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/mp.c 
b/arch/arm/cpu/armv8/fsl-layerscape/mp.c
index 80fe1ad..ab61ac3 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/mp.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/mp.c
@@ -29,9 +29,14 @@ void update_os_arch_secondary_cores(uint8_t os_arch)
u64 *table = get_spin_tbl_addr();
int i;
 
-   for (i = 1; i < CONFIG_MAX_CPUS; i++)
-   table[i * WORDS_PER_SPIN_TABLE_ENTRY +
-   SPIN_TABLE_ELEM_OS_ARCH_IDX] = os_arch;
+   for (i = 1; i < CONFIG_MAX_CPUS; i++) {
+   if (os_arch == IH_ARCH_DEFAULT)
+   table[i * WORDS_PER_SPIN_TABLE_ENTRY +
+   SPIN_TABLE_ELEM_ARCH_COMP_IDX] = OS_ARCH_SAME;
+   else
+   table[i * WORDS_PER_SPIN_TABLE_ENTRY +
+   SPIN_TABLE_ELEM_ARCH_COMP_IDX] = OS_ARCH_DIFF;
+   }
 }
 
 #ifdef CONFIG_FSL_LSCH3
diff --git a/arch/arm/include/asm/arch-fsl-layerscape/mp.h 
b/arch/arm/include/asm/arch-fsl-layerscape/mp.h
index fd3f851..88f40c0 100644
--- a/arch/arm/include/asm/arch-fsl-layerscape/mp.h
+++ b/arch/arm/include/asm/arch-fsl-layerscape/mp.h
@@ -13,7 +13,7 @@
 *  uint64_t entry_addr;
 *  uint64_t status;
 *  uint64_t lpid;
-*  uint64_t os_arch;
+*  uint64_t arch_comp;
 * };
 * we pad this struct to 64 bytes so each entry is in its own cacheline
 * the actual spin table is an array of these structures
@@ -21,10 +21,16 @@
 #define SPIN_TABLE_ELEM_ENTRY_ADDR_IDX 0
 #define SPIN_TABLE_ELEM_STATUS_IDX 1
 #define SPIN_TABLE_ELEM_LPID_IDX   2
-#define SPIN_TABLE_ELEM_OS_ARCH_IDX3
+/* compare os arch and cpu arch */
+#define SPIN_TABLE_ELEM_ARCH_COMP_IDX  3
 #define WORDS_PER_SPIN_TABLE_ENTRY 8   /* pad to 64 bytes */
 #define SPIN_TABLE_ELEM_SIZE   64
 
+/* os arch is same as cpu arch */
+#define OS_ARCH_SAME   0
+/* os arch is different from cpu arch */
+#define OS_ARCH_DIFF   1
+
 #define id_to_core(x)  ((x & 3) | (x >> 6))
 #ifndef __ASSEMBLY__
 extern u64 __spin_table[];
@@ -43,7 +49,4 @@ int is_core_online(u64 cpu_id);
 u32 cpu_pos_mask(void);
 #endif
 
-#define IH_ARCH_ARM2   /* ARM */
-#define IH_ARCH_ARM64  22  /* ARM64 */
-
 #endif /* _FSL_LAYERSCAPE_MP_H */
-- 
2.1.0.27.g96db324

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH] armv8: Support loading 32-bit OS which is not in the form of FIT

2017-06-08 Thread Alison Wang
Hi, Tom,

> On Tue, Jun 06, 2017 at 03:32:40PM +0800, Alison Wang wrote:
> 
> > As only FIT image is supported now, this patch is to support loading
> > 32-bit uImage, dtb and rootfs separately.
> >
> > Signed-off-by: Alison Wang <alison.w...@nxp.com>
> 
> Reviewed-by: Tom Rini <tr...@konsulko.com>
> 
> However, entirely unrelated, I found this while reviewing the patch:
> $ grep IH_ARCH_ arch/arm/include/asm/arch-fsl-layerscape/mp.h
> #define IH_ARCH_ARM 2   /* ARM */
> #define IH_ARCH_ARM64   22  /* ARM64 */
> 
> And that's dangerous and whatever needs those defines needs to be using
>  instead where we have the canonical enum of those values.
> Please correct this, thanks!
> 
[Alison Wang] Thanks for your suggestion. Yes, it's dangerous and  
should be used.

In , IH_ARCH_ARM and IH_ARCH_ARM64 are defined in an enumeration type. 
In the assembly file arch/arm/cpu/armv8/fsl-layerscape/lowlevel.S, 
IH_ARCH_DEFAULT is used.

#ifndef CONFIG_ARM64
#define IH_ARCH_DEFAULT IH_ARCH_ARM
#else
#define IH_ARCH_DEFAULT IH_ARCH_ARM64
#endif

So IH_ARCH_ARM or IH_ARCH_ARM64 need to be used in the assembly code. The way 
to include  in the assembly file will cause more problems.

I will send a patch to use IH_ARCH_ARM and IH_ARCH_ARM64 in the C programming, 
and remove the duplicate definition in mp.h.

Best Regards,
Alison Wang
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] armv8: Support loading 32-bit OS which is not in the form of FIT

2017-06-06 Thread Alison Wang
As only FIT image is supported now, this patch is to support loading
32-bit uImage, dtb and rootfs separately.

Signed-off-by: Alison Wang <alison.w...@nxp.com>
---
 include/image.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/image.h b/include/image.h
index 8d380e0..fcfe730 100644
--- a/include/image.h
+++ b/include/image.h
@@ -785,7 +785,8 @@ static inline int image_check_type(const image_header_t 
*hdr, uint8_t type)
 }
 static inline int image_check_arch(const image_header_t *hdr, uint8_t arch)
 {
-   return (image_get_arch(hdr) == arch);
+   return (image_get_arch(hdr) == arch) ||
+   (image_get_arch(hdr) == IH_ARCH_ARM && arch == IH_ARCH_ARM64);
 }
 static inline int image_check_os(const image_header_t *hdr, uint8_t os)
 {
-- 
2.1.0.27.g96db324

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v4 1/5] GPT: read partition table from device into a data structure

2017-06-04 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

Make the partition table available for modification by reading it from
the user-specified device into a linked list.   Provide an accessor
function for command-line testing.

Changes since v3:
Fixed problem with NULL termination of the newly created uuid[]
member of the partitions list in allocate_disk_part.   This
version has been tested in the u-boot sandbox.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 cmd/gpt.c  | 116 +
 include/part.h |   7 
 2 files changed, 123 insertions(+)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index 4d00a35..e898f35 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -19,6 +19,9 @@
 #include 
 #include 
 #include 
+#include 
+
+static LIST_HEAD(disk_partitions);
 
 /**
  * extract_env(): Expand env name from string format '&{env_name}'
@@ -151,6 +154,115 @@ static bool found_key(const char *str, const char *key)
return result;
 }
 
+static void del_gpt_info(void)
+{
+   struct list_head *pos = _partitions;
+   struct disk_part *curr;
+   while (!list_empty(pos)) {
+   curr = list_entry(pos->next, struct disk_part, list);
+   list_del(pos->next);
+   free(curr);
+   }
+}
+
+static struct disk_part *allocate_disk_part(disk_partition_t *info, int 
partnum)
+{
+   struct disk_part *newpart;
+   newpart = (struct disk_part *)malloc(sizeof(*newpart));
+   if (!newpart)
+   return ERR_PTR(-ENOMEM);
+   memset(newpart, '\0', sizeof(newpart));
+
+   newpart->gpt_part_info.start = info->start;
+   newpart->gpt_part_info.size = info->size;
+   newpart->gpt_part_info.blksz = info->blksz;
+   strncpy((char *)newpart->gpt_part_info.name, (const char *)info->name,
+   PART_NAME_LEN);
+   newpart->gpt_part_info.name[PART_NAME_LEN - 1] = '\0';
+   strncpy((char *)newpart->gpt_part_info.type, (const char *)info->type,
+   PART_TYPE_LEN);
+   newpart->gpt_part_info.type[PART_TYPE_LEN - 1] = '\0';
+   newpart->gpt_part_info.bootable = info->bootable;
+#ifdef CONFIG_PARTITION_UUIDS
+   strncpy(newpart->gpt_part_info.uuid, (const char *)info->uuid,
+   UUID_STR_LEN);
+   /* UUID_STR_LEN is correct, as uuid[]'s length is UUID_STR_LEN+1 chars 
*/
+   newpart->gpt_part_info.uuid[UUID_STR_LEN] = '\0';
+#endif
+   newpart->partnum = partnum;
+
+   return newpart;
+}
+
+static void print_gpt_info(void)
+{
+   struct list_head *pos;
+   struct disk_part *curr;
+
+   list_for_each(pos, _partitions) {
+   curr = list_entry(pos, struct disk_part, list);
+   printf("Partition %d:\n", curr->partnum);
+   printf("1st block %x, size %x\n", 
(unsigned)curr->gpt_part_info.start,
+  (unsigned)curr->gpt_part_info.size);
+   printf("Block size %lu, name %s\n", curr->gpt_part_info.blksz,
+  curr->gpt_part_info.name);
+   printf("Type %s, bootable %d\n", curr->gpt_part_info.type,
+  curr->gpt_part_info.bootable);
+#ifdef CONFIG_PARTITION_UUIDS
+   printf("UUID %s\n", curr->gpt_part_info.uuid);
+#endif
+   printf("\n");
+   }
+}
+
+/*
+ * read partition info into disk_partitions list where
+ * it can be printed or modified
+ */
+static int get_gpt_info(struct blk_desc *dev_desc)
+{
+   /* start partition numbering at 1, as U-Boot does */
+   int valid_parts = 1, p, ret;
+   disk_partition_t info;
+   struct disk_part *new_disk_part;
+
+   if (disk_partitions.next == NULL)
+   INIT_LIST_HEAD(_partitions);
+
+   for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
+   ret = part_get_info(dev_desc, p, );
+   if (ret)
+   continue;
+
+   new_disk_part = allocate_disk_part(, valid_parts);
+   if (IS_ERR(new_disk_part) && valid_parts >= 2)
+   return -ENODEV;
+
+   list_add_tail(_disk_part->list, _partitions);
+   valid_parts++;
+   }
+   if (!valid_parts) {
+   printf("** No valid partitions found **\n");
+   del_gpt_info();
+   return -ENODEV;
+   }
+   return --valid_parts;
+}
+
+/* a wrapper to test get_gpt_info */
+static int do_get_gpt_info(struct blk_desc *dev_desc)
+{
+   int ret;
+
+   ret = get_gpt_info(dev_desc);
+   if (ret > 0) {
+   print_gpt_info();
+   del_gpt_info();
+   }
+   return ret;
+}
+
+
 /**
  * set_gpt_info(): Fill partition information from string
  * function allocates memory, remember to free!
@@ -455,6 +567,8 @@ s

[U-Boot] [PATCH 4/5] sandbox: README: fix partition command invocation

2017-06-04 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

The instructions for creating a disk image that are presently in
README.sandbox fail because sfdisk doesn't know about GPT.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 board/sandbox/README.sandbox | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/board/sandbox/README.sandbox b/board/sandbox/README.sandbox
index 02d8ab3..9dc2eb0 100644
--- a/board/sandbox/README.sandbox
+++ b/board/sandbox/README.sandbox
@@ -333,7 +333,7 @@ the contents of the root directory on the second partion of 
the image
 A disk image can be created using the following commands:
 
 $> truncate -s 1200M ./disk.raw
-$> echo -e "label: gpt\n,64M,U\n,,L" | /usr/sbin/sfdisk  ./disk.raw
+$> echo -e "label: gpt\n,64M,U\n,,L" | /usr/sbin/sgdisk  ./disk.raw
 $> lodev=`sudo losetup -P -f --show ./disk.raw`
 $> sudo mkfs.vfat -n EFI -v ${lodev}p1
 $> sudo mkfs.ext4 -L ROOT -v ${lodev}p2
-- 
2.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v4 3/5] GPT: fix error in partitions string doc

2017-06-04 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

The existing partitions-list parsing in cmd/gpt.c passes a value
from gpt_default() to set_gpt_info() that README.gpt suggests
should begin with 'partitions='.  Partition-list strings should
in fact begin with 'uuid_disk', as otherwise the call from
set_gpt_info() to extract_val() to find 'uuid_disk' will fail.
Change README.gpt accordingly.

Changes since v3:
-- The part of this patch dealing with the partition-flipping
   behavior was squashed into the patch that introduces that
   feature.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 doc/README.gpt | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/doc/README.gpt b/doc/README.gpt
index e29b188..754e490 100644
--- a/doc/README.gpt
+++ b/doc/README.gpt
@@ -156,10 +156,10 @@ Creating GPT partitions in U-Boot:
 To restore GUID partition table one needs to:
 1. Define partition layout in the environment.
Format of partitions layout:
- "partitions=uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
+ "uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
name=kernel,size=60MiB,uuid=...;"
  or
- "partitions=uuid_disk=${uuid_gpt_disk};name=${uboot_name},
+ "uuid_disk=${uuid_gpt_disk};name=${uboot_name},
size=${uboot_size},uuid=${uboot_uuid};"
 
The fields 'name' and 'size' are mandatory for every partition.
@@ -233,7 +233,7 @@ PARTITION_BASIC_DATA_GUID 
(EBD0A0A2-B9E5-4433-87C0-68B6B72699C7).
 If you define 'CONFIG_PARTITION_TYPE_GUID', a optionnal parameter 'type'
 can specify a other partition type guid:
 
- "partitions=uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
+ "uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
name=kernel,size=60MiB,uuid=...,
type=0FC63DAF-8483-4772-8E79-3D69D8477DE4;"
 
@@ -255,7 +255,7 @@ Some strings can be also used at the place of known GUID :
"lvm"= PARTITION_LINUX_LVM_GUID
   (E6D6D379-F507-44C2-A23C-238F2A3DF928)
 
-"partitions=uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
+"uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
name=kernel,size=60MiB,uuid=...,type=linux;"
 
 They are also used to display the type of partition in "part list" command.
-- 
2.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 5/5] cmd gpt: test in sandbox

2017-06-04 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

Make minor changes to README.gpt and sandbox_defconfig to support
testing of the gpt command's functionality in the sandbox.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 doc/README.gpt | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/doc/README.gpt b/doc/README.gpt
index 754e490..7b3936b 100644
--- a/doc/README.gpt
+++ b/doc/README.gpt
@@ -224,6 +224,16 @@ U-BOOT> gpt flip mmc 0
 
 Choose different partition names by modifying these strings in gpt.c.
 
+The GPT functionality may be tested with the 'sandbox' board by
+creating a disk image as described under 'Block Device Emulation' in
+board/sandbox/README.sandbox:
+
+=>host bind 0 ./disk.raw
+=> gpt read host 0
+[ . . . ]
+=> gpt flip host 0
+[ . . . ]
+
 Partition type GUID:
 
 
-- 
2.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 4/5] rename GPT partitions to detect boot failure

2017-06-02 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

This patch provides support in u-boot for renaming GPT
partitions.  The renaming is accomplished via a new 'gpt flip'
command.

The concept for the bootloader state machine is the following:

-- u-boot renames ‘primary’ partitions as ‘candidate’ and tries
   to boot them.
-- Linux, at boot, will rename ‘candidate’ partitions as
   ‘primary’.
-- If u-boot sees a ‘candidate’ partition after a boot attempt,
   it tries to boot the ‘backup’ partition.

Rewriting the partition table has the side-effect that all partitions
end up with "msftdata" flag set.  The reason is that partition type
PARTITION_BASIC_DATA_GUID is hard-coded in the gpt_fill_pte()
function.  This does not appear to cause any harm.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 cmd/Kconfig|   7 ++
 cmd/gpt.c  | 199 +++--
 doc/README.gpt |  13 
 3 files changed, 215 insertions(+), 4 deletions(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 6f75b86..8b925e5 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -593,6 +593,13 @@ config CMD_GPT
  Enable the 'gpt' command to ready and write GPT style partition
  tables.
 
+config CMD_GPT_FLIP
+   bool "GPT flip-partitions command"
+   depends on CMD_GPT
+   help
+ Enables the 'gpt' command to write modified GPT partition
+ tables via the 'gpt flip' command.
+
 config CMD_ARMFLASH
#depends on FLASH_CFI_DRIVER
bool "armflash"
diff --git a/cmd/gpt.c b/cmd/gpt.c
index 5c2651f..f6968de 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static LIST_HEAD(disk_partitions);
 
@@ -190,16 +191,33 @@ static struct disk_part 
*allocate_disk_part(disk_partition_t *info, int partnum)
return newpart;
 }
 
+static void prettyprint_part_size(char *sizestr, unsigned long partsize,
+ unsigned long blksize)
+{
+   unsigned long long partbytes;
+   unsigned long partmegabytes;
+
+   partbytes = partsize * blksize;
+   partmegabytes = lldiv(partbytes, SZ_1M);
+   snprintf(sizestr, 16, "%luMiB", partmegabytes);
+}
+
 static void print_gpt_info(void)
 {
struct list_head *pos;
struct disk_part *curr;
+   char partstartstr[16];
+   char partsizestr[16];
 
list_for_each(pos, _partitions) {
curr = list_entry(pos, struct disk_part, list);
+   prettyprint_part_size(partstartstr, (unsigned 
long)curr->gpt_part_info.start,
+ (unsigned long) 
curr->gpt_part_info.blksz);
+   prettyprint_part_size(partsizestr, (unsigned 
long)curr->gpt_part_info.size,
+ (unsigned long) 
curr->gpt_part_info.blksz);
+
printf("Partition %d:\n", curr->partnum);
-   printf("1st block %x, size %x\n", 
(unsigned)curr->gpt_part_info.start,
-  (unsigned)curr->gpt_part_info.size);
+   printf("Start %s, size %s\n", partstartstr, partsizestr);
printf("Block size %lu, name %s\n", curr->gpt_part_info.blksz,
   curr->gpt_part_info.name);
printf("Type %s, bootable %d\n", curr->gpt_part_info.type,
@@ -211,6 +229,85 @@ static void print_gpt_info(void)
}
 }
 
+#ifdef CONFIG_CMD_GPT_FLIP
+static int calc_parts_list_len(int numparts)
+{
+   /*
+* prefatory string:
+* doc/README.GPT, suggests that
+* int partlistlen = UUID_STR_LEN + 1 + strlen("partitions=uuid_disk=");
+* is correct, but extract_val() expects "uuid_disk" first.
+*/
+   int partlistlen = UUID_STR_LEN + 1 + strlen("uuid_disk=");
+   /* for the comma */
+   partlistlen++;
+
+   /* per-partition additions; numparts starts at 1, so this should be 
correct */
+   partlistlen += numparts * (strlen("name=,") + PART_NAME_LEN + 1);
+   /* 17 because partstr in create_gpt_partitions_list() is 16 chars */
+   partlistlen += numparts * (strlen("start=MiB,") + 17);
+   partlistlen += numparts * (strlen("size=MiB,") + 17);
+   partlistlen += numparts * (strlen("uuid=;") + UUID_STR_LEN + 1);
+   /* for the terminating null */
+   partlistlen++;
+   debug("Length of partitions_list is %d for %d partitions\n", 
partlistlen,
+  numparts);
+   return partlistlen;
+}
+
+/*
+ * create the string that upstream 'gpt write' command will accept as an
+ * argument
+ *
+ * From doc/README.gpt, Format of partitions layout:
+ *"partitions=uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
+ * name=kernel,size=60MiB,uuid=...;"
+ * The fields 'name' and 'size' a

[U-Boot] [PATCH v3 5/5] GPT: fix error in partitions string doc

2017-06-02 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

The existing partitions-list parsing in cmd/gpt.c passes a value
from gpt_default() to set_gpt_info() that README.gpt suggests
should begin with 'partitions='.  Partition-list strings should
in fact begin with 'uuid_disk', as otherwise the call from
set_gpt_info() to extract_val() to find 'uuid_disk' will fail.
Change README.gpt and file comments accordingly.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 cmd/gpt.c  | 13 +
 doc/README.gpt |  8 
 2 files changed, 5 insertions(+), 16 deletions(-)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index f6968de..e2cb2a1 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -232,12 +232,6 @@ static void print_gpt_info(void)
 #ifdef CONFIG_CMD_GPT_FLIP
 static int calc_parts_list_len(int numparts)
 {
-   /*
-* prefatory string:
-* doc/README.GPT, suggests that
-* int partlistlen = UUID_STR_LEN + 1 + strlen("partitions=uuid_disk=");
-* is correct, but extract_val() expects "uuid_disk" first.
-*/
int partlistlen = UUID_STR_LEN + 1 + strlen("uuid_disk=");
/* for the comma */
partlistlen++;
@@ -260,7 +254,7 @@ static int calc_parts_list_len(int numparts)
  * argument
  *
  * From doc/README.gpt, Format of partitions layout:
- *"partitions=uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
+ *"uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
  * name=kernel,size=60MiB,uuid=...;"
  * The fields 'name' and 'size' are mandatory for every partition.
  * The field 'start' is optional. The fields 'uuid' and 'uuid_disk'
@@ -275,11 +269,6 @@ static int create_gpt_partitions_list(int numparts, const 
char *guid, char *part
if (!partitions_list)
return -1;
 
-   /*
-* README.gpt specifies starting with "partitions=" like so:
-*  strcpy(partitions_list, "partitions=uuid_disk=");
-* but that breaks extract_val, which doesn't skip over 'partitions='.
-*/
strcpy(partitions_list, "uuid_disk=");
strncat(partitions_list, guid, UUID_STR_LEN + 1);
strcat(partitions_list, ";");
diff --git a/doc/README.gpt b/doc/README.gpt
index e29b188..754e490 100644
--- a/doc/README.gpt
+++ b/doc/README.gpt
@@ -156,10 +156,10 @@ Creating GPT partitions in U-Boot:
 To restore GUID partition table one needs to:
 1. Define partition layout in the environment.
Format of partitions layout:
- "partitions=uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
+ "uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
name=kernel,size=60MiB,uuid=...;"
  or
- "partitions=uuid_disk=${uuid_gpt_disk};name=${uboot_name},
+ "uuid_disk=${uuid_gpt_disk};name=${uboot_name},
size=${uboot_size},uuid=${uboot_uuid};"
 
The fields 'name' and 'size' are mandatory for every partition.
@@ -233,7 +233,7 @@ PARTITION_BASIC_DATA_GUID 
(EBD0A0A2-B9E5-4433-87C0-68B6B72699C7).
 If you define 'CONFIG_PARTITION_TYPE_GUID', a optionnal parameter 'type'
 can specify a other partition type guid:
 
- "partitions=uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
+ "uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
name=kernel,size=60MiB,uuid=...,
type=0FC63DAF-8483-4772-8E79-3D69D8477DE4;"
 
@@ -255,7 +255,7 @@ Some strings can be also used at the place of known GUID :
"lvm"= PARTITION_LINUX_LVM_GUID
   (E6D6D379-F507-44C2-A23C-238F2A3DF928)
 
-"partitions=uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
+"uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
name=kernel,size=60MiB,uuid=...,type=linux;"
 
 They are also used to display the type of partition in "part list" command.
-- 
2.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 2/5] partitions: increase MAX_SEARCH_PARTITIONS and move to part.h

2017-06-02 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

Move MAX_SEARCH_PARTITIONS to part.h so that functions in cmd
directory can find it.  At the same time, increase the value to
64 since some operating systems use many, and the resources
consumed by a larger value are minimal.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 disk/part.c| 1 -
 include/part.h | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/disk/part.c b/disk/part.c
index 491b02d..e640a55 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -388,7 +388,6 @@ cleanup:
 
 #define PART_UNSPECIFIED -2
 #define PART_AUTO -1
-#define MAX_SEARCH_PARTITIONS 16
 int blk_get_device_part_str(const char *ifname, const char *dev_part_str,
 struct blk_desc **dev_desc,
 disk_partition_t *info, int allow_whole_dev)
diff --git a/include/part.h b/include/part.h
index 16c4a46..c41aa6a 100644
--- a/include/part.h
+++ b/include/part.h
@@ -49,6 +49,7 @@ struct block_drvr {
 
 #define PART_NAME_LEN 32
 #define PART_TYPE_LEN 32
+#define MAX_SEARCH_PARTITIONS 64
 
 typedef struct disk_partition {
lbaint_tstart;  /* # of first block in partition*/
-- 
2.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 3/5] GPT: read partition table from device into a data structure

2017-06-02 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

Make the partition table available for modification by reading it from
the user-specified device into a linked list.   Provide an accessor
function for command-line testing.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 cmd/gpt.c  | 112 +
 include/part.h |   7 
 2 files changed, 119 insertions(+)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index 4d00a35..5c2651f 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -19,6 +19,9 @@
 #include 
 #include 
 #include 
+#include 
+
+static LIST_HEAD(disk_partitions);
 
 /**
  * extract_env(): Expand env name from string format '&{env_name}'
@@ -151,6 +154,111 @@ static bool found_key(const char *str, const char *key)
return result;
 }
 
+static void del_gpt_info(void)
+{
+   struct list_head *pos = _partitions;
+   struct disk_part *curr;
+   while (!list_empty(pos)) {
+   curr = list_entry(pos->next, struct disk_part, list);
+   list_del(pos->next);
+   free(curr);
+   }
+}
+
+static struct disk_part *allocate_disk_part(disk_partition_t *info, int 
partnum)
+{
+   struct disk_part *newpart;
+   newpart = (struct disk_part *)malloc(sizeof(*newpart));
+   if (!newpart)
+   return ERR_PTR(-ENOMEM);
+   memset(newpart, '\0', sizeof(newpart));
+
+   newpart->gpt_part_info.start = info->start;
+   newpart->gpt_part_info.size = info->size;
+   newpart->gpt_part_info.blksz = info->blksz;
+   strncpy((char *)newpart->gpt_part_info.name, (const char *)info->name, 
PART_NAME_LEN);
+   newpart->gpt_part_info.name[PART_NAME_LEN - 1] = '\0';
+   strncpy((char *)newpart->gpt_part_info.type, (const char *)info->type, 
PART_TYPE_LEN);
+   newpart->gpt_part_info.type[PART_TYPE_LEN - 1] = '\0';
+   newpart->gpt_part_info.bootable = info->bootable;
+#ifdef CONFIG_PARTITION_UUIDS
+   strncpy(newpart->gpt_part_info.uuid, (const char *)info->uuid,
+   UUID_STR_LEN);
+#endif
+   newpart->partnum = partnum;
+
+   return newpart;
+}
+
+static void print_gpt_info(void)
+{
+   struct list_head *pos;
+   struct disk_part *curr;
+
+   list_for_each(pos, _partitions) {
+   curr = list_entry(pos, struct disk_part, list);
+   printf("Partition %d:\n", curr->partnum);
+   printf("1st block %x, size %x\n", 
(unsigned)curr->gpt_part_info.start,
+  (unsigned)curr->gpt_part_info.size);
+   printf("Block size %lu, name %s\n", curr->gpt_part_info.blksz,
+  curr->gpt_part_info.name);
+   printf("Type %s, bootable %d\n", curr->gpt_part_info.type,
+  curr->gpt_part_info.bootable);
+#ifdef CONFIG_PARTITION_UUIDS
+   printf("UUID %s\n", curr->gpt_part_info.uuid);
+#endif
+   printf("\n");
+   }
+}
+
+/*
+ * read partition info into disk_partitions list where
+ * it can be printed or modified
+ */
+static int get_gpt_info(struct blk_desc *dev_desc)
+{
+   /* start partition numbering at 1, as U-Boot does */
+   int valid_parts = 1, p, ret;
+   disk_partition_t info;
+   struct disk_part *new_disk_part;
+
+   if (disk_partitions.next == NULL)
+   INIT_LIST_HEAD(_partitions);
+
+   for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
+   ret = part_get_info(dev_desc, p, );
+   if (ret)
+   continue;
+
+   new_disk_part = allocate_disk_part(, valid_parts);
+   if (IS_ERR(new_disk_part) && valid_parts >= 2)
+   return -ENODEV;
+
+   list_add_tail(_disk_part->list, _partitions);
+   valid_parts++;
+   }
+   if (!valid_parts) {
+   printf("** No valid partitions found **\n");
+   del_gpt_info();
+   return -ENODEV;
+   }
+   return --valid_parts;
+}
+
+/* a wrapper to test get_gpt_info */
+static int do_get_gpt_info(struct blk_desc *dev_desc)
+{
+   int ret;
+
+   ret = get_gpt_info(dev_desc);
+   if (ret > 0) {
+   print_gpt_info();
+   del_gpt_info();
+   }
+   return ret;
+}
+
+
 /**
  * set_gpt_info(): Fill partition information from string
  * function allocates memory, remember to free!
@@ -455,6 +563,8 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
printf("Verify GPT: ");
} else if (strcmp(argv[1], "guid") == 0) {
return do_disk_guid(blk_dev_desc, argv[4]);
+   } else if (strcmp(argv[1], "read") == 0) {
+   return do_get_gpt_info(blk_dev_desc);
} 

[U-Boot] [PATCH v3 1/5] GPT: add accessor function for disk GUID

2017-06-02 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

In order to read the GPT, modify the partition name strings, and then
write out a new GPT, the disk GUID is needed.  While there is an
existing accessor for the partition UUIDs, there is none yet for the
disk GUID.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 cmd/gpt.c   | 26 ++
 disk/part_efi.c | 31 +++
 doc/README.gpt  |  3 ++-
 include/part.h  | 15 +++
 4 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index 3e98821..4d00a35 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -398,6 +398,23 @@ static int gpt_verify(struct blk_desc *blk_dev_desc, const 
char *str_part)
return ret;
 }
 
+static int do_disk_guid(struct blk_desc *dev_desc, char * const namestr)
+{
+   int ret;
+   char disk_guid[UUID_STR_LEN + 1];
+
+   ret = get_disk_guid(dev_desc, disk_guid);
+   if (ret < 0)
+   return CMD_RET_FAILURE;
+
+   if (namestr)
+   setenv(namestr, disk_guid);
+   else
+   printf("%s\n", disk_guid);
+
+   return ret;
+}
+
 /**
  * do_gpt(): Perform GPT operations
  *
@@ -436,6 +453,8 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
} else if ((strcmp(argv[1], "verify") == 0)) {
ret = gpt_verify(blk_dev_desc, argv[4]);
printf("Verify GPT: ");
+   } else if (strcmp(argv[1], "guid") == 0) {
+   return do_disk_guid(blk_dev_desc, argv[4]);
} else {
return CMD_RET_USAGE;
}
@@ -458,4 +477,11 @@ U_BOOT_CMD(gpt, CONFIG_SYS_MAXARGS, 1, do_gpt,
" Example usage:\n"
" gpt write mmc 0 $partitions\n"
" gpt verify mmc 0 $partitions\n"
+   " guid  \n"
+   "- print disk GUID\n"
+   " guid   \n"
+   "- set environment variable to disk GUID\n"
+   " Example usage:\n"
+   " gpt guid mmc 0\n"
+   " gpt guid mmc 0 varname\n"
 );
diff --git a/disk/part_efi.c b/disk/part_efi.c
index 20d33ef..71c3cb3 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -178,6 +178,37 @@ static void prepare_backup_gpt_header(gpt_header *gpt_h)
  * Public Functions (include/part.h)
  */
 
+/*
+ * UUID is displayed as 32 hexadecimal digits, in 5 groups,
+ * separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters
+ */
+int get_disk_guid(struct blk_desc * dev_desc, char *guid)
+{
+   ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
+   gpt_entry *gpt_pte = NULL;
+   unsigned char *guid_bin;
+
+   /* This function validates AND fills in the GPT header and PTE */
+   if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA,
+gpt_head, _pte) != 1) {
+   printf("%s: *** ERROR: Invalid GPT ***\n", __func__);
+   if (is_gpt_valid(dev_desc, dev_desc->lba - 1,
+gpt_head, _pte) != 1) {
+   printf("%s: *** ERROR: Invalid Backup GPT ***\n",
+  __func__);
+   return -EINVAL;
+   } else {
+   printf("%s: ***Using Backup GPT ***\n",
+  __func__);
+   }
+   }
+
+   guid_bin = gpt_head->disk_guid.b;
+   uuid_bin_to_str(guid_bin, guid, UUID_STR_FORMAT_GUID);
+
+   return 0;
+}
+
 void part_print_efi(struct blk_desc *dev_desc)
 {
ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
diff --git a/doc/README.gpt b/doc/README.gpt
index 3fcd835..c0779a4 100644
--- a/doc/README.gpt
+++ b/doc/README.gpt
@@ -171,7 +171,8 @@ To restore GUID partition table one needs to:
The fields 'uuid' and 'uuid_disk' are optional if CONFIG_RANDOM_UUID is
enabled. A random uuid will be used if omitted or they point to an empty/
non-existent environment variable. The environment variable will be set to
-   the generated UUID.
+   the generated UUID.  The 'gpt guid' command reads the current value of the
+   uuid_disk from the GPT.
 
The field 'bootable' is optional, it is used to mark the GPT partition
bootable (set attribute flags "Legacy BIOS bootable").
diff --git a/include/part.h b/include/part.h
index 87b..16c4a46 100644
--- a/include/part.h
+++ b/include/part.h
@@ -371,6 +371,21 @@ int gpt_verify_headers(struct blk_desc *dev_desc, 
gpt_header *gpt_head,
 int gpt_verify_partitions(struct blk_desc *dev_desc,
  disk_partition_t *partitions, int parts,
  gpt_header *gpt_head, gpt_entry **gpt_pte);
+
+
+/**
+ * get_disk_guid() - Function to read the GUID string from a device's GPT
+ *
+ *

[U-Boot] [PATCH v3 0/5] add support for GPT partition name manipulation

2017-06-02 Thread alison
From: Alison Chaiken <ali...@peloton-tech.com>

One way for userspace and the bootloader to exchange information about
dynamic image selection is via the storage device partition table, as
described at

https://source.android.com/devices/tech/ota/ab_updates

The scheme described there relies on setting partitions' "boot" flag.
When no partition on a device is bootable since the kernel and U-Boot
are stored elsewhere, the name field in the GPT partition table offers
another logical place to store information.  These patches allow users
to easily modify GPT partition names via bootscripts that can select
different images based on a boot-failure counter, or when userspace
installs a software update.

These patches have been (re)tested on a TI DRA7xx-based SOM with
U-Boot 2015.07.  The storage device is an eMMC.

Significant changes since v2:
-- Got rid of the need to allocate memory for the GUID string in
   do_gpt();
-- Fixed the problems with string NULL termination in
   allocate_disk_part();
-- Removed duplicate definition of MAX_SEARCH_PARTITIONS from
   disk/part.c and increased the value in include/part.h to 64;
-- Improved the commit message for "rename GPT partitions to detect
   boot failure" to better describe the version of the patch I
   submitted;
-- Fixed numerous small problems with function return values.

Significant changes since v1:
-- Put the gpt_flip() function and auxiliary ones inside a new
   CONFIG_CMD_GPT_FLIP option that depends on CMD_GPT.
-- Replace intentional overwriting of name and type string arrays with
   memset() instead.
-- Move part.h changes earlier in the patchset.
-- Add a few lines to README.gpt about the new gpt subcommands.

Added a few simple patches to do the following:
-- Replace remaining occurrences of '37' with UUID_STR_LEN+1;
-- Introduce new macros to get rid of the similar '32';
-- fix a smaller error in doc/README.gpt.

There are also some fixups of whitespace and formatting errors (plus
usual inevitable addition of new ones).

To do in future:
-- Add support for preserving the type flag for partitions. The u-boot
   version on which this patchset is based did not have this feature,
   and it's easy to add, but I need to figure how to test it first.

-- Add tests for the new gpt commands to the sandbox.


Alison Chaiken (5):
  GPT: add accessor function for disk GUID
  partitions: increase MAX_SEARCH_PARTITIONS and move to part.h
  GPT: read partition table from device into a data structure
  rename GPT partitions to detect boot failure
  GPT: fix error in partitions string doc

 cmd/Kconfig |   7 ++
 cmd/gpt.c   | 318 
 disk/part.c |   1 -
 disk/part_efi.c |  31 ++
 doc/README.gpt  |  24 -
 include/part.h  |  23 
 6 files changed, 398 insertions(+), 6 deletions(-)

-- 
2.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v2 5/6] rename GPT partitions to detect boot failure

2017-06-01 Thread Chaiken, Alison
Lukasz Majewski wrote:

> Maybe it would be better to have
> 
> gpt flip mmc 0 
> 
> (By default we have "primary" and "backup")
> 
> In that way we could set other names to GPT partitions without the
> need to modify the code.

I answered: 

>> Another possibility is to support
>> 
>> gpt flip mmc 0  
>> 
>> where two names are required, with defaults 'primary' and 'backup'.   
>> Perhaps I should rework patch 5 that way?

Lukasz responded: 

> Please correct my understanding if I'm wrong.
> 
> You parse GPT partitions to a list and there are only two names
> possible:
> 
> "primary" and "backup".
> 
> When we call gpt filp we rename those names ("primary" -> "backup" and
> the other way).
> 
> Ahhh. so your patch would allow to rename "primary" to  and
> "backup" to  for all names.
> 
> My idea was rather to have a gpt call to set name of a GPT partition

> I can image that somebody would like to change on the fly single GPT
> partition name (when having/care about 2 partitions for his/her project
> specific data).
> 
> But, I don't know how much effort it would take to implement it (and if
> others would see it beneficial).

I would propose then two options: 

gpt rename mmc 0   

which renames all the 1's to 2's, and 

gpt flip mmc 0   

which swaps the two name strings for all partitions where they're found.
 These two operations together with 'gpt write' then cover all the
common use cases I can imagine. 

I'm open to any other suggestions, of course.   I just posted what I
already had to get started. 

-- Alison 

---
Alison Chaiken  ali...@she-devel.com, 650-279-5600 
http://{ she-devel.com, exerciseforthereader.org } 
"We are giving up our privacy, one convenience at a time." -- Evangelos
Simoudis
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v2 5/6] rename GPT partitions to detect boot failure

2017-06-01 Thread Chaiken, Alison

On 2017-05-31 01:12, Lukasz Majewski wrote:

[ SNIP ]


Maybe it would be better to have

gpt flip mmc 0 

(By default we have "primary" and "backup")

In that way we could set other names to GPT partitions without the
need to modify the code.


Another possibility is to support

gpt flip mmc 0  

where two names are required, with defaults 'primary' and 'backup'.   
Perhaps I should rework patch 5 that way?  I considered this form for 
the original submission, but wasn't sure what other projects might find 
useful.



And another request -> Could you consider adding tests for those new
gpt commands to the 'sandbox' (sandbox_defconfig) ?


I will look into adding another patch to do that.   I'm sure such tests 
are a good idea for our project.



Despite above comments - you did a great job :-)


Thanks.   I'm sorry to have omitted you, Lukasz, from the original 
submission, but I consulted an old version of MAINTAINERS from my 
original 2015.07.


-- Alison

---
Alison Chaiken  ali...@she-devel.com, 650-279-5600
http://{ she-devel.com, exerciseforthereader.org }
"We are giving up our privacy, one convenience at a time." -- Evangelos 
Simoudis

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v2 4/6] GPT: read partition table from device into a data structure

2017-06-01 Thread Chaiken, Alison

On 2017-05-30 00:37, Lothar Waßmann wrote:
[ SNIP]

+#define MAX_SEARCH_PARTITIONS 16

Why the hard limit to 16 partitions?
A standard Android system will jump right in your face with this limit.


Lothar, I'm working on making the other changes you suggested.   
Meanwhile, the answer to this question is that I copied the macro from a 
header file in 2015.07, which is the version for which I developed the 
patches.   I saw no equivalent value in this latest release of Das 
U-Boot.   Do you have a better suggestion?   Is there a similar macro 
elsewhere that I failed to discover?


Thanks,
Alison

---
Alison Chaiken  ali...@she-devel.com, 650-279-5600
http://{ she-devel.com, exerciseforthereader.org }
"We are giving up our privacy, one convenience at a time." -- Evangelos 
Simoudis

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 4/6] GPT: read partition table from device into a data structure

2017-05-29 Thread alison
From: Alison Chaiken <ali...@she-devel.com>

Make the partition table available for modification by reading it from
the user-specified device into a linked list.   Provide an accessor
function for command-line testing.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 cmd/gpt.c  | 112 +
 include/part.h |   8 +
 2 files changed, 120 insertions(+)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index 3b7d929..c61d2b1 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -19,6 +19,9 @@
 #include 
 #include 
 #include 
+#include 
+
+static LIST_HEAD(disk_partitions);
 
 /**
  * extract_env(): Expand env name from string format '&{env_name}'
@@ -151,6 +154,111 @@ static bool found_key(const char *str, const char *key)
return result;
 }
 
+static void del_gpt_info(void)
+{
+   struct list_head *pos = _partitions;
+   struct disk_part *curr;
+   while (!list_empty(pos)) {
+   curr = list_entry(pos->next, struct disk_part, list);
+   list_del(pos->next);
+   free(curr);
+   }
+}
+
+static struct disk_part *allocate_disk_part(disk_partition_t *info, int 
partnum)
+{
+   struct disk_part *newpart;
+   newpart = (struct disk_part *)malloc(sizeof(*newpart));
+   memset(newpart, '\0', sizeof(newpart));
+   if (!newpart)
+   return ERR_PTR(-ENOMEM);
+
+   newpart->gpt_part_info.start = info->start;
+   newpart->gpt_part_info.size = info->size;
+   newpart->gpt_part_info.blksz = info->blksz;
+   strncpy((char *)newpart->gpt_part_info.name, (const char *)info->name, 
PART_NAME_LEN);
+   memset(newpart->gpt_part_info.name + 31, '\0', 1);
+   strncpy((char *)newpart->gpt_part_info.type, (const char *)info->type, 
PART_TYPE_LEN);
+   memset(newpart->gpt_part_info.type + 31, '\0', 1);
+   newpart->gpt_part_info.bootable = info->bootable;
+#ifdef CONFIG_PARTITION_UUIDS
+   strncpy(newpart->gpt_part_info.uuid, (const char *)info->uuid,
+   UUID_STR_LEN);
+#endif
+   newpart->partnum = partnum;
+
+   return newpart;
+}
+
+static void print_gpt_info(void)
+{
+   struct list_head *pos;
+   struct disk_part *curr;
+
+   list_for_each(pos, _partitions) {
+   curr = list_entry(pos, struct disk_part, list);
+   printf("Partition %d:\n", curr->partnum);
+   printf("1st block %x, size %x\n", 
(unsigned)curr->gpt_part_info.start,
+  (unsigned)curr->gpt_part_info.size);
+   printf("Block size %lu, name %s\n", curr->gpt_part_info.blksz,
+  curr->gpt_part_info.name);
+   printf("Type %s, bootable %d\n", curr->gpt_part_info.type,
+  curr->gpt_part_info.bootable);
+#ifdef CONFIG_PARTITION_UUIDS
+   printf("UUID %s\n", curr->gpt_part_info.uuid);
+#endif
+   printf("\n");
+   }
+}
+
+/*
+ * read partition info into disk_partitions list where
+ * it can be printed or modified
+ */
+static int get_gpt_info(struct blk_desc *dev_desc)
+{
+   /* start partition numbering at 1, as u-boot does */
+   int valid_parts = 1, p, ret = 0;
+   disk_partition_t info;
+   struct disk_part *new_disk_part;
+
+   if (disk_partitions.next == NULL)
+   INIT_LIST_HEAD(_partitions);
+
+   for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
+   ret = part_get_info(dev_desc, p, );
+   if (ret)
+   continue;
+
+   new_disk_part = allocate_disk_part(, valid_parts);
+   if (IS_ERR(new_disk_part) && (valid_parts >= 2))
+   return -1;
+
+   list_add_tail(_disk_part->list, _partitions);
+   valid_parts++;
+   }
+   if (!valid_parts) {
+   printf("** No valid partitions found **\n");
+   del_gpt_info();
+   return -ENODEV;
+   }
+   return --valid_parts;
+}
+
+/* a wrapper to test get_gpt_info */
+static int do_get_gpt_info(struct blk_desc *dev_desc)
+{
+   int ret;
+
+   ret = get_gpt_info(dev_desc);
+   if (ret > 0) {
+   print_gpt_info();
+   del_gpt_info();
+   }
+   return ret;
+}
+
+
 /**
  * set_gpt_info(): Fill partition information from string
  * function allocates memory, remember to free!
@@ -457,6 +565,8 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
if (argc == 5)
   strcpy(varname, argv[4]);
return do_disk_guid(blk_dev_desc, varname);
+   } else if (strcmp(argv[1], "read") == 0) {
+   return do_get_gpt_info(blk_dev_desc);
} else {
return CMD_

[U-Boot] [PATCH v2 6/6] GPT: fix error in partitions string doc

2017-05-29 Thread alison
From: Alison Chaiken <ali...@she-devel.com>

The existing partitions-list parsing in cmd/gpt.c passes a value
from gpt_default() to set_gpt_info() that README.gpt suggests
should begin with 'partitions='.  Partition-list strings should
in fact begin with 'uuid_disk', as otherwise the call from
set_gpt_info() to extract_val() to find 'uuid_disk' will fail.
Change README.gpt and file comments accordingly.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 cmd/gpt.c  | 13 +
 doc/README.gpt |  8 
 2 files changed, 5 insertions(+), 16 deletions(-)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index 6a0b70f..487314b 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -232,12 +232,6 @@ static void print_gpt_info(void)
 #ifdef CONFIG_CMD_GPT_FLIP
 static int calc_parts_list_len(int numparts)
 {
-   /*
-* prefatory string:
-* doc/README.GPT, suggests that
-* int partlistlen = UUID_STR_LEN + 1 + strlen("partitions=uuid_disk=");
-* is correct, but extract_val() expects "uuid_disk" first.
-*/
int partlistlen = UUID_STR_LEN + 1 + strlen("uuid_disk=");
/* for the comma */
partlistlen++;
@@ -260,7 +254,7 @@ static int calc_parts_list_len(int numparts)
  * argument
  *
  * From doc/README.gpt, Format of partitions layout:
- *"partitions=uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
+ *"uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
  * name=kernel,size=60MiB,uuid=...;"
  * The fields 'name' and 'size' are mandatory for every partition.
  * The field 'start' is optional. The fields 'uuid' and 'uuid_disk'
@@ -275,11 +269,6 @@ static int create_gpt_partitions_list(int numparts, const 
char *guid, char *part
if (!partitions_list)
return -1;
 
-   /*
-* README.gpt specifies starting with "partitions=" like so:
-*  strcpy(partitions_list, "partitions=uuid_disk=");
-* but that breaks extract_val, which doesn't skip over 'partitions='.
-*/
strcpy(partitions_list, "uuid_disk=");
strncat(partitions_list, guid, UUID_STR_LEN + 1);
strcat(partitions_list, ";");
diff --git a/doc/README.gpt b/doc/README.gpt
index e29b188..754e490 100644
--- a/doc/README.gpt
+++ b/doc/README.gpt
@@ -156,10 +156,10 @@ Creating GPT partitions in U-Boot:
 To restore GUID partition table one needs to:
 1. Define partition layout in the environment.
Format of partitions layout:
- "partitions=uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
+ "uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
name=kernel,size=60MiB,uuid=...;"
  or
- "partitions=uuid_disk=${uuid_gpt_disk};name=${uboot_name},
+ "uuid_disk=${uuid_gpt_disk};name=${uboot_name},
size=${uboot_size},uuid=${uboot_uuid};"
 
The fields 'name' and 'size' are mandatory for every partition.
@@ -233,7 +233,7 @@ PARTITION_BASIC_DATA_GUID 
(EBD0A0A2-B9E5-4433-87C0-68B6B72699C7).
 If you define 'CONFIG_PARTITION_TYPE_GUID', a optionnal parameter 'type'
 can specify a other partition type guid:
 
- "partitions=uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
+ "uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
name=kernel,size=60MiB,uuid=...,
type=0FC63DAF-8483-4772-8E79-3D69D8477DE4;"
 
@@ -255,7 +255,7 @@ Some strings can be also used at the place of known GUID :
"lvm"= PARTITION_LINUX_LVM_GUID
   (E6D6D379-F507-44C2-A23C-238F2A3DF928)
 
-"partitions=uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
+"uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
name=kernel,size=60MiB,uuid=...,type=linux;"
 
 They are also used to display the type of partition in "part list" command.
-- 
2.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 5/6] rename GPT partitions to detect boot failure

2017-05-29 Thread alison
From: Alison Chaiken <ali...@she-devel.com>

This patch provides support in u-boot for renaming GPT
partitions.  The renaming is accomplished via a new 'gpt flip'
command which is enabled via a CONFIG_CMD_GPT_FLIP option.

The concept for the bootloader state machine is the following:

-- u-boot renames ‘primary’ partitions as ‘candidate’ and tries
   to boot them.
-- Linux, at boot, will rename ‘candidate’ partitions as
   ‘primary’.
-- If u-boot sees a ‘candidate’ partition after a boot attempt,
   it renames it failed’ and renames the ‘backup’ partition as
   ‘candidate’.

Logic:
-- Partitions can go to ‘failed’ only from ‘candidate’ and only
   via u-boot.  Partitions can go to ‘backup’ only from ‘primary’
   and vice-versa, only via Linux.  Partitions go to ‘candidate’
   from ‘primary’ or ‘backup’ only via u-boot.  Only system
   update software will rename 'failed' partitions.

Rewriting the partition table has the side-effect that all partitions
end up with "msftdata" flag set.  The reason is that partition type
PARTITION_BASIC_DATA_GUID is hard-coded in the gpt_fill_pte()
function.  This does not appear to cause any harm.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 cmd/Kconfig|   7 ++
 cmd/gpt.c  | 199 +++--
 doc/README.gpt |  13 
 3 files changed, 215 insertions(+), 4 deletions(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 5ee52f6..a8f7716 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -575,6 +575,13 @@ config CMD_GPT
  Enable the 'gpt' command to ready and write GPT style partition
  tables.
 
+config CMD_GPT_FLIP
+   bool "GPT flip-partitions command"
+   depends on CMD_GPT
+   help
+ Enables the 'gpt' command to write modified GPT partition
+ tables via the 'gpt flip' command.
+
 config CMD_ARMFLASH
#depends on FLASH_CFI_DRIVER
bool "armflash"
diff --git a/cmd/gpt.c b/cmd/gpt.c
index c61d2b1..6a0b70f 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static LIST_HEAD(disk_partitions);
 
@@ -190,16 +191,33 @@ static struct disk_part 
*allocate_disk_part(disk_partition_t *info, int partnum)
return newpart;
 }
 
+static void prettyprint_part_size(char *sizestr, unsigned long partsize,
+ unsigned long blksize)
+{
+   unsigned long long partbytes;
+   unsigned long partmegabytes;
+
+   partbytes = partsize * blksize;
+   partmegabytes = lldiv(partbytes, SZ_1M);
+   snprintf(sizestr, 16, "%luMiB", partmegabytes);
+}
+
 static void print_gpt_info(void)
 {
struct list_head *pos;
struct disk_part *curr;
+   char partstartstr[16];
+   char partsizestr[16];
 
list_for_each(pos, _partitions) {
curr = list_entry(pos, struct disk_part, list);
+   prettyprint_part_size(partstartstr, (unsigned 
long)curr->gpt_part_info.start,
+ (unsigned long) 
curr->gpt_part_info.blksz);
+   prettyprint_part_size(partsizestr, (unsigned 
long)curr->gpt_part_info.size,
+ (unsigned long) 
curr->gpt_part_info.blksz);
+
printf("Partition %d:\n", curr->partnum);
-   printf("1st block %x, size %x\n", 
(unsigned)curr->gpt_part_info.start,
-  (unsigned)curr->gpt_part_info.size);
+   printf("Start %s, size %s\n", partstartstr, partsizestr);
printf("Block size %lu, name %s\n", curr->gpt_part_info.blksz,
   curr->gpt_part_info.name);
printf("Type %s, bootable %d\n", curr->gpt_part_info.type,
@@ -211,6 +229,85 @@ static void print_gpt_info(void)
}
 }
 
+#ifdef CONFIG_CMD_GPT_FLIP
+static int calc_parts_list_len(int numparts)
+{
+   /*
+* prefatory string:
+* doc/README.GPT, suggests that
+* int partlistlen = UUID_STR_LEN + 1 + strlen("partitions=uuid_disk=");
+* is correct, but extract_val() expects "uuid_disk" first.
+*/
+   int partlistlen = UUID_STR_LEN + 1 + strlen("uuid_disk=");
+   /* for the comma */
+   partlistlen++;
+
+   /* per-partition additions; numparts starts at 1, so this should be 
correct */
+   partlistlen += numparts * (strlen("name=,") + PART_NAME_LEN + 1);
+   /* 17 because partstr in create_gpt_partitions_list() is 16 chars */
+   partlistlen += numparts * (strlen("start=MiB,") + 17);
+   partlistlen += numparts * (strlen("size=MiB,") + 17);
+   partlistlen += numparts * (strlen("uuid=;") + UUID_STR_LEN + 1);
+   /* for the terminating null */
+   partlistlen++;
+   debug("Length of partitions_list i

[U-Boot] [PATCH v2 2/6] disk_partition: introduce macros for description string lengths

2017-05-29 Thread alison
From: Alison Chaiken <ali...@she-devel.com>

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 include/part.h | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/include/part.h b/include/part.h
index 6ace09f..87b 100644
--- a/include/part.h
+++ b/include/part.h
@@ -47,12 +47,15 @@ struct block_drvr {
 #define DEV_TYPE_CDROM 0x05/* CD-ROM */
 #define DEV_TYPE_OPDISK0x07/* optical disk */
 
+#define PART_NAME_LEN 32
+#define PART_TYPE_LEN 32
+
 typedef struct disk_partition {
lbaint_tstart;  /* # of first block in partition*/
lbaint_tsize;   /* number of blocks in partition*/
ulong   blksz;  /* block size in bytes  */
-   uchar   name[32];   /* partition name   */
-   uchar   type[32];   /* string type description  */
+   uchar   name[PART_NAME_LEN];/* partition name   
*/
+   uchar   type[PART_TYPE_LEN];/* string type description  
*/
int bootable;   /* Active/Bootable flag is set  */
 #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
charuuid[UUID_STR_LEN + 1]; /* filesystem UUID as string, if exists 
*/
-- 
2.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 3/6] GPT: add accessor function for disk GUID

2017-05-29 Thread alison
From: Alison Chaiken <ali...@she-devel.com>

In order to read the GPT, modify the partition name strings, and then
write out a new GPT, the disk GUID is needed.  While there is an
existing accessor for the partition UUIDs, there is none yet for the
disk GUID.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 cmd/gpt.c   | 30 +-
 disk/part_efi.c | 31 +++
 doc/README.gpt  |  3 ++-
 include/part.h  | 15 +++
 4 files changed, 77 insertions(+), 2 deletions(-)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index 3e98821..3b7d929 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -398,6 +398,23 @@ static int gpt_verify(struct blk_desc *blk_dev_desc, const 
char *str_part)
return ret;
 }
 
+static int do_disk_guid(struct blk_desc *dev_desc, char * const namestr)
+{
+   int ret;
+   char disk_guid[UUID_STR_LEN + 1];
+
+   ret = get_disk_guid(dev_desc, disk_guid);
+   if (ret < 0)
+   return 1;
+
+   if (namestr)
+   setenv(namestr, disk_guid);
+   else
+   printf("%s\n", disk_guid);
+
+   return 0;
+}
+
 /**
  * do_gpt(): Perform GPT operations
  *
@@ -412,7 +429,7 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
 {
int ret = CMD_RET_SUCCESS;
int dev = 0;
-   char *ep;
+   char *ep, *varname = NULL;
struct blk_desc *blk_dev_desc = NULL;
 
if (argc < 4 || argc > 5)
@@ -436,6 +453,10 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
} else if ((strcmp(argv[1], "verify") == 0)) {
ret = gpt_verify(blk_dev_desc, argv[4]);
printf("Verify GPT: ");
+   } else if (strcmp(argv[1], "guid") == 0) {
+   if (argc == 5)
+  strcpy(varname, argv[4]);
+   return do_disk_guid(blk_dev_desc, varname);
} else {
return CMD_RET_USAGE;
}
@@ -458,4 +479,11 @@ U_BOOT_CMD(gpt, CONFIG_SYS_MAXARGS, 1, do_gpt,
" Example usage:\n"
" gpt write mmc 0 $partitions\n"
" gpt verify mmc 0 $partitions\n"
+   " guid  \n"
+   "- print disk GUID\n"
+   " guid   \n"
+   "- set environment variable to disk GUID\n"
+   " Example usage:\n"
+   " gpt guid mmc 0\n"
+   " gpt guid mmc 0 varname\n"
 );
diff --git a/disk/part_efi.c b/disk/part_efi.c
index 20d33ef..ff9f408 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -178,6 +178,37 @@ static void prepare_backup_gpt_header(gpt_header *gpt_h)
  * Public Functions (include/part.h)
  */
 
+/*
+ * UUID is displayed as 32 hexadecimal digits, in 5 groups,
+ * separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters
+ */
+int get_disk_guid(struct blk_desc * dev_desc, char *guid)
+{
+   ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
+   gpt_entry *gpt_pte = NULL;
+   unsigned char *guid_bin;
+
+   /* This function validates AND fills in the GPT header and PTE */
+   if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA,
+gpt_head, _pte) != 1) {
+   printf("%s: *** ERROR: Invalid GPT ***\n", __func__);
+   if (is_gpt_valid(dev_desc, (dev_desc->lba - 1),
+gpt_head, _pte) != 1) {
+   printf("%s: *** ERROR: Invalid Backup GPT ***\n",
+  __func__);
+   return -1;
+   } else {
+   printf("%s: ***Using Backup GPT ***\n",
+  __func__);
+   }
+   }
+
+   guid_bin = (unsigned char *)(gpt_head->disk_guid.b);
+   uuid_bin_to_str(guid_bin, guid, UUID_STR_FORMAT_GUID);
+
+   return 0;
+}
+
 void part_print_efi(struct blk_desc *dev_desc)
 {
ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
diff --git a/doc/README.gpt b/doc/README.gpt
index 3fcd835..c0779a4 100644
--- a/doc/README.gpt
+++ b/doc/README.gpt
@@ -171,7 +171,8 @@ To restore GUID partition table one needs to:
The fields 'uuid' and 'uuid_disk' are optional if CONFIG_RANDOM_UUID is
enabled. A random uuid will be used if omitted or they point to an empty/
non-existent environment variable. The environment variable will be set to
-   the generated UUID.
+   the generated UUID.  The 'gpt guid' command reads the current value of the
+   uuid_disk from the GPT.
 
The field 'bootable' is optional, it is used to mark the GPT partition
bootable (set attribute flags "Legacy BIOS bootable").
diff --git a/include/part.h b/include/part.h
index 87b..16c4a46 100644
--- a/include/part.h
+++ b/include/part.h

[U-Boot] [PATCH v2 1/6] EFI: replace number with UUID_STR_LEN macro

2017-05-29 Thread alison
From: Alison Chaiken <ali...@she-devel.com>

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 disk/part_efi.c | 2 +-
 include/part.h  | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/disk/part_efi.c b/disk/part_efi.c
index 1b7ba27..20d33ef 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -183,7 +183,7 @@ void part_print_efi(struct blk_desc *dev_desc)
ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
gpt_entry *gpt_pte = NULL;
int i = 0;
-   char uuid[37];
+   char uuid[UUID_STR_LEN + 1];
unsigned char *uuid_bin;
 
/* This function validates AND fills in the GPT header and PTE */
diff --git a/include/part.h b/include/part.h
index 83bce05..6ace09f 100644
--- a/include/part.h
+++ b/include/part.h
@@ -9,6 +9,7 @@
 
 #include 
 #include 
+#include 
 
 struct block_drvr {
char *name;
@@ -54,10 +55,10 @@ typedef struct disk_partition {
uchar   type[32];   /* string type description  */
int bootable;   /* Active/Bootable flag is set  */
 #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
-   charuuid[37];   /* filesystem UUID as string, if exists */
+   charuuid[UUID_STR_LEN + 1]; /* filesystem UUID as string, if exists 
*/
 #endif
 #ifdef CONFIG_PARTITION_TYPE_GUID
-   chartype_guid[37];  /* type GUID as string, if exists   */
+   chartype_guid[UUID_STR_LEN + 1];/* type GUID as string, if 
exists   */
 #endif
 #ifdef CONFIG_DOS_PARTITION
uchar   sys_ind;/* partition type   */
-- 
2.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 0/6] add support for GPT partition name manipulation

2017-05-29 Thread alison
From: Alison Chaiken <ali...@she-devel.com>

One way for userspace and the bootloader to exchange information about
dynamic image selection is via the storage device partition table, as
described at

https://source.android.com/devices/tech/ota/ab_updates

The scheme described there relies on setting partitions' "boot" flag.
When no partition on a device is bootable since the kernel and U-Boot
are stored elsewhere, the name field in the GPT partition table offers
another logical place to store information.  These patches allow users
to easily modify GPT partition names via bootscripts that can select
different images based on a boot-failure counter, or when userspace
installs a software update.

These patches have been tested on a TI DRA7xx-based SOM with U-Boot
2015.07.  The storage device is an eMMC.

Significant changes since v1:
-- Put the gpt_flip() function and auxiliary ones inside a new
   CONFIG_CMD_GPT_FLIP option that depends on CMD_GPT.
-- Replace intentional overwriting of name and type string arrays with
   memset() instead.
-- Move part.h changes earlier in the patchset.
-- Add a few lines to README.gpt about the new gpt subcommands.

Added a few simple patches to do the following:
-- Replace remaining occurrences of '37' with UUID_STR_LEN+1;
-- Introduce new macros to get rid of the similar '32';
-- fix a smaller error in doc/README.gpt.

There are also some fixups of whitespace and formatting errors (plus
usual inevitable addition of new ones).

To do in future:
-- Add support for preserving the type flag for partitions. The u-boot
   version on which this patchset is based did not have this feature,
   and it's easy to add, but I need to figure how to test it first.



Alison Chaiken (6):
  EFI: replace number with UUID_STR_LEN macro
  disk_partition: introduce macros for description string lengths
  GPT: add accessor function for disk GUID
  GPT: read partition table from device into a data structure
  rename GPT partitions to detect boot failure
  GPT: fix error in partitions string doc

 cmd/Kconfig |   7 ++
 cmd/gpt.c   | 322 +++-
 disk/part_efi.c |  33 +-
 doc/README.gpt  |  24 -
 include/part.h  |  35 +-
 5 files changed, 410 insertions(+), 11 deletions(-)

-- 
2.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] arm: ls1021atwr: Add distro boot support

2017-05-26 Thread Alison Wang
This patch includes common config_distro_defaults.h and
config_distro_bootcmd.h for u-boot enviroments to support distro boot
which automatically scan boot.scr from storage devices(e.g.
SD/USB/SATA/SCSI disk) and execute autoboot script on LS1021ATWR board.

Signed-off-by: Shengzhou Liu <shengzhou@nxp.com>
Signed-off-by: Alison Wang <alison.w...@nxp.com>
---
 configs/ls1021atwr_nor_defconfig |  1 +
 configs/ls1021atwr_sdcard_ifc_defconfig  |  1 +
 configs/ls1021atwr_sdcard_qspi_defconfig |  1 +
 include/configs/ls1021atwr.h | 81 ++--
 4 files changed, 81 insertions(+), 3 deletions(-)

diff --git a/configs/ls1021atwr_nor_defconfig b/configs/ls1021atwr_nor_defconfig
index c56533a..dcacdac 100644
--- a/configs/ls1021atwr_nor_defconfig
+++ b/configs/ls1021atwr_nor_defconfig
@@ -44,3 +44,4 @@ CONFIG_USB_XHCI_DWC3=y
 CONFIG_USB_STORAGE=y
 CONFIG_VIDEO_FSL_DCU_FB=y
 # CONFIG_VIDEO_SW_CURSOR is not set
+CONFIG_DISTRO_DEFAULTS=y
diff --git a/configs/ls1021atwr_sdcard_ifc_defconfig 
b/configs/ls1021atwr_sdcard_ifc_defconfig
index 9809c60..616bec6 100644
--- a/configs/ls1021atwr_sdcard_ifc_defconfig
+++ b/configs/ls1021atwr_sdcard_ifc_defconfig
@@ -56,3 +56,4 @@ CONFIG_USB_XHCI_DWC3=y
 CONFIG_USB_STORAGE=y
 CONFIG_VIDEO_FSL_DCU_FB=y
 # CONFIG_VIDEO_SW_CURSOR is not set
+CONFIG_DISTRO_DEFAULTS=y
diff --git a/configs/ls1021atwr_sdcard_qspi_defconfig 
b/configs/ls1021atwr_sdcard_qspi_defconfig
index 5ccfc96..293e735 100644
--- a/configs/ls1021atwr_sdcard_qspi_defconfig
+++ b/configs/ls1021atwr_sdcard_qspi_defconfig
@@ -63,3 +63,4 @@ CONFIG_USB_XHCI_DWC3=y
 CONFIG_USB_STORAGE=y
 CONFIG_VIDEO_FSL_DCU_FB=y
 # CONFIG_VIDEO_SW_CURSOR is not set
+CONFIG_DISTRO_DEFAULTS=y
diff --git a/include/configs/ls1021atwr.h b/include/configs/ls1021atwr.h
index 60c3d5d..74ee74d 100644
--- a/include/configs/ls1021atwr.h
+++ b/include/configs/ls1021atwr.h
@@ -354,7 +354,6 @@
 #endif
 
 #define CONFIG_CMDLINE_TAG
-#define CONFIG_CMDLINE_EDITING
 
 #define CONFIG_PEN_ADDR_BIG_ENDIAN
 #define CONFIG_LAYERSCAPE_NS_ACCESS
@@ -366,19 +365,95 @@
 
 #define CONFIG_FSL_DEVICE_DISABLE
 
+#include 
+#define BOOT_TARGET_DEVICES(func) \
+   func(MMC, mmc, 0) \
+   func(USB, usb, 0)
+#include 
 
 #ifdef CONFIG_LPUART
 #define CONFIG_EXTRA_ENV_SETTINGS   \
"bootargs=root=/dev/ram0 rw console=ttyLP0,115200\0" \
"initrd_high=0x\0"  \
-   "fdt_high=0x\0"
+   "fdt_high=0x\0" \
+   "fdt_addr=0x64f0\0" \
+   "kernel_addr=0x6500\0"  \
+   "scriptaddr=0x8000\0"   \
+   "fdtheader_addr_r=0x8010\0" \
+   "kernelheader_addr_r=0x8020\0"  \
+   "kernel_addr_r=0x8100\0"\
+   "fdt_addr_r=0x9000\0"   \
+   "ramdisk_addr_r=0xa000\0"   \
+   "load_addr=0xa000\0"\
+   "kernel_size=0x280\0"   \
+   BOOTENV \
+   "boot_scripts=ls1021atwr_boot.scr\0"\
+   "scan_dev_for_boot_part="   \
+   "part list ${devtype} ${devnum} devplist; " \
+   "env exists devplist || setenv devplist 1; "\
+   "for distro_bootpart in ${devplist}; do "   \
+   "if fstype ${devtype} " \
+   "${devnum}:${distro_bootpart} " \
+   "bootfstype; then " \
+   "run scan_dev_for_boot; "   \
+   "fi; "  \
+   "done\0"\
+   "installer=load mmc 0:2 $load_addr "\
+   "/flex_installer_arm32.itb; "   \
+   "bootm $load_addr#ls1021atwr\0" \
+   "qspi_bootcmd=echo Trying load from qspi..;"\
+   "sf probe && sf read $load_addr "   \
+   "$kernel_addr $kernel_size && bootm $load_addr#$board\0"
\
+   "nor_bootcmd=echo Trying load from nor..;"  \
+   "cp.b $kernel_addr $load_addr " \
+   "$kernel_size && bootm $load_addr#$board\0"
 #else
 #define CONFIG_EXTRA_ENV_SETTINGS  \
"bootargs=root=/dev/ram0 rw console=ttyS0,115200\0" \
"initrd_high=0x\0"  \
-   "fdt_high=0x\0"
+   "fdt_high=0x\0" \
+   "fdt_addr=0x64f0\0" \
+   "kernel_addr=0x6500\0"  \
+   "scriptaddr=0x8000\0&q

[U-Boot] [PATCH 3/3] rename GPT partitions to detect boot failure

2017-05-21 Thread alison
From: Alison Chaiken <ali...@she-devel.com>

This patch provides support in u-boot for renaming GPT
partitions.  The renaming is accomplished via a new 'gpt flip'
command.

The concept for the bootloader state machine is the following:

-- u-boot renames ‘primary’ partitions as ‘candidate’ and tries
   to boot them.
-- Linux, at boot, will rename ‘candidate’ partitions as
   ‘primary’.
-- If u-boot sees a ‘candidate’ partition after a boot attempt,
   it renames it failed’ and renames the ‘backup’ partition as
   ‘candidate’.

Logic:
-- Partitions can go to ‘failed’ only from ‘candidate’ and only
   via u-boot.  Partitions can go to ‘backup’ only from ‘primary’
   and vice-versa, only via Linux.  Partitions go to ‘candidate’
   from ‘primary’ or ‘backup’ only via u-boot.  Only system
   update software will rename 'failed' partitions.

Rewriting the partition table has the side-effect that all partitions
end up with "msftdata" flag set.  The reason is that partition type
PARTITION_BASIC_DATA_GUID is hard-coded in the gpt_fill_pte()
function.  This does not appear to cause any harm.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 cmd/gpt.c | 207 --
 1 file changed, 201 insertions(+), 6 deletions(-)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index 128c895..f2c32ae 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -21,6 +21,9 @@
 #include 
 #include 
 
+/* ONEMIB is 2**20 */
+#define ONEMIB 1024*1024
+
 static LIST_HEAD(disk_partitions);
 
 /**
@@ -114,7 +117,6 @@ static char *extract_val(const char *str, const char *key)
break;
}
}
-
free(strcopy);
 
return new;
@@ -158,6 +160,7 @@ static void del_gpt_info(void)
 {
struct list_head *pos = _partitions;
struct disk_part *curr;
+
while (!list_empty(pos)) {
curr = list_entry(pos->next, struct disk_part, list);
list_del(pos->next);
@@ -165,6 +168,11 @@ static void del_gpt_info(void)
}
 }
 
+/*
+ * The number '33' comes from the '32' in the definition of disk_partition_t
+ * in include/part.h.   That file has '37' rather than UUID_STR_LEN + 1, from
+ * include/uuid.h
+ */
 static struct disk_part *allocate_disk_part(disk_partition_t *info, int 
partnum)
 {
struct disk_part *newpart;
@@ -191,16 +199,33 @@ static struct disk_part 
*allocate_disk_part(disk_partition_t *info, int partnum)
return newpart;
 }
 
+static void prettyprint_part_size(char *sizestr, unsigned long partsize,
+ unsigned long blksize)
+{
+   unsigned long long partbytes;
+   unsigned long partmegabytes;
+
+   partbytes = partsize * blksize;
+   partmegabytes = lldiv(partbytes, ONEMIB);
+   snprintf(sizestr, 16, "%luMiB", partmegabytes);
+}
+
 static void print_gpt_info(void)
 {
struct list_head *pos;
struct disk_part *curr;
+   char partstartstr[16];
+   char partsizestr[16];
 
list_for_each(pos, _partitions) {
curr = list_entry(pos, struct disk_part, list);
+   prettyprint_part_size(partstartstr, (unsigned 
long)curr->gpt_part_info.start,
+ (unsigned long) 
curr->gpt_part_info.blksz);
+   prettyprint_part_size(partsizestr, (unsigned 
long)curr->gpt_part_info.size,
+ (unsigned long) 
curr->gpt_part_info.blksz);
+
printf("Partition %d:\n", curr->partnum);
-   printf("1st block %x, size %x\n", 
(unsigned)curr->gpt_part_info.start,
-  (unsigned)curr->gpt_part_info.size);
+   printf("Start %s, size %s\n", partstartstr, partsizestr);
printf("Block size %lu, name %s\n", curr->gpt_part_info.blksz,
   curr->gpt_part_info.name);
printf("Type %s, bootable %d\n", curr->gpt_part_info.type,
@@ -212,6 +237,89 @@ static void print_gpt_info(void)
}
 }
 
+static int calc_parts_list_len(int numparts)
+{
+   /*
+* prefatory string:
+* doc/README.GPT, suggests that
+* int partlistlen = UUID_STR_LEN + 1 + strlen("partitions=uuid_disk=");
+* is correct, but extract_val() expects "uuid_disk" first.
+*/
+   int partlistlen = UUID_STR_LEN + 1 + strlen("uuid_disk=");
+   /* for the comma */
+   partlistlen++;
+
+   /* per-partition additions; numparts starts at 1, so this should be 
correct */
+   partlistlen += numparts * (strlen("name=,") + 33);
+   /* 17 because partstr below is 16 chars */
+   partlistlen += numparts * (strlen("start=MiB,") + 17);
+   partlistlen += numparts * (strlen("size=MiB,") + 17);
+   partlistlen += numparts * (strl

[U-Boot] [PATCH 2/3] GPT: read partition table from device into a data structure

2017-05-21 Thread alison
From: Alison Chaiken <ali...@she-devel.com>

Make the partition table available for modification by reading it from
the user-specified device into a linked list.   Provide an accessor
function for command-line testing.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 cmd/gpt.c  | 113 +
 include/part.h |   9 +
 2 files changed, 122 insertions(+)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index 814cb11..128c895 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -19,6 +19,9 @@
 #include 
 #include 
 #include 
+#include 
+
+static LIST_HEAD(disk_partitions);
 
 /**
  * extract_env(): Expand env name from string format '&{env_name}'
@@ -151,6 +154,112 @@ static bool found_key(const char *str, const char *key)
return result;
 }
 
+static void del_gpt_info(void)
+{
+   struct list_head *pos = _partitions;
+   struct disk_part *curr;
+   while (!list_empty(pos)) {
+   curr = list_entry(pos->next, struct disk_part, list);
+   list_del(pos->next);
+   free(curr);
+   }
+}
+
+static struct disk_part *allocate_disk_part(disk_partition_t *info, int 
partnum)
+{
+   struct disk_part *newpart;
+   newpart = (struct disk_part *)malloc(sizeof(*newpart));
+
+   if (!newpart)
+   return ERR_PTR(-ENOMEM);
+   newpart->gpt_part_info.start = info->start;
+   newpart->gpt_part_info.size = info->size;
+   newpart->gpt_part_info.blksz = info->blksz;
+   /*
+* 33 rather than 32, as each string must be null-terminated;
+* other extract_val() above will fail.
+*/
+   strncpy((char *)newpart->gpt_part_info.name, (const char *)info->name, 
33);
+   strncpy((char *)newpart->gpt_part_info.type, (const char *)info->type, 
33);
+   newpart->gpt_part_info.bootable = info->bootable;
+#ifdef CONFIG_PARTITION_UUIDS
+   strncpy(newpart->gpt_part_info.uuid, (const char *)info->uuid,
+   UUID_STR_LEN + 1);
+#endif
+   newpart->partnum = partnum;
+
+   return newpart;
+}
+
+static void print_gpt_info(void)
+{
+   struct list_head *pos;
+   struct disk_part *curr;
+
+   list_for_each(pos, _partitions) {
+   curr = list_entry(pos, struct disk_part, list);
+   printf("Partition %d:\n", curr->partnum);
+   printf("1st block %x, size %x\n", 
(unsigned)curr->gpt_part_info.start,
+  (unsigned)curr->gpt_part_info.size);
+   printf("Block size %lu, name %s\n", curr->gpt_part_info.blksz,
+  curr->gpt_part_info.name);
+   printf("Type %s, bootable %d\n", curr->gpt_part_info.type,
+  curr->gpt_part_info.bootable);
+#ifdef CONFIG_PARTITION_UUIDS
+   printf("UUID %s\n", curr->gpt_part_info.uuid);
+#endif
+   printf("\n");
+   }
+}
+
+/*
+ * read partition info into disk_partitions list where
+ * it can be printed or modified
+ */
+static int get_gpt_info(struct blk_desc *dev_desc)
+{
+   /* start partition numbering at 1, as u-boot does */
+   int valid_parts = 1, p, ret = 0;
+   disk_partition_t info;
+   struct disk_part *new_disk_part;
+
+   if (disk_partitions.next == NULL)
+   INIT_LIST_HEAD(_partitions);
+
+   for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
+   ret = part_get_info(dev_desc, p, );
+   if (ret)
+   continue;
+
+   new_disk_part = allocate_disk_part(, valid_parts);
+   if (IS_ERR(new_disk_part) && (valid_parts >= 2))
+   return -1;
+
+   list_add_tail(_disk_part->list, _partitions);
+   valid_parts++;
+   }
+   if (!valid_parts) {
+   printf("** No valid partitions found **\n");
+   del_gpt_info();
+   return -1;
+   }
+   return --valid_parts;
+}
+
+/* a wrapper to test get_gpt_info */
+static int do_get_gpt_info(struct blk_desc *dev_desc)
+{
+   int ret;
+
+   ret = get_gpt_info(dev_desc);
+   if (ret > 0) {
+   print_gpt_info();
+   del_gpt_info();
+   }
+   return ret;
+}
+
+
 /**
  * set_gpt_info(): Fill partition information from string
  * function allocates memory, remember to free!
@@ -456,6 +565,8 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
} else if (strcmp(argv[1], "guid") == 0) {
if (argc == 5) strcpy(varname, argv[4]);
return do_disk_guid(blk_dev_desc, varname);
+   } else if (strcmp(argv[1], "read") == 0) {
+   return do_get_gpt_info(blk_dev_desc);
} else {
return CMD_RET_USAGE;
 

[U-Boot] [PATCH 1/3] GPT: add accessor function for disk GUID

2017-05-21 Thread alison
From: Alison Chaiken <ali...@she-devel.com>

In order to read the GPT, modify the partition name strings, and then
write out a new GPT, the disk GUID is needed.  While there is an
existing accessor for the partition UUIDs, there is none yet for the
disk GUID.

Signed-off-by: Alison Chaiken <ali...@peloton-tech.com>
---
 cmd/gpt.c   | 29 -
 disk/part_efi.c | 31 +++
 include/part.h  | 15 +++
 3 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index 3e98821..814cb11 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -398,6 +398,23 @@ static int gpt_verify(struct blk_desc *blk_dev_desc, const 
char *str_part)
return ret;
 }
 
+static int do_disk_guid(struct blk_desc *dev_desc, char * const namestr)
+{
+   int ret;
+   char disk_guid[UUID_STR_LEN + 1];
+
+   ret = get_disk_guid(dev_desc, disk_guid);
+   if (ret < 0)
+   return 1;
+
+   if (namestr != NULL)
+   setenv(namestr, disk_guid);
+   else
+   printf("%s\n", disk_guid);
+
+   return 0;
+}
+
 /**
  * do_gpt(): Perform GPT operations
  *
@@ -412,7 +429,7 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
 {
int ret = CMD_RET_SUCCESS;
int dev = 0;
-   char *ep;
+   char *ep, *varname = NULL;
struct blk_desc *blk_dev_desc = NULL;
 
if (argc < 4 || argc > 5)
@@ -436,6 +453,9 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
} else if ((strcmp(argv[1], "verify") == 0)) {
ret = gpt_verify(blk_dev_desc, argv[4]);
printf("Verify GPT: ");
+   } else if (strcmp(argv[1], "guid") == 0) {
+   if (argc == 5) strcpy(varname, argv[4]);
+   return do_disk_guid(blk_dev_desc, varname);
} else {
return CMD_RET_USAGE;
}
@@ -458,4 +478,11 @@ U_BOOT_CMD(gpt, CONFIG_SYS_MAXARGS, 1, do_gpt,
" Example usage:\n"
" gpt write mmc 0 $partitions\n"
" gpt verify mmc 0 $partitions\n"
+   " guid  \n"
+   "- print disk GUID\n"
+   " guid   \n"
+   "- set environment variable to disk GUID\n"
+   " Example usage:\n"
+   " gpt guid mmc 0\n"
+   " gpt guid mmc 0 varname\n"
 );
diff --git a/disk/part_efi.c b/disk/part_efi.c
index 1b7ba27..de35c9b 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -178,6 +178,37 @@ static void prepare_backup_gpt_header(gpt_header *gpt_h)
  * Public Functions (include/part.h)
  */
 
+/*
+ * UUID is displayed as 32 hexadecimal digits, in 5 groups,
+ * separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters
+ */
+int get_disk_guid(struct blk_desc * dev_desc, char *guid)
+{
+   ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
+   gpt_entry *gpt_pte = NULL;
+   unsigned char *guid_bin;
+
+   /* This function validates AND fills in the GPT header and PTE */
+   if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA,
+gpt_head, _pte) != 1) {
+   printf("%s: *** ERROR: Invalid GPT ***\n", __func__);
+   if (is_gpt_valid(dev_desc, (dev_desc->lba - 1),
+gpt_head, _pte) != 1) {
+   printf("%s: *** ERROR: Invalid Backup GPT ***\n",
+  __func__);
+   return -1;
+   } else {
+   printf("%s: ***Using Backup GPT ***\n",
+  __func__);
+   }
+   }
+
+   guid_bin = (unsigned char *)(gpt_head->disk_guid.b);
+   uuid_bin_to_str(guid_bin, guid, UUID_STR_FORMAT_GUID);
+
+   return 0;
+}
+
 void part_print_efi(struct blk_desc *dev_desc)
 {
ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
diff --git a/include/part.h b/include/part.h
index 83bce05..69143bb 100644
--- a/include/part.h
+++ b/include/part.h
@@ -367,6 +367,21 @@ int gpt_verify_headers(struct blk_desc *dev_desc, 
gpt_header *gpt_head,
 int gpt_verify_partitions(struct blk_desc *dev_desc,
  disk_partition_t *partitions, int parts,
  gpt_header *gpt_head, gpt_entry **gpt_pte);
+
+
+/**
+ * get_disk_guid() - Function to read the GUID string from a device's GPT
+ *
+ * This function reads the GUID string from a block device whose descriptor
+ * is provided.
+ *
+ * @param dev_desc - block device descriptor
+ * @param guid - pre-allocated string in which to return the GUID
+ *
+ * @return - '0' on success, otherwise error
+ */
+int get_disk_guid(struct blk_desc *dev_desc, char *guid);
+
 #endif
 
 #if CONFIG_IS_ENABLED(DOS_PARTITION)
-- 
2.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 0/3] add support for GPT partition name manipulation

2017-05-21 Thread alison
From: Alison Chaiken <ali...@she-devel.com>

One way for userspace and the bootloader to exchange information about
dynamic image selection is via the storage device partition table, as
described at

https://source.android.com/devices/tech/ota/ab_updates

The scheme described there relies on setting partitions' "boot" flag.
When no partition on a device is bootable since the kernel and U-Boot
are stored elsewhere, the name field in the GPT partition table offers
another logical place to store information.  These patches allow users
to easily modify GPT partition names via bootscripts that can select
different images based on a boot-failure counter, or when userspace
installs a software update.

These patches have been tested on a TI DRA7xx-based SOM with U-Boot
2015.07.  The storage device is an eMMC.

Alison Chaiken (3):
  GPT: add accessor function for disk GUID
  GPT: read partition table from device into a data structure
  rename GPT partitions to detect boot failure

 cmd/gpt.c   | 339 +++-
 disk/part_efi.c |  31 ++
 include/part.h  |  24 
 3 files changed, 392 insertions(+), 2 deletions(-)

-- 
2.1.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 2/3] armv8: layerscape: Adjust memory mapping for Flash/SD card on LS1043A

2017-05-15 Thread Alison Wang
On 04/27/2017 01:08 AM, Alison Wang wrote:
> This patch is to adjust the memory mapping for FLash/SD card on 
> LS1043AQDS and LS1043ARDB, such as PPA firmware load address, FMAN 
> firmware load address, QE firmware load address, U-Boot start address 
> on serial flash and environment address.
>
> Signed-off-by: Alison Wang <alison.w...@nxp.com>
> ---
>  arch/arm/cpu/armv8/fsl-layerscape/Kconfig |  8 
>  include/configs/ls1043a_common.h  | 10 +-
>  include/configs/ls1043aqds.h  | 10 +-
>  include/configs/ls1043ardb.h  |  8 
>  4 files changed, 18 insertions(+), 18 deletions(-)
>
> diff --git a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig 
> b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
> index 4c16c4c..82c76e2 100644
> --- a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
> +++ b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
> @@ -163,11 +163,11 @@ endchoice
>  config SYS_LS_PPA_FW_ADDR
>   hex "Address of PPA firmware loading from"
>   depends on FSL_LS_PPA
> - default 0x4050 if SYS_LS_PPA_FW_IN_XIP && QSPI_BOOT
> + default 0x4040 if SYS_LS_PPA_FW_IN_XIP && QSPI_BOOT
>   default 0x580a0 if SYS_LS_PPA_FW_IN_XIP && ARCH_LS2080A
> - default 0x6050 if SYS_LS_PPA_FW_IN_XIP
> - default 0x50 if SYS_LS_PPA_FW_IN_MMC
> - default 0x50 if SYS_LS_PPA_FW_IN_NAND
> + default 0x6040 if SYS_LS_PPA_FW_IN_XIP
> + default 0x40 if SYS_LS_PPA_FW_IN_MMC
> + default 0x40 if SYS_LS_PPA_FW_IN_NAND
>
>   help
> If the PPA firmware locate at XIP flash, such as NOR or diff --git 
> a/include/configs/ls1043a_common.h b/include/configs/ls1043a_common.h
> index e269248..155da92 100644
> --- a/include/configs/ls1043a_common.h
> +++ b/include/configs/ls1043a_common.h
> @@ -208,9 +208,9 @@
>  #define CONFIG_SYS_FM_MURAM_SIZE 0x6
>
>  #ifdef CONFIG_NAND_BOOT
> -/* Store Fman ucode at offeset 0x16(11 blocks). */
> +/* Store Fman ucode at offeset 0x90(72 blocks). */
>  #define CONFIG_SYS_QE_FMAN_FW_IN_NAND
> -#define CONFIG_SYS_FMAN_FW_ADDR  (11 * 
> CONFIG_SYS_NAND_BLOCK_SIZE)
> +#define CONFIG_SYS_FMAN_FW_ADDR  (72 * 
> CONFIG_SYS_NAND_BLOCK_SIZE)
>  #elif defined(CONFIG_SD_BOOT)
>  /*
>   * PBL SD boot image should stored at 0x1000(8 blocks), the size of 
> the image is @@ -218,10 +218,10 @@
>   * 0x2000 (16 blocks), 8 + 2040 + 16 = 2064, enlarge it to 2080(0x820).
>   */
>  #define CONFIG_SYS_QE_FMAN_FW_IN_MMC
> -#define CONFIG_SYS_FMAN_FW_ADDR  (512 * 0x820)
> +#define CONFIG_SYS_FMAN_FW_ADDR  (512 * 0x4800)

Alison,

Please update the comments. It still says 0x820.
[Alison Wang] Yes, I will update. Thanks for reminding me.

Best Regards,
Alison Wang
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 1/3] arm: ls1021a: Adjust memory mapping for Flash/SD card on LS1021AQDS/TWR

2017-05-15 Thread Alison Wang
This patch is to adjust the memory mapping for FLash/SD card on LS1021AQDS
and LS1021ATWR, such as U-Boot start address on serial Flash, QE firmware
load address and environment address.

Signed-off-by: Alison Wang <alison.w...@nxp.com>
---
Changes:
- None

 include/configs/ls1021aqds.h | 10 +-
 include/configs/ls1021atwr.h | 10 +-
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/include/configs/ls1021aqds.h b/include/configs/ls1021aqds.h
index c3224c8..97f6c43 100644
--- a/include/configs/ls1021aqds.h
+++ b/include/configs/ls1021aqds.h
@@ -69,7 +69,7 @@ unsigned long get_board_ddr_clk(void);
 #endif
 
 #ifdef CONFIG_QSPI_BOOT
-#define CONFIG_SYS_TEXT_BASE   0x4001
+#define CONFIG_SYS_TEXT_BASE   0x4010
 #endif
 
 #ifdef CONFIG_NAND_BOOT
@@ -499,7 +499,7 @@ unsigned long get_board_ddr_clk(void);
 #define CONFIG_FSL_DEVICE_DISABLE
 
 
-#define CONFIG_SYS_QE_FW_ADDR 0x600c
+#define CONFIG_SYS_QE_FW_ADDR 0x6094
 
 #ifdef CONFIG_LPUART
 #define CONFIG_EXTRA_ENV_SETTINGS   \
@@ -550,14 +550,14 @@ unsigned long get_board_ddr_clk(void);
 #define CONFIG_ENV_OVERWRITE
 
 #if defined(CONFIG_SD_BOOT)
-#define CONFIG_ENV_OFFSET  0x10
+#define CONFIG_ENV_OFFSET  0x30
 #define CONFIG_ENV_IS_IN_MMC
 #define CONFIG_SYS_MMC_ENV_DEV 0
 #define CONFIG_ENV_SIZE0x2000
 #elif defined(CONFIG_QSPI_BOOT)
 #define CONFIG_ENV_IS_IN_SPI_FLASH
 #define CONFIG_ENV_SIZE0x2000  /* 8KB */
-#define CONFIG_ENV_OFFSET  0x10/* 1MB */
+#define CONFIG_ENV_OFFSET  0x30/* 3MB */
 #define CONFIG_ENV_SECT_SIZE   0x1
 #elif defined(CONFIG_NAND_BOOT)
 #define CONFIG_ENV_IS_IN_NAND
@@ -565,7 +565,7 @@ unsigned long get_board_ddr_clk(void);
 #define CONFIG_ENV_OFFSET  (10 * CONFIG_SYS_NAND_BLOCK_SIZE)
 #else
 #define CONFIG_ENV_IS_IN_FLASH
-#define CONFIG_ENV_ADDR(CONFIG_SYS_MONITOR_BASE - 
CONFIG_ENV_SECT_SIZE)
+#define CONFIG_ENV_ADDR(CONFIG_SYS_FLASH_BASE + 
0x30)
 #define CONFIG_ENV_SIZE0x2000
 #define CONFIG_ENV_SECT_SIZE   0x2 /* 128K (one sector) */
 #endif
diff --git a/include/configs/ls1021atwr.h b/include/configs/ls1021atwr.h
index 1d0b469..aecbee0 100644
--- a/include/configs/ls1021atwr.h
+++ b/include/configs/ls1021atwr.h
@@ -133,7 +133,7 @@
 #endif
 
 #ifdef CONFIG_QSPI_BOOT
-#define CONFIG_SYS_TEXT_BASE   0x4001
+#define CONFIG_SYS_TEXT_BASE   0x4010
 #endif
 
 #ifndef CONFIG_SYS_TEXT_BASE
@@ -410,7 +410,7 @@
 #define CONFIG_SYS_MONITOR_BASE CONFIG_SYS_TEXT_BASE/* start of monitor */
 #endif
 
-#define CONFIG_SYS_QE_FW_ADDR 0x600c
+#define CONFIG_SYS_QE_FW_ADDR 0x6094
 
 /*
  * Environment
@@ -418,18 +418,18 @@
 #define CONFIG_ENV_OVERWRITE
 
 #if defined(CONFIG_SD_BOOT)
-#define CONFIG_ENV_OFFSET  0x10
+#define CONFIG_ENV_OFFSET  0x30
 #define CONFIG_ENV_IS_IN_MMC
 #define CONFIG_SYS_MMC_ENV_DEV 0
 #define CONFIG_ENV_SIZE0x2
 #elif defined(CONFIG_QSPI_BOOT)
 #define CONFIG_ENV_IS_IN_SPI_FLASH
 #define CONFIG_ENV_SIZE0x2000
-#define CONFIG_ENV_OFFSET  0x10
+#define CONFIG_ENV_OFFSET  0x30
 #define CONFIG_ENV_SECT_SIZE   0x1
 #else
 #define CONFIG_ENV_IS_IN_FLASH
-#define CONFIG_ENV_ADDR(CONFIG_SYS_MONITOR_BASE - 
CONFIG_ENV_SECT_SIZE)
+#define CONFIG_ENV_ADDR(CONFIG_SYS_FLASH_BASE + 
0x30)
 #define CONFIG_ENV_SIZE0x2
 #define CONFIG_ENV_SECT_SIZE   0x2 /* 128K (one sector) */
 #endif
-- 
2.1.0.27.g96db324

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 3/3] armv8: layerscape: Adjust memory mapping for Flash/SD card on LS1046A

2017-05-15 Thread Alison Wang
This patch is to adjust the memory mapping for FLash/SD card on
LS1046AQDS and LS1046ARDB, such as FMAN firmware load address, U-Boot
start address on serial flash and environment address.

Signed-off-by: Alison Wang <alison.w...@nxp.com>
---
Changes:
- Update the comments and README.

 board/freescale/ls1046ardb/README | 16 
 include/configs/ls1046a_common.h  | 10 +-
 include/configs/ls1046aqds.h  | 10 +-
 include/configs/ls1046ardb.h  |  4 ++--
 4 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/board/freescale/ls1046ardb/README 
b/board/freescale/ls1046ardb/README
index 1ef7d47..a38c9d4 100644
--- a/board/freescale/ls1046ardb/README
+++ b/board/freescale/ls1046ardb/README
@@ -59,14 +59,14 @@ Start AddressEnd Address Description
Size
 QSPI flash map:
 Start AddressEnd Address Description   Size
 0x00_4000_ - 0x00_400F_  RCW + PBI 1MB
-0x00_4010_ - 0x00_401F_  U-Boot1MB
-0x00_4020_ - 0x00_402F_  U-Boot Env1MB
-0x00_4030_ - 0x00_403F_  FMan ucode1MB
-0x00_4040_ - 0x00_404F_  UEFI  1MB
-0x00_4050_ - 0x00_406F_  PPA   2MB
-0x00_4070_ - 0x00_408F_  Secure boot header
-+ bootscript   2MB
-0x00_4090_ - 0x00_40FF_  Reserved  7MB
+0x00_4010_ - 0x00_402F_  U-Boot2MB
+0x00_4030_ - 0x00_403F_  U-Boot Env1MB
+0x00_4040_ - 0x00_405F_  PPA   2MB
+0x00_4060_ - 0x00_408F_  Secure boot header
++ bootscript   3MB
+0x00_4090_ - 0x00_4093_  FMan ucode256KB
+0x00_4094_ - 0x00_4097_  QE/uQE firmware   256KB
+0x00_4098_ - 0x00_40FF_  Reserved  6MB
 0x00_4100_ - 0x00_43FF_  FIT Image 48MB
 
 Booting Options
diff --git a/include/configs/ls1046a_common.h b/include/configs/ls1046a_common.h
index 957ffd3..61bf3eb 100644
--- a/include/configs/ls1046a_common.h
+++ b/include/configs/ls1046a_common.h
@@ -166,23 +166,23 @@
 /*
  * PBL SD boot image should stored at 0x1000(8 blocks), the size of the image 
is
  * about 1MB (2048 blocks), Env is stored after the image, and the env size is
- * 0x2000 (16 blocks), 8 + 2048 + 16 = 2072, enlarge it to 2080(0x820).
+ * 0x2000 (16 blocks), 8 + 2048 + 16 = 2072, enlarge it to 18432(0x4800).
  */
 #define CONFIG_SYS_QE_FMAN_FW_IN_MMC
-#define CONFIG_SYS_FMAN_FW_ADDR(512 * 0x820)
+#define CONFIG_SYS_FMAN_FW_ADDR(512 * 0x4800)
 #elif defined(CONFIG_QSPI_BOOT)
 #define CONFIG_SYS_QE_FW_IN_SPIFLASH
-#define CONFIG_SYS_FMAN_FW_ADDR0x4030
+#define CONFIG_SYS_FMAN_FW_ADDR0x4090
 #define CONFIG_ENV_SPI_BUS 0
 #define CONFIG_ENV_SPI_CS  0
 #define CONFIG_ENV_SPI_MAX_HZ  100
 #define CONFIG_ENV_SPI_MODE0x03
 #elif defined(CONFIG_NAND_BOOT)
 #define CONFIG_SYS_QE_FMAN_FW_IN_NAND
-#define CONFIG_SYS_FMAN_FW_ADDR(6 * CONFIG_SYS_NAND_BLOCK_SIZE)
+#define CONFIG_SYS_FMAN_FW_ADDR(72 * 
CONFIG_SYS_NAND_BLOCK_SIZE)
 #else
 #define CONFIG_SYS_QE_FMAN_FW_IN_NOR
-#define CONFIG_SYS_FMAN_FW_ADDR0x6030
+#define CONFIG_SYS_FMAN_FW_ADDR0x6090
 #endif
 #define CONFIG_SYS_QE_FMAN_FW_LENGTH   0x1
 #define CONFIG_SYS_FDT_PAD (0x3000 + CONFIG_SYS_QE_FMAN_FW_LENGTH)
diff --git a/include/configs/ls1046aqds.h b/include/configs/ls1046aqds.h
index 0cf6010..5d2e819 100644
--- a/include/configs/ls1046aqds.h
+++ b/include/configs/ls1046aqds.h
@@ -12,7 +12,7 @@
 #if defined(CONFIG_NAND_BOOT) || defined(CONFIG_SD_BOOT)
 #define CONFIG_SYS_TEXT_BASE   0x8200
 #elif defined(CONFIG_QSPI_BOOT)
-#define CONFIG_SYS_TEXT_BASE   0x4001
+#define CONFIG_SYS_TEXT_BASE   0x4010
 #else
 #define CONFIG_SYS_TEXT_BASE   0x6010
 #endif
@@ -447,20 +447,20 @@ unsigned long get_board_ddr_clk(void);
 #ifdef CONFIG_NAND_BOOT
 #define CONFIG_ENV_IS_IN_NAND
 #define CONFIG_ENV_SIZE0x2000
-#define CONFIG_ENV_OFFSET  (5 * CONFIG_SYS_NAND_BLOCK_SIZE)
+#define CONFIG_ENV_OFFSET  (24 * CONFIG_SYS_NAND_BLOCK_SIZE)
 #elif defined(CONFIG_SD_BOOT)
-#define CONFIG_ENV_OFFSET  (1024 * 1024)
+#define CONFIG_ENV_OFFSET  (3 * 1024 * 1024)
 #define CONFIG_ENV_IS_IN_MMC
 #define CONFIG_SYS_MMC_ENV_DEV 0
 #define CONFIG_ENV_SIZE0x2000
 #elif defined(CONFIG_QSPI_BOOT)
 #define CONFIG_ENV_IS_IN_SPI_FLASH
 #define CONFIG_ENV_SIZE0x2000  /* 8KB */
-#define CONFIG_ENV_OFFSET  0x10/* 1MB */
+#define CONFIG_ENV_OFFSET  0x30/* 3MB */
 #define CONFIG_ENV_SEC

[U-Boot] [PATCH v2 2/3] armv8: layerscape: Adjust memory mapping for Flash/SD card on LS1043A

2017-05-15 Thread Alison Wang
This patch is to adjust the memory mapping for FLash/SD card on
LS1043AQDS and LS1043ARDB, such as PPA firmware load address, FMAN
firmware load address, QE firmware load address, U-Boot start address on
serial flash and environment address.

Signed-off-by: Alison Wang <alison.w...@nxp.com>
---
Changes:
- Update the comments.

 arch/arm/cpu/armv8/fsl-layerscape/Kconfig |  8 
 include/configs/ls1043a_common.h  | 12 ++--
 include/configs/ls1043aqds.h  | 10 +-
 include/configs/ls1043ardb.h  |  8 
 4 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig 
b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
index 4c16c4c..82c76e2 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
+++ b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
@@ -163,11 +163,11 @@ endchoice
 config SYS_LS_PPA_FW_ADDR
hex "Address of PPA firmware loading from"
depends on FSL_LS_PPA
-   default 0x4050 if SYS_LS_PPA_FW_IN_XIP && QSPI_BOOT
+   default 0x4040 if SYS_LS_PPA_FW_IN_XIP && QSPI_BOOT
default 0x580a0 if SYS_LS_PPA_FW_IN_XIP && ARCH_LS2080A
-   default 0x6050 if SYS_LS_PPA_FW_IN_XIP
-   default 0x50 if SYS_LS_PPA_FW_IN_MMC
-   default 0x50 if SYS_LS_PPA_FW_IN_NAND
+   default 0x6040 if SYS_LS_PPA_FW_IN_XIP
+   default 0x40 if SYS_LS_PPA_FW_IN_MMC
+   default 0x40 if SYS_LS_PPA_FW_IN_NAND
 
help
  If the PPA firmware locate at XIP flash, such as NOR or
diff --git a/include/configs/ls1043a_common.h b/include/configs/ls1043a_common.h
index e269248..05419fe 100644
--- a/include/configs/ls1043a_common.h
+++ b/include/configs/ls1043a_common.h
@@ -208,20 +208,20 @@
 #define CONFIG_SYS_FM_MURAM_SIZE   0x6
 
 #ifdef CONFIG_NAND_BOOT
-/* Store Fman ucode at offeset 0x16(11 blocks). */
+/* Store Fman ucode at offeset 0x90(72 blocks). */
 #define CONFIG_SYS_QE_FMAN_FW_IN_NAND
-#define CONFIG_SYS_FMAN_FW_ADDR(11 * 
CONFIG_SYS_NAND_BLOCK_SIZE)
+#define CONFIG_SYS_FMAN_FW_ADDR(72 * 
CONFIG_SYS_NAND_BLOCK_SIZE)
 #elif defined(CONFIG_SD_BOOT)
 /*
  * PBL SD boot image should stored at 0x1000(8 blocks), the size of the image 
is
  * about 1MB (2040 blocks), Env is stored after the image, and the env size is
- * 0x2000 (16 blocks), 8 + 2040 + 16 = 2064, enlarge it to 2080(0x820).
+ * 0x2000 (16 blocks), 8 + 2040 + 16 = 2064, enlarge it to 18432(0x4800).
  */
 #define CONFIG_SYS_QE_FMAN_FW_IN_MMC
-#define CONFIG_SYS_FMAN_FW_ADDR(512 * 0x820)
+#define CONFIG_SYS_FMAN_FW_ADDR(512 * 0x4800)
 #elif defined(CONFIG_QSPI_BOOT)
 #define CONFIG_SYS_QE_FW_IN_SPIFLASH
-#define CONFIG_SYS_FMAN_FW_ADDR0x400d
+#define CONFIG_SYS_FMAN_FW_ADDR0x4090
 #define CONFIG_ENV_SPI_BUS 0
 #define CONFIG_ENV_SPI_CS  0
 #define CONFIG_ENV_SPI_MAX_HZ  100
@@ -229,7 +229,7 @@
 #else
 #define CONFIG_SYS_QE_FMAN_FW_IN_NOR
 /* FMan fireware Pre-load address */
-#define CONFIG_SYS_FMAN_FW_ADDR0x6030
+#define CONFIG_SYS_FMAN_FW_ADDR0x6090
 #endif
 #define CONFIG_SYS_QE_FMAN_FW_LENGTH   0x1
 #define CONFIG_SYS_FDT_PAD (0x3000 + CONFIG_SYS_QE_FMAN_FW_LENGTH)
diff --git a/include/configs/ls1043aqds.h b/include/configs/ls1043aqds.h
index b14e944..04d74ac 100644
--- a/include/configs/ls1043aqds.h
+++ b/include/configs/ls1043aqds.h
@@ -12,7 +12,7 @@
 #if defined(CONFIG_NAND_BOOT) || defined(CONFIG_SD_BOOT)
 #define CONFIG_SYS_TEXT_BASE   0x8200
 #elif defined(CONFIG_QSPI_BOOT)
-#define CONFIG_SYS_TEXT_BASE   0x4001
+#define CONFIG_SYS_TEXT_BASE   0x4010
 #else
 #define CONFIG_SYS_TEXT_BASE   0x6010
 #endif
@@ -413,20 +413,20 @@ unsigned long get_board_ddr_clk(void);
 #ifdef CONFIG_NAND_BOOT
 #define CONFIG_ENV_IS_IN_NAND
 #define CONFIG_ENV_SIZE0x2000
-#define CONFIG_ENV_OFFSET  (10 * CONFIG_SYS_NAND_BLOCK_SIZE)
+#define CONFIG_ENV_OFFSET  (24 * CONFIG_SYS_NAND_BLOCK_SIZE)
 #elif defined(CONFIG_SD_BOOT)
-#define CONFIG_ENV_OFFSET  (1024 * 1024)
+#define CONFIG_ENV_OFFSET  (3 * 1024 * 1024)
 #define CONFIG_ENV_IS_IN_MMC
 #define CONFIG_SYS_MMC_ENV_DEV 0
 #define CONFIG_ENV_SIZE0x2000
 #elif defined(CONFIG_QSPI_BOOT)
 #define CONFIG_ENV_IS_IN_SPI_FLASH
 #define CONFIG_ENV_SIZE0x2000  /* 8KB */
-#define CONFIG_ENV_OFFSET  0x10/* 1MB */
+#define CONFIG_ENV_OFFSET  0x30/* 3MB */
 #define CONFIG_ENV_SECT_SIZE   0x1
 #else
 #define CONFIG_ENV_IS_IN_FLASH
-#define CONFIG_ENV_ADDR(CONFIG_SYS_FLASH_BASE + 
0x20)
+#define CONFIG_ENV_ADDR(CON

[U-Boot] [PATCH 2/3] armv8: layerscape: Adjust memory mapping for Flash/SD card on LS1043A

2017-04-27 Thread Alison Wang
This patch is to adjust the memory mapping for FLash/SD card on
LS1043AQDS and LS1043ARDB, such as PPA firmware load address, FMAN
firmware load address, QE firmware load address, U-Boot start address on
serial flash and environment address.

Signed-off-by: Alison Wang <alison.w...@nxp.com>
---
 arch/arm/cpu/armv8/fsl-layerscape/Kconfig |  8 
 include/configs/ls1043a_common.h  | 10 +-
 include/configs/ls1043aqds.h  | 10 +-
 include/configs/ls1043ardb.h  |  8 
 4 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig 
b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
index 4c16c4c..82c76e2 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
+++ b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
@@ -163,11 +163,11 @@ endchoice
 config SYS_LS_PPA_FW_ADDR
hex "Address of PPA firmware loading from"
depends on FSL_LS_PPA
-   default 0x4050 if SYS_LS_PPA_FW_IN_XIP && QSPI_BOOT
+   default 0x4040 if SYS_LS_PPA_FW_IN_XIP && QSPI_BOOT
default 0x580a0 if SYS_LS_PPA_FW_IN_XIP && ARCH_LS2080A
-   default 0x6050 if SYS_LS_PPA_FW_IN_XIP
-   default 0x50 if SYS_LS_PPA_FW_IN_MMC
-   default 0x50 if SYS_LS_PPA_FW_IN_NAND
+   default 0x6040 if SYS_LS_PPA_FW_IN_XIP
+   default 0x40 if SYS_LS_PPA_FW_IN_MMC
+   default 0x40 if SYS_LS_PPA_FW_IN_NAND
 
help
  If the PPA firmware locate at XIP flash, such as NOR or
diff --git a/include/configs/ls1043a_common.h b/include/configs/ls1043a_common.h
index e269248..155da92 100644
--- a/include/configs/ls1043a_common.h
+++ b/include/configs/ls1043a_common.h
@@ -208,9 +208,9 @@
 #define CONFIG_SYS_FM_MURAM_SIZE   0x6
 
 #ifdef CONFIG_NAND_BOOT
-/* Store Fman ucode at offeset 0x16(11 blocks). */
+/* Store Fman ucode at offeset 0x90(72 blocks). */
 #define CONFIG_SYS_QE_FMAN_FW_IN_NAND
-#define CONFIG_SYS_FMAN_FW_ADDR(11 * 
CONFIG_SYS_NAND_BLOCK_SIZE)
+#define CONFIG_SYS_FMAN_FW_ADDR(72 * 
CONFIG_SYS_NAND_BLOCK_SIZE)
 #elif defined(CONFIG_SD_BOOT)
 /*
  * PBL SD boot image should stored at 0x1000(8 blocks), the size of the image 
is
@@ -218,10 +218,10 @@
  * 0x2000 (16 blocks), 8 + 2040 + 16 = 2064, enlarge it to 2080(0x820).
  */
 #define CONFIG_SYS_QE_FMAN_FW_IN_MMC
-#define CONFIG_SYS_FMAN_FW_ADDR(512 * 0x820)
+#define CONFIG_SYS_FMAN_FW_ADDR(512 * 0x4800)
 #elif defined(CONFIG_QSPI_BOOT)
 #define CONFIG_SYS_QE_FW_IN_SPIFLASH
-#define CONFIG_SYS_FMAN_FW_ADDR0x400d
+#define CONFIG_SYS_FMAN_FW_ADDR0x4090
 #define CONFIG_ENV_SPI_BUS 0
 #define CONFIG_ENV_SPI_CS  0
 #define CONFIG_ENV_SPI_MAX_HZ  100
@@ -229,7 +229,7 @@
 #else
 #define CONFIG_SYS_QE_FMAN_FW_IN_NOR
 /* FMan fireware Pre-load address */
-#define CONFIG_SYS_FMAN_FW_ADDR0x6030
+#define CONFIG_SYS_FMAN_FW_ADDR0x6090
 #endif
 #define CONFIG_SYS_QE_FMAN_FW_LENGTH   0x1
 #define CONFIG_SYS_FDT_PAD (0x3000 + CONFIG_SYS_QE_FMAN_FW_LENGTH)
diff --git a/include/configs/ls1043aqds.h b/include/configs/ls1043aqds.h
index b14e944..04d74ac 100644
--- a/include/configs/ls1043aqds.h
+++ b/include/configs/ls1043aqds.h
@@ -12,7 +12,7 @@
 #if defined(CONFIG_NAND_BOOT) || defined(CONFIG_SD_BOOT)
 #define CONFIG_SYS_TEXT_BASE   0x8200
 #elif defined(CONFIG_QSPI_BOOT)
-#define CONFIG_SYS_TEXT_BASE   0x4001
+#define CONFIG_SYS_TEXT_BASE   0x4010
 #else
 #define CONFIG_SYS_TEXT_BASE   0x6010
 #endif
@@ -413,20 +413,20 @@ unsigned long get_board_ddr_clk(void);
 #ifdef CONFIG_NAND_BOOT
 #define CONFIG_ENV_IS_IN_NAND
 #define CONFIG_ENV_SIZE0x2000
-#define CONFIG_ENV_OFFSET  (10 * CONFIG_SYS_NAND_BLOCK_SIZE)
+#define CONFIG_ENV_OFFSET  (24 * CONFIG_SYS_NAND_BLOCK_SIZE)
 #elif defined(CONFIG_SD_BOOT)
-#define CONFIG_ENV_OFFSET  (1024 * 1024)
+#define CONFIG_ENV_OFFSET  (3 * 1024 * 1024)
 #define CONFIG_ENV_IS_IN_MMC
 #define CONFIG_SYS_MMC_ENV_DEV 0
 #define CONFIG_ENV_SIZE0x2000
 #elif defined(CONFIG_QSPI_BOOT)
 #define CONFIG_ENV_IS_IN_SPI_FLASH
 #define CONFIG_ENV_SIZE0x2000  /* 8KB */
-#define CONFIG_ENV_OFFSET  0x10/* 1MB */
+#define CONFIG_ENV_OFFSET  0x30/* 3MB */
 #define CONFIG_ENV_SECT_SIZE   0x1
 #else
 #define CONFIG_ENV_IS_IN_FLASH
-#define CONFIG_ENV_ADDR(CONFIG_SYS_FLASH_BASE + 
0x20)
+#define CONFIG_ENV_ADDR(CONFIG_SYS_FLASH_BASE + 
0x30)
 #define CONFIG_ENV_SECT_SIZE   0x2
 #define CONFIG_ENV_SIZE0x2
 #endif
diff --git a/include/configs/ls1043ard

[U-Boot] [PATCH 1/3] arm: ls1021a: Adjust memory mapping for Flash/SD card on LS1021AQDS/TWR

2017-04-27 Thread Alison Wang
This patch is to adjust the memory mapping for FLash/SD card on LS1021AQDS
and LS1021ATWR, such as U-Boot start address on serial Flash, QE firmware
load address and environment address.

Signed-off-by: Alison Wang <alison.w...@nxp.com>
---
 include/configs/ls1021aqds.h | 10 +-
 include/configs/ls1021atwr.h | 10 +-
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/include/configs/ls1021aqds.h b/include/configs/ls1021aqds.h
index c3224c8..97f6c43 100644
--- a/include/configs/ls1021aqds.h
+++ b/include/configs/ls1021aqds.h
@@ -69,7 +69,7 @@ unsigned long get_board_ddr_clk(void);
 #endif
 
 #ifdef CONFIG_QSPI_BOOT
-#define CONFIG_SYS_TEXT_BASE   0x4001
+#define CONFIG_SYS_TEXT_BASE   0x4010
 #endif
 
 #ifdef CONFIG_NAND_BOOT
@@ -499,7 +499,7 @@ unsigned long get_board_ddr_clk(void);
 #define CONFIG_FSL_DEVICE_DISABLE
 
 
-#define CONFIG_SYS_QE_FW_ADDR 0x600c
+#define CONFIG_SYS_QE_FW_ADDR 0x6094
 
 #ifdef CONFIG_LPUART
 #define CONFIG_EXTRA_ENV_SETTINGS   \
@@ -550,14 +550,14 @@ unsigned long get_board_ddr_clk(void);
 #define CONFIG_ENV_OVERWRITE
 
 #if defined(CONFIG_SD_BOOT)
-#define CONFIG_ENV_OFFSET  0x10
+#define CONFIG_ENV_OFFSET  0x30
 #define CONFIG_ENV_IS_IN_MMC
 #define CONFIG_SYS_MMC_ENV_DEV 0
 #define CONFIG_ENV_SIZE0x2000
 #elif defined(CONFIG_QSPI_BOOT)
 #define CONFIG_ENV_IS_IN_SPI_FLASH
 #define CONFIG_ENV_SIZE0x2000  /* 8KB */
-#define CONFIG_ENV_OFFSET  0x10/* 1MB */
+#define CONFIG_ENV_OFFSET  0x30/* 3MB */
 #define CONFIG_ENV_SECT_SIZE   0x1
 #elif defined(CONFIG_NAND_BOOT)
 #define CONFIG_ENV_IS_IN_NAND
@@ -565,7 +565,7 @@ unsigned long get_board_ddr_clk(void);
 #define CONFIG_ENV_OFFSET  (10 * CONFIG_SYS_NAND_BLOCK_SIZE)
 #else
 #define CONFIG_ENV_IS_IN_FLASH
-#define CONFIG_ENV_ADDR(CONFIG_SYS_MONITOR_BASE - 
CONFIG_ENV_SECT_SIZE)
+#define CONFIG_ENV_ADDR(CONFIG_SYS_FLASH_BASE + 
0x30)
 #define CONFIG_ENV_SIZE0x2000
 #define CONFIG_ENV_SECT_SIZE   0x2 /* 128K (one sector) */
 #endif
diff --git a/include/configs/ls1021atwr.h b/include/configs/ls1021atwr.h
index 1d0b469..aecbee0 100644
--- a/include/configs/ls1021atwr.h
+++ b/include/configs/ls1021atwr.h
@@ -133,7 +133,7 @@
 #endif
 
 #ifdef CONFIG_QSPI_BOOT
-#define CONFIG_SYS_TEXT_BASE   0x4001
+#define CONFIG_SYS_TEXT_BASE   0x4010
 #endif
 
 #ifndef CONFIG_SYS_TEXT_BASE
@@ -410,7 +410,7 @@
 #define CONFIG_SYS_MONITOR_BASE CONFIG_SYS_TEXT_BASE/* start of monitor */
 #endif
 
-#define CONFIG_SYS_QE_FW_ADDR 0x600c
+#define CONFIG_SYS_QE_FW_ADDR 0x6094
 
 /*
  * Environment
@@ -418,18 +418,18 @@
 #define CONFIG_ENV_OVERWRITE
 
 #if defined(CONFIG_SD_BOOT)
-#define CONFIG_ENV_OFFSET  0x10
+#define CONFIG_ENV_OFFSET  0x30
 #define CONFIG_ENV_IS_IN_MMC
 #define CONFIG_SYS_MMC_ENV_DEV 0
 #define CONFIG_ENV_SIZE0x2
 #elif defined(CONFIG_QSPI_BOOT)
 #define CONFIG_ENV_IS_IN_SPI_FLASH
 #define CONFIG_ENV_SIZE0x2000
-#define CONFIG_ENV_OFFSET  0x10
+#define CONFIG_ENV_OFFSET  0x30
 #define CONFIG_ENV_SECT_SIZE   0x1
 #else
 #define CONFIG_ENV_IS_IN_FLASH
-#define CONFIG_ENV_ADDR(CONFIG_SYS_MONITOR_BASE - 
CONFIG_ENV_SECT_SIZE)
+#define CONFIG_ENV_ADDR(CONFIG_SYS_FLASH_BASE + 
0x30)
 #define CONFIG_ENV_SIZE0x2
 #define CONFIG_ENV_SECT_SIZE   0x2 /* 128K (one sector) */
 #endif
-- 
2.1.0.27.g96db324

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v3 5/6] video: fsl_dcu_fb: add additional modes for DCU

2017-04-12 Thread Alison Wang
> -Original Message-
> From: Sanchayan Maity [mailto:maitysancha...@gmail.com]
> Sent: Tuesday, April 11, 2017 1:42 PM
> To: u-boot@lists.denx.de; sba...@denx.de; ag...@denx.de
> Cc: albert.u.b...@aribaud.net; Feng Li <feng.l...@nxp.com>;
> alison.w...@freescale.com; Sumit Garg <sumit.g...@nxp.com>; Stefan
> Agner <stefan.ag...@toradex.com>; york sun <york@nxp.com>; Z.Q. Hou
> <zhiqiang@nxp.com>; Xiaoliang Yang <xiaoliang.y...@nxp.com>;
> Sanchayan Maity <maitysancha...@gmail.com>
> Subject: [PATCH v3 5/6] video: fsl_dcu_fb: add additional modes for DCU
> 
> From: Stefan Agner <stefan.ag...@toradex.com>
> 
> Add common widescreen modes 800x480 and 1024x600.
> 
> Signed-off-by: Stefan Agner <stefan.ag...@toradex.com>
> Signed-off-by: Sanchayan Maity <maitysancha...@gmail.com>
> ---
>  drivers/video/fsl_dcu_fb.c | 61
> ++++--
>  1 file changed, 59 insertions(+), 2 deletions(-)
> 
Reviewed-by: Alison Wang <alison.w...@nxp.com>

Best Regards,
Alison Wang
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


  1   2   3   4   5   >