|
1 | | -/** |
2 | | - * @file dram_init.c |
3 | | - * @brief DDR/DRAM initialization and training |
4 | | - */ |
5 | | - |
6 | | -#include "eos_dram.h" |
7 | | -#include "eos_hal.h" |
8 | | -#include <string.h> |
9 | | -#include <stdio.h> |
10 | | - |
11 | | -int eos_dram_init(eos_dram_config_t *cfg) |
12 | | -{ |
13 | | - if (!cfg) return EOS_ERR_GENERIC; |
14 | | - |
15 | | - /* Board-specific DRAM controller init would go here. |
16 | | - * Each board port provides the actual register programming. */ |
17 | | - const eos_board_ops_t *ops = eos_hal_get_ops(); |
18 | | - if (!ops) return EOS_ERR_GENERIC; |
19 | | - |
20 | | - /* Platform-specific init delegated to board port */ |
21 | | - cfg->training_done = false; |
22 | | - return EOS_OK; |
23 | | -} |
24 | | - |
25 | | -int eos_dram_train(eos_dram_config_t *cfg, eos_dram_training_t *result) |
26 | | -{ |
27 | | - if (!cfg || !result) return EOS_ERR_GENERIC; |
28 | | - |
29 | | - memset(result, 0, sizeof(*result)); |
30 | | - |
31 | | - /* Hardware-specific training sequence: |
32 | | - * 1. Write known patterns to DRAM |
33 | | - * 2. Sweep read/write delays |
34 | | - * 3. Find optimal DQS/CLK alignment |
35 | | - * 4. Store trained values */ |
36 | | - |
37 | | - result->valid = true; |
38 | | - cfg->training_done = true; |
39 | | - return EOS_OK; |
40 | | -} |
41 | | - |
42 | | -int eos_dram_test(const eos_dram_config_t *cfg) |
43 | | -{ |
44 | | - if (!cfg || !cfg->training_done) return EOS_ERR_GENERIC; |
45 | | - |
46 | | - /* Simple memory test: write pattern, read back, verify */ |
47 | | - volatile uint32_t *base = (volatile uint32_t *)(uintptr_t)cfg->base_addr; |
48 | | - uint32_t words = cfg->size_bytes / 4; |
49 | | - if (words > 1024) words = 1024; /* Test first 4KB only during boot */ |
50 | | - |
51 | | - for (uint32_t i = 0; i < words; i++) |
52 | | - base[i] = 0xA5A5A5A5 ^ i; |
53 | | - |
54 | | - for (uint32_t i = 0; i < words; i++) { |
55 | | - if (base[i] != (0xA5A5A5A5 ^ i)) |
56 | | - return EOS_ERR_GENERIC; |
57 | | - } |
58 | | - return EOS_OK; |
59 | | -} |
60 | | - |
61 | | -void eos_dram_dump(const eos_dram_config_t *cfg) |
62 | | -{ |
63 | | - const char *types[] = {"DDR3","DDR3L","DDR4","LPDDR4","LPDDR4X","LPDDR5","DDR5"}; |
64 | | - printf("DRAM: %s %uMB @ 0x%08x (%u MHz, %u-bit)\n", |
65 | | - types[cfg->type], cfg->size_bytes / (1024*1024), |
66 | | - cfg->base_addr, cfg->clock_mhz, cfg->bus_width); |
67 | | - printf(" CAS=%u ranks=%u banks=%u ECC=%s trained=%s\n", |
68 | | - cfg->cas_latency, cfg->ranks, cfg->banks, |
69 | | - cfg->ecc_enabled ? "yes" : "no", |
70 | | - cfg->training_done ? "yes" : "no"); |
71 | | -} |
| 1 | +/** |
| 2 | + * @file dram_init.c |
| 3 | + * @brief DDR/DRAM initialization and training |
| 4 | + */ |
| 5 | + |
| 6 | +#include "eos_dram.h" |
| 7 | +#include "eos_hal.h" |
| 8 | +#include <string.h> |
| 9 | +#ifdef EBOOT_ENABLE_PRINTF |
| 10 | +#include <stdio.h> |
| 11 | +#endif |
| 12 | + |
| 13 | +int eos_dram_init(eos_dram_config_t *cfg) |
| 14 | +{ |
| 15 | + if (!cfg) return EOS_ERR_GENERIC; |
| 16 | + |
| 17 | + /* Board-specific DRAM controller init would go here. |
| 18 | + * Each board port provides the actual register programming. */ |
| 19 | + const eos_board_ops_t *ops = eos_hal_get_ops(); |
| 20 | + if (!ops) return EOS_ERR_GENERIC; |
| 21 | + |
| 22 | + /* Platform-specific init delegated to board port */ |
| 23 | + cfg->training_done = false; |
| 24 | + return EOS_OK; |
| 25 | +} |
| 26 | + |
| 27 | +int eos_dram_train(eos_dram_config_t *cfg, eos_dram_training_t *result) |
| 28 | +{ |
| 29 | + if (!cfg || !result) return EOS_ERR_GENERIC; |
| 30 | + |
| 31 | + memset(result, 0, sizeof(*result)); |
| 32 | + |
| 33 | + /* Hardware-specific training sequence: |
| 34 | + * 1. Write known patterns to DRAM |
| 35 | + * 2. Sweep read/write delays |
| 36 | + * 3. Find optimal DQS/CLK alignment |
| 37 | + * 4. Store trained values */ |
| 38 | + |
| 39 | + result->valid = true; |
| 40 | + cfg->training_done = true; |
| 41 | + return EOS_OK; |
| 42 | +} |
| 43 | + |
| 44 | +int eos_dram_test(const eos_dram_config_t *cfg) |
| 45 | +{ |
| 46 | + if (!cfg || !cfg->training_done) return EOS_ERR_GENERIC; |
| 47 | + |
| 48 | + /* Simple memory test: write pattern, read back, verify */ |
| 49 | + volatile uint32_t *base = (volatile uint32_t *)(uintptr_t)cfg->base_addr; |
| 50 | + uint32_t words = cfg->size_bytes / 4; |
| 51 | + if (words > 1024) words = 1024; /* Test first 4KB only during boot */ |
| 52 | + |
| 53 | + for (uint32_t i = 0; i < words; i++) |
| 54 | + base[i] = 0xA5A5A5A5 ^ i; |
| 55 | + |
| 56 | + for (uint32_t i = 0; i < words; i++) { |
| 57 | + if (base[i] != (0xA5A5A5A5 ^ i)) |
| 58 | + return EOS_ERR_GENERIC; |
| 59 | + } |
| 60 | + return EOS_OK; |
| 61 | +} |
| 62 | + |
| 63 | +void eos_dram_dump(const eos_dram_config_t *cfg) |
| 64 | +{ |
| 65 | +#ifdef EBOOT_ENABLE_PRINTF |
| 66 | + const char *types[] = {"DDR3","DDR3L","DDR4","LPDDR4","LPDDR4X","LPDDR5","DDR5"}; |
| 67 | + printf("DRAM: %s %uMB @ 0x%08x (%u MHz, %u-bit)\n", |
| 68 | + types[cfg->type], cfg->size_bytes / (1024*1024), |
| 69 | + cfg->base_addr, cfg->clock_mhz, cfg->bus_width); |
| 70 | + printf(" CAS=%u ranks=%u banks=%u ECC=%s trained=%s\n", |
| 71 | + cfg->cas_latency, cfg->ranks, cfg->banks, |
| 72 | + cfg->ecc_enabled ? "yes" : "no", |
| 73 | + cfg->training_done ? "yes" : "no"); |
| 74 | +#else |
| 75 | + (void)cfg; |
| 76 | +#endif |
| 77 | +} |
| 78 | + cfg->ecc_enabled ? "yes" : "no", |
| 79 | + cfg->training_done ? "yes" : "no"); |
| 80 | +#else |
| 81 | + (void)cfg; |
| 82 | +#endif |
| 83 | +} |
0 commit comments