Re: [U-Boot] [PATCH 3/5] fsl PPA: add support PPA image loading from NAND and SD

2017-03-06 Thread Z.Q. Hou
Hi York,

Thanks so much for your suggestion! Will add a comment there.

Thanks,
Zhiqiang

From: york sun
Sent: Monday, March 06, 2017 12:36 PM
To: Z.Q. Hou ; u-boot@lists.denx.de; o...@buserror.net; 
mingkai...@freescale.com; s...@chromium.org; Xiaobo Xie 
Subject: RE: [PATCH 3/5] fsl PPA: add support PPA image loading from NAND and SD


Sorry for top posting (using my phone).
I think we should flush the cache by range. If you are relying on PPA flushing 
the cache for you (it is the case now), it's better to put a comment there.

York


 Original Message 
From: "Z.Q. Hou" mailto:zhiqiang@nxp.com>>
Sent: Sunday, March 5, 2017 07:07 PM
To: york sun 
mailto:york@nxp.com>>,u-boot@lists.denx.de,o...@buserror.net,mingkai...@freescale.com,s...@chromium.org,Xiaobo
 Xie mailto:xiaobo@nxp.com>>
Subject: RE: [PATCH 3/5] fsl PPA: add support PPA image loading from NAND and SD

Hi York,

Thanks a lot for your comments!

