riscv: starfive: jh7110: add check_eeprom_dram_info

Make sure that the read DDR information is a valid value

Signed-off-by: Samin Guo <samin.guo@starfivetech.com>
This commit is contained in:
Samin Guo 2023-02-24 15:08:35 +08:00
parent 97f3b2aaee
commit 479dc3cb7e

View file

@ -11,12 +11,26 @@
DECLARE_GLOBAL_DATA_PTR;
static bool check_eeprom_dram_info(phys_size_t size)
{
switch (size) {
case 0x80000000:
case 0x100000000:
case 0x200000000:
case 0x400000000:
return true;
default:
return false;
}
}
int dram_init(void)
{
int ret;
u8 data;
u32 len;
u32 offset;
phys_size_t size;
data = 0;
len = 1;
@ -27,8 +41,11 @@ int dram_init(void)
/*read memory size info*/
ret = get_data_from_eeprom(offset, len, &data);
if (ret == len)
gd->ram_size = ((phys_size_t)hextoul(&data, NULL)) << 30;
if (ret == len) {
size = ((phys_size_t)hextoul(&data, NULL)) << 30;
if (check_eeprom_dram_info(size))
gd->ram_size = size;
}
ret = 0;
err: