查看: 5042|回复: 0

[分享] i.MX8MPlus U-Boot中lpddr4的初始化

[复制链接]

该用户从未签到

723

主题

6382

帖子

0

超级版主

Rank: 8Rank: 8

积分
25491
最后登录
2025-9-9
发表于 2021-12-30 16:21:03 | 显示全部楼层 |阅读模式
1、ddr时序的写入

spl阶段将时序写入ddr寄存器。一般来说自己移植ddr的时候就需要干两件事:(1)使用ddr工具获取稳定的ddr时序,(2)修改uboot中定义的ddr各个bank的 大小。

  1. spl_dram_init //board/freescale/imx8mp_evk/spl.c

  2.         ->ddr_init //drivers/ddr/imx/imx8m/ddr_init.c
复制代码

2、ddr bank的初始化dram_init_banksize

从芯片手册可知,i.MX8MP共分为两个ddr区域,3072MB的区域起始地址为0x40000000,第二块5120MB区域的起始地址为0x1000000000。

这里我们以6GB内存的EVK为例,ddr大小的定义:include/configs/imx8mp_evk.h.
  1. /* Totally 6GB DDR */
  2. #define CONFIG_SYS_SDRAM_BASE                0x40000000
  3. #define PHYS_SDRAM                        0x40000000
  4. #define PHYS_SDRAM_SIZE                        0xC0000000        /* 3 GB */
  5. #define PHYS_SDRAM_2                        0x100000000
  6. #ifdef CONFIG_TARGET_IMX8MP_DDR4_EVK
  7. #define PHYS_SDRAM_2_SIZE                0x40000000        /* 1 GB */
  8. #else
  9. #define PHYS_SDRAM_2_SIZE                0xC0000000        /* 3 GB */
  10. #endif
复制代码
board_phys_sdram_size获取ddr 每个bank大小。
  1. __weak int board_phys_sdram_size(phys_size_t *size)
  2. {
  3.         if (!size)
  4.                 return -EINVAL;

  5.         *size = PHYS_SDRAM_SIZE;//0xC0000000

  6. #ifdef PHYS_SDRAM_2_SIZE
  7.         *size += PHYS_SDRAM_2_SIZE;//0xC0000000
  8. #endif
  9.         return 0;
  10. }
复制代码

arch/arm/mach-imx/imx8m/soc.其中bank1的大小不能超过3072MB,超过3GB的部分会被舍弃。

  1. int dram_init_banksize(void)
  2. {
  3.         int bank = 0;
  4.         int ret;
  5.         phys_size_t sdram_size;
  6.         phys_size_t sdram_b1_size, sdram_b2_size;

  7.         ret = board_phys_sdram_size(&sdram_size);
  8.         if (ret)
  9.                 return ret;

  10.         /* Bank 1 can't cross over 4GB space */
  11.         if (sdram_size > 0xc0000000) {
  12.                 sdram_b1_size = 0xc0000000;
  13.                 sdram_b2_size = sdram_size - 0xc0000000;
  14.         } else {
  15.                 sdram_b1_size = sdram_size;
  16.                 sdram_b2_size = 0;
  17.         }
  18.         //设置ddr第一个bank的起始地址0x40000000
  19.         gd->bd->bi_dram[bank].start = PHYS_SDRAM;
  20.         if (rom_pointer[1]) {
  21.     //带optee的处理
  22.                 phys_addr_t optee_start = (phys_addr_t)rom_pointer[0];
  23.                 phys_size_t optee_size = (size_t)rom_pointer[1];

  24.                 gd->bd->bi_dram[bank].size = optee_start - gd->bd->bi_dram[bank].start;
  25.                 if ((optee_start + optee_size) < (PHYS_SDRAM + sdram_b1_size)) {
  26.                         if (++bank >= CONFIG_NR_DRAM_BANKS) {
  27.                                 puts("CONFIG_NR_DRAM_BANKS is not enough\n");
  28.                                 return -1;
  29.                         }

  30.                         gd->bd->bi_dram[bank].start = optee_start + optee_size;
  31.                         gd->bd->bi_dram[bank].size = PHYS_SDRAM +
  32.                                 sdram_b1_size - gd->bd->bi_dram[bank].start;
  33.                 }
  34.         } else {
  35.                 gd->bd->bi_dram[bank].size = sdram_b1_size;
  36.         }

  37.         if (sdram_b2_size) {
  38.                 if (++bank >= CONFIG_NR_DRAM_BANKS) {
  39.                         puts("CONFIG_NR_DRAM_BANKS is not enough for SDRAM_2\n");
  40.                         return -1;
  41.                 }
  42.     //第二个bank的起始地址0x100000000
  43.                 gd->bd->bi_dram[bank].start = 0x100000000UL;
  44.     //设置大小
  45.                 gd->bd->bi_dram[bank].size = sdram_b2_size;
  46.         }

  47.         return 0;
  48. }
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /3 下一条

Archiver|手机版|小黑屋|恩智浦技术社区

GMT+8, 2025-9-10 14:02 , Processed in 0.082344 second(s), 19 queries , MemCache On.

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.

快速回复 返回顶部 返回列表