> -Original Message-
> From: york sun
> Sent: Saturday, March 04, 2017 12:51 AM
> To: Z.Q. Hou mailto:zhiqiang@nxp.com>>; 
> u-boot@lists.denx.de;
> o...@buserror.net; 
> mingkai...@freescale.com; 
> s...@chromium.org; Xiaobo
> Xie mailto:xiaobo@nxp.com>>
> Subject: Re: [PATCH 3/5] fsl PPA: add support PPA image loading from NAND
> and SD
>
> On 03/03/2017 05:45 AM, Zhiqiang Hou wrote:
> > From: Hou Zhiqiang mailto:zhiqiang@nxp.com>>
> >
> > Signed-off-by: Hou Zhiqiang 
> > mailto:zhiqiang@nxp.com>>
> > ---
> >  arch/arm/cpu/armv8/fsl-layerscape/ppa.c | 118
> > +++-
> >  1 file changed, 117 insertions(+), 1 deletion(-)
>
> 
>
> >
> >  #ifdef CONFIG_SYS_LS_PPA_FW_IN_XIP
> >  ppa_fit_addr = (void *)CONFIG_SYS_LS_PPA_FW_ADDR;
> > + debug("%s: PPA image load from XIP\n", __func__); #else /*
> > +!CONFIG_SYS_LS_PPA_FW_IN_XIP */
> > + size_t fw_length, fdt_header_len = sizeof(struct fdt_header);
> > +
> > + /* Copy PPA image from MMC/SD/NAND to allocated memory */
> #ifdef
> > +CONFIG_SYS_LS_PPA_FW_IN_MMC
> > + struct mmc *mmc;
> > + int dev = CONFIG_SYS_MMC_ENV_DEV;
> > + struct fdt_header *fitp;
> > + u32 cnt;
> > + u32 blk = CONFIG_SYS_LS_PPA_FW_ADDR / 512;
> > +
> > + debug("%s: PPA image load from eMMC/SD\n", __func__);
> > +
> > + mmc_initialize(gd->bd);
> > + mmc = find_mmc_device(dev);
> > + if (!mmc) {
> > + printf("PPA: MMC cannot find device for PPA firmware\n");
> > + return -ENODEV;
> > + }
> > +
> > + mmc_init(mmc);
> > +
> > + fitp = malloc(roundup(fdt_header_len, 512));
> > + if (!fitp) {
> > + printf("PPA: malloc failed for FIT header(size 0x%zx)\n",
> > +roundup(fdt_header_len, 512));
> > + return -ENOMEM;
> > + }
> > +
> > + cnt = DIV_ROUND_UP(fdt_header_len, 512);
> > + debug("%s: MMC read PPA FIT header: dev # %u, block # %u,
> count %u\n",
> > +   __func__, dev, blk, cnt);
> > + ret = mmc->block_dev.block_read(&mmc->block_dev, blk, cnt, fitp);
> > + if (ret != cnt) {
> > + free(fitp);
> > + printf("MMC/SD read of PPA FIT header at offset 0x%x
> failed\n",
> > +CONFIG_SYS_LS_PPA_FW_ADDR);
> > + return -EIO;
> > + }
> > +
> > + /* flush cache after read */
> > + flush_cache((ulong)fitp, cnt * 512);
> > +
> > + fw_length = fdt_totalsize(fitp);
> > + free(fitp);
> > +
> > + fw_length = roundup(fw_length, 512);
> > + ppa_fit_addr = malloc(fw_length);
> > + if (!ppa_fit_addr) {
> > + printf("PPA: malloc failed for PPA image(size 0x%zx)\n",
> > +fw_length);
> > + return -ENOMEM;
> > + }
> > +
> > + cnt = DIV_ROUND_UP(fw_length, 512);
> > + debug("%s: MMC read PPA FIT image: dev # %u, block # %u,
> count %u\n",
> > +   __func__, dev, blk, cnt);
> > + ret = mmc->block_dev.block_read(&mmc->block_dev,
> > + blk, cnt, ppa_fit_addr);
> > + if (ret != cnt) {
> > + free(ppa_fit_addr);
> > + printf("MMC/SD read of PPA FIT header at offset 0x%x
> failed\n",
> > +CONFIG_SYS_LS_PPA_FW_ADDR);
> > + return -EIO;
> > + }
> > +
> > + flush_cache((ulong)ppa_fit_addr, cnt * 512);
> > +
> > +#elif CONFIG_SYS_LS_PPA_FW_IN_NAND
> > + struct fdt_header fit;
> > +
> > + debug("%s: PPA image load from NAND\n", __func__);
> > +
> > + nand_init();
> > + ret = nand_read(nand_info[0],
> (loff_t)CONFIG_SYS_LS_PPA_FW_ADDR,
> > +&fdt_header_len, (u_char *)&fit);
> > + if (ret == -EUCLEAN) {
> > + printf("NAND read of PPA FIT header at offset 0x%x failed\n",
> > +CONFIG_SYS_LS_PPA_FW_ADDR);
> > + return -EIO;
> > + }
> > +
> > + fw_length = fdt_totalsize(&fit);
> > +
> > + ppa_fit_addr = malloc(fw_length);
> > + if (!ppa_fit_addr) {
> > + printf("PPA: malloc failed for PPA image(size 0x%zx)\n",
> > +fw_length);
> > + return -ENOMEM;
> > + }
> > +
> > + ret = nand_read(nand_info[0],
> (loff_t)CONFIG_SYS_LS_PPA_FW_ADDR,
> > +&fw_length, (u_char *)ppa_fit_addr);
> > + if (ret == -EUCLEAN) {
> > + free(ppa_fit_addr);
> > + printf("NAND read of PPA firmware at offset 

Re: [U-Boot] [PATCH 3/5] fsl PPA: add support PPA image loading from NAND and SD

2017-03-05 Thread york sun

Sorry for top posting (using my phone).
I think we should flush the cache by range. If you are relying on PPA flushing 
the cache for you (it is the case now), it's better to put a comment there.

York


 Original Message 
From: "Z.Q. Hou" 
Sent: Sunday, March 5, 2017 07:07 PM
To: york sun 
,u-boot@lists.denx.de,o...@buserror.net,mingkai...@freescale.com,s...@chromium.org,Xiaobo
 Xie 
Subject: RE: [PATCH 3/5] fsl PPA: add support PPA image loading from NAND and SD


Hi York,

Thanks a lot for your comments!

> -Original Message-
> From: york sun
> Sent: Saturday, March 04, 2017 12:51 AM
> To: Z.Q. Hou ; u-boot@lists.denx.de;
> o...@buserror.net; mingkai...@freescale.com; s...@chromium.org; Xiaobo
> Xie 
> Subject: Re: [PATCH 3/5] fsl PPA: add support PPA image loading from NAND
> and SD
>
> On 03/03/2017 05:45 AM, Zhiqiang Hou wrote:
> > From: Hou Zhiqiang 
> >
> > Signed-off-by: Hou Zhiqiang 
> > ---
> >  arch/arm/cpu/armv8/fsl-layerscape/ppa.c | 118
> > +++-
> >  1 file changed, 117 insertions(+), 1 deletion(-)
>
> 
>
> >
> >  #ifdef CONFIG_SYS_LS_PPA_FW_IN_XIP
> >  ppa_fit_addr = (void *)CONFIG_SYS_LS_PPA_FW_ADDR;
> > + debug("%s: PPA image load from XIP\n", __func__); #else /*
> > +!CONFIG_SYS_LS_PPA_FW_IN_XIP */
> > + size_t fw_length, fdt_header_len = sizeof(struct fdt_header);
> > +
> > + /* Copy PPA image from MMC/SD/NAND to allocated memory */
> #ifdef
> > +CONFIG_SYS_LS_PPA_FW_IN_MMC
> > + struct mmc *mmc;
> > + int dev = CONFIG_SYS_MMC_ENV_DEV;
> > + struct fdt_header *fitp;
> > + u32 cnt;
> > + u32 blk = CONFIG_SYS_LS_PPA_FW_ADDR / 512;
> > +
> > + debug("%s: PPA image load from eMMC/SD\n", __func__);
> > +
> > + mmc_initialize(gd->bd);
> > + mmc = find_mmc_device(dev);
> > + if (!mmc) {
> > + printf("PPA: MMC cannot find device for PPA firmware\n");
> > + return -ENODEV;
> > + }
> > +
> > + mmc_init(mmc);
> > +
> > + fitp = malloc(roundup(fdt_header_len, 512));
> > + if (!fitp) {
> > + printf("PPA: malloc failed for FIT header(size 0x%zx)\n",
> > +roundup(fdt_header_len, 512));
> > + return -ENOMEM;
> > + }
> > +
> > + cnt = DIV_ROUND_UP(fdt_header_len, 512);
> > + debug("%s: MMC read PPA FIT header: dev # %u, block # %u,
> count %u\n",
> > +   __func__, dev, blk, cnt);
> > + ret = mmc->block_dev.block_read(&mmc->block_dev, blk, cnt, fitp);
> > + if (ret != cnt) {
> > + free(fitp);
> > + printf("MMC/SD read of PPA FIT header at offset 0x%x
> failed\n",
> > +CONFIG_SYS_LS_PPA_FW_ADDR);
> > + return -EIO;
> > + }
> > +
> > + /* flush cache after read */
> > + flush_cache((ulong)fitp, cnt * 512);
> > +
> > + fw_length = fdt_totalsize(fitp);
> > + free(fitp);
> > +
> > + fw_length = roundup(fw_length, 512);
> > + ppa_fit_addr = malloc(fw_length);
> > + if (!ppa_fit_addr) {
> > + printf("PPA: malloc failed for PPA image(size 0x%zx)\n",
> > +fw_length);
> > + return -ENOMEM;
> > + }
> > +
> > + cnt = DIV_ROUND_UP(fw_length, 512);
> > + debug("%s: MMC read PPA FIT image: dev # %u, block # %u,
> count %u\n",
> > +   __func__, dev, blk, cnt);
> > + ret = mmc->block_dev.block_read(&mmc->block_dev,
> > + blk, cnt, ppa_fit_addr);
> > + if (ret != cnt) {
> > + free(ppa_fit_addr);
> > + printf("MMC/SD read of PPA FIT header at offset 0x%x
> failed\n",
> > +CONFIG_SYS_LS_PPA_FW_ADDR);
> > + return -EIO;
> > + }
> > +
> > + flush_cache((ulong)ppa_fit_addr, cnt * 512);
> > +
> > +#elif CONFIG_SYS_LS_PPA_FW_IN_NAND
> > + struct fdt_header fit;
> > +
> > + debug("%s: PPA image load from NAND\n", __func__);
> > +
> > + nand_init();
> > + ret = nand_read(nand_info[0],
> (loff_t)CONFIG_SYS_LS_PPA_FW_ADDR,
> > +&fdt_header_len, (u_char *)&fit);
> > + if (ret == -EUCLEAN) {
> > + printf("NAND read of PPA FIT header at offset 0x%x failed\n",
> > +CONFIG_SYS_LS_PPA_FW_ADDR);
> > + return -EIO;
> > + }
> > +
> > + fw_length = fdt_totalsize(&fit);
> > +
> > + ppa_fit_addr = malloc(fw_length);
> > + if (!ppa_fit_addr) {
> > + printf("PPA: malloc failed for PPA image(size 0x%zx)\n",
> > +fw_length);
> > + return -ENOMEM;
> > + }
> > +
> > + ret = nand_read(nand_info[0],
> (loff_t)CONFIG_SYS_LS_PPA_FW_ADDR,
> > +&fw_length, (u_char *)ppa_fit_addr);
> > + if (ret == -EUCLEAN) {
> > + free(ppa_fit_addr);
> > + printf("NAND read of PPA firmware at offset 0x%x failed\n",
> > +CONFIG_SYS_LS_PPA_FW_ADDR);
> > + return -EIO;
> > + }
> >  #else
> >  #error "No CONFIG_SYS_LS_PPA_FW_IN_xxx defined"
> >  #endif
> >
>
> Why do you flush the cache after reading from SD but not from NAND?

Added the flush operation because I referred to the FMan ucode loading process.
It works well when loading from SD without the flush cache action, will remove 
the flush action.

Thanks,
Zhiqiang
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 3/5] fsl PPA: add support PPA image loading from NAND and SD

2017-03-05 Thread Z.Q. Hou
Hi York,

Thanks a lot for your comments!

> -Original Message-
> From: york sun
> Sent: Saturday, March 04, 2017 12:51 AM
> To: Z.Q. Hou ; u-boot@lists.denx.de;
> o...@buserror.net; mingkai...@freescale.com; s...@chromium.org; Xiaobo
> Xie 
> Subject: Re: [PATCH 3/5] fsl PPA: add support PPA image loading from NAND
> and SD
> 
> On 03/03/2017 05:45 AM, Zhiqiang Hou wrote:
> > From: Hou Zhiqiang 
> >
> > Signed-off-by: Hou Zhiqiang 
> > ---
> >  arch/arm/cpu/armv8/fsl-layerscape/ppa.c | 118
> > +++-
> >  1 file changed, 117 insertions(+), 1 deletion(-)
> 
> 
> 
> >
> >  #ifdef CONFIG_SYS_LS_PPA_FW_IN_XIP
> > ppa_fit_addr = (void *)CONFIG_SYS_LS_PPA_FW_ADDR;
> > +   debug("%s: PPA image load from XIP\n", __func__); #else /*
> > +!CONFIG_SYS_LS_PPA_FW_IN_XIP */
> > +   size_t fw_length, fdt_header_len = sizeof(struct fdt_header);
> > +
> > +   /* Copy PPA image from MMC/SD/NAND to allocated memory */
> #ifdef
> > +CONFIG_SYS_LS_PPA_FW_IN_MMC
> > +   struct mmc *mmc;
> > +   int dev = CONFIG_SYS_MMC_ENV_DEV;
> > +   struct fdt_header *fitp;
> > +   u32 cnt;
> > +   u32 blk = CONFIG_SYS_LS_PPA_FW_ADDR / 512;
> > +
> > +   debug("%s: PPA image load from eMMC/SD\n", __func__);
> > +
> > +   mmc_initialize(gd->bd);
> > +   mmc = find_mmc_device(dev);
> > +   if (!mmc) {
> > +   printf("PPA: MMC cannot find device for PPA firmware\n");
> > +   return -ENODEV;
> > +   }
> > +
> > +   mmc_init(mmc);
> > +
> > +   fitp = malloc(roundup(fdt_header_len, 512));
> > +   if (!fitp) {
> > +   printf("PPA: malloc failed for FIT header(size 0x%zx)\n",
> > +  roundup(fdt_header_len, 512));
> > +   return -ENOMEM;
> > +   }
> > +
> > +   cnt = DIV_ROUND_UP(fdt_header_len, 512);
> > +   debug("%s: MMC read PPA FIT header: dev # %u, block # %u,
> count %u\n",
> > + __func__, dev, blk, cnt);
> > +   ret = mmc->block_dev.block_read(&mmc->block_dev, blk, cnt, fitp);
> > +   if (ret != cnt) {
> > +   free(fitp);
> > +   printf("MMC/SD read of PPA FIT header at offset 0x%x
> failed\n",
> > +  CONFIG_SYS_LS_PPA_FW_ADDR);
> > +   return -EIO;
> > +   }
> > +
> > +   /* flush cache after read */
> > +   flush_cache((ulong)fitp, cnt * 512);
> > +
> > +   fw_length = fdt_totalsize(fitp);
> > +   free(fitp);
> > +
> > +   fw_length = roundup(fw_length, 512);
> > +   ppa_fit_addr = malloc(fw_length);
> > +   if (!ppa_fit_addr) {
> > +   printf("PPA: malloc failed for PPA image(size 0x%zx)\n",
> > +  fw_length);
> > +   return -ENOMEM;
> > +   }
> > +
> > +   cnt = DIV_ROUND_UP(fw_length, 512);
> > +   debug("%s: MMC read PPA FIT image: dev # %u, block # %u,
> count %u\n",
> > + __func__, dev, blk, cnt);
> > +   ret = mmc->block_dev.block_read(&mmc->block_dev,
> > +   blk, cnt, ppa_fit_addr);
> > +   if (ret != cnt) {
> > +   free(ppa_fit_addr);
> > +   printf("MMC/SD read of PPA FIT header at offset 0x%x
> failed\n",
> > +  CONFIG_SYS_LS_PPA_FW_ADDR);
> > +   return -EIO;
> > +   }
> > +
> > +   flush_cache((ulong)ppa_fit_addr, cnt * 512);
> > +
> > +#elif CONFIG_SYS_LS_PPA_FW_IN_NAND
> > +   struct fdt_header fit;
> > +
> > +   debug("%s: PPA image load from NAND\n", __func__);
> > +
> > +   nand_init();
> > +   ret = nand_read(nand_info[0],
> (loff_t)CONFIG_SYS_LS_PPA_FW_ADDR,
> > +  &fdt_header_len, (u_char *)&fit);
> > +   if (ret == -EUCLEAN) {
> > +   printf("NAND read of PPA FIT header at offset 0x%x failed\n",
> > +  CONFIG_SYS_LS_PPA_FW_ADDR);
> > +   return -EIO;
> > +   }
> > +
> > +   fw_length = fdt_totalsize(&fit);
> > +
> > +   ppa_fit_addr = malloc(fw_length);
> > +   if (!ppa_fit_addr) {
> > +   printf("PPA: malloc failed for PPA image(size 0x%zx)\n",
> > +  fw_length);
> > +   return -ENOMEM;
> > +   }
> > +
> > +   ret = nand_read(nand_info[0],
> (loff_t)CONFIG_SYS_LS_PPA_FW_ADDR,
> > +  &fw_length, (u_char *)ppa_fit_addr);
> > +   if (ret == -EUCLEAN) {
> > +   free(ppa_fit_addr);
> > +   printf("NAND read of PPA firmware at offset 0x%x failed\n",
> > +  CONFIG_SYS_LS_PPA_FW_ADDR);
> > +   return -EIO;
> > +   }
> >  #else
> >  #error "No CONFIG_SYS_LS_PPA_FW_IN_xxx defined"
> >  #endif
> >
> 
> Why do you flush the cache after reading from SD but not from NAND?

Added the flush operation because I referred to the FMan ucode loading process.
It works well when loading from SD without the flush cache action, will remove 
the flush action.

Thanks,
Zhiqiang
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 3/5] fsl PPA: add support PPA image loading from NAND and SD

