Example #1
0
/**************************************************************************
 *  READ SECRO
 **************************************************************************/
uint32 sec_fs_read_secroimg (char* path, char* buf)
{
    uint32 ret  = SEC_OK;    
    const uint32 size = sizeof(AND_SECROIMG_T);
    uint32 temp = 0;    
    ASF_FILE fd;

    /* ------------------------ */    
    /* check parameter          */
    /* ------------------------ */
    SMSG(TRUE,"[%s] open '%s'\n",MOD,path);
    if(0 == size)
    {
        ret = ERR_FS_SECRO_READ_SIZE_CANNOT_BE_ZERO;
        goto _end;
    }

    /* ------------------------ */    
    /* open secro               */
    /* ------------------------ */    
    fd = ASF_OPEN(path);
    
    if (ASF_IS_ERR(fd)) 
    {
        ret = ERR_FS_SECRO_OPEN_FAIL;
        goto _open_fail;
    }

    /* ------------------------ */
    /* read secro               */
    /* ------------------------ */    
    /* configure file system type */
    osal_set_kernel_fs();
    
    /* adjust read off */
    ASF_SEEK_SET(fd,0);     
    
    /* read secro content */   
    if(0 >= (temp = ASF_READ(fd,buf,size)))
    {
        ret = ERR_FS_SECRO_READ_FAIL;
        goto _end;
    }

    if(size != temp)
    {
        SMSG(TRUE,"[%s] size '0x%x', read '0x%x'\n",MOD,size,temp);
        ret = ERR_FS_SECRO_READ_WRONG_SIZE;
        goto _end;
    }

    /* ------------------------ */       
    /* check integrity          */
    /* ------------------------ */
    if(SEC_OK != (ret = sec_secro_check()))
    {        
        goto _end;
    }

    /* ------------------------ */       
    /* SECROIMG is valid        */
    /* ------------------------ */
    bSecroExist = TRUE;    

_end:    
    ASF_CLOSE(fd);
    osal_restore_fs();
    
_open_fail:
    return ret;
}
Example #2
0
int sec_dev_read_secroimg(void) 
{    
    int ret  = SEC_OK;  
    
    uint32 search_offset = SECRO_SEARCH_START;
    uint32 search_len = SECRO_SEARCH_LEN;

    uint32 mtd_num;
    uint32 mtd_off = SECRO_SEARCH_START;
    
    const uint32 img_len = rom_info.m_sec_ro_length;
    const uint32 cipher_len = sizeof(AND_AC_ANDRO_T) + sizeof(AND_AC_MD_T)+ sizeof(AND_AC_MD2_T);

    /* ------------------------ */    
    /* check status             */    
    /* ------------------------ */    
    if(0 == secro_img_mtd_num)
    {
        ret = ERR_SECROIMG_PART_NOT_FOUND;
        goto _end;
    }

    mtd_num = secro_img_mtd_num;

    /* ------------------------ */    
    /* check parameter          */    
    /* ------------------------ */    
    if(0 == img_len)
    {
        ret = ERR_SECROIMG_INVALID_IMG_LEN;
        goto _end;
    }    

    if(img_len != sizeof(secroimg))
    {
        ret = ERR_SECROIMG_LEN_INCONSISTENT_WITH_PL;
        goto _end;
    }

    SMSG(TRUE,"[%s] SECRO image len '0x%x'\n",MOD, sizeof(secroimg));

    /* ------------------------ */    
    /* find ac region           */
    /* ------------------------ */    

    /* read 1MB nand flash data to search rom info */
    for(search_offset = SECRO_SEARCH_START; search_offset < (search_len + SECRO_SEARCH_START); search_offset += SECRO_SEARCH_REGION)
    {
        /* search partition */
        if(mtd_off < mtd_part_map[mtd_num].sz)
        {
            if(FALSE == dump_secro_info)
            {
                SMSG(TRUE,"dev %2d, 0x%08x, 0x%08x\n", mtd_num, mtd_off, search_offset);     
                dump_secro_info = TRUE;
            }

            /* ------------------------ */    
            /* search secro image       */
            /* ------------------------ */              
            ret = read_info (mtd_num, mtd_off, SECRO_SEARCH_REGION, ROM_SEC_AC_REGION_ID, ROM_SEC_AC_REGION_ID_LEN, img_len, (uchar*)&secroimg);
            
            if(SEC_OK == ret)
            {
                SMSG(TRUE,"[%s] SECRO img is found (lock)\n",MOD);
                
                /* ------------------------ */       
                /* decrypt secro image      */
                /* ------------------------ */           
                osal_secro_lock();
                
                dump_buf((uchar*)&secroimg.m_andro,0x4);
                if(TRUE == sec_secro_ac())
                {
                    sp_hacc_dec((uchar*)&secroimg.m_andro, cipher_len, TRUE,HACC_USER1,TRUE);
                }
                dump_buf((uchar*)&secroimg.m_andro,0x4);    

                /* ------------------------ */       
                /* check integrity          */
                /* ------------------------ */
                if(SEC_OK != (ret = sec_secro_check()))
                {
                    osal_secro_unlock();
                    goto _end;
                }

                /* ------------------------ */       
                /* encrypt secro image      */
                /* ------------------------ */
                if(TRUE == sec_secro_ac())
                {                        
                    sp_hacc_enc((uchar*)&secroimg.m_andro, cipher_len, TRUE,FALSE,TRUE);
                }
                dump_buf((uchar*)&secroimg.m_andro,0x4);   

                /* ------------------------ */       
                /* SECROIMG is valid        */
                /* ------------------------ */                
                bSecroExist = TRUE;
                        
                osal_secro_unlock();
                
                goto _end;

            }
            
        }
    
        /* next should move to next partition ? */
        if(search_offset >= mtd_part_map[mtd_num+1].off)
        {
            mtd_num ++;
            mtd_off = 0;
            search_offset -= SECRO_SEARCH_REGION;
        }
        else
        {
            mtd_off += SECRO_SEARCH_REGION;            
        } 
    }

    ret = ERR_SECROIMG_MTD_NOT_FOUND;

_end:

    return ret;
}