Example #1
0
void sc_test_read(u32 read_cnt)
{
    u8* read_buf = NULL;
    u32 i;

    if(read_cnt>0)
    {
        read_buf = osl_malloc(read_cnt);
        if(NULL != read_buf)
        {
            memset(read_buf,0,read_cnt);
            /* write to file*/
            (void)bsp_sc_restore(read_buf, read_cnt);

            for(i=0;i<read_cnt;i++)
            {
                if(0x5A != read_buf[i])
                {
                    sc_error_printf("data is wrong, i is %d,data is 0x%x!\n",i,read_buf[i]);
                }
            }
            osl_free(read_buf);
        }
    }
}
Example #2
0
void*
osl_debug_malloc(osl_t *osh, uint size, int line, char* file)
{
	bcm_mem_link_t *p;
	char* basename;

	ASSERT(size);

	if ((p = (bcm_mem_link_t*)osl_malloc(osh, sizeof(bcm_mem_link_t) + size)) == NULL)
		return (NULL);

	p->size = size;
	p->line = line;

	basename = strrchr(file, '/');
	
	if (basename)
		basename++;

	if (!basename)
		basename = file;

	strncpy(p->file, basename, BCM_MEM_FILENAME_LEN);
	p->file[BCM_MEM_FILENAME_LEN - 1] = '\0';

	
	p->prev = NULL;
	p->next = osh->dbgmem_list;
	if (p->next)
		p->next->prev = p;
	osh->dbgmem_list = p;

	return p + 1;
}
/*****************************************************************************
* 函 数 名  : bsp_malloc
*
* 功能描述  : BSP 动态内存分配
*
* 输入参数  : u32Size: 分配的大小(byte)
*             enFlags: 内存属性(暂不使用,预留)
* 输出参数  : 无
* 返 回 值  : 分配出来的内存指针
*****************************************************************************/
void* bsp_malloc(u32 u32Size, MEM_POOL_TYPE enFlags)
{
    void *pItem;
    pItem = (void *)osl_malloc(u32Size);

    return (void*)pItem;
}
/* 子通道重新分配, 每个通道分配64个子通道, 0-31为实际使用子通道, 32-64为测试用子通道 */
static s32 icc_test_channel_reinit(u32 channel_idx, u32 new_sub_chn_size)
{
	struct icc_channel *channel = g_icc_ctrl.channels[channel_idx];
	struct icc_channel_vector *buf = NULL;
	
	/* 备份原通道的子通道 */
	g_icc_test.channels[channel_idx].vec_bak = channel->rector;
	g_icc_test.channels[channel_idx].func_size_bak = channel->func_size;

	/* 分配64个子通道 */
	buf = (struct icc_channel_vector *)osl_malloc(sizeof(struct icc_channel_vector) * new_sub_chn_size);
	if (!buf)
	{
		icc_print_error("malloc memory failed\n");
		return ICC_MALLOC_VECTOR_FAIL;
	}
	memset(buf, 0, sizeof(struct icc_channel_vector) * new_sub_chn_size); /*lint !e665 */

	/* 实际使用通道保留,实际子通道不超过32个 */
	memcpy(buf, channel->rector, sizeof(struct icc_channel_vector) * channel->func_size);/*lint !e516 */

	/* 实际通道+测试用通道 */
	channel->rector = buf;
	channel->func_size = new_sub_chn_size;
	channel->fifo_send->read = channel->fifo_send->write= 0;

	/* fifo长度减小,以便进行压力测试 */
	g_icc_test.channels[channel_idx].fifo_size_bak = channel->fifo_send->size;
	channel->fifo_recv->size = channel->fifo_send->size = ICC_TEST_FIFO_SIZE;

	return ICC_OK;
}
void modem_pinctrl_init(void)
{
    struct modem_pintrl_cfg *pin_source = SHM_MEM_MODEM_PINTRL_ADDR;
    u32 addr_temp = 0;
    u32 pin_num   = pin_source->pintrl_size[MODEM_PIN_INIT] + pin_source->pintrl_size[MODEM_PIN_NORMAL]\
                  + pin_source->pintrl_size[MODEM_PIN_POWERDOWN];

    u32 size      = sizeof(struct modem_pintrl_cfg) + pin_num * sizeof(struct pintrl_stru);
    g_pin_cfg = osl_malloc(size);
    if(NULL == g_pin_cfg){
        ios_print_error("modem pinctrl malloc fail!size:0x%x\n",SHM_MEM_MODEM_PINTRL_SIZE);
        g_pin_cfg = SHM_MEM_MODEM_PINTRL_ADDR;
        return ;
    }
    memcpy(g_pin_cfg,SHM_MEM_MODEM_PINTRL_ADDR,size);
    addr_temp = (u32)g_pin_cfg + sizeof(struct modem_pintrl_cfg);
    g_pin_cfg->pintrl_addr[MODEM_PIN_INIT].addr.low = addr_temp;
    addr_temp = addr_temp + (g_pin_cfg->pintrl_size[MODEM_PIN_INIT])*sizeof(struct pintrl_stru);
    g_pin_cfg->pintrl_addr[MODEM_PIN_NORMAL].addr.low = addr_temp;
    addr_temp = addr_temp + (g_pin_cfg->pintrl_size[MODEM_PIN_NORMAL])*sizeof(struct pintrl_stru);
    g_pin_cfg->pintrl_addr[MODEM_PIN_POWERDOWN].addr.low = addr_temp;
    if(size > SHM_MEM_MODEM_PINTRL_SIZE){
        ios_print_error("modem pinctrl memory expend 6k!\n");
    }
    ios_print_error("modem pinctrl init ok!\n");
}
s32  icc_debug_init(u32 channel_num)
{
	u32 i = 0;
	struct icc_channel_info * channel = NULL;
	struct icc_channel_stat_info *sub_channel = NULL;
	struct icc_channel *icc_channel = NULL;
	
	memset(&g_icc_dbg, 0, sizeof(struct icc_dbg));

	for(i = 0; i < channel_num; i++)
	{
		/* 使用g_icc_ctrl而不是g_icc_init_info,因为测试编进去以后,统计通道不需要再处理 */
		icc_channel = g_icc_ctrl.channels[g_icc_init_info[i].real_channel_id];
		channel = (struct icc_channel_info *)osl_malloc(sizeof(struct icc_channel_info));
		if (!channel)
		{
			icc_print_error("malloc icc_channel_info memory fail!\n");
			return (s32)ICC_ERR;
		}

		/* 收发子通道一同分配 */
		sub_channel = (struct icc_channel_stat_info *)osl_malloc(sizeof(struct icc_channel_stat_info) * icc_channel->func_size * 2);
		if (!sub_channel)
		{
			osl_free((void *)channel);
			icc_print_error("malloc icc_channel_stat_info memory fail!\n");
			return (s32)ICC_ERR;
		}

		/* channel init */
		memset((void *)channel, 0, sizeof(struct icc_channel_info));
		channel->id = icc_channel->id;
		channel->recv.func_size= icc_channel->func_size;
		channel->send.func_size= icc_channel->func_size;

		/* sub channel init */
		memset((void *)sub_channel, 0, sizeof(struct icc_channel_stat_info) * icc_channel->func_size * 2); /*lint !e665 */
		channel->send.sub_chn  = sub_channel;
		channel->recv.sub_chn  = &(sub_channel[icc_channel->func_size]);
		
		g_icc_dbg.channel_stat[channel->id] = channel;
	}

	icc_dump_init();

	return ICC_OK;
}
int BSP_ICC_Open(unsigned int u32ChanId, ICC_CHAN_ATTR_S *pChanAttr)
{
    u32 channel_id = 0;
    u32 channel_index = 0;
    struct bsp_icc_cb_info *pICC_cb_info;

    if (icc_channel_logic2phy(u32ChanId, &channel_id))
    {
        icc_print_error("icc_channel_logic2phy err logic id 0x%x\n", u32ChanId);
        goto out; /*lint !e801 */
    }

    channel_index = channel_id >> 16;
    if ((ICC_CHN_ID_MAX <= channel_index) || (!g_icc_ctrl.channels[channel_index]))
    {
        icc_print_error("invalid channel_index[%d]\n", channel_index);
        goto out; /*lint !e801 */
    }

    /* coverity[REVERSE_INULL] */
    if(!pChanAttr)
    {
        icc_print_error("pChanAttr is null!\n");
        goto out; /*lint !e801 */
    }
    else if(pChanAttr->u32FIFOOutSize != pChanAttr->u32FIFOInSize)
    {
        icc_print_error("invalid param u32ChanId[%d],pChanAttr[0x%p],fifo_in[0x%x],fifo_out[0x%x]\n",
            channel_index, pChanAttr, pChanAttr->u32FIFOInSize, pChanAttr->u32FIFOOutSize);
        goto out; /*lint !e801 */
    }

    if(pChanAttr->u32FIFOInSize > g_icc_ctrl.channels[channel_index]->fifo_send->size)/*lint !e574 */
    {
        icc_print_error("channel_id 0x%x user fifo_size(0x%x) > fifo_size(0x%x) defined in icc\n",
                        channel_id,
                        pChanAttr->u32FIFOInSize, g_icc_ctrl.channels[channel_index]->fifo_send->size);
        goto out; /*lint !e801 */
    }

    pICC_cb_info = osl_malloc(sizeof(struct bsp_icc_cb_info));
    if (pICC_cb_info == NULL) {
        icc_print_error("Fail to malloc memory \n");
        return ICC_MALLOC_MEM_FAIL;
    }

    pICC_cb_info->read_cb = pChanAttr->read_cb;
    pICC_cb_info->channel = u32ChanId;
    /* coverity[leaked_storage] */
    return (BSP_S32)bsp_icc_event_register(channel_id, icc_read_cb_wraper, pICC_cb_info, icc_write_cb_wraper, (void*)pChanAttr->write_cb);

out:
    return ICC_INVALID_PARA;
}
Example #8
0
void *
osl_mallocz(osl_t *osh, uint size)
{
	void *ptr;

	ptr = osl_malloc(osh, size);

	if (ptr != NULL) {
		bzero(ptr, size);
	}

	return ptr;
}
Example #9
0
/* test ex*/
void sc_test_write(u32 write_cnt)
{
    u8* write_buf = NULL;

    if(write_cnt>0)
    {
        write_buf = osl_malloc(write_cnt);
        if(NULL != write_buf)
        {
            memset(write_buf,0x5A,write_cnt);
            /* write to file*/
            (void)bsp_sc_backup(write_buf, write_cnt);

            osl_free(write_buf);
        }
    }
}
/* 子通道初始化 */
static s32 icc_test_sub_chn_init(u32 channel_idx, u32 test_sub_chn_size, u32 start)
{
	u32 i = 0;
	u8 *buf = NULL;
	read_cb_func read_cb = NULL;
	u32 sub_chn_idx = 0;
	struct icc_test_sub_channel *sub_channel = NULL;

	/* 读写buffer一起分配 */
	buf = (u8 *)osl_malloc(ICC_TEST_FIFO_SIZE * test_sub_chn_size * 2); /*lint !e516 */
	if(NULL == buf)
	{
		icc_print_error("buf=0x%x, \n", buf);
		return ICC_MALLOC_MEM_FAIL;
	}
	memset(buf, 0x00,  ICC_TEST_FIFO_SIZE * test_sub_chn_size * 2); /*lint !e665 */

	for(i = 0; i < test_sub_chn_size; i++)
	{
		/* 32-64为测试用子通道 */
		sub_chn_idx = i + start;
		sub_channel = &(g_icc_test.channels[channel_idx].sub_channels[sub_chn_idx]);
		sub_channel->wr_buf = buf + i * ICC_TEST_FIFO_SIZE;
		sub_channel->rd_buf = buf + i * (ICC_TEST_FIFO_SIZE + test_sub_chn_size);
#if defined(__KERNEL__) || defined(__VXWORKS__)
		osl_sem_init(ICC_SEM_EMPTY, &(sub_channel->confirm_sem)); /*lint !e40 */
#endif
		/* 子通道交替注册cb0和cb1 */
		read_cb = ((i & 0x01)? icc_send_test_001_cb1: icc_send_test_001_cb0);
		g_icc_ctrl.channels[channel_idx]->rector[sub_chn_idx].read_cb = read_cb;
		g_icc_ctrl.channels[channel_idx]->rector[sub_chn_idx].read_context = (void *)sub_chn_idx;

#ifdef ICC_HAS_DEBUG_FEATURE		
		icc_print_debug("i:0x%x, read_cb: 0x%x", i, read_cb);
		if(g_icc_dbg.msg_print_sw)
		{
			icc_channel_vector_dump(channel_idx,sub_chn_idx);
		}
#endif

	}

	return ICC_OK;
}
static char *pmic_alloc_copy(const char *src_str)
{
	unsigned int len;
	char         *dst_str = NULL;

	if (!src_str)
	{
		return NULL;
	}

	len = strlen(src_str) + 1;
	dst_str = osl_malloc(len);
	if (dst_str)
	{
		(void)memcpy_s(dst_str, len, src_str, len);
	}

	return dst_str;
}
int bsp_om_into_send_list(u32 buf_addr,u32 len)
{
    bsp_om_list_s  *ptemp = NULL;
    unsigned long int_lock_lvl = 0;

    ptemp = osl_malloc(sizeof(bsp_om_list_s));

    if(ptemp == NULL)
    {
        return -1;
    }

    ptemp->buf_addr = buf_addr;
    ptemp->buf_len = len;
    ptemp->pnext = NULL;

    local_irq_save(int_lock_lvl);
    if(g_send_list_head != NULL)
    {
        g_send_list_head->ptail->pnext  = ptemp;

        g_send_list_head->ptail =g_send_list_head->ptail->pnext;
    }
    else
    {
        g_send_list_head = ptemp;
        g_send_list_head->ptail = g_send_list_head;

    }

    g_list_debug.list_in++;

    local_irq_restore(int_lock_lvl);

    osl_sem_up(&send_task_sem);

    return BSP_OK;

}
Example #13
0
void *utlMem_alloc(UINT32 size, UINT32 allocFlags)
{
    void *buf;
    UINT32 allocSize;

#ifdef UTL_MEM_LEAK_TRACING
    initAllocSeq();
#endif

    allocSize = REAL_ALLOC_SIZE(size);

    buf = osl_malloc(allocSize);
    if (buf)
    {
        mStats.bytesAllocd += size;
        mStats.numAllocs++;
    }


    if (buf != NULL)
    {
        UINTPTR *intBuf = (UINTPTR *) buf;
#ifdef UTL_MEM_DEBUG
        UINT32 intSize = allocSize / sizeof(UINTPTR);
#endif


        if (allocFlags & ALLOC_ZEROIZE)
        {
            memset(buf, 0, allocSize);
        }
#ifdef UTL_MEM_POISON_ALLOC_FREE
        else
        {
            /*
             * Set alloc'ed buffer to garbage to catch use-before-init.
             * But we also allocate huge buffers for storing image downloads.
             * Don't bother writing garbage to those huge buffers.
             */
            if (allocSize < 64 * 1024)
            {
                memset(buf, UTL_MEM_ALLOC_PATTERN, allocSize);
            }
        }
#endif

        /*
         * Record the allocFlags in the first word, and the 
         * size of user buffer in the next 2 words of the buffer.
         * Make 2 copies of the size in case one of the copies gets corrupted by
         * an underflow.  Make one copy the XOR of the other so that there are
         * not so many 0's in size fields.
         */
        intBuf[0] = allocFlags;
        intBuf[1] = size;
        intBuf[2] = intBuf[1] ^ UTL_MEM_HEADER_MASK;

        buf = &(intBuf[3]); /* this gets returned to user */

#ifdef UTL_MEM_DEBUG
        {
            UINT8 *charBuf = (UINT8 *) buf;
            UINT32 i, roundupSize = ROUNDUP(size);

            for (i=size; i < roundupSize; i++)
            {
                charBuf[i] = UTL_MEM_FOOTER_PATTERN & 0xff;
            }

            intBuf[intSize - 1] = UTL_MEM_FOOTER_PATTERN;
            intBuf[intSize - 2] = UTL_MEM_FOOTER_PATTERN;
        }
#endif

#ifdef UTL_MEM_LEAK_TRACING
        {
            AllocRecord *allocRec;
            if (!(allocRec = calloc(1, sizeof(AllocRecord))))
            {
                utlLog_error("could not malloc a record to track alloc");
            }
            else
            {
                allocRec->bufAddr = buf;
                allocRec->userSize = size;
                allocRec->seq = allocSeq++;
                backtrace(allocRec->stackAddr, NUM_STACK_ENTRIES);
                /*
                 * new allocs are placed at the beginning of the list, right after
                 * the head.
                 */
                dlist_append((struct dlist_node *)allocRec, &glbAllocRec);
            }

            /*
             * do periodic garbage collection on the allocRecs which point
             * to shmBuf's that has been freed by another app.
             */
            if ((allocSeq % 2000) == 0)
            {
                utlLog_debug("Starting allocRec garbage collection");
                garbageCollectAllocRec();
                utlLog_debug("garbage collection done");
            }
        }
#endif
    }
    return buf;
}
Example #14
0
s32 startSecure(void)
{
	s32 sec_err_code = SEC_OK;
    u8  flag = 0;
	u8 * m3boot_ram_addr = NULL;
    u32 ulEfuseRootCaHash[SHA256_HASH_SIZE] = {0}; /*用来存放SHA256值的临时buffer*/
    u32 efuse_security_flag = 0;
	u32 md5_hash[MD5_HASH_SIZE] = {0};

    sec_err_code = secureAlreadyUse(&flag);
	if(sec_err_code)
	{
		return -1;
	}
    if( SECURE_ENABLE == flag )                    /* has been written */
    {
        return SEC_OK;
    }
	sec_err_code = secureSupport(&flag);
    if(SEC_OK != sec_err_code)
    {
		bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_SECURITY, "[SEC ERROR]check Secure support error!\n");
        return sec_err_code;
    }
    if(SECURE_NOT_SUPPORT == flag)
    {
		bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_SECURITY, "[SEC ERROR]Secure not support!\n");
        return SEC_ERROR_IMG_SECURY_NOT_SUPPORT;
    }

	m3boot_ram_addr = (u8*)osl_malloc(ROOT_CA_LEN);
	if(!m3boot_ram_addr)
	{
		bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_SECURITY, "[SEC ERROR]NO mem error!\n");
		return -1;
	}
	sec_err_code = BSP_mass_read("m3boot", /*P531_M3_LEN_INDEX + sizeof(u32)*/ROOT_CA_INDEX, ROOT_CA_LEN, m3boot_ram_addr);
    if(SEC_OK != sec_err_code)
    {
		bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_SECURITY, "BSP_mass_read error!\n");
        return sec_err_code;
    }

#if 0//for debug, print rootca
	printf("\n");
	for(i = 0; i < ROOT_CA_LEN / 4; i += 4)
	{
		printf("%X\n", *(unsigned long *)(m3boot_ram_addr + i));
	}
	printf("\n");
#endif

	/*计算ROOT CA HASH*/
	sec_err_code = kdf_sha256(m3boot_ram_addr, ROOT_CA_LEN, (u8*)ulEfuseRootCaHash);
    if(SEC_OK != sec_err_code)
    {
		bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_SECURITY, "\r\ncalc RootCa sha1 err!\n");
        return SEC_ERROR_SHA_ERR;
    }
	/*计算HASH值的MD5值*/
	sec_err_code = encrypt_lock_md5_data(ulEfuseRootCaHash, SHA256_HASH_SIZE * sizeof(u32), md5_hash);
	if(sec_err_code)
	{
		return -1;
	}

	sec_err_code = bsp_efuse_read(&efuse_security_flag, EFUSE_GRP_SECURITY, 1);
    if( SEC_OK != sec_err_code)
    {
    	bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_SECURITY, "startSecure: run efuse_read error!\n");
        return SEC_ERROR_EFUSE_READ_ERR;
    }
    efuse_security_flag |= EFUSEC_SEC_EN;

    /* write RootCA hash */
    if( SEC_OK != bsp_efuse_write( md5_hash, EFUSE_GRP_ROOT_CA, 4 ) )
    {
        return -1;
    }

    /* Last step, enable security boot */
    if( SEC_OK != bsp_efuse_write( (u32 *)&efuse_security_flag, EFUSE_GRP_SECURITY, 1 ) )
    {
        return -1;
    }

	bsp_trace(BSP_LOG_LEVEL_INFO, BSP_MODU_SECURITY, "\r\nstartSecure SUCC!\r\n", 0, 0, 0, 0, 0, 0 );
    return 0;
}
Example #15
0
u32 report_cpu_trace(void)
{
    u32 task_num = 0;
    BSP_CPU_TRACE_STRU  *p_cpu_trace_stru = NULL;
    BSP_TASK_CPU_TRACE_STRU *p_cpu_trace_data = NULL;
    u32          buf_len = 0;
    u32          task_slices = 0;


    buf_len = sizeof(BSP_CPU_TRACE_STRU) + sizeof(BSP_TASK_CPU_TRACE_STRU)*g_task_num;

    if(cpu_info_stru.report_swt == BSP_SYSVIEW_SWT_ON)
    {
        if(bsp_om_buf_sem_take())
        {
            return BSP_ERR_SYSVIEW_FAIL;
        }
        p_cpu_trace_stru = (BSP_CPU_TRACE_STRU *)bsp_om_get_buf(BSP_OM_SOCP_BUF_TYPE,buf_len);
         if(NULL == p_cpu_trace_stru)
        {
            bsp_om_buf_sem_give();
            return BSP_ERR_SYSVIEW_MALLOC_FAIL;
        }
    }
    else
    {
        p_cpu_trace_stru = (BSP_CPU_TRACE_STRU *)osl_malloc(buf_len);
         if(NULL == p_cpu_trace_stru)
        {
            return BSP_ERR_SYSVIEW_MALLOC_FAIL;
        }
    }

#ifdef ENABLE_BUILD_SYSVIEW
    sysview_trace_packet((u8*)p_cpu_trace_stru,buf_len,BSP_SYSVIEW_CPU_INFO);
#endif

    p_cpu_trace_data = p_cpu_trace_stru->cpu_info_stru;

    for(task_num =0;task_num < g_task_num; task_num++)
    {
        /*lint -save -e701*/
        p_cpu_trace_data[task_num].task_id =  PID_PPID_GET(kernel_tid_list[task_num]);
        /*lint -restore*/
        strncpy( (char *)(p_cpu_trace_data[task_num].task_name), (char *)(g_om_cpu_trace[task_num].task_name), BSP_SYSVIEW_TASK_NAME_LEN);
        p_cpu_trace_data[task_num].task_name[BSP_SYSVIEW_TASK_NAME_LEN-1] = '\0';
        task_slices =g_om_cpu_trace[task_num].slices - g_om_cpu_trace[task_num].cmdslice;
        p_cpu_trace_data[task_num].interval_slice = task_slices;

        /* for uart debug begin*/
        if(cpu_info_stru.report_swt == BSP_SYSVIEW_SWT_OFF)
        {
            if(task_slices != 0)
            {
                printk("taskid:0x%x,  %-11s,  rate = %u%% \n"
                                        ,p_cpu_trace_data[task_num].task_id,p_cpu_trace_data[task_num].task_name
                                        ,(u32)((task_slices *100)/g_cpu_task_taet));
            }
        }
        /* for uart debug end*/
    }

    if(cpu_info_stru.report_swt == BSP_SYSVIEW_SWT_ON)
    {
        if( BSP_OK != bsp_om_into_send_list((u32)p_cpu_trace_stru,buf_len))
        {
            bsp_om_free_buf((u32)p_cpu_trace_stru,buf_len );
            bsp_om_buf_sem_give();
            return BSP_ERR_SYSVIEW_FAIL;
        }

        bsp_om_buf_sem_give();
    }
    else
    {
        osl_free(p_cpu_trace_stru);
    }

    return BSP_OK;
}
/*
* 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 ret         = -1;
    s32 icc_len     = 0;
    sc_icc_stru icc_trans;

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

        sc_debug_printf("icc task, recv from acore ok, chanid :0x%x\n",SC_ICC_CHAN_ID);

        icc_len = bsp_icc_read(SC_ICC_CHAN_ID, (u8 * )&icc_trans, sizeof(sc_icc_stru));
        if((icc_len > sizeof(sc_icc_stru)))
        {
            sc_error_printf("bsp icc read error, chanid :0x%x opt_len :0x%x\n",SC_ICC_CHAN_ID,icc_len);
            osl_sem_up(&g_sc_stat.sc_tsk_sem);
            continue;
        }
        else if(0 >= icc_len)
        {
            sc_debug_printf("bsp icc read error, length is 0!\n");
            continue ;
        }
        
        g_sc_stat.sc_ram_len = icc_trans.sc_total_len;
        sc_debug_printf("len is 0x%x\n", g_sc_stat.sc_ram_len);
        
        
        icc_trans.sc_cnf_ret = SC_OK;
        /* get buffer */
        g_sc_stat.sc_ram_addr = (u8* )osl_malloc(icc_trans.sc_total_len);
        if(!g_sc_stat.sc_ram_addr)
        {
            sc_error_printf("bsp icc read error, chanid :0x%x ret :0x%x\n",SC_ICC_CHAN_ID,ret);
            icc_trans.sc_cnf_ret = BSP_ERR_SC_MALLOC_FAIL;
            goto confirm;
        }
        else
        {
            sc_debug_printf("malloc ok!\n");
        }

        if(MISC_SC_OPT_WRITE== icc_trans.sc_opt_type)
        {
            if(SC_OK != sc_bakup(g_sc_stat.sc_ram_addr, g_sc_stat.sc_ram_len))
            {
                icc_trans.sc_cnf_ret = BSP_ERR_SC_WRITE_FILE_FAIL;
            }
        }
        else
        {
            if(SC_OK != sc_restore(g_sc_stat.sc_ram_addr, g_sc_stat.sc_ram_len))
            {
                icc_trans.sc_cnf_ret = BSP_ERR_SC_READ_FILE_FAIL; 
            }
        }
        osl_free(g_sc_stat.sc_ram_addr);
        
        
confirm:
        /* send pkt to modem */
        icc_len = bsp_icc_send(ICC_CPU_MODEM, SC_ICC_CHAN_ID, (u8*)&icc_trans, sizeof(sc_icc_stru));
        if(icc_len != sizeof(sc_icc_stru))
        {
            sc_error_printf("send to modem failed 0,icc_len is 0x%x!\n",icc_len);
        }
        else
        {
            sc_debug_printf("send to mdoem ok,icc_len is 0x%x!\n",icc_len);
        }
        
        continue;
    }
        
}
struct coresight_platform_data_s *of_get_coresight_platform_cfg(struct device_node *node)
{
	int i, ret = 0;
	int outports_len = 0;
/*
	struct clk *clk;
*/
	struct device_node *child_node, *cpu;
	struct coresight_platform_data_s *pdata;

	pdata = osl_malloc(sizeof(*pdata));
	if (!pdata)
		return NULL;

    memset_s((void *)pdata, sizeof(*pdata), 0, sizeof(*pdata));

	ret = of_property_read_u32(node, "coresight-id", (u32*)&pdata->id);
	if (ret)
		goto err;

	ret = of_property_read_string(node, "coresight-name", &pdata->name);
	if (ret)
		goto err;

	ret = of_property_read_u32(node, "coresight-nr-inports",
				   (u32*)&pdata->nr_inports);
	if (ret)
		goto err;

	pdata->nr_outports = 0;
	if (of_get_property(node, "coresight-outports", &outports_len))
		pdata->nr_outports = (unsigned int)outports_len/sizeof(uint32_t);

	if (pdata->nr_outports)
    {
        pdata->outports = osl_malloc((unsigned int)pdata->nr_outports*sizeof(*pdata->outports));
		if (!pdata->outports)
            goto err;

        memset_s((void *)pdata->outports, (unsigned int)pdata->nr_outports*sizeof(*pdata->outports), 0,
            (unsigned int)pdata->nr_outports*sizeof(*pdata->outports));

		ret = of_property_read_u32_array(node, "coresight-outports",
						 (u32 *)pdata->outports,
						 pdata->nr_outports);
		if (ret)
			goto err;

        pdata->child_ids = osl_malloc(pdata->nr_outports*sizeof(*pdata->child_ids));
		if (!pdata->child_ids)
			goto err;

        memset_s((void *)pdata->child_ids, pdata->nr_outports*sizeof(*pdata->child_ids), 0,
            pdata->nr_outports*sizeof(*pdata->child_ids));

		for (i = 0; i < (int)pdata->nr_outports; i++) {
			child_node = of_parse_phandle(node,
						      "coresight-child-list",
						      i);
			if (!child_node)
                goto err;

			ret = of_property_read_u32(child_node, "coresight-id",
						   (u32 *)&pdata->child_ids[i]);
			of_node_put(child_node);
			if (ret)
				goto err;
		}

        pdata->child_ports = osl_malloc(pdata->nr_outports*sizeof(*pdata->child_ports));
		if (!pdata->child_ports)
			goto err;

        memset_s((void *)pdata->child_ports,pdata->nr_outports*sizeof(*pdata->child_ports),0,
            pdata->nr_outports*sizeof(*pdata->child_ports));

		ret = of_property_read_u32_array(node, "coresight-child-ports",
						 (u32 *)pdata->child_ports,
						 pdata->nr_outports);
		if (ret)
			goto err;
	}