2017-03-03 Thread york sun
On 03/03/2017 05:45 AM, Zhiqiang Hou wrote:
> From: Hou Zhiqiang 
>
> Signed-off-by: Hou Zhiqiang 
> ---
>  arch/arm/cpu/armv8/fsl-layerscape/ppa.c | 118 
> +++-
>  1 file changed, 117 insertions(+), 1 deletion(-)



>
>  #ifdef CONFIG_SYS_LS_PPA_FW_IN_XIP
>   ppa_fit_addr = (void *)CONFIG_SYS_LS_PPA_FW_ADDR;
> + debug("%s: PPA image load from XIP\n", __func__);
> +#else /* !CONFIG_SYS_LS_PPA_FW_IN_XIP */
> + size_t fw_length, fdt_header_len = sizeof(struct fdt_header);
> +
> + /* Copy PPA image from MMC/SD/NAND to allocated memory */
> +#ifdef CONFIG_SYS_LS_PPA_FW_IN_MMC
> + struct mmc *mmc;
> + int dev = CONFIG_SYS_MMC_ENV_DEV;
> + struct fdt_header *fitp;
> + u32 cnt;
> + u32 blk = CONFIG_SYS_LS_PPA_FW_ADDR / 512;
> +
> + debug("%s: PPA image load from eMMC/SD\n", __func__);
> +
> + mmc_initialize(gd->bd);
> + mmc = find_mmc_device(dev);
> + if (!mmc) {
> + printf("PPA: MMC cannot find device for PPA firmware\n");
> + return -ENODEV;
> + }
> +
> + mmc_init(mmc);
> +
> + fitp = malloc(roundup(fdt_header_len, 512));
> + if (!fitp) {
> + printf("PPA: malloc failed for FIT header(size 0x%zx)\n",
> +roundup(fdt_header_len, 512));
> + return -ENOMEM;
> + }
> +
> + cnt = DIV_ROUND_UP(fdt_header_len, 512);
> + debug("%s: MMC read PPA FIT header: dev # %u, block # %u, count %u\n",
> +   __func__, dev, blk, cnt);
> + ret = mmc->block_dev.block_read(&mmc->block_dev, blk, cnt, fitp);
> + if (ret != cnt) {
> + free(fitp);
> + printf("MMC/SD read of PPA FIT header at offset 0x%x failed\n",
> +CONFIG_SYS_LS_PPA_FW_ADDR);
> + return -EIO;
> + }
> +
> + /* flush cache after read */
> + flush_cache((ulong)fitp, cnt * 512);
> +
> + fw_length = fdt_totalsize(fitp);
> + free(fitp);
> +
> + fw_length = roundup(fw_length, 512);
> + ppa_fit_addr = malloc(fw_length);
> + if (!ppa_fit_addr) {
> + printf("PPA: malloc failed for PPA image(size 0x%zx)\n",
> +fw_length);
> + return -ENOMEM;
> + }
> +
> + cnt = DIV_ROUND_UP(fw_length, 512);
> + debug("%s: MMC read PPA FIT image: dev # %u, block # %u, count %u\n",
> +   __func__, dev, blk, cnt);
> + ret = mmc->block_dev.block_read(&mmc->block_dev,
> + blk, cnt, ppa_fit_addr);
> + if (ret != cnt) {
> + free(ppa_fit_addr);
> + printf("MMC/SD read of PPA FIT header at offset 0x%x failed\n",
> +CONFIG_SYS_LS_PPA_FW_ADDR);
> + return -EIO;
> + }
> +
> + flush_cache((ulong)ppa_fit_addr, cnt * 512);
> +
> +#elif CONFIG_SYS_LS_PPA_FW_IN_NAND
> + struct fdt_header fit;
> +
> + debug("%s: PPA image load from NAND\n", __func__);
> +
> + nand_init();
> + ret = nand_read(nand_info[0], (loff_t)CONFIG_SYS_LS_PPA_FW_ADDR,
> +&fdt_header_len, (u_char *)&fit);
> + if (ret == -EUCLEAN) {
> + printf("NAND read of PPA FIT header at offset 0x%x failed\n",
> +CONFIG_SYS_LS_PPA_FW_ADDR);
> + return -EIO;
> + }
> +
> + fw_length = fdt_totalsize(&fit);
> +
> + ppa_fit_addr = malloc(fw_length);
> + if (!ppa_fit_addr) {
> + printf("PPA: malloc failed for PPA image(size 0x%zx)\n",
> +fw_length);
> + return -ENOMEM;
> + }
> +
> + ret = nand_read(nand_info[0], (loff_t)CONFIG_SYS_LS_PPA_FW_ADDR,
> +&fw_length, (u_char *)ppa_fit_addr);
> + if (ret == -EUCLEAN) {
> + free(ppa_fit_addr);
> + printf("NAND read of PPA firmware at offset 0x%x failed\n",
> +CONFIG_SYS_LS_PPA_FW_ADDR);
> + return -EIO;
> + }
>  #else
>  #error "No CONFIG_SYS_LS_PPA_FW_IN_xxx defined"
>  #endif
>

