MTK 平台 NVRAM 分区修改及应用解析--双logo切换


apple and android 以前在4.4系统上做个一个关于双开机logo的切换的需求,现在把一些当时的技术细节记录如下,以做后续参考:

MT8312 android 4.4 logo 分为三个部分:uboot( lk )、kernel( libshowlogo )、android ( bootanimation )。
方法说明:

  • 通过mtk的系统保留分区pro_info分区存放全局的系统变量,然后分别在uboot,kernel和android层去读取对应的值进行logo切换。
  • 在拨号盘采用"*#*#556#*#*"的方式进行双Logo的变量值的更改,目前设计有3个值,但仅用一个值作为判断,保留3个值作为后续扩展使用。

主要步骤如下:

一、增加文件:

1. 在mediatek/custom/common/lk/logo/对应的目录下增加文件,按照如下方式命名为:xxxx_kernel0.bmp,xxxx_uboot0.bmp,如:wsvga_uboot0.bmp,wsvga_kernel0.bmp
2. 在frameworks/base/data/sounds/目录下增加bootanimation.zip文件,或者直接将文件拷贝至:out\target\product\{project}\system\media目录下,运行:./mk {project} snod打包到系统。
3. 修改mediatek/custom/common/lk/logo/rules.mk文件,保证编译时可以增加文件到系统。
具体修改例子如下:

# add for double logo
ifeq ($(MTK_DOUBLE_LOGO_SUPPORT),yes)
RESOURCE_OBJ_LIST += \
$(BOOT_LOGO_DIR)/$(BOOT_LOGO)/$(BOOT_LOGO)_uboot0.raw \
$(BOOT_LOGO_DIR)/$(BOOT_LOGO)/$(BOOT_LOGO)_kernel0.raw
endif

4. 修改frameworks/base/data/sounds/OriginalAudio.mk,增加如下内容:

$(LOCAL_PATH)/bootanimation.zip:system/media/bootanimation.zip

5. 在mediatek/custom/common/lk/include/target/cust_display.h中增加对应logoindex 的宏,保证第3点中的rules.mk中序号与该文件一致,如:

#ifdef MTK_DOUBLE_LOGO_SUPPORT
#define BOOT_LOGO_OTHER_INDEX 39
#define KEL_LOGO_OTHER_INDEX 40
#endif

二、修改pro_info的配置,增加变量值:

1. 修改 CFG_PRODUCT_INFO_File.h,增加变量:

typedef struct{
unsigned char barcode[64];
nvram_ef_imei_imeisv_struct IMEI[4];
unsigned char logoinfo[3]; // add for double logo
unsigned char reserved[1024-40-64-3];
}PRODUCT_INFO_SAMPLE;

路径:mediatek/custom/{project}/cgen/cfgfileinc/
2. 修改:CFG_PRODUCT_INFO_Default.h,使两个文件保持一致。

路径:mediatek/custom/{project}/cgen/cfgdefault/

三、修改lk双logo切换:

1. 修改mediatek/platform/mt6582/lk/load_image.c增加nvram读取的函数及对应的变量值,函数主要内容如下:

int  mboot_common_get_logo_info()
{
    unsigned long begin;
    long len;
    #ifdef MTK_EMMC_SUPPORT
    unsigned long long start_addr;
    #else
    unsigned long start_addr;
    #endif
    part_t *part;	
    part_dev_t *dev;
    u8* data;
    char part_name[]="PRO_INFO";
    PRODUCT_INFO_SAMPLE *pro_info;

    dev = mt_part_get_device();
    if (!dev)
    {	
        return -ENODEV;
    }
    part = mt_part_get_partition(part_name);	
    if (!part)
    {	
        return -ENOENT;
    }

    #ifdef MTK_EMMC_SUPPORT
    start_addr = (u64)part->startblk * 512; 
    #else
    start_addr = part->startblk * 512;
    #endif  

    printf("part->startblk == 0x%lx\n",part->startblk);
    printf("start_addr000 == 0x%x\n",start_addr);

    pro_info = (PRODUCT_INFO_SAMPLE*)malloc(sizeof(PRODUCT_INFO_SAMPLE));

    begin = get_timer(0);	

    //****************
    //* read image data
    //*
    //****************		
    len = dev->read(dev, start_addr, (uchar*)pro_info, sizeof(PRODUCT_INFO_SAMPLE));
    if (len < 0) { len = -EIO; goto exit; } logoInfo[0]=pro_info->logoinfo[0];
    logoInfo[1]=pro_info->logoinfo[1];
    logoInfo[2]=pro_info->logoinfo[2];

    printf("[logoinfo]=======logoinfo[0]= %d,logoinfo[1]=%d,logoinfo[2]=%d\n",logoInfo[0],logoInfo[1],logoInfo[2]);

    exit:
    if (pro_info) 
    free(pro_info);

    return 0;
}

