[Feature]add MT2731_MP2_MR2_SVN388 baseline version

Change-Id: Ief04314834b31e27effab435d3ca8ba33b499059
diff --git a/src/bach/build.bach/tools/emigenemi.pl b/src/bach/build.bach/tools/emigenemi.pl
new file mode 100644
index 0000000..090ff60
--- /dev/null
+++ b/src/bach/build.bach/tools/emigenemi.pl
@@ -0,0 +1,540 @@
+#!/usr/bin/perl
+
+use Class::Struct ();
+
+my $DebugPrint    = 0;
+
+#****************************************************************************
+# subroutine:  custom_EMI_release_h_file_body_for_91
+# return:
+#****************************************************************************
+sub custom_EMI_release_h_file_body_for_91
+{
+    my ($MAKEFILE_OPTIONS_LOCAL, $CUSTOM_MEM_DEV_OPTIONS_LOCAL, $MDL_INFO_LIST_LOCAL, $COMM_MDL_INFO_LOCAL, $LPSDRAM_CHIP_SELECT_LOCAL, $emi_clk_config_LOCAL) = @_;
+    my ($cus_include, $cus_def, $cus_enum, $cus_struct, $cus_api);
+    my $emi_clk_str;
+    my $emi_device_mode;
+
+    if (($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{FLASH_ACCESS_TYPE} eq 'SYNC_ACCESS') && ($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{RAM_ACCESS_TYPE} eq 'SYNC_ACCESS'))
+    {
+        $emi_clk_str = sprintf("#define __EMI_CLK_%sMHZ__", $emi_clk_config_LOCAL);
+        if ($emi_clk_str =~ /\./)
+        {
+            $emi_clk_str =~ s/\./_/;
+        }
+    }
+    if ($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{MEMORY_DEVICE_TYPE} =~ /LPDDR3/)
+    {
+        $emi_device_mode = "#define __EMI_DEVICE_LPDDR3__\n#define __EMI_MODE_2X__";
+    }
+    elsif ($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{MEMORY_DEVICE_TYPE} =~ /LPDDR2/)
+    {
+        $emi_device_mode = "#define __EMI_DEVICE_LPDDR2__\n#define __EMI_MODE_2X__";
+    }
+    elsif ($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{MEMORY_DEVICE_TYPE} =~ /LPDDR/)
+    {
+        $emi_device_mode = "#define __EMI_DEVICE_LPDDR1__\n#define __EMI_MODE_1X__";
+    }
+    else
+    {
+        &error_handler("MEMORY_DEVICE_TYPE:$CUSTOM_MEM_DEV_OPTIONS_LOCAL->{MEMORY_DEVICE_TYPE} didn't support yet!", __FILE__, __LINE__);
+    }
+
+    print "MDL info:$COMM_MDL_INFO_LOCAL->{1}->{'Size (Mb)'}\n" if ($DebugPrint == 1);
+
+    my $template = <<"__TEMPLATE";
+#ifndef __CUSTOM_EMI_RELEASE_H__
+#define __CUSTOM_EMI_RELEASE_H__
+/********************************************
+ * Include.
+ ********************************************/
+$cus_include
+/********************************************
+ * Definition.
+ ********************************************/
+/**
+  * Define EMI's clock rate.
+  * comes from EMI_CLK definition in custom_MemoryDevice.h, or highest freq in MDL
+  */
+$emi_clk_str
+
+/**
+  * Define memory's mode.
+  */
+$emi_device_mode
+
+/**
+  * Define RAM size in Bytes.
+  */
+#define EMI_EXTSRAM_SIZE ((($COMM_MDL_INFO_LOCAL->{1}->{'Size (Mb)'})>>3)<<20)
+$cus_def
+/********************************************
+ * Enum.
+ ********************************************/
+$cus_enum
+/********************************************
+ * Struct.
+ ********************************************/
+$cus_struct
+/********************************************
+ * Exposed APIs.
+ ********************************************/
+$cus_api
+#endif /* __CUSTOM_EMI_RELEASE_H__ */
+
+__TEMPLATE
+
+    return $template;
+}
+
+#****************************************************************************
+# subroutine:  custom_EMI_h_file_body_for_91
+# return:
+#****************************************************************************
+sub custom_EMI_h_file_body_for_91
+{
+    ### EMI register value for each MCP
+    #my ($MAKEFILE_OPTIONS_LOCAL, $CUSTOM_MEM_DEV_OPTIONS_LOCAL, $MDL_INFO_LIST_LOCAL, $cus_include, $cus_def, $cus_enum, $cus_struct, $cus_api) = @_;
+    my ($MAKEFILE_OPTIONS_LOCAL, $CUSTOM_MEM_DEV_OPTIONS_LOCAL, $MDL_INFO_LIST_LOCAL, $COMM_MDL_INFO_LOCAL, $PART_NUMBER_LOCAL, $CUSTOM_MEMORY_DEVICE_HDR_LOCAL, $LPSDRAM_CHIP_SELECT_LOCAL, $emi_clk_config_LOCAL) = @_;
+    my ($cus_include, $cus_def, $cus_enum, $cus_struct, $cus_api);
+    my ($combo_mem_emi_reg, $combo_mem_emi_reg_clk);
+    my $emi_reg_bb_key_ref;
+    my $clk, $first_parse_clk;
+    my $mtk_emi_info;
+
+    $cus_def = <<"__TEMPLATE";
+/* Initial EMI Definition */
+#define DRAM_START          (0x00000000)
+
+#define MAX_DQ_DATA_WIDTH   (32)
+#define DQ_NUMBER_PER_DQS   (8)
+#define DQS_NUMBER          (MAX_DQ_DATA_WIDTH / DQ_NUMBER_PER_DQS)
+__TEMPLATE
+
+    $cus_api = <<"__TEMPLATE";
+int custom_InitDRAM(void);
+__TEMPLATE
+
+    for (1..$CUSTOM_MEM_DEV_OPTIONS_LOCAL->{COMBO_MEM_ENTRY_COUNT})
+    {
+        my $combo_idx = $_ - 1;
+        my $def_pre = undef;
+        undef $mtk_emi_info;
+        undef $first_parse_clk;
+
+        $combo_mem_emi_reg .= <<"__TEMPLATE";
+/*
+ * EMI register value definition
+ * EMI/MEM configuration information of MCP$combo_idx
+ */
+__TEMPLATE
+        $def_pre = "#define DRAM_VENDOR_MCP$combo_idx";
+        $combo_mem_emi_reg .= $def_pre;
+        $combo_mem_emi_reg .= " " x (47 - length($def_pre));
+        $combo_mem_emi_reg .= " (\"$MDL_INFO_LIST_LOCAL->[$_]->{0}->{'Vendor'}\")\n";
+        $def_pre = "#define DRAM_PART_NUMBER_MCP$combo_idx";
+        $combo_mem_emi_reg .= $def_pre;
+        $combo_mem_emi_reg .= " " x (47 - length($def_pre));
+        $combo_mem_emi_reg .= " (\"$MDL_INFO_LIST_LOCAL->[$_]->{0}->{'Part Number'}\")\n";
+        my $emi_reg_bb_key_ref = $MDL_INFO_LIST_LOCAL->[$_]->{0}->{$MAKEFILE_OPTIONS_LOCAL->{'platform'}};
+        foreach my $emi_key (sort keys %{$emi_reg_bb_key_ref})
+        {
+            if ($emi_key =~ /(\d+)MHZ EMI Driving/)
+            {
+                $clk = $1;
+                if (! defined $first_parse_clk)
+                {
+                    $first_parse_clk = $clk;
+                }
+                if (! defined $combo_mem_emi_reg_clk)
+                {
+                    $combo_mem_emi_reg_clk = "#if defined(__EMI_CLK_$clk\MHZ__)\n";
+                }
+                else
+                {
+                    $combo_mem_emi_reg_clk .= "#elif defined(__EMI_CLK_$clk\MHZ__)\n";
+                }
+                my $emi_clk_dri = $emi_key;
+                foreach my $emi_key (sort keys %{$emi_reg_bb_key_ref->{$emi_clk_dri}})
+                {
+                    my $val = $emi_reg_bb_key_ref->{$emi_clk_dri}->{$emi_key};
+                    if (($val ne 'x') && ($val ne 'X') && ($val ne ''))
+                    {
+                        $def_pre = "#define $emi_key\_MCP$combo_idx";
+                        $combo_mem_emi_reg_clk .= $def_pre;
+                        # for alignment
+                        $combo_mem_emi_reg_clk .= " " x (47 - length($def_pre));
+                        $combo_mem_emi_reg_clk .= " ($val)\n";
+                    }
+
+                    if ($first_parse_clk == $clk)
+                    {
+                        $mtk_emi_info .= "    unsigned int " . lc($emi_key) . ";\n";
+                    }
+                }
+            }
+            else
+            {
+                my $val = $emi_reg_bb_key_ref->{$emi_key};
+                $def_pre = "#define $emi_key\_MCP$combo_idx";
+                if (($val ne 'x') && ($val ne 'X') && ($val ne ''))
+                {
+                    $combo_mem_emi_reg .= $def_pre;
+                    # for alignment
+                    $combo_mem_emi_reg .= " " x (47 - length($def_pre));
+                    $combo_mem_emi_reg .= " ($val)\n";
+                }
+                $mtk_emi_info .= "    unsigned int " . lc($emi_key) . ";\n";
+            }
+        }
+        $combo_mem_emi_reg_clk .= "#endif /* __EMI_CLK_$clk\MHZ__ */\n";
+
+        $combo_mem_emi_reg .= <<"__TEMPLATE";
+
+$combo_mem_emi_reg_clk
+/*
+ * End of EMI/MEM configuration information of MCP$combo_idx
+ */
+__TEMPLATE
+
+        undef $combo_mem_emi_reg_clk;
+    }
+
+    my $template = <<"__TEMPLATE";
+#ifndef __CUSTOM_EMI_H__
+#define __CUSTOM_EMI_H__
+/********************************************
+ * Include.
+ ********************************************/
+#include "custom_EMI_release.h"
+$cus_include
+/********************************************
+ * Definition.
+ ********************************************/
+$combo_mem_emi_reg
+$cus_def
+/********************************************
+ * Enum.
+ ********************************************/
+typedef enum {
+    DRAMType_Invalid = 0x0,
+    DRAMType_DDR,
+    DRAMType_DDR2,
+    DRAMType_DDR_166M,
+    DRAMType_DDR_200M,
+    DRAMType_DDR2_166M,
+    DRAMType_DDR2_200M,
+    DRAMType_LPDDR = 0x800,
+    DRAMType_LPDDR2,
+    DRAMType_LPDDR_166M,
+    DRAMType_LPDDR_200M,
+    DRAMType_LPDDR2_166M,
+    DRAMType_LPDDR2_200M,
+    DRAMType_LPDDR2_266M,
+    DRAMType_LPDDR3_303M = 0x900,
+    DRAMType_DDR_166M_SIP = 0x1000,
+    DRAMType_DDR_200M_SIP,
+    DRAMType_DDR2_166M_SIP,
+    DRAMType_DDR2_200M_SIP,
+    DRAMType_LPDDR_SIP = 0x1800,
+    DRAMType_LPDDR2_SIP,
+    DRAMType_LPDDR_166M_SIP,
+    DRAMType_LPDDR_200M_SIP,
+    DRAMType_LPDDR2_166M_SIP,
+    DRAMType_LPDDR2_200M_SIP,
+    DRAMType_End = 0x42424242
+} DRAMType;
+$cus_enum
+/********************************************
+ * Struct.
+ ********************************************/
+typedef struct {
+    DRAMType ramType;
+$mtk_emi_info} MTK_EMI_Info;
+$cus_struct
+/********************************************
+ * Exposed APIs.
+ ********************************************/
+$cus_api
+#endif /* end of __CUSTOM_EMI_H__ */
+__TEMPLATE
+
+    return $template;
+}
+
+#****************************************************************************
+# subroutine:  custom_EMI_info_h_file_body
+# return:
+#****************************************************************************
+sub custom_EMI_info_h_file_body
+{
+    my ($MAKEFILE_OPTIONS_LOCAL, $CUSTOM_MEM_DEV_OPTIONS_LOCAL, $MDL_INFO_LIST_LOCAL, $emi_clk_config_LOCAL, $cus_include, $cus_def, $cus_enum, $cus_struct, $cus_api) = @_;
+    my $combo_mem_emi_info_struct;
+    my $combo_mem_emi_type;
+
+    $combo_mem_emi_type = "DRAMType_";
+    if ($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{MEMORY_DEVICE_TYPE} =~ /[A-Za-z]*DDR[0-9]*/)
+    {
+        $combo_mem_emi_type .= $&;
+    }
+    if (($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{FLASH_ACCESS_TYPE} eq 'SYNC_ACCESS') && ($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{RAM_ACCESS_TYPE} eq 'SYNC_ACCESS'))
+    {
+        $combo_mem_emi_type .= sprintf("_%sM", $emi_clk_config_LOCAL);
+    }
+    if ($MAKEFILE_OPTIONS_LOCAL->{'sip_ram_size'} ne "NONE") {
+        $combo_mem_emi_type .= "_SIP";
+    }
+    for (1..$CUSTOM_MEM_DEV_OPTIONS_LOCAL->{COMBO_MEM_ENTRY_COUNT})
+    {
+        my $combo_idx = $_ - 1;
+        $combo_mem_emi_info_struct .= <<"__TEMPLATE";
+    {
+        .ramType = $combo_mem_emi_type,
+__TEMPLATE
+        my $emi_reg_bb_key_ref = $MDL_INFO_LIST_LOCAL->[$_]->{0}->{$MAKEFILE_OPTIONS_LOCAL->{'platform'}};
+        foreach my $emi_key (sort keys %{$emi_reg_bb_key_ref})
+        {
+            if ($emi_key =~ /(\d+)MHZ EMI Driving/)
+            {
+                my $emi_clk_dri = $emi_key;
+                foreach my $emi_key (sort keys %{$emi_reg_bb_key_ref->{$emi_clk_dri}})
+                {
+                    my $val = $emi_reg_bb_key_ref->{$emi_clk_dri}->{$emi_key};
+                    if (($val ne 'x') && ($val ne 'X') && ($val ne ''))
+                    {
+                        my $emi_info_def = "$emi_key\_MCP$combo_idx";
+                        $combo_mem_emi_info_struct .= "        ." . lc($emi_key) . " = " . $emi_info_def . ",\n";
+                    }
+                }
+            }
+            else
+            {
+                my $val = $emi_reg_bb_key_ref->{$emi_key};
+                if (($val ne 'x') && ($val ne 'X') && ($val ne ''))
+                {
+                    my $emi_info_def = "$emi_key\_MCP$combo_idx";
+                    $combo_mem_emi_info_struct .= "        ." . lc($emi_key) . " = " . $emi_info_def . ",\n";
+                }
+            }
+        }
+        $combo_mem_emi_info_struct .= "    },\n";
+    }
+    my $template = <<"__TEMPLATE";
+#ifndef __CUSTOM_EMI_INFO_H__
+#define __CUSTOM_EMI_INFO_H__
+/********************************************
+ * Include.
+ ********************************************/
+#include "custom_EMI_release.h"
+#include "custom_EMI.h"
+$cus_include
+/********************************************
+ * Definition.
+ ********************************************/
+$cus_def
+/********************************************
+ * Enum.
+ ********************************************/
+$cus_enum
+/********************************************
+ * Struct.
+ ********************************************/
+MTK_EMI_Info EMI_INFO[] = {
+$combo_mem_emi_info_struct
+}; /* End of EMI_INFO struct */
+$cus_struct
+/********************************************
+ * Exposed APIs.
+ ********************************************/
+$cus_api
+
+#endif /* __CUSTOM_EMI_INFO_H__ */
+__TEMPLATE
+
+    return $template;
+}
+
+#****************************************************************************
+# subroutine:  custom_EMI_info_c_file_body
+# return:
+#****************************************************************************
+sub custom_EMI_info_c_file_body_for_91
+{
+    my ($MAKEFILE_OPTIONS_LOCAL, $CUSTOM_MEM_DEV_OPTIONS_LOCAL, $MDL_INFO_LIST_LOCAL, $COMM_MDL_INFO_LOCAL, $PART_NUMBER_LOCAL, $CUSTOM_MEMORY_DEVICE_HDR_LOCAL, $LPSDRAM_CHIP_SELECT_LOCAL, $emi_clk_config_LOCAL, $emi_nor_cmd_num_max_LOCAL, $emi_psram_cmd_num_max_LOCAL) = @_;
+    my ($cus_include, $cus_def, $cus_enum, $cus_struct, $cus_api);
+    my $combo_mem_emi_info_struct;
+    my $combo_mem_emi_type;
+
+    $combo_mem_emi_type = "DRAMType_";
+    if ($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{MEMORY_DEVICE_TYPE} =~ /[A-Za-z]*DDR[0-9]*/)
+    {
+        $combo_mem_emi_type .= $&;
+    }
+    if (($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{FLASH_ACCESS_TYPE} eq 'SYNC_ACCESS') && ($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{RAM_ACCESS_TYPE} eq 'SYNC_ACCESS'))
+    {
+        $combo_mem_emi_type .= sprintf("_%sM", $emi_clk_config_LOCAL);
+    }
+    if ($MAKEFILE_OPTIONS_LOCAL->{'sip_ram_size'} ne "NONE") {
+        $combo_mem_emi_type .= "_SIP";
+    }
+    for (1..$CUSTOM_MEM_DEV_OPTIONS_LOCAL->{COMBO_MEM_ENTRY_COUNT})
+    {
+        my $combo_idx = $_ - 1;
+        $combo_mem_emi_info_struct .= <<"__TEMPLATE";
+    {
+        .ramType = $combo_mem_emi_type,
+__TEMPLATE
+        my $emi_reg_bb_key_ref = $MDL_INFO_LIST_LOCAL->[$_]->{0}->{$MAKEFILE_OPTIONS_LOCAL->{'platform'}};
+        foreach my $emi_key (sort keys %{$emi_reg_bb_key_ref})
+        {
+            if ($emi_key =~ /(\d+)MHZ EMI Driving/)
+            {
+                my $emi_clk_dri = $emi_key;
+                foreach my $emi_key (sort keys %{$emi_reg_bb_key_ref->{$emi_clk_dri}})
+                {
+                    my $val = $emi_reg_bb_key_ref->{$emi_clk_dri}->{$emi_key};
+                    if (($val ne 'x') && ($val ne 'X') && ($val ne ''))
+                    {
+                        my $emi_info_def = "$emi_key\_MCP$combo_idx";
+                        $combo_mem_emi_info_struct .= "        ." . lc($emi_key) . " = " . $emi_info_def . ",\n";
+                    }
+                }
+            }
+            else
+            {
+                my $val = $emi_reg_bb_key_ref->{$emi_key};
+                if (($val ne 'x') && ($val ne 'X') && ($val ne ''))
+                {
+                    my $emi_info_def = "$emi_key\_MCP$combo_idx";
+                    $combo_mem_emi_info_struct .= "        ." . lc($emi_key) . " = " . $emi_info_def . ",\n";
+                }
+            }
+        }
+        $combo_mem_emi_info_struct .= "    },\n";
+    }
+    my $template = <<"__TEMPLATE";
+/********************************************
+ * Include.
+ ********************************************/
+#include "custom_EMI_release.h"
+#include "custom_EMI.h"
+$cus_include
+/********************************************
+ * Definition.
+ ********************************************/
+$cus_def
+/********************************************
+ * Enum.
+ ********************************************/
+$cus_enum
+/********************************************
+ * Struct.
+ ********************************************/
+MTK_EMI_Info EMI_INFO[] = {
+$combo_mem_emi_info_struct
+}; /* End of EMI_INFO struct */
+$cus_struct
+/********************************************
+ * Exposed APIs.
+ ********************************************/
+$cus_api
+
+__TEMPLATE
+
+    return $template;
+}
+
+
+#****************************************************************************
+# custom_emi_h for MT6297
+#****************************************************************************
+Class::Struct::struct(EMI_SETTING => {name => '$', xls_name => '$', value => '$'});
+my @EMI_SETTINGS = (
+    EMI_SETTING->new(name => "sub_version", xls_name => undef, value => 0x1),
+    EMI_SETTING->new(name => "type", xls_name => "Type"),
+    EMI_SETTING->new(name => "dram_cbt_mode_extern", xls_name => "Mode"),
+    EMI_SETTING->new(name => "DRAM_RANK_SIZE", xls_name => "Density (Mb)"),
+    EMI_SETTING->new(name => "DRAM_RANK_SIZE_0L", xls_name => undef),
+    EMI_SETTING->new(name => "DRAM_RANK_SIZE_0H", xls_name => undef),
+    EMI_SETTING->new(name => "DRAM_RANK_SIZE_1L", xls_name => undef),
+    EMI_SETTING->new(name => "DRAM_RANK_SIZE_1H", xls_name => undef),
+    # by platform
+    EMI_SETTING->new(name => "EMI_CONA_VAL", xls_name => "CONA_VAL"),
+    EMI_SETTING->new(name => "CHN0_EMI_CONA_VAL", xls_name => "CHN0_CONA_VAL"),
+    EMI_SETTING->new(name => "CHN1_EMI_CONA_VAL", xls_name => "CHN1_CONA_VAL"),
+    EMI_SETTING->new(name => "EMI_CONF_VAL", xls_name => "CONF_VAL"),
+    EMI_SETTING->new(name => "EMI_CONH_VAL", xls_name => "CONH_VAL"),
+    EMI_SETTING->new(name => "iLPDDR3_MODE_REG_5", xls_name => "MODE_REG5"),
+    EMI_SETTING->new(name => "PIN_MUX_TYPE", xls_name => "PIN_MUX_TYPE"),
+);
+
+sub emi_setting_type
+{
+    my $typ = shift;
+    my %mcp = ("Discrete" => 0, "NAND" => 1, "eMMC" => 2, "UFS" => 3);
+    my %ddr = ("DDR1" => 1, "LPDDR2" => 2, "LPDDR3" => 3, "PCDDR3" => 4, "LPDDR4" => 5, "LPDR4X" => 6, "LPDDR4P" => 7);
+
+    if (($typ =~ /(Discrete)\s+(\w+)/) or ($typ =~ /MCP\((\w+)\+(\w+)\)/)) {
+        return ($mcp{$1} << 8) + ($ddr{$2});
+    }
+    return undef;
+}
+
+sub emi_setting_cbt
+{
+    my $cbt = shift;
+    my %cbt_h = ( "CBT_R0_R1_NORMAL" => 0, "CBT_R0_R1_BYTE" => 1, "CBT_R0_NORMAL_R1_BYTE" => 2, "CBT_R0_BYTE_R1_NORMAL" => 3);
+
+    return $cbt_h{$cbt};
+}
+
+sub custom_emi_h_file_body_for_97
+{
+    my ($MAKEFILE_OPTIONS_LOCAL, $MDL_INFO_LIST_LOCAL) = @_;
+    my $platform = $MAKEFILE_OPTIONS_LOCAL->{platform};
+    my @size;
+
+    for my $emi (@EMI_SETTINGS) {  # update value
+        if ($emi->name eq "type") {
+            $emi->value(sprintf "%#05x", &emi_setting_type($MDL_INFO_LIST_LOCAL->[1]->{0}->{$emi->xls_name}));
+        } elsif ($emi->name eq "dram_cbt_mode_extern") {
+            my $v = $MDL_INFO_LIST_LOCAL->[1]->{0}->{$emi->xls_name};
+            $emi->value(sprintf "%d/*%s*/", &emi_setting_cbt($v), $v);
+        } elsif ($emi->name eq "DRAM_RANK_SIZE") {
+            for (split(/\+/, $MDL_INFO_LIST_LOCAL->[1]->{0}->{$emi->xls_name})) {
+                my $s = int($_) * 1024 * 1024 / 8; # Mbit -> Byte
+                push @size, sprintf("%#x", $s & 0xffffffff);
+                push @size, sprintf("%#x", $s >> 32);
+            }
+        } elsif ($emi->name =~ /DRAM_RANK_SIZE_\d[LH]/i) {
+            $emi->value(shift @size);
+        } elsif (defined $emi->xls_name) {
+            $emi->value($MDL_INFO_LIST_LOCAL->[1]->{0}->{$platform}->{$emi->xls_name});
+        }
+    }
+
+    my @setting;
+    for my $emi (@EMI_SETTINGS) {
+        push(@setting, ".".$emi->name." = ".$emi->value) if defined($emi->value);
+    }
+    my $setting_str = join(",\n    ", @setting);
+
+    my $template = <<"__TEMPLATE";
+#ifndef __CUSTOM_EMI_H__
+#define __CUSTOM_EMI_H__
+
+#include "emi.h"
+
+// $MDL_INFO_LIST_LOCAL->[1]->{0}->{"Part Number"}
+EMI_SETTINGS default_emi_setting =
+{
+    $setting_str
+};
+
+#endif
+__TEMPLATE
+
+    return $template;
+}
+
+return 1;