Why do you flush the cache after reading from SD but not from NAND?

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


[U-Boot] [PATCH 3/5] fsl PPA: add support PPA image loading from NAND and SD

2017-03-03 Thread Zhiqiang Hou
From: Hou Zhiqiang 

Signed-off-by: Hou Zhiqiang 
---
 arch/arm/cpu/armv8/fsl-layerscape/ppa.c | 118 +++-
 1 file changed, 117 insertions(+), 1 deletion(-)

diff --git a/arch/arm/cpu/armv8/fsl-layerscape/ppa.c 
b/arch/arm/cpu/armv8/fsl-layerscape/ppa.c
index b68e87d..322432b 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/ppa.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/ppa.c
@@ -4,6 +4,7 @@
  * SPDX-License-Identifier:GPL-2.0+
  */
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -21,9 +22,17 @@
 #include 
 #endif
 
+#ifdef CONFIG_SYS_LS_PPA_FW_IN_NAND
+#include 
+#elif defined(CONFIG_SYS_LS_PPA_FW_IN_MMC)
+#include 
+#endif
+
+DECLARE_GLOBAL_DATA_PTR;
+
 int ppa_init(void)
 {
-   const void *ppa_fit_addr;
+   void *ppa_fit_addr;
u32 *boot_loc_ptr_l, *boot_loc_ptr_h;
int ret;
 
@@ -34,10 +43,112 @@ int ppa_init(void)
 
 #ifdef CONFIG_SYS_LS_PPA_FW_IN_XIP
ppa_fit_addr = (void *)CONFIG_SYS_LS_PPA_FW_ADDR;
+   debug("%s: PPA image load from XIP\n", __func__);
+#else /* !CONFIG_SYS_LS_PPA_FW_IN_XIP */
+   size_t fw_length, fdt_header_len = sizeof(struct fdt_header);
+
+   /* Copy PPA image from MMC/SD/NAND to allocated memory */
+#ifdef CONFIG_SYS_LS_PPA_FW_IN_MMC
+   struct mmc *mmc;
+   int dev = CONFIG_SYS_MMC_ENV_DEV;
+   struct fdt_header *fitp;
+   u32 cnt;
+   u32 blk = CONFIG_SYS_LS_PPA_FW_ADDR / 512;
+
+   debug("%s: PPA image load from eMMC/SD\n", __func__);
+
+   mmc_initialize(gd->bd);
+   mmc = find_mmc_device(dev);
+   if (!mmc) {
+   printf("PPA: MMC cannot find device for PPA firmware\n");
+   return -ENODEV;
+   }
+
+   mmc_init(mmc);
+
+   fitp = malloc(roundup(fdt_header_len, 512));
+   if (!fitp) {
+   printf("PPA: malloc failed for FIT header(size 0x%zx)\n",
+  roundup(fdt_header_len, 512));
+   return -ENOMEM;
+   }
+
+   cnt = DIV_ROUND_UP(fdt_header_len, 512);
+   debug("%s: MMC read PPA FIT header: dev # %u, block # %u, count %u\n",
+ __func__, dev, blk, cnt);
+   ret = mmc->block_dev.block_read(&mmc->block_dev, blk, cnt, fitp);
+   if (ret != cnt) {
+   free(fitp);
+   printf("MMC/SD read of PPA FIT header at offset 0x%x failed\n",
+  CONFIG_SYS_LS_PPA_FW_ADDR);
+   return -EIO;
+   }
+
+   /* flush cache after read */
+   flush_cache((ulong)fitp, cnt * 512);
+
+   fw_length = fdt_totalsize(fitp);
+   free(fitp);
+
+   fw_length = roundup(fw_length, 512);
+   ppa_fit_addr = malloc(fw_length);
+   if (!ppa_fit_addr) {
+   printf("PPA: malloc failed for PPA image(size 0x%zx)\n",
+  fw_length);
+   return -ENOMEM;
+   }
+
+   cnt = DIV_ROUND_UP(fw_length, 512);
+   debug("%s: MMC read PPA FIT image: dev # %u, block # %u, count %u\n",
+ __func__, dev, blk, cnt);
+   ret = mmc->block_dev.block_read(&mmc->block_dev,
+   blk, cnt, ppa_fit_addr);
+   if (ret != cnt) {
+   free(ppa_fit_addr);
+   printf("MMC/SD read of PPA FIT header at offset 0x%x failed\n",
+  CONFIG_SYS_LS_PPA_FW_ADDR);
+   return -EIO;
+   }
+
+   flush_cache((ulong)ppa_fit_addr, cnt * 512);
+
+#elif CONFIG_SYS_LS_PPA_FW_IN_NAND
+   struct fdt_header fit;
+
+   debug("%s: PPA image load from NAND\n", __func__);
+
+   nand_init();
+   ret = nand_read(nand_info[0], (loff_t)CONFIG_SYS_LS_PPA_FW_ADDR,
+  &fdt_header_len, (u_char *)&fit);
+   if (ret == -EUCLEAN) {
+   printf("NAND read of PPA FIT header at offset 0x%x failed\n",
+  CONFIG_SYS_LS_PPA_FW_ADDR);
+   return -EIO;
+   }
+
+   fw_length = fdt_totalsize(&fit);
+
+   ppa_fit_addr = malloc(fw_length);
+   if (!ppa_fit_addr) {
+   printf("PPA: malloc failed for PPA image(size 0x%zx)\n",
+  fw_length);
+   return -ENOMEM;
+   }
+
+   ret = nand_read(nand_info[0], (loff_t)CONFIG_SYS_LS_PPA_FW_ADDR,
+  &fw_length, (u_char *)ppa_fit_addr);
+   if (ret == -EUCLEAN) {
+   free(ppa_fit_addr);
+   printf("NAND read of PPA firmware at offset 0x%x failed\n",
+  CONFIG_SYS_LS_PPA_FW_ADDR);
+   return -EIO;
+   }
 #else
 #error "No CONFIG_SYS_LS_PPA_FW_IN_xxx defined"
 #endif
 
+#endif
+
 #ifdef CONFIG_CHAIN_OF_TRUST
ppa_img_addr = (uintptr_t)ppa_fit_addr;
if (fsl_check_boot_mode_secure() != 0) {
@@ -65,5 +176,10 @@ int ppa_init(void)
  boot_loc_ptr_l, boot_loc_ptr_h);
ret = sec_firmware_init(ppa_fit_addr, boot_loc_ptr_l, boot_loc_ptr_h);
 
+#if defined(CONFIG_SYS_LS_PPA_FW_IN_MMC) || \
+   defined(CONFIG_SYS_LS_PPA_FW_IN_