diff --git a/Makefile b/Makefile
index b5d633d..90bcf28 100755
--- a/Makefile
+++ b/Makefile
@@ -33,7 +33,7 @@ OBJS = $(addprefix $(BUILDDIR)/$(TARGET)/, \
# Hardware.
OBJS += $(addprefix $(BUILDDIR)/$(TARGET)/, \
clock.o cluster.o di.o gpio.o i2c.o mc.o sdram.o pinmux.o se.o smmu.o tsec.o uart.o \
- fuse.o kfuse.o \
+ fuse.o kfuse.o minerva.o \
sdmmc.o sdmmc_driver.o emummc.o nx_emmc.o \
bq24193.o max17050.o max7762x.o max77620-rtc.o \
hw_init.o \
@@ -47,7 +47,7 @@ OBJS += $(addprefix $(BUILDDIR)/$(TARGET)/, \
# Horizon.
OBJS += $(addprefix $(BUILDDIR)/$(TARGET)/, \
- hos.o hos_config.o pkg1.o pkg2.o fss.o secmon_exo.o sept.o \
+ hos.o hos_config.o pkg1.o pkg2.o pkg2_ini_kippatch.o fss.o secmon_exo.o sept.o \
)
# Libraries.
diff --git a/bootloader/hos/hos.c b/bootloader/hos/hos.c
index 329930b..56ae936 100644
--- a/bootloader/hos/hos.c
+++ b/bootloader/hos/hos.c
@@ -28,6 +28,7 @@
#include "../gfx/di.h"
#include "../mem/heap.h"
#include "../mem/mc.h"
+#include "../mem/minerva.h"
#include "../sec/se.h"
#include "../sec/se_t210.h"
#include "../sec/tsec.h"
@@ -385,6 +386,7 @@ static void _free_launch_components(launch_ctxt_t *ctxt)
int hos_launch(ini_sec_t *cfg)
{
+ minerva_change_freq(FREQ_1600);
launch_ctxt_t ctxt;
tsec_ctxt_t tsec_ctxt;
volatile secmon_mailbox_t *secmon_mb;
@@ -675,6 +677,8 @@ int hos_launch(ini_sec_t *cfg)
// Clear EMC_SCRATCH0.
EMC(EMC_SCRATCH0) = 0;
+ minerva_change_freq(FREQ_800);
+
// Wait for secmon to get ready.
if (smmu_is_used())
smmu_exit();
diff --git a/bootloader/ianos/ianos.c b/bootloader/ianos/ianos.c
index 246a40f..fe973a6 100644
--- a/bootloader/ianos/ianos.c
+++ b/bootloader/ianos/ianos.c
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2018 M4xw
- * Copyright (c) 2018 CTCaer
+ * Copyright (c) 2018-2019 CTCaer
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
@@ -88,8 +88,9 @@ void ianos_print_error(int errorno)
}
//TODO: Support shared libraries.
-int ianos_loader(bool sdmount, char *path, elfType_t type, void *moduleConfig)
+uintptr_t ianos_loader(bool sdmount, char *path, elfType_t type, void *moduleConfig)
{
+ uintptr_t epaddr = 0;
int res = 0;
if (sdmount)
@@ -155,19 +156,18 @@ int ianos_loader(bool sdmount, char *path, elfType_t type, void *moduleConfig)
}
// Launch.
- uintptr_t epaddr = ctx.ehdr.e_entry + (uintptr_t)elfBuf;
+ epaddr = ctx.ehdr.e_entry + (uintptr_t)elfBuf;
moduleEntrypoint_t ep = (moduleEntrypoint_t)epaddr;
_ianos_call_ep(ep, moduleConfig);
elfFreeOut:
- if ((u32)elfBuf >= 0x90000000 && (u32)elfBuf <= DRAM_LIB_ADDR)
- free(elfBuf);
free(fileBuf);
elfBuf = NULL;
fileBuf = NULL;
+ ianos_print_error(res);
elfLoadFinalOut:
- return res;
+ return epaddr;
}
\ No newline at end of file
diff --git a/bootloader/ianos/ianos.h b/bootloader/ianos/ianos.h
index 2d651ba..74d02c1 100644
--- a/bootloader/ianos/ianos.h
+++ b/bootloader/ianos/ianos.h
@@ -29,6 +29,6 @@ typedef enum
KEEP_IN_RAM = (1 << 31) // Shared library mask.
} elfType_t;
-int ianos_loader(bool sdmount, char *path, elfType_t type, void* config);
+uintptr_t ianos_loader(bool sdmount, char *path, elfType_t type, void* config);
#endif
\ No newline at end of file
diff --git a/bootloader/main.c b/bootloader/main.c
index cf4abe2..36276fd 100644
--- a/bootloader/main.c
+++ b/bootloader/main.c
@@ -31,6 +31,7 @@
#include "libs/compr/blz.h"
#include "libs/fatfs/ff.h"
#include "mem/heap.h"
+#include "mem/minerva.h"
#include "mem/sdram.h"
#include "power/max77620.h"
#include "rtc/max77620-rtc.h"
@@ -1172,9 +1173,14 @@ void ipl_main()
// Set bootloader's default configuration.
set_default_configuration();
+ sd_mount();
+
// Save sdram lp0 config.
- if (ianos_loader(true, "bootloader/sys/libsys_lp0.bso", DRAM_LIB, (void *)sdram_get_params_patched()))
+ if (!ianos_loader(false, "bootloader/sys/libsys_lp0.bso", DRAM_LIB, (void *)sdram_get_params_patched()))
h_cfg.errors |= ERR_LIBSYS_LP0;
+
+ minerva_init();
+ minerva_change_freq(FREQ_1600);
display_init();
@@ -1203,6 +1209,8 @@ void ipl_main()
// Load saved configuration and auto boot if enabled.
auto_launch_firmware();
+ minerva_change_freq(FREQ_800);
+
while (true)
tui_do_menu(&menu_top);
diff --git a/bootloader/mem/minerva.c b/bootloader/mem/minerva.c
new file mode 100644
index 0000000..4b3c3bc
--- /dev/null
+++ b/bootloader/mem/minerva.c
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2019 CTCaer
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include
+#include
+
+#include "minerva.h"
+#include "../soc/fuse.h"
+#include "../utils/util.h"
+
+#include "../soc/clock.h"
+#include "../ianos/ianos.h"
+#include "../soc/fuse.h"
+#include "../soc/t210.h"
+
+extern volatile nyx_storage_t *nyx_str;
+
+void minerva_init()
+{
+ u32 curr_ram_idx = 0;
+
+ mtc_config_t *mtc_cfg = (mtc_config_t *)&nyx_str->mtc_cfg;
+
+ // Set table to ram.
+ mtc_cfg->mtc_table = NULL;
+ mtc_cfg->sdram_id = (fuse_read_odm(4) >> 3) & 0x1F;
+ u32 ep_addr = ianos_loader(false, "bootloader/sys/libsys_minerva.bso", DRAM_LIB, (void *)mtc_cfg);
+ minerva_cfg = (void *)ep_addr;
+
+ if (!minerva_cfg)
+ return;
+
+ // Get current frequency
+ for (curr_ram_idx = 0; curr_ram_idx < 10; curr_ram_idx++)
+ {
+ if (CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_EMC) == mtc_cfg->mtc_table[curr_ram_idx].clk_src_emc)
+ break;
+ }
+
+ mtc_cfg->rate_from = mtc_cfg->mtc_table[curr_ram_idx].rate_khz;
+ mtc_cfg->rate_to = 204000;
+ mtc_cfg->train_mode = OP_TRAIN;
+ minerva_cfg(mtc_cfg, NULL);
+ mtc_cfg->rate_to = 800000;
+ minerva_cfg(mtc_cfg, NULL);
+ mtc_cfg->rate_to = 1600000;
+ minerva_cfg(mtc_cfg, NULL);
+}
+
+void minerva_change_freq(minerva_freq_t freq)
+{
+ if (!minerva_cfg)
+ return;
+ mtc_config_t *mtc_cfg = (mtc_config_t *)&nyx_str->mtc_cfg;
+ if (minerva_cfg && (mtc_cfg->rate_from != freq))
+ {
+ mtc_cfg->rate_to = freq;
+ mtc_cfg->train_mode = OP_SWITCH;
+ minerva_cfg(mtc_cfg, NULL);
+ }
+}
+
+void minerva_periodic_training()
+{
+ if (!minerva_cfg)
+ return;
+ mtc_config_t *mtc_cfg = (mtc_config_t *)&nyx_str->mtc_cfg;
+ if (minerva_cfg && mtc_cfg->rate_from == FREQ_1600)
+ {
+ mtc_cfg->train_mode = OP_PERIODIC_TRAIN;
+ minerva_cfg(mtc_cfg, NULL);
+ }
+}
\ No newline at end of file
diff --git a/bootloader/mem/minerva.h b/bootloader/mem/minerva.h
new file mode 100644
index 0000000..dd71658
--- /dev/null
+++ b/bootloader/mem/minerva.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2019 CTCaer
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef _FE_MINERVA_H_
+#define _FE_MINERVA_H_
+
+#include "mtc_table.h"
+#include "../utils/types.h"
+
+#define EMC_PERIODIC_TRAIN_MS 100
+
+typedef struct
+{
+ s32 rate_to;
+ s32 rate_from;
+ emc_table_t *mtc_table;
+ u32 table_entries;
+ emc_table_t *current_emc_table;
+ u32 train_mode;
+ u32 sdram_id;
+ u32 prev_temp;
+ bool emc_2X_clk_src_is_pllmb;
+ bool fsp_for_src_freq;
+ bool train_ram_patterns;
+} mtc_config_t;
+
+enum train_mode_t
+{
+ OP_SWITCH = 0,
+ OP_TRAIN = 1,
+ OP_TRAIN_SWITCH = 2,
+ OP_PERIODIC_TRAIN = 3,
+ OP_TEMP_COMP = 4
+};
+
+typedef enum
+{
+ FREQ_204 = 204000,
+ FREQ_800 = 800000,
+ FREQ_1600 = 1600000
+} minerva_freq_t;
+
+void (*minerva_cfg)(mtc_config_t *mtc_cfg, void *);
+void minerva_init();
+void minerva_change_freq(minerva_freq_t freq);
+void minerva_periodic_training();
+
+#endif
diff --git a/bootloader/mem/mtc_table.h b/bootloader/mem/mtc_table.h
new file mode 100644
index 0000000..7f18232
--- /dev/null
+++ b/bootloader/mem/mtc_table.h
@@ -0,0 +1,560 @@
+/*
+ * Minerva Training Cell
+ * DRAM Training for Tegra X1 SoC. Supports DDR2/3 and LPDDR3/4.
+ *
+ * Copyright (c) 2018 CTCaer
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef _MTC_TABLE_H_
+#define _MTC_TABLE_H_
+
+#include "../utils/types.h"
+
+typedef struct
+{
+ s32 pll_osc_in;
+ s32 pll_out;
+ u32 pll_feedback_div;
+ u32 pll_input_div;
+ u32 pll_post_div;
+} pllm_clk_config_t;
+
+typedef struct
+{
+ u32 emc_rc_idx;
+ u32 emc_rfc_idx;
+ u32 emc_rfcpb_idx;
+ u32 emc_refctrl2_idx;
+ u32 emc_rfc_slr_idx;
+ u32 emc_ras_idx;
+ u32 emc_rp_idx;
+ u32 emc_r2w_idx;
+ u32 emc_w2r_idx;
+ u32 emc_r2p_idx;
+ u32 emc_w2p_idx;
+ u32 emc_r2r_idx;
+ u32 emc_tppd_idx;
+ u32 emc_ccdmw_idx;
+ u32 emc_rd_rcd_idx;
+ u32 emc_wr_rcd_idx;
+ u32 emc_rrd_idx;
+ u32 emc_rext_idx;
+ u32 emc_wext_idx;
+ u32 emc_wdv_chk_idx;
+ u32 emc_wdv_idx;
+ u32 emc_wsv_idx;
+ u32 emc_wev_idx;
+ u32 emc_wdv_mask_idx;
+ u32 emc_ws_duration_idx;
+ u32 emc_we_duration_idx;
+ u32 emc_quse_idx;
+ u32 emc_quse_width_idx;
+ u32 emc_ibdly_idx;
+ u32 emc_obdly_idx;
+ u32 emc_einput_idx;
+ u32 emc_mrw6_idx;
+ u32 emc_einput_duration_idx;
+ u32 emc_puterm_extra_idx;
+ u32 emc_puterm_width_idx;
+ u32 emc_qrst_idx;
+ u32 emc_qsafe_idx;
+ u32 emc_rdv_idx;
+ u32 emc_rdv_mask_idx;
+ u32 emc_rdv_early_idx;
+ u32 emc_rdv_early_mask_idx;
+ u32 emc_refresh_idx;
+ u32 emc_burst_refresh_num_idx;
+ u32 emc_pre_refresh_req_cnt_idx;
+ u32 emc_pdex2wr_idx;
+ u32 emc_pdex2rd_idx;
+ u32 emc_pchg2pden_idx;
+ u32 emc_act2pden_idx;
+ u32 emc_ar2pden_idx;
+ u32 emc_rw2pden_idx;
+ u32 emc_cke2pden_idx;
+ u32 emc_pdex2cke_idx;
+ u32 emc_pdex2mrr_idx;
+ u32 emc_txsr_idx;
+ u32 emc_txsrdll_idx;
+ u32 emc_tcke_idx;
+ u32 emc_tckesr_idx;
+ u32 emc_tpd_idx;
+ u32 emc_tfaw_idx;
+ u32 emc_trpab_idx;
+ u32 emc_tclkstable_idx;
+ u32 emc_tclkstop_idx;
+ u32 emc_mrw7_idx;
+ u32 emc_trefbw_idx;
+ u32 emc_odt_write_idx;
+ u32 emc_fbio_cfg5_idx;
+ u32 emc_fbio_cfg7_idx;
+ u32 emc_cfg_dig_dll_idx;
+ u32 emc_cfg_dig_dll_period_idx;
+ u32 emc_pmacro_ib_rxrt_idx;
+ u32 emc_cfg_pipe_1_idx;
+ u32 emc_cfg_pipe_2_idx;
+ u32 emc_pmacro_quse_ddll_rank0_4_idx;
+ u32 emc_pmacro_quse_ddll_rank0_5_idx;
+ u32 emc_pmacro_quse_ddll_rank1_4_idx;
+ u32 emc_pmacro_quse_ddll_rank1_5_idx;
+ u32 emc_mrw8_idx;
+ u32 emc_pmacro_ob_ddll_long_dq_rank1_4_idx;
+ u32 emc_pmacro_ob_ddll_long_dq_rank1_5_idx;
+ u32 emc_pmacro_ob_ddll_long_dqs_rank0_0_idx;
+ u32 emc_pmacro_ob_ddll_long_dqs_rank0_1_idx;
+ u32 emc_pmacro_ob_ddll_long_dqs_rank0_2_idx;
+ u32 emc_pmacro_ob_ddll_long_dqs_rank0_3_idx;
+ u32 emc_pmacro_ob_ddll_long_dqs_rank0_4_idx;
+ u32 emc_pmacro_ob_ddll_long_dqs_rank0_5_idx;
+ u32 emc_pmacro_ob_ddll_long_dqs_rank1_0_idx;
+ u32 emc_pmacro_ob_ddll_long_dqs_rank1_1_idx;
+ u32 emc_pmacro_ob_ddll_long_dqs_rank1_2_idx;
+ u32 emc_pmacro_ob_ddll_long_dqs_rank1_3_idx;
+ u32 emc_pmacro_ob_ddll_long_dqs_rank1_4_idx;
+ u32 emc_pmacro_ob_ddll_long_dqs_rank1_5_idx;
+ u32 emc_pmacro_ddll_long_cmd_0_idx;
+ u32 emc_pmacro_ddll_long_cmd_1_idx;
+ u32 emc_pmacro_ddll_long_cmd_2_idx;
+ u32 emc_pmacro_ddll_long_cmd_3_idx;
+ u32 emc_pmacro_ddll_long_cmd_4_idx;
+ u32 emc_pmacro_ddll_short_cmd_0_idx;
+ u32 emc_pmacro_ddll_short_cmd_1_idx;
+ u32 emc_pmacro_ddll_short_cmd_2_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte0_3_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte1_3_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte2_3_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte3_3_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte4_3_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte5_3_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte6_3_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte7_3_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd0_3_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd1_3_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd2_3_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd3_3_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte0_3_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte1_3_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte2_3_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte3_3_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte4_3_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte5_3_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte6_3_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte7_3_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd0_0_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd0_1_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd0_2_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd0_3_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd1_0_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd1_1_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd1_2_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd1_3_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd2_0_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd2_1_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd2_2_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd2_3_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd3_0_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd3_1_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd3_2_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_cmd3_3_idx;
+ u32 emc_txdsrvttgen_idx;
+ u32 emc_fdpd_ctrl_dq_idx;
+ u32 emc_fdpd_ctrl_cmd_idx;
+ u32 emc_fbio_spare_idx;
+ u32 emc_zcal_interval_idx;
+ u32 emc_zcal_wait_cnt_idx;
+ u32 emc_mrs_wait_cnt_idx;
+ u32 emc_mrs_wait_cnt2_idx;
+ u32 emc_auto_cal_channel_idx;
+ u32 emc_dll_cfg_0_idx;
+ u32 emc_dll_cfg_1_idx;
+ u32 emc_pmacro_autocal_cfg_common_idx;
+ u32 emc_pmacro_zctrl_idx;
+ u32 emc_cfg_idx;
+ u32 emc_cfg_pipe_idx;
+ u32 emc_dyn_self_ref_control_idx;
+ u32 emc_qpop_idx;
+ u32 emc_dqs_brlshft_0_idx;
+ u32 emc_dqs_brlshft_1_idx;
+ u32 emc_cmd_brlshft_2_idx;
+ u32 emc_cmd_brlshft_3_idx;
+ u32 emc_pmacro_pad_cfg_ctrl_idx;
+ u32 emc_pmacro_data_pad_rx_ctrl_idx;
+ u32 emc_pmacro_cmd_pad_rx_ctrl_idx;
+ u32 emc_pmacro_data_rx_term_mode_idx;
+ u32 emc_pmacro_cmd_rx_term_mode_idx;
+ u32 emc_pmacro_cmd_pad_tx_ctrl_idx;
+ u32 emc_pmacro_data_pad_tx_ctrl_idx;
+ u32 emc_pmacro_common_pad_tx_ctrl_idx;
+ u32 emc_pmacro_vttgen_ctrl_0_idx;
+ u32 emc_pmacro_vttgen_ctrl_1_idx;
+ u32 emc_pmacro_vttgen_ctrl_2_idx;
+ u32 emc_pmacro_brick_ctrl_rfu1_idx;
+ u32 emc_pmacro_cmd_brick_ctrl_fdpd_idx;
+ u32 emc_pmacro_brick_ctrl_rfu2_idx;
+ u32 emc_pmacro_data_brick_ctrl_fdpd_idx;
+ u32 emc_pmacro_bg_bias_ctrl_0_idx;
+ u32 emc_cfg_3_idx;
+ u32 emc_pmacro_tx_pwrd_0_idx;
+ u32 emc_pmacro_tx_pwrd_1_idx;
+ u32 emc_pmacro_tx_pwrd_2_idx;
+ u32 emc_pmacro_tx_pwrd_3_idx;
+ u32 emc_pmacro_tx_pwrd_4_idx;
+ u32 emc_pmacro_tx_pwrd_5_idx;
+ u32 emc_config_sample_delay_idx;
+ u32 emc_pmacro_tx_sel_clk_src_0_idx;
+ u32 emc_pmacro_tx_sel_clk_src_1_idx;
+ u32 emc_pmacro_tx_sel_clk_src_2_idx;
+ u32 emc_pmacro_tx_sel_clk_src_3_idx;
+ u32 emc_pmacro_tx_sel_clk_src_4_idx;
+ u32 emc_pmacro_tx_sel_clk_src_5_idx;
+ u32 emc_pmacro_ddll_bypass_idx;
+ u32 emc_pmacro_ddll_pwrd_0_idx;
+ u32 emc_pmacro_ddll_pwrd_1_idx;
+ u32 emc_pmacro_ddll_pwrd_2_idx;
+ u32 emc_pmacro_cmd_ctrl_0_idx;
+ u32 emc_pmacro_cmd_ctrl_1_idx;
+ u32 emc_pmacro_cmd_ctrl_2_idx;
+ u32 emc_tr_timing_0_idx;
+ u32 emc_tr_dvfs_idx;
+ u32 emc_tr_ctrl_1_idx;
+ u32 emc_tr_rdv_idx;
+ u32 emc_tr_qpop_idx;
+ u32 emc_tr_rdv_mask_idx;
+ u32 emc_mrw14_idx;
+ u32 emc_tr_qsafe_idx;
+ u32 emc_tr_qrst_idx;
+ u32 emc_training_ctrl_idx;
+ u32 emc_training_settle_idx;
+ u32 emc_training_vref_settle_idx;
+ u32 emc_training_ca_fine_ctrl_idx;
+ u32 emc_training_ca_ctrl_misc_idx;
+ u32 emc_training_ca_ctrl_misc1_idx;
+ u32 emc_training_ca_vref_ctrl_idx;
+ u32 emc_training_quse_cors_ctrl_idx;
+ u32 emc_training_quse_fine_ctrl_idx;
+ u32 emc_training_quse_ctrl_misc_idx;
+ u32 emc_training_quse_vref_ctrl_idx;
+ u32 emc_training_read_fine_ctrl_idx;
+ u32 emc_training_read_ctrl_misc_idx;
+ u32 emc_training_read_vref_ctrl_idx;
+ u32 emc_training_write_fine_ctrl_idx;
+ u32 emc_training_write_ctrl_misc_idx;
+ u32 emc_training_write_vref_ctrl_idx;
+ u32 emc_training_mpc_idx;
+ u32 emc_mrw15_idx;
+} burst_regs_t;
+
+
+typedef struct
+{
+ u32 burst_regs[221];
+ u32 burst_reg_per_ch[8];
+ u32 shadow_regs_ca_train[221];
+ u32 shadow_regs_quse_train[221];
+ u32 shadow_regs_rdwr_train[221];
+} burst_regs_table_t;
+
+typedef struct
+{
+ u32 ptfv_dqsosc_movavg_c0d0u0_idx;
+ u32 ptfv_dqsosc_movavg_c0d0u1_idx;
+ u32 ptfv_dqsosc_movavg_c0d1u0_idx;
+ u32 ptfv_dqsosc_movavg_c0d1u1_idx;
+ u32 ptfv_dqsosc_movavg_c1d0u0_idx;
+ u32 ptfv_dqsosc_movavg_c1d0u1_idx;
+ u32 ptfv_dqsosc_movavg_c1d1u0_idx;
+ u32 ptfv_dqsosc_movavg_c1d1u1_idx;
+ u32 ptfv_write_samples_idx;
+ u32 ptfv_dvfs_samples_idx;
+ u32 ptfv_movavg_weight_idx;
+ u32 ptfv_config_ctrl_idx;
+} ptfv_list_table_t;
+
+typedef struct
+{
+ u32 emc0_mrw10_idx;
+ u32 emc1_mrw10_idx;
+ u32 emc0_mrw11_idx;
+ u32 emc1_mrw11_idx;
+ u32 emc0_mrw12_idx;
+ u32 emc1_mrw12_idx;
+ u32 emc0_mrw13_idx;
+ u32 emc1_mrw13_idx;
+} burst_reg_per_ch_t;
+
+typedef struct
+{
+ u32 emc_pmacro_ib_ddll_long_dqs_rank0_0_idx;
+ u32 emc_pmacro_ib_ddll_long_dqs_rank0_1_idx;
+ u32 emc_pmacro_ib_ddll_long_dqs_rank0_2_idx;
+ u32 emc_pmacro_ib_ddll_long_dqs_rank0_3_idx;
+ u32 emc_pmacro_ib_ddll_long_dqs_rank1_0_idx;
+ u32 emc_pmacro_ib_ddll_long_dqs_rank1_1_idx;
+ u32 emc_pmacro_ib_ddll_long_dqs_rank1_2_idx;
+ u32 emc_pmacro_ib_ddll_long_dqs_rank1_3_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank0_byte0_0_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank0_byte0_1_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank0_byte0_2_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank0_byte1_0_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank0_byte1_1_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank0_byte1_2_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank0_byte2_0_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank0_byte2_1_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank0_byte2_2_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank0_byte3_0_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank0_byte3_1_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank0_byte3_2_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank0_byte4_0_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank0_byte4_1_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank0_byte4_2_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank0_byte5_0_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank0_byte5_1_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank0_byte5_2_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank0_byte6_0_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank0_byte6_1_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank0_byte6_2_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank0_byte7_0_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank0_byte7_1_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank0_byte7_2_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank1_byte0_0_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank1_byte0_1_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank1_byte0_2_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank1_byte1_0_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank1_byte1_1_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank1_byte1_2_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank1_byte2_0_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank1_byte2_1_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank1_byte2_2_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank1_byte3_0_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank1_byte3_1_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank1_byte3_2_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank1_byte4_0_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank1_byte4_1_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank1_byte4_2_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank1_byte5_0_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank1_byte5_1_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank1_byte5_2_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank1_byte6_0_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank1_byte6_1_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank1_byte6_2_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank1_byte7_0_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank1_byte7_1_idx;
+ u32 emc_pmacro_ib_ddll_short_dq_rank1_byte7_2_idx;
+ u32 emc_pmacro_ib_vref_dqs_0_idx;
+ u32 emc_pmacro_ib_vref_dqs_1_idx;
+ u32 emc_pmacro_ib_vref_dq_0_idx;
+ u32 emc_pmacro_ib_vref_dq_1_idx;
+ u32 emc_pmacro_ob_ddll_long_dq_rank0_0_idx;
+ u32 emc_pmacro_ob_ddll_long_dq_rank0_1_idx;
+ u32 emc_pmacro_ob_ddll_long_dq_rank0_2_idx;
+ u32 emc_pmacro_ob_ddll_long_dq_rank0_3_idx;
+ u32 emc_pmacro_ob_ddll_long_dq_rank0_4_idx;
+ u32 emc_pmacro_ob_ddll_long_dq_rank0_5_idx;
+ u32 emc_pmacro_ob_ddll_long_dq_rank1_0_idx;
+ u32 emc_pmacro_ob_ddll_long_dq_rank1_1_idx;
+ u32 emc_pmacro_ob_ddll_long_dq_rank1_2_idx;
+ u32 emc_pmacro_ob_ddll_long_dq_rank1_3_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte0_0_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte0_1_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte0_2_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte1_0_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte1_1_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte1_2_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte2_0_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte2_1_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte2_2_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte3_0_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte3_1_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte3_2_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte4_0_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte4_1_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte4_2_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte5_0_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte5_1_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte5_2_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte6_0_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte6_1_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte6_2_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte7_0_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte7_1_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_byte7_2_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd0_0_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd0_1_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd0_2_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd1_0_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd1_1_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd1_2_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd2_0_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd2_1_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd2_2_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd3_0_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd3_1_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank0_cmd3_2_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte0_0_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte0_1_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte0_2_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte1_0_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte1_1_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte1_2_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte2_0_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte2_1_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte2_2_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte3_0_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte3_1_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte3_2_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte4_0_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte4_1_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte4_2_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte5_0_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte5_1_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte5_2_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte6_0_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte6_1_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte6_2_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte7_0_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte7_1_idx;
+ u32 emc_pmacro_ob_ddll_short_dq_rank1_byte7_2_idx;
+ u32 emc_pmacro_quse_ddll_rank0_0_idx;
+ u32 emc_pmacro_quse_ddll_rank0_1_idx;
+ u32 emc_pmacro_quse_ddll_rank0_2_idx;
+ u32 emc_pmacro_quse_ddll_rank0_3_idx;
+ u32 emc_pmacro_quse_ddll_rank1_0_idx;
+ u32 emc_pmacro_quse_ddll_rank1_1_idx;
+ u32 emc_pmacro_quse_ddll_rank1_2_idx;
+ u32 emc_pmacro_quse_ddll_rank1_3_idx;
+} trim_regs_t;
+
+typedef struct
+{
+ u32 emc_cmd_brlshft_0_idx;
+ u32 emc_cmd_brlshft_1_idx;
+ u32 emc0_data_brlshft_0_idx;
+ u32 emc1_data_brlshft_0_idx;
+ u32 emc0_data_brlshft_1_idx;
+ u32 emc1_data_brlshft_1_idx;
+ u32 emc_quse_brlshft_0_idx;
+ u32 emc_quse_brlshft_1_idx;
+ u32 emc_quse_brlshft_2_idx;
+ u32 emc_quse_brlshft_3_idx;
+} trim_perch_regs_t;
+
+typedef struct
+{
+ u32 t_rp;
+ u32 t_fc_lpddr4;
+ u32 t_rfc;
+ u32 t_pdex;
+ u32 rl;
+} dram_timings_t;
+
+typedef struct
+{
+ u32 emc0_training_opt_dqs_ib_vref_rank0_idx;
+ u32 emc1_training_opt_dqs_ib_vref_rank0_idx;
+ u32 emc0_training_opt_dqs_ib_vref_rank1_idx;
+ u32 emc1_training_opt_dqs_ib_vref_rank1_idx;
+} vref_perch_regs_t;
+
+typedef struct
+{
+ u32 trim_regs[138];
+ u32 trim_perch_regs[10];
+ u32 vref_perch_regs[4];
+} trim_regs_table_t;
+
+typedef struct
+{
+ u32 rev;
+ char dvfs_ver[60];
+ u32 rate_khz;
+ u32 min_volt;
+ u32 gpu_min_volt;
+ char clock_src[32];
+ u32 clk_src_emc;
+ u32 needs_training;
+ u32 training_pattern;
+ u32 trained;
+ u32 periodic_training;
+ u32 trained_dram_clktree_c0d0u0;
+ u32 trained_dram_clktree_c0d0u1;
+ u32 trained_dram_clktree_c0d1u0;
+ u32 trained_dram_clktree_c0d1u1;
+ u32 trained_dram_clktree_c1d0u0;
+ u32 trained_dram_clktree_c1d0u1;
+ u32 trained_dram_clktree_c1d1u0;
+ u32 trained_dram_clktree_c1d1u1;
+ u32 current_dram_clktree_c0d0u0;
+ u32 current_dram_clktree_c0d0u1;
+ u32 current_dram_clktree_c0d1u0;
+ u32 current_dram_clktree_c0d1u1;
+ u32 current_dram_clktree_c1d0u0;
+ u32 current_dram_clktree_c1d0u1;
+ u32 current_dram_clktree_c1d1u0;
+ u32 current_dram_clktree_c1d1u1;
+ u32 run_clocks;
+ u32 tree_margin;
+ u32 num_burst;
+ u32 num_burst_per_ch;
+ u32 num_trim;
+ u32 num_trim_per_ch;
+ u32 num_mc_regs;
+ u32 num_up_down;
+ u32 vref_num;
+ u32 training_mod_num;
+ u32 dram_timing_num;
+
+ ptfv_list_table_t ptfv_list;
+
+ burst_regs_t burst_regs;
+ burst_reg_per_ch_t burst_reg_per_ch;
+ burst_regs_t shadow_regs_ca_train;
+ burst_regs_t shadow_regs_quse_train;
+ burst_regs_t shadow_regs_rdwr_train;
+ trim_regs_t trim_regs;
+ trim_perch_regs_t trim_perch_regs;
+ vref_perch_regs_t vref_perch_regs;
+ dram_timings_t dram_timings;
+
+ u32 training_mod_regs[20];
+ u32 save_restore_mod_regs[12];
+ u32 burst_mc_regs[33];
+ u32 la_scale_regs[24];
+
+ u32 min_mrs_wait;
+ u32 emc_mrw;
+ u32 emc_mrw2;
+ u32 emc_mrw3;
+ u32 emc_mrw4;
+ u32 emc_mrw9;
+ u32 emc_mrs;
+ u32 emc_emrs;
+ u32 emc_emrs2;
+ u32 emc_auto_cal_config;
+ u32 emc_auto_cal_config2;
+ u32 emc_auto_cal_config3;
+ u32 emc_auto_cal_config4;
+ u32 emc_auto_cal_config5;
+ u32 emc_auto_cal_config6;
+ u32 emc_auto_cal_config7;
+ u32 emc_auto_cal_config8;
+ u32 emc_cfg_2;
+ u32 emc_sel_dpd_ctrl;
+ u32 emc_fdpd_ctrl_cmd_no_ramp;
+ u32 dll_clk_src;
+ u32 clk_out_enb_x_0_clk_enb_emc_dll;
+ u32 latency;
+} emc_table_t;
+
+#endif
\ No newline at end of file
diff --git a/bootloader/soc/hw_init.c b/bootloader/soc/hw_init.c
index caf7ada..7d1f5f9 100644
--- a/bootloader/soc/hw_init.c
+++ b/bootloader/soc/hw_init.c
@@ -28,6 +28,7 @@
#include "uart.h"
#include "../gfx/di.h"
#include "../mem/mc.h"
+#include "../mem/minerva.h"
#include "../mem/sdram.h"
#include "../power/max77620.h"
#include "../power/max7762x.h"
@@ -251,6 +252,8 @@ void config_hw()
void reconfig_hw_workaround(bool extra_reconfig, u32 magic)
{
+ minerva_change_freq(FREQ_204);
+
// Re-enable clocks to Audio Processing Engine as a workaround to hanging.
CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_V) |= (1 << 10); // Enable AHUB clock.
CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_Y) |= (1 << 6); // Enable APE clock.
diff --git a/modules/hekate_libsys_minerva/sys_sdrammtc.c b/modules/hekate_libsys_minerva/sys_sdrammtc.c
index 0668e1f..5031a05 100644
--- a/modules/hekate_libsys_minerva/sys_sdrammtc.c
+++ b/modules/hekate_libsys_minerva/sys_sdrammtc.c
@@ -3856,9 +3856,9 @@ u32 _minerva_do_periodic_compensation(emc_table_t *mtc_table_entry)
if (channel1_enabled)
_wait_emc_status(EMC_EMC_STATUS, IN_SELF_REFRESH_MASK, 0, channel1_enabled);
- _wait_emc_status(EMC_EMC_STATUS, REQ_FIFO_EMPTY, 0, EMC_CH0); //v1.6
- if (channel1_enabled)
- _wait_emc_status(EMC_EMC_STATUS, REQ_FIFO_EMPTY, 0, channel1_enabled); //v1.6
+ //_wait_emc_status(EMC_EMC_STATUS, REQ_FIFO_EMPTY, 0, EMC_CH0); //v1.6
+ //if (channel1_enabled)
+ // _wait_emc_status(EMC_EMC_STATUS, REQ_FIFO_EMPTY, 0, channel1_enabled); //v1.6
u32 emc_cfg_update = EMC(EMC_CFG_UPDATE);
EMC(EMC_CFG_UPDATE) = (emc_cfg_update & 0xFFFFF9FF) | 0x400;