Exemplo n.º 1
0
TZ_RESULT UREE_ReleaseTzmem (int *fd_p)
{
    int fd;
    int ret = TZ_RESULT_SUCCESS;    
    UREE_SESSION_HANDLE session;
    uint32_t size;

    if (fd_p == NULL)
    {
        return TZ_RESULT_ERROR_BAD_PARAMETERS;
    }

    pthread_mutex_lock(&mtee_tzmemInfo.mutex);

    if (mtee_tzmemInfo.control != 0)
    {
        ret = TZ_RESULT_ERROR_GENERIC;
        goto out;
    }
    
	ret = UREE_CreateSession(TZ_TA_MEM_UUID, &session);
	if (ret != TZ_RESULT_SUCCESS)
	{
	    printf("UREE_ReleaseTzmem: CreateSession Error = %s\n", TZ_GetErrorString(ret));
	    goto out;
	}  

    ret = UREE_ReleaseSecurechunkmem (session, 0x0, &size);
    printf ("released size = 0x%x\n", size);
    if (ret != TZ_RESULT_SUCCESS)
    {
        ret = TZ_RESULT_ERROR_GENERIC;
        goto out_release_fail;
    }
    
    fd = open("/dev/tzmem", O_RDWR);
    if (fd < 0)
    {
        ret = TZ_RESULT_ERROR_GENERIC;
        goto out_release_fail;
    }
    else
    {
        *fd_p = fd;
    }

    mtee_tzmemInfo.session = session;
    mtee_tzmemInfo.control = 1;
    
    pthread_mutex_unlock(&mtee_tzmemInfo.mutex);    
    return ret;
    
out_release_fail:
    UREE_CloseSession (session);
out:
    pthread_mutex_unlock(&mtee_tzmemInfo.mutex);
    
    return ret;
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
    TZ_RESULT ret;
    UREE_SESSION_HANDLE dbg_session;
    UREE_SECUREMEM_INFO info;

    printf ("Run memory CA\n");

    ret = UREE_CreateSession(TZ_TA_DBG_UUID, &dbg_session);
    if (ret != TZ_RESULT_SUCCESS)
    {
        // Should provide strerror style error string in UREE.
        printf("CreateSession Error: %s\n", TZ_GetErrorString(ret));
        return 1;
    }

    // get secure memory information
    ret = UREE_GetSecurememinfo (dbg_session, &info);
    if (ret != TZ_RESULT_SUCCESS)
    {
        printf("UREE_GetSecurememinfo Error: %s\n", TZ_GetErrorString(ret));
        return 0;
    }
    printf ("secure memory: Used = 0x%x bytes, Total = 0x%x bytes,\n"
            "               Max free continuous mem sz = 0x%x bytes\n"
            "               Max foot print = 0x%x bytes\n"
            , info.used_byte, info.total_byte, info.max_free_cont_mem_sz, info.max_foot_print);


    // get secure chunk memory information
    ret = UREE_GetSecurechunkmeminfo (dbg_session, &info);
    if (ret != TZ_RESULT_SUCCESS)
    {
        printf("UREE_GetSecurechunkmeminfo Error: %s\n", TZ_GetErrorString(ret));
        return 0;
    }
    printf ("secure chunk memory: Used = 0x%x bytes, Total = 0x%x bytes,\n"
            "                     Max free continuous mem sz = 0x%x bytes\n"
            "                     Max foot print = 0x%x bytes\n"
            , info.used_byte, info.total_byte, info.max_free_cont_mem_sz, info.max_foot_print);


    ret = UREE_CloseSession(dbg_session);
    if (ret != TZ_RESULT_SUCCESS)
    {
        printf("CloseSeesion dbg_session_A Error: %d\n", ret);
    }

    printf ("Memory CA done\n");

    return 0;
}