Beispiel #1
0
/*
* Function   : sc_icc_task
* Discription: c core nv init,this phase build upon the a core kernel init,
*              this phase after icc init,this phase ensure to use all nv api normal
*              start at this phase ,ops global ddr need spinlock
* Parameter  : none
* Output     : result
* History    : 
*/
void sc_icc_task(void)
{
    s32 read_len    = 0;
    s32 sc_fp       = 0;
    s8* sc_path     = (s8*)SC_PACKET_TRANS_FILE;
    sc_icc_stru     icc_recv = {MISC_SC_OPT_BUTT};

    /* coverity[no_escape] */
    /* coverity[loop_top] */
    for(;;)
    {
        osl_sem_down(&g_sc_stat.sc_tsk_sem);

        sc_debug_printf("get sem ok!\n");
        
        read_len = bsp_icc_read(SC_ICC_CHAN_ID, (u8*)&icc_recv, sizeof(sc_icc_stru));
        if(read_len > (s32)sizeof(sc_icc_stru))
        {
            osl_sem_up(&g_sc_stat.sc_tsk_sem);
            sc_error_printf("bsp icc read error, chanid :0x%x ret :0x%x\n",SC_ICC_CHAN_ID,read_len);
            continue;
        }
        else if(0 >= read_len)
        {
            sc_error_printf("bsp icc read error, length is 0x%x!\n", read_len);
            continue ;
        }

        if( MISC_SC_OPT_READ == icc_recv.sc_opt_type)
        {
            if(SC_OK == icc_recv.sc_cnf_ret)
            {
                sc_fp = bsp_open(sc_path, (RFILE_RDONLY), 0660); /* [false alarm]: fortify 误报*/
                if(sc_fp < 0)
                {
                    sc_error_printf("open file %s failed!\n",sc_path);
                    g_sc_stat.sc_opt_ret = BSP_ERR_SC_NO_FILE;
                    osl_sem_up(&g_sc_stat.sc_api_sem);
                    continue ;
                }
                
                read_len = bsp_read((u32)sc_fp, (s8 *)(g_sc_stat.sc_ram_addr), g_sc_stat.sc_ram_len); /* [false alarm]: fortify 误报*/
                if(read_len != (s32)(g_sc_stat.sc_ram_len))
                {
                    sc_error_printf("read %s fail, read len is 0x%x, given len is 0x%x!\n",sc_path,read_len,g_sc_stat.sc_ram_len);
                    bsp_close((u32)sc_fp);
                    g_sc_stat.sc_opt_ret = BSP_ERR_SC_READ_FILE_FAIL;
                    osl_sem_up(&g_sc_stat.sc_api_sem);
                    continue ;
                }
                bsp_close((u32)sc_fp);
            }
        }

        sc_debug_printf("send to api interface\n");
        
        g_sc_stat.sc_opt_ret = icc_recv.sc_cnf_ret;
        osl_sem_up(&g_sc_stat.sc_api_sem);
    }
}
void socp_debug_CountStore(char* p,int len)
{
    /* [false alarm]:alarm */
    char path[128];
    /* [false alarm]:alarm */
    int fd = -1;
    /* [false alarm]:alarm */
    int ret;


    Socp_Memset(path,0,sizeof(path));

#if defined(__OS_RTOSCK__)
    (void)sprintf_s(path,128,"%s%s%d.bin",SOCP_ROOT_PATH,p,bsp_get_slice_value());
#else
    snprintf(path,128,"%s%s%d.bin",SOCP_ROOT_PATH,p,bsp_get_slice_value());
#endif
    /* [false alarm]:alarm */
    fd = bsp_open((s8*)path, RFILE_RDWR|RFILE_CREAT, 0660);
    /* [false alarm]:alarm */
    if(fd<0){
        socp_printf("create %s error,save failed!\n",path);
        return;
    }
    /* [false alarm]:alarm */
    ret = bsp_write((u32)fd,(s8*)&g_stSocpDebugInfo,sizeof(g_stSocpDebugInfo));
    /* [false alarm]:alarm */
    if(ret != (int)sizeof(g_stSocpDebugInfo)){
        socp_printf("write %s error,save failed!\n",path);
        (void)bsp_close((u32)fd);
        return;
    }
    (void)bsp_close((u32)fd);
    return;
}
/*
* Function   : sc_bakup
* Discription: c core nv init,this phase build upon the a core kernel init,
*              this phase after icc init,this phase ensure to use all nv api normal
*              start at this phase ,ops global ddr need spinlock
* Parameter  : none
* Output     : result
* History    : 
*/
s32  sc_bakup(s8 *pdata, u32 len)
{
    s32 sc_fp       = 0;
    s32 wlen        = 0;
    u32 sc_mtd_len  = 0;
    struct mtd_info* mtd;
    
    sc_fp = bsp_open((char *)SC_PACKET_TRANS_FILE,(RFILE_RDONLY),0660);
    if(!sc_fp)
    {   
        sc_error_printf("bsp_open error, chanid :0x%x sc_fp :0x%x\n",SC_ICC_CHAN_ID,sc_fp);
        return BSP_ERR_SC_NO_FILE;
    }
    else
    {
        sc_debug_printf("bsp_open ok, file is 0x%x!\n",sc_fp);
    }

    wlen = bsp_read(sc_fp, pdata, len);
    if(wlen != len)
    {
        sc_error_printf("bsp_read error, opt_len :0x%x sc_ram_len :0x%x\n", wlen, len);
        bsp_close(sc_fp);
        return BSP_ERR_SC_READ_FILE_FAIL;
    }
    else
    {
        sc_debug_printf("bsp_read ok, len is 0x%x!\n",(u32)(wlen));
    }
    
    bsp_close(sc_fp);
    
    mtd = get_mtd_device_nm((char*)SC_BACKUP_SEC_NAME);
    if (IS_ERR(mtd))
    {
        sc_error_printf("get mtd device err! %s\n",mtd);
        return BSP_ERR_READ_MTD_FAIL;
    }
    sc_mtd_len = mtd->size;
    sc_debug_printf("mtd len: 0x%x\n",sc_mtd_len);
    put_mtd_device(mtd);
    
    if((sc_mtd_len < SC_MTD_PTABLE_OFFSET) || (len >= SC_MTD_PTABLE_OFFSET))
    {
        sc_error_printf("mtd length err! sc_mtd_len: 0x%x, len: 0x%x\n",sc_mtd_len, len);
        return BSP_ERR_READ_LGTH_FAIL;
    }

    wlen = bsp_nand_write((char*)SC_BACKUP_SEC_NAME, (sc_mtd_len - SC_MTD_PTABLE_OFFSET), pdata, len);
    if(wlen != BSP_OK)
    {
        sc_error_printf("mtd length err! wlen 0x%x, len is 0x%x\n",wlen,len);
        return BSP_ERR_SC_WRITE_FILE_FAIL;
    }
    
    sc_debug_printf("sc write to nand ok, len is 0x%x!\n",(u32)(wlen));
    
    return SC_OK;
}
Beispiel #4
0
void rfile_test_003(void)
{
    s32 ret;

    ret = bsp_close(pfile);
    if(BSP_OK != ret)
    {
        bsp_trace(BSP_LOG_LEVEL_DEBUG, BSP_MODU_RFILE, "%d.\n", __LINE__);

        return ;
    }
}
void socp_debug_RegStore(void)
{
    /* [false alarm]:alarm */
    char path[128];
    /* [false alarm]:alarm */
    char p[] = "Reg_";
    /* [false alarm]:alarm */
    int fd = -1;
    /* [false alarm]:alarm */
    int ret;


    Socp_Memset(path,0,sizeof(path));

#if defined(__OS_RTOSCK__)
    (void)sprintf_s(path,128,"%s%s%d.bin",SOCP_ROOT_PATH,p,bsp_get_slice_value());
#else
    snprintf(path,128,"%s%s%d.bin",SOCP_ROOT_PATH,p,bsp_get_slice_value());
#endif
    /* [false alarm]:alarm */
    fd = bsp_open((s8*)path, RFILE_RDWR|RFILE_CREAT, 0660);
    /* [false alarm]:alarm */
    if(fd<0){
        socp_printf("create %s error,save failed!\n",path);
        return;
    }
    /* [false alarm]:alarm */
    ret = bsp_write((u32)fd,(s8*)g_strSocpStat.baseAddr,4096);
    /* [false alarm]:alarm */
    if(ret != (int)4096){
        socp_printf("write %s error | 0x%x,save failed!\n",path,ret);
        (void)bsp_close((u32)fd);
        return;
    }
    (void)bsp_close((u32)fd);
    return;
}
/*************************************************************************
 函 数 名   : rfile_test_001
 功能描述   : 新建目录-->新建文件-->写入内容-->读取内容-->关闭文件-->获取文件状态
*************************************************************************/
s32 rfile_test_001(void)
{
    s32 ret;
    s8 *dirpar = "/rfiletest001";
    s8 *filepath = "/rfiletest001/rfile001.txt";
    s8 *wrbuf = "1234567890abcdefghijklmnopqrstuvwxyz";
    s8 *rfilewrtmp = NULL;
    s8 *rfilerdtmp = NULL;
    s8 rdbuf[64] = {0};
    s32 pfile;
    struct rfile_stat_stru buf = {0};

    rfile_print_info("[%s] start =======================================.\n\n", __FUNCTION__);
    rfile_print_info("test for : mkdir-->fopen-->fseek-->fwrite-->fwrite-->");
    rfile_print_info("ftell-->fseek-->ftell-->fread-->fread-->fclose-->stat.\n\n");

    rfilewrtmp = Rfile_Malloc(8888);
    memset(rfilewrtmp, 'x', 8888);

    rfilerdtmp = Rfile_Malloc(8888);
    memset(rfilerdtmp, 0, 8888);

    ret = bsp_mkdir(dirpar, 0660);
    if(BSP_OK != ret)
    {
        rfile_print_info("!!!!!!!! BSP_mkdir failed.\n");

        goto rfile_test_001_fail_1;
    }

    pfile = bsp_open(filepath, (RFILE_CREAT|RFILE_RDWR), 0755);
    if(pfile < 0)
    {
        rfile_print_info("!!!!!!!! bsp_open failed.\n");

        goto rfile_test_001_fail_1;
    }

    ret = bsp_lseek(pfile, 0, SEEK_SET);
    if(BSP_OK != ret)
    {
        rfile_print_info("!!!!!!!! BSP_fseek 1 failed .\n");

        goto rfile_test_001_fail_2;
    }

    ret = bsp_write(pfile, wrbuf, strlen(wrbuf));
    if(ret <= 0)
    {
        rfile_print_info("!!!!!!!! BSP_fwrite 1 failed .\n");

        goto rfile_test_001_fail_2;
    }

    ret = bsp_write(pfile, rfilewrtmp, 8888);
    if(ret <= 0)
    {
        rfile_print_info("!!!!!!!! BSP_fwrite 2 failed .\n");

        goto rfile_test_001_fail_2;
    }

    rfile_print_info("BSP_fwrite %d bytes.\n", ret);

    for(ret = 0; ret < 28; ret++)
    {
        rfile_print_info("-0x%x-", rfilewrtmp[ret]);
    }

    rfile_print_info(".\n");

    for(ret = 8880; ret < 8888; ret++)
    {
        rfile_print_info("-0x%x-", rfilewrtmp[ret]);
    }

    rfile_print_info(".\n");

    ret = bsp_tell(pfile);
    if(ret < 0)
    {
        rfile_print_info("!!!!!!!! BSP_ftell 1 failed 0x%x.\n", ret);
    }
    else
    {
        rfile_print_info("!!!!!!!! BSP_ftell 1 success 0x%x .\n", ret);
    }

    ret = bsp_lseek(pfile, 0, SEEK_SET);
    if(BSP_OK != ret)
    {
        rfile_print_info("!!!!!!!! BSP_fseek 2 failed .\n");
    }

    ret = bsp_tell(pfile);
    if(ret < 0)
    {
        rfile_print_info("!!!!!!!! BSP_ftell 2 failed 0x%x.\n", ret);
    }
    else
    {
        rfile_print_info("!!!!!!!! BSP_ftell 2 success 0x%x .\n", ret);
    }

    ret = bsp_read(pfile, rdbuf, 64);
    if(ret <= 0)
    {
        rfile_print_info("!!!!!!!! BSP_fread 1 failed .\n");

        goto rfile_test_001_fail_2;
    }

    ret = bsp_read(pfile, rfilerdtmp, 8888);
    if(ret <= 0)
    {
        rfile_print_info("!!!!!!!! BSP_fread 2 failed .\n");

        goto rfile_test_001_fail_2;
    }

    rfile_print_info("BSP_fread %d bytes.\n", ret);

    for(ret = 0; ret < 28; ret++)
    {
        rfile_print_info(" 0x%x ", rfilerdtmp[ret]);
    }

    rfile_print_info(".\n");

    for(ret = 8880; ret < 8888; ret++)
    {
        rfile_print_info(" 0x%x ", rfilerdtmp[ret]);
    }

    rfile_print_info(".\n");

    ret = bsp_close(pfile);
    if(BSP_OK != ret)
    {
        rfile_print_info("!!!!!!!! bsp_close failed.\n");

        goto rfile_test_001_fail_1;
    }

    ret = bsp_stat(filepath, &buf);
    if(BSP_OK != ret)
    {
        rfile_print_info("!!!!!!!! BSP_stat failed.\n");

        goto rfile_test_001_fail_1;
    }
    else
    {
        rfile_print_info("BSP_stat : buf.mtime.tv_sec %d, buf.mtime.tv_nsec %d, buf.blksize %d\n",
            (int)buf.mtime.tv_sec, (int)buf.mtime.tv_nsec, (int)buf.blksize);
    }

    rfile_print_info("[%s] success.\n", __FUNCTION__);

    rfile_print_info("[%s] end =======================================.\n", __FUNCTION__);

    return 0;

rfile_test_001_fail_2:
    bsp_close(pfile);

rfile_test_001_fail_1:

    rfile_print_info("[%s] end =======================================.\n", __FUNCTION__);

    return -1;
}
/*
* Function   : sc_restore
* Discription: c core nv init,this phase build upon the a core kernel init,
*              this phase after icc init,this phase ensure to use all nv api normal
*              start at this phase ,ops global ddr need spinlock
* Parameter  : none
* Output     : result
* History    : 
*/
s32  sc_restore(s8 *pdata, u32 len)
{
    s32 sc_fp       = 0;
    s32 rlen        = 0;
    s32 wlen        = 0;
    u32 sc_mtd_len  = 0;
    struct mtd_info* mtd;

    mtd = get_mtd_device_nm((char*)SC_BACKUP_SEC_NAME);
    if (IS_ERR(mtd))
    {
        sc_error_printf("get mtd device err! %s\n",mtd);
        return BSP_ERR_READ_MTD_FAIL;
    }
    sc_mtd_len = mtd->size;
    put_mtd_device(mtd);
    
    if((sc_mtd_len < SC_MTD_PTABLE_OFFSET) || (len >= SC_MTD_PTABLE_OFFSET))
    {
        sc_error_printf("mtd length err! size 0x%x\n",mtd->size);
        return BSP_ERR_READ_LGTH_FAIL;
    }

    rlen = bsp_nand_read((char*)SC_BACKUP_SEC_NAME, (sc_mtd_len - SC_MTD_PTABLE_OFFSET), pdata, len, NULL);
    if(rlen != BSP_OK)
    {
        sc_error_printf("mtd length err! read_ret 0x%x, len is 0x%x\n",rlen,len);
        return BSP_ERR_SC_READ_FILE_FAIL;
    }
    else
    {
        sc_debug_printf("mtd length read ok len is 0x%x\n",rlen);
    }

    /* write to file */
    sc_fp = bsp_open((char*)SC_PACKET_TRANS_FILE,(RFILE_CREAT|RFILE_RDWR),0660);
    if(!sc_fp)
    {   
        sc_error_printf("bsp_open error, chanid :0x%x sc_fp :0x%x\n",SC_ICC_CHAN_ID,sc_fp);
        return BSP_ERR_SC_NO_FILE;
    }
    else
    {
        sc_debug_printf("bsp_open ok, file is 0x%x!\n",sc_fp);
    }

    /* write to file */
    wlen = bsp_write(sc_fp, pdata, len);
    if(wlen != len)
    {
        sc_error_printf("bsp_write error, chanid :0x%x wlen :0x%x, len : 0x%x\n",SC_ICC_CHAN_ID,wlen,len);
        bsp_close(sc_fp);
        return BSP_ERR_SC_WRITE_FILE_FAIL;
    }
    else
    {
        sc_debug_printf("bsp_write ok,wlen is 0x%x",wlen);
    }

    bsp_close(sc_fp);

    return SC_OK;
}
Beispiel #8
0
s32 ltcov_hutaf_save_ccore_data(void)
{	
	s32 fp;	       /* stream to read from*/
	u32 len = 0;
	s8* p_buffer = NULL;
	s8* filepath = "/data/ltcov_ccore.bin";
    s32 ret = 0;
	
    /* 判断文件是否存在,如果存在则删除 */
    ret = bsp_access(filepath, 0);
    if(BSP_OK == ret)
    {
        bsp_remove(filepath);
    }

	fp = bsp_open(filepath, (RFILE_CREAT|RFILE_RDWR), 0755);
	if (fp < 0)
	{
		printf("ltcov_hutaf_save_ccore_data:open file ERROR!\n");
		return -1;
	}
	
	/* len以字节为单位 */
	len = HLLT_Agent_GetCovDataSize();
	if (0 == len)
	{
		printf("ltcov_hutaf_save_ccore_data:HLLT_Agent_GetCovDataSize ERROR!\n");
        fclose(fp);
		return -1;
	}
	
	p_buffer = malloc(len);
	if(NULL == p_buffer)
    {
        printf("ltcov_hutaf_save_ccore_data:malloc failed\n");
        fclose(fp);
		return -1;
    }

	/* 将覆盖率数据写到Buffer中 */
	if(1 != HLLT_Coverage_GetCoverageData(p_buffer, len))
	{
		printf("ltcov_hutaf_save_ccore_data:HLLT_Coverage_GetCoverageData failed\n");
	    free(p_buffer);
        fclose(fp);
		return -1;
	}

    /*ret = bsp_lseek(fp, 0, SEEK_SET);
    if(BSP_OK != ret)
    {
        printf("!!!!!!!! bsp_fseek 1 failed .\n");

        return;
    }*/

	/* 写文件 */
    ret = bsp_write(fp, p_buffer, len);
    if(len != ret)
    {
        printf("ltcov_hutaf_save_ccore_data:bsp_write 1 failed.\n");

        return -1;
    }
    bsp_close(fp);
	fp = NULL;
	
	free(p_buffer);

	printf("ltcov_hutaf_save_ccore_data: success\n"); 
	return 0;
}
Beispiel #9
0
/*
* Function   : sc_opt_comm
* Discription: c core nv init,this phase build upon the a core kernel init,
*              this phase after icc init,this phase ensure to use all nv api normal
*              start at this phase ,ops global ddr need spinlock
* Parameter  : none
* Output     : result
* History    : 
*/
s32 sc_opt_comm(MISC_SC_OPT_ENUM sc_enum, u8* pRamAddr, u32 len)
{
    s32 write_len   = 0;
    s32 sc_fp       = 0;
    s8* sc_path     = (s8*)SC_PACKET_TRANS_FILE;
    sc_icc_stru     sc_send_msg = {MISC_SC_OPT_BUTT};
    
    /* judge para */
    if(sc_enum >= MISC_SC_OPT_BUTT)
    {
        sc_error_printf("para wrong, sc_enum is %d!\n",sc_enum); /* [false alarm]: fortify 误报*/
        return BSP_ERR_SC_INVALID_PARAM;
    }

    if((NULL == pRamAddr)||( len >= SC_MTD_PTABLE_OFFSET))
    {
        sc_error_printf("para wrong, addr is 0x%x, len is 0x%x!\n",(unsigned long)pRamAddr,len);
        return BSP_ERR_SC_INVALID_PARAM;
    }
    
    g_sc_stat.sc_ram_addr   = pRamAddr;
    g_sc_stat.sc_ram_len    = len;
    g_sc_stat.sc_opt_type   = sc_enum;

    if(bsp_access(sc_path,0))
    {
        bsp_remove(sc_path);
    }

    if(MISC_SC_OPT_WRITE == sc_enum)
    {
        sc_fp = bsp_open(sc_path, (RFILE_CREAT|RFILE_RDWR), 0660); /* [false alarm]: fortify 误报*/
        if(sc_fp < 0)
        {
            sc_error_printf("open file %s failed!\n",sc_path);
            return BSP_ERR_SC_NO_FILE;
        }
        
        write_len = bsp_write((u32)sc_fp, (const s8*)pRamAddr, len); /* [false alarm]: fortify 误报*/
        if(write_len != (s32)len)
        {
            sc_error_printf("write %s fail, write len is 0x%x, given len is 0x%x!\n",sc_path,write_len,len);
            bsp_close((u32)sc_fp);
            return BSP_ERR_SC_WRITE_FILE_FAIL;
        }
        
        bsp_close((u32)sc_fp);
    }

    /* send handshake packet */
    sc_send_msg.sc_opt_type     = sc_enum;
    sc_send_msg.sc_total_len    = len;
    write_len = bsp_icc_send(ICC_CPU_APP, SC_ICC_CHAN_ID, (u8*)&sc_send_msg, sizeof(sc_icc_stru));
    if((u32)write_len != sizeof(sc_icc_stru))
    {
        sc_error_printf("send to app filed, write_len is 0x%x!\n",write_len);
        return BSP_ERR_SC_ICC_SEND;
    }
    else
    {
        sc_debug_printf("send to app ok!\n");
    }
    
    /* wait recv sem */
    if(osl_sem_downtimeout(&g_sc_stat.sc_api_sem, 1000))
    {
        sc_error_printf("get result from acore timeout failed!\n");
        return BSP_ERR_SC_SEM_TIMEOUT;
    }
    else
    {
        if((g_sc_stat.sc_opt_type != sc_enum)||(SC_OK != g_sc_stat.sc_opt_ret) )
        {
            sc_error_printf("recv wrong result,sc_icc_type is %d, sc_ret is %d!\n",g_sc_stat.sc_opt_type,g_sc_stat.sc_opt_ret);
            return BSP_ERR_SC_CNF_ABNORMAL;
        }
    }

    if(bsp_access(sc_path, 0))
    {
        bsp_remove(sc_path);
    }

    sc_debug_printf("api opterate %d success !\n",g_sc_stat.sc_opt_type);
    
    return SC_OK;
}