2. 在mediatek/platform/mt6582/lk/mt_logo.c中修改进行双logo切换判断,在函数 mt_disp_show_boot_logo()中增加如下内容进行切换:

mboot_common_get_logo_info();
if(get_logoinfo_value(0) == 0)
{
    fill_animation_logo(BOOT_LOGO_INDEX, mt_get_fb_addr(), mt_get_tempfb_addr(), logo_addr, phical_screen);
}
else if(get_logoinfo_value(0) == 1)
{
    fill_animation_logo(BOOT_LOGO_OTHER_INDEX, mt_get_fb_addr(), mt_get_tempfb_addr(), logo_addr, phical_screen);
}

四、kernel双logo切换:

1. 修改mediatek/external/libshowlogo/charging_animation.cpp,增加如下函数:

static int get_logo_flag(int index)
{
    F_ID fid;
    int rec_size = 0;
    int rec_num = 0;
    bool isread = true;
    int logo_flag_lid = AP_CFG_REEB_PRODUCT_INFO_LID;
    PRODUCT_INFO_SAMPLE_0 *logo_flag_struct;
    
    logo_flag_struct= (PRODUCT_INFO_SAMPLE_0 *)malloc(sizeof(PRODUCT_INFO_SAMPLE_0));
    if(logo_flag_struct == NULL)
    {
        return false;
    }
    
    fid = NVM_GetFileDesc(logo_flag_lid, &rec_size, &rec_num, isread);

    if(fid.iFileDesc < 0)
    {
        LOG_ANIM("fid.iFileDesc < 0"); return false; } if(rec_size != read(fid.iFileDesc, logo_flag_struct, rec_size)) { free(logo_flag_struct); return false; } logoinfo[0]= logo_flag_struct->logoinfo[0];
    logoinfo[1]= logo_flag_struct->logoinfo[1];
    logoinfo[2]= logo_flag_struct->logoinfo[2];			

    free(logo_flag_struct);
    if(!NVM_CloseFileDesc(fid))
    {
        return false;
    }			
    return logoinfo[index];
}

2. 修改show_kernel_logo()函数,如下:

#ifdef MTK_DOUBLE_LOGO_SUPPORT
if(get_logo_flag(0) == 0)
{
    anim_show_logo(kernel_logo_position); 
}
else if (get_logo_flag(0) == 1)
{
    anim_show_logo(KEL_LOGO_OTHER_INDEX); 
}
#else
    anim_show_logo(kernel_logo_position); 
#endif

2. 修改mediatek/external/libshowlogo/Android.mk,保证函数的调用时,可以正确编译链接,修改如下:

LOCAL_SHARED_LIBRARIES += libnvram
LOCAL_C_INCLUDES += $(MTK_PATH_CUSTOM)/cgen/inc
LOCAL_C_INCLUDES += $(MTK_PATH_SOURCE)/external/nvram/libnvram

五、android双logo切换:

1. 按照第四条的说明1,2修改增加函数及Android.mk,获取pro_info的值,具体文件如下:

frameworks/base/cmds/bootanimation/Android.mk
frameworks/base/cmds/bootanimation/BootAnimation.cpp

2. 修改void BootAnimation::getResourceFile(int index, void * path) ,在如下判断中增加条件:

#ifdef MTK_DOUBLE_LOGO_SUPPORT					
    if ((access(pathAddr, R_OK) == 0) && (mZip.open(pathAddr)
            == NO_ERROR)&& (get_logo_flag(0) == 1)) 
