sbl1功能模块 -- 重启与下载模式

来源:互联网 发布:空间站软件下载 编辑:程序博客网 时间:2024/06/07 08:57

1. 系统重启

1)重启

boot_hw_reset()

-> boot_pm_pon_ps_hold_cfg(0,PM_PON_RESET_CFG_WARM_RESET);             // 配置warm reset

-> HWIO_OUTF(MPM2_MPM_PS_HOLD, PSHOLD, 0x0);     // 拉低ps hold

 

2)关机

boot_hw_powerdown()

-> boot_pm_pon_ps_hold_cfg(0,PM_PON_RESET_CFG_NORMAL_SHUTDOWN);// 配置shutdown

-> HWIO_OUTF(MPM2_MPM_PS_HOLD, PSHOLD, 0x0);     // 拉低ps hold

 

3)获取开关机原因

// 获取开机原因 --0x808寄存器

pm_pon_get_pon_reason(unsignedpmic_device_index, pm_pon_pon_reason_type* reason)

 

// 获取关机原因 --0x80c寄存器

pm_pon_get_poff_reason(unsignedpmic_device_index, pm_pon_poff_reason_type* reason)

 

// 获取warm reset原因 --0x80a/0x80b寄存器

pm_pon_get_warm_reset_reason(0,pm_pon_warm_reset_reason_type* reason)

 

// 配置reset行为

pm_pon_reset_source_cfg(unsignedpmic_device_index,             // 0

pm_pon_reset_source_type  reset_source,        // reset source

                        uint32 s1_timer, // s1timer

uint32 s2_timer, // s2 timer

pm_pon_reset_cfg_type reset_cfg_type)             // reset type

 

// 配置ps hold reset行为 --操作0x85a寄存器

pm_pon_ps_hold_cfg(unsignedpmic_device_index, pm_pon_reset_cfg_type ps_hold_cfg)

2. 开机流程

1)长按power键开机

  开机时,需要长按power键1s以后才能开机,不足1s执行关机;如果音量下键和power键一起按下,则不做此要求,直接进入testmode。

 

pm_pwr_key_detected(void)

{

// 获取power-on reasonwarm reset reason

pm_pon_get_pon_reason(0, &pon_reason);

pm_pon_get_warm_reset_reason(0,&warm_reset_reason);

 

// // check pon reason is kpdpwr?

if((*(char*)&pon_reason == 0x80) &&(*(char*)&warm_reset_reason == 0))

{

    while(1){

      if(count>= 100)      // power key pressed 1s

        break;

 

err_flag = pm_spmi_lite_read_byte(0,PMIO_PON_INT_RT_STS_ADDR, &data, 0);

    if(data& 0x2)             // if vol_downpressed, exit to testmode

      break;

    if((data& 0x1) == 0)    // if power_key released, power down

      boot_hw_powerdown();

 

pm_clk_busy_wait(10000);         // wait 10ms

count++;

}

}

 

2)进入紧急下载模式

如果在插入USB线开机的同时,按下power键,则会进入紧急下载模式,窗口时间大概500ms;

 

// usb power on, thenpress power key to enter dload

if(pon_reason.usb_chg ==1 && pon_reason.kpdpwr == 0 \

     && pon_reason.hard_reset == 0&& *(char*)&warm_reset_reason == 0)

{

  for(i=0; i<50; i++)

  {

    pm_clk_busy_wait(10000); // 10ms each count

    pm_spmi_lite_read_byte(0,PMIO_PON_INT_RT_STS_ADDR, &keydata, 0);        //获取power键状态

    if(keydata & 0x1)

    {

      //Disable watchdog -- watchdog timer大概在16s,如果不关闭watchdog,系统在16s后会重启

      //err_flag |= pm_pon_wdog_enable(0,PM_OFF);

      boot_log_message("Enter 9008 emergencydownload\n");

      pm_pon_wdog_enable(0, PM_ON);

      boot_dload_transition_pbl_forced_dload();             // 重启并进入PBL紧急下载模式

    }

  }

}

 

3)修改power键的行为

使用下面的两个函数可以配置长按pwrkey或pwrkey+resin的行为,此处配置长按pwrkey 8s关机:

 

// PON KPDPWRconfiguration:  s1_timer=6720ms,S2_timer=100ms,  Warm Reset

// err_flag |=pm_pon_reset_source_cfg(0, PM_PON_RESET_SOURCE_KPDPWR, 6720, 2000,

PM_PON_RESET_CFG_WARM_RESET);

  err_flag |= pm_pon_reset_source_cfg(0,PM_PON_RESET_SOURCE_KPDPWR, 6720, 2000,

PM_PON_RESET_CFG_NORMAL_SHUTDOWN);

 

// PON RESIN_AND_KPDPWRconfiguration:  s1_timer=6720ms,S2_timer=100ms,  Hard Reset

  err_flag |= pm_pon_reset_source_cfg(0,PM_PON_RESET_SOURCE_RESIN_AND_KPDPWR, 6720,

2000,PM_PON_RESET_CFG_HARD_RESET);

 

4)增加led指示灯

在进入下载模式或ramdump时点亮led指示灯

 

--- a/core/boot/secboot3/src/boot_dload.c

+++b/core/boot/secboot3/src/boot_dload.c

@@ -66,6 +66,7 @@when       who     what, where, why

 #include "boot_shared_imem_cookie.h"

 #include"boot_extern_hsusb_interface.h"

 #include"boot_extern_pmic_interface.h"

+#include"boot_visual_indication.h"

 

 /*=============================================================================

 

@@ -331,6 +332,7 @@ voidboot_dload_check

             UEFI_CRASH_DUMP_MAGIC_NUM ) )

     {

       /* Enter downloader for QPST */ 

+      boot_enable_led(TRUE);

       sbl_dload_entry();

     }

   }

 

3. 下载模式

1)PBL紧急下载模式

  高通平台紧急下载是在PBL中实现的,在紧急下载模式可以使用Firehouse或QPST等工具download image文件。高通原始代码通过boot_check_for_pbl_dload()函数检测USB D+线是否接地,如果是则在share memory指定地址写入魔数,并重启进入紧急下载模式。

 

boot_check_for_pbl_dload()

-> boot_dload_transition_pbl_forced_dload()

-> pbl_dload_id_ptr->magic_1 =FORCE_DLOAD_HS_USB_MAGIC_NUM_1;

  -> pbl_dload_id_ptr->magic_2 =FORCE_DLOAD_HS_USB_MAGIC_NUM_2;

  -> pbl_dload_id_ptr->magic_3 = FORCE_DLOAD_HS_USB_MAGIC_NUM_3;

  -> boot_hw_warm_reset();    // warm reset

 

2)普通下载模式

  普通下载模式可以使用QPST工具download image文件。高通原始代码使用boot_dload_check()函数检测是否进入普通下载模式。另外在普通下载模式还可以dump ram信息;

boot_dload_check()

-> boot_dload_entry()               // 检测magic number

-> boot_enable_led(TRUE)              // 显示指示灯

-> sbl_dload_entry()                 // 进入dload模式,sbl_dload_entry =sbl1_dload_entry

 

 

sbl1_dload_entry()

->boot_do_procedures(&bl_shared_data, sbl1_pre_dload_procs );

-> boot_ram_dump_to_raw_parition()        // ramdump to raw partition

-> boot_ram_dumps_to_sd_card()             // ramdump to sd card

->boot_dload_transition_enter_sahara()        // 进入sahara dload mode

3 0