	pdata->default_sink = of_property_read_bool(node,
						    "coresight-default-sink");

	/* affinity defaults to CPU0 */
	pdata->cpu = 0;
	cpu = of_parse_phandle(node, "cpu", 0);
	if (cpu) {
		const u32 *mpidr;
		int len;

		mpidr = of_get_property(cpu, "reg", &len);
		if (mpidr && (unsigned int)len == 4) {
            pdata->cpu = (int)be32_to_cpup(mpidr);
		}
	}

	/* clock specifics */
/*
	pdata->clk = NULL;
	clk = of_clk_get(node, 0);
	if (!IS_ERR(clk))
		pdata->clk = clk;
*/
   	return pdata;

err:
    if(NULL != pdata->child_ports)
        osl_free((void*)pdata->child_ports);
    if(NULL != pdata->child_ids)
        osl_free((void*)pdata->child_ids);
    if(NULL != pdata->outports)
        osl_free((void*)pdata->outports);
    osl_free(pdata);
    return NULL;
}
Example #18
0
s32 kdf_sha256(const u8*  pucInBuf, u32 ulInLen, u8* pucOutBuf)
{
    s32 iRet = SEC_OK;
	KEY_CONFIG_INFO_S key_cfg = {SHA_KEY_SOURCE_MAX, 0, NULL};
	S_CONFIG_INFO_S s_cfg = {SHA_S_SOURCE_MAX, 0, 0, NULL};
	KEY_MAKE_S k_make = {CIPHER_KEY_OUTPUT_BUTTOM, {0, 0, 0}};
	KEY_GET_S k_g_s = {0, 0, 0};
	u8 * temp_hash = NULL;
	u32 out_hash_len;

    if ((NULL == pucInBuf) || (0 == ulInLen) || (NULL == pucOutBuf))
    {
        bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_SECURITY, "secDataSha: Input Parameter Error!\n");
        return -1;
    }

    {
#ifdef CONFIG_CIPHER
    	/*这里应该是使用SHA256,cipher实现的,因为onchiprom换成这样的*/
		temp_hash = (u8*)osl_malloc(SHA256_HASH_SIZE * sizeof(u32));
		if(NULL == temp_hash)
		{
			bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_SECURITY, "secDataSha: Error! NO MEM TO MALLOC\n");
			goto end;
		}
		memset(temp_hash, 0, SHA256_HASH_SIZE * sizeof(u32));/*onchiprom里使用的初始key也是256bit全零*/
		k_g_s.enKeyLen = CIPHER_KEY_L256;
		k_g_s.penOutKeyLen = &out_hash_len;
		k_g_s.pKeyAddr = temp_hash;
		k_make.enKeyOutput = CIPHER_KEY_OUTPUT;
		k_make.stKeyGet = k_g_s;
		key_cfg.enShaKeySource = SHA_KEY_SOURCE_DDR;
		key_cfg.pKeySourceAddr = temp_hash;
		key_cfg.u32ShaKeyIndex = 0;
		s_cfg.enShaSSource = SHA_S_SOURCE_DDR;
		s_cfg.pSAddr = (void*)pucInBuf;
		s_cfg.u32ShaSIndex = 0;
		s_cfg.u32ShaSLength = ulInLen > 512 ? 512 : ulInLen;/*kdf 一次最大只能处理512字节*/
		do
		{
			iRet = bsp_kdf_key_make(&key_cfg, &s_cfg, 0/*不使用,所以无所谓*/, &k_make);
			if(iRet)
			{
				bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_SECURITY,
					"secDataSha: run sha error : %X!\n", iRet);
				break;
			}
			pucInBuf += s_cfg.u32ShaSLength;
			s_cfg.pSAddr = (void*)pucInBuf;
			ulInLen -= s_cfg.u32ShaSLength;
			s_cfg.u32ShaSLength = ulInLen > 512 ? 512 : ulInLen;
			/*memcpy(key_cfg.pKeySourceAddr, k_make.stKeyGet.pKeyAddr, 256 >> 3);*//*没必要,两个指针是同一块地址空间*/
		}while(ulInLen > 0);
		memcpy(pucOutBuf, temp_hash, 256 >> 3);/*key的最大长度256bits*/
#else
		bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_SECURITY, "cipher is not compiled and the onchiprom SHA algorithm is not used\n");
#endif
    }

end:
	free(temp_hash);
    return iRet;
}
static void pmic_clk_setup(struct device_node *node)
{
    struct clk_init_data *init = NULL;
    struct clk *pclk = NULL;
    struct pmic_clk *clk_pmic = NULL;
    const char *clk_name;
    struct device_node *child_node = NULL;
    const char *parent_names = "tcxo";
    u32   data[2] = {0};
	struct clk_lookup    *ptr_clk_lookup = NULL;
    u32   freq_cfg[3] = {0};


	for_each_available_child_of_node(node, child_node)
	{
        if (of_property_read_string(child_node, "clock-output-names", &clk_name))
        {
            pmu_print_error("node %s doesn't have clock-output-name property!\n", child_node->name);
            return ;
        }

        if (of_property_read_u32_array(child_node, "reg_offset_bit", &data[0], 2))
        {
            pmu_print_error("node %s doesn't have reg_offset_bit property!\n", child_node->name);
            return ;
        }

        if (of_property_read_u32_array(child_node, "freq_cfg", &freq_cfg[0], 3))
        {
            pmu_print_error("node %s doesn't have freq_cfg property!\n", child_node->name);
            return ;
        }

        pmu_print_error("clk_name %s\n", clk_name);
        clk_pmic = osl_malloc(sizeof(struct pmic_clk));
        if (!clk_pmic)
        {
            pmu_print_error("[%s] fail to alloc clk_pmic!\n", __func__);
            goto err_pmic_clk;
        }



        init = osl_malloc(sizeof(struct clk_init_data));
        if (!init)
        {
            pmu_print_error("malloc init err\n");
            goto err_init;
        }

        init->name = pmic_alloc_copy(clk_name);
        init->ops = &g_pmic_clk_ops;
        init->flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED;
        init->parent_names = &parent_names;
        init->num_parents = 1;

        clk_pmic->hw.init = init;

        clk_pmic->en_dis_offset = data[0];
        clk_pmic->en_dis_bit = data[1];
        clk_pmic->freq_addr_offset = freq_cfg[0];
        clk_pmic->freq_mask = freq_cfg[1];
        clk_pmic->delay_us = freq_cfg[2];


        pclk = drv_clk_register(NULL, &clk_pmic->hw);
        if (IS_ERR(pclk))
        {
            pmu_print_error("drv_clk_register ERR\n");
            goto err_register;
        }

        ptr_clk_lookup = osl_malloc(sizeof(struct clk_lookup));
        if (IS_ERR(ptr_clk_lookup))
        {
             pmu_print_error("clk %s fail to malloc clk_lookup\n", pclk->name);
            goto err_register;
        }

        /* 申请成功 */
        (void)memset_s(ptr_clk_lookup, sizeof(struct clk_lookup), 0, sizeof(struct clk_lookup));

        ptr_clk_lookup->dev_id = NULL;
        ptr_clk_lookup->con_id = pmic_alloc_copy(pclk->name);
        ptr_clk_lookup->clk = pclk;

        drv_clkdev_add(ptr_clk_lookup);

        continue;

    err_register:
        osl_free((void*)init);
    err_init:
        osl_free((void*)clk_pmic);
    err_pmic_clk:
        return ;
    }

    pmu_print_error("pmic_clk setup ok\n");
    /* coverity[leaked_storage] */
    return ;
}