#else
    if ((access(pathAddr, R_OK) == 0) && (mZip.open(pathAddr)
            == NO_ERROR)) 
#endif

3. 修改bootanimation server 的用户和用户组,mediatek/config/mt6582/init.rc。

service bootanim /system/bin/bootanimation
class main
#user graphics
user root
#group graphics media
group root graphics media
disabled
oneshot

六、修改拨号盘,增加切换动作:

1. 拷贝mediatek/packages/apps/NvRAM/NvRAMAgent.java到packages/apps/Dialer/src/com/android/dialer/

2. 修改packages/apps/Dialer/src/com/android/dialer/dialpad/DigitsEditText.java,增加对于判断的切换:

2.1 增加如下package

import com.android.dialer.NvRAMAgent;
import android.os.ServiceManager;
import android.os.IBinder;
import com.mediatek.common.featureoption.FeatureOption;

2.2 增加函数:

public void writeData(int n) {
    IBinder binder = ServiceManager.getService("NvRAMAgent");
    NvRAMAgent agent = NvRAMAgent.Stub.asInterface(binder);		
    byte[] by = getBytes(n);		
    for(int i=104;i<107;i++){ buff[i] = by[i-104]; try { int flag = agent.writeFile(file_lid, buff); if (flag > 0) {
                //System.out.println("write success");
            } else {
                //System.out.println("write failed");
            }
       } catch (Exception e) {
                    e.printStackTrace();
       }
    }
}

public int  readData() {
    IBinder binder = ServiceManager.getService("NvRAMAgent");
    NvRAMAgent agent = NvRAMAgent.Stub.asInterface(binder);
    
    try {
        buff = agent.readFile(file_lid);// read buffer from nvram
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }			
        int b = (int)buff[104];
        //System.out.println("b:"+b);
    return b;		
}

3. 增加界面显示及切换调用:

@Override
protected void onTextChanged(CharSequence text, int start, int before,
        int after) {
    if(FeatureOption.MTK_DOUBLE_LOGO_SUPPORT){
        if (text.toString().equals("*#*#556#*#*")) {   
                    
            if(readData() == 1)
            {
                writeData(0);
                Toast.makeText(getContext(), "Reset Logo", Toast.LENGTH_SHORT).show();
                
            }
            else 			
            {
                writeData(1);
                Toast.makeText(getContext(), "Update Logo", Toast.LENGTH_SHORT).show();
            }
            //this.setText(""); 	
        } 		
    }
    super.onTextChanged(text, start, before, after);
}

七、修改文件列表

# modified: frameworks/base/cmds/bootanimation/Android.mk
# modified: frameworks/base/cmds/bootanimation/BootAnimation.cpp
# modified: frameworks/base/data/sounds/OriginalAudio.mk
# modified: mediatek/build/tools/javaoption.pm
# modified: mediatek/config/mt6582/init.rc
# modified: mediatek/config/m874v3/ProjectConfig.mk
# modified: mediatek/custom/common/lk/include/target/cust_display.h
# modified: mediatek/custom/common/lk/logo/rules.mk
# modified: mediatek/custom/m874v3/cgen/cfgdefault/CFG_PRODUCT_INFO_Default.h
# modified: mediatek/custom/m874v3/cgen/cfgfileinc/CFG_PRODUCT_INFO_File.h
# modified: mediatek/external/libshowlogo/Android.mk
# modified: mediatek/external/libshowlogo/charging_animation.cpp
# modified: mediatek/external/libshowlogo/show_animation_common.h
# modified: mediatek/platform/mt6582/lk/load_image.c
# modified: mediatek/platform/mt6582/lk/mt_logo.c
# modified: packages/apps/Dialer/src/com/android/dialer/dialpad/DigitsEditText.java

增加的文件:

packages/apps/Dialer/src/com/android/dialer/NvRAMAgent.java

版权所有丨如未注明,均为原创,转载请注明转自:https://whonee.net/mtk-nvram-coding-instruction-for-double-logo-change.html

1 thought on “MTK 平台 NVRAM 分区修改及应用解析--双logo切换”

发表评论

电子邮件地址不会被公开。 必填项已用*标注