Hi Raef

Based on your advice, I made the modifications as below and confirmed that it works properly.

Thank you for your help.

JK Park




enum integrity_checker_error_t integrity_checker_compute_value_bl2(struct integrity_checker_dev_t *dev,
                                                               enum integrity_checker_mode_t mode,
                                                               const uint32_t *data, size_t size,
                                                               uint32_t *value, size_t value_size,
                                                               size_t *value_len)
{
    //volatile uint32_t __ALIGNED(INTEGRITY_CHECKER_REQUIRED_ALIGNMENT)
    //    temp_val[INTEGRITY_CHECKER_OUTPUT_SIZE_SHA256 / sizeof(uint32_t)] = {0};  //jkpark

volatile uint32_t __ALIGNED(32)
        temp_val[INTEGRITY_CHECKER_OUTPUT_SIZE_SHA256 / sizeof(uint32_t)] = {0};

    volatile uint32_t *value_ptr = value;
    struct _integrity_checker_reg_map_t* p_integrity_checker =
        (struct _integrity_checker_reg_map_t*)dev->cfg->base;
    enum integrity_checker_error_t err;

    uint32_t iccval = 0;


    err = check_mode_is_supported(dev, mode, true);
    if (err != INTEGRITY_CHECKER_ERROR_NONE) {
        return err;
    }

    if (value_size < mode_sizes[mode]) {
        FATAL_ERR(INTEGRITY_CHECKER_ERROR_COMPUTE_VALUE_BUFFER_TOO_SMALL);
        return INTEGRITY_CHECKER_ERROR_COMPUTE_VALUE_BUFFER_TOO_SMALL;
    }

    if (((uintptr_t)data % INTEGRITY_CHECKER_REQUIRED_ALIGNMENT) != 0) {
        FATAL_ERR(INTEGRITY_CHECKER_ERROR_COMPUTE_VALUE_INVALID_ALIGNMENT);
        return INTEGRITY_CHECKER_ERROR_COMPUTE_VALUE_INVALID_ALIGNMENT;
    }

    if ((size % INTEGRITY_CHECKER_REQUIRED_ALIGNMENT) != 0) {
        FATAL_ERR(INTEGRITY_CHECKER_ERROR_COMPUTE_VALUE_INVALID_LENGTH);
        return INTEGRITY_CHECKER_ERROR_COMPUTE_VALUE_INVALID_LENGTH;
    }

   
    init_integrity_checker(dev, &iccval);

    /* Set algorithm */
    iccval |= (mode & 0b111) << 1;

    /* Set to compute mode */
    iccval |= 1 << 4;

    /* Configure input data. Size is in words */
    p_integrity_checker->icda = remap_addr(dev, (uintptr_t)data);
    p_integrity_checker->icdl = size / INTEGRITY_CHECKER_REQUIRED_ALIGNMENT;

    /* Set output address */
    p_integrity_checker->iccva = remap_addr(dev, (uintptr_t)value_ptr);

    /* Start integrity checker */
    iccval |= 1;

    p_integrity_checker->icc = iccval;

    /* Poll for any interrupts */
    while(!p_integrity_checker->icis) {}

    /* Check for any unusual error interrupts */
    if (p_integrity_checker->icis & (~0b11)) {
        FATAL_ERR(INTEGRITY_CHECKER_ERROR_COMPUTE_VALUE_OPERATION_FAILED);
        return INTEGRITY_CHECKER_ERROR_COMPUTE_VALUE_OPERATION_FAILED;
    }

SCB_InvalidateDCache_by_Addr((void *)temp_val, 32);


    if (value_ptr != value) {
        for (int idx = 0; idx < mode_sizes[mode] / sizeof(uint32_t); idx++) {
            value[idx] = value_ptr[idx];
        }
    }

    if (value_len != NULL) {
        *value_len = mode_sizes[mode];
    }

    return INTEGRITY_CHECKER_ERROR_NONE;
}

enum integrity_checker_error_t integrity_checker_check_value_bl2(struct integrity_checker_dev_t *dev,
                                                             enum integrity_checker_mode_t mode,
                                                             const uint32_t *data, size_t size,
                                                             const uint32_t *value, size_t value_size)
{
    //volatile uint32_t __ALIGNED(INTEGRITY_CHECKER_REQUIRED_ALIGNMENT)
    //    temp_val[INTEGRITY_CHECKER_OUTPUT_SIZE_SHA256 / sizeof(uint32_t)] = {0};  //jkpark

volatile uint32_t __ALIGNED(32)
    temp_val[INTEGRITY_CHECKER_OUTPUT_SIZE_SHA256 / sizeof(uint32_t)] = {0};
   
    const volatile uint32_t *value_ptr = value;
    struct _integrity_checker_reg_map_t* p_integrity_checker =
        (struct _integrity_checker_reg_map_t*)dev->cfg->base;
    enum integrity_checker_error_t err;
    uint32_t iccval = 0;

    err = check_mode_is_supported(dev, mode, false);
    if (err != INTEGRITY_CHECKER_ERROR_NONE) {
        return err;
    }

    if (value_size < mode_sizes[mode]) {
        FATAL_ERR(INTEGRITY_CHECKER_ERROR_CHECK_VALUE_BUFFER_TOO_SMALL);
        return INTEGRITY_CHECKER_ERROR_CHECK_VALUE_BUFFER_TOO_SMALL;
    }

    if (((uintptr_t)data % INTEGRITY_CHECKER_REQUIRED_ALIGNMENT) != 0) {
        FATAL_ERR(INTEGRITY_CHECKER_ERROR_CHECK_VALUE_INVALID_ALIGNMENT);
        return INTEGRITY_CHECKER_ERROR_CHECK_VALUE_INVALID_ALIGNMENT;
    }

    if ((size % INTEGRITY_CHECKER_REQUIRED_ALIGNMENT) != 0) {
        FATAL_ERR(INTEGRITY_CHECKER_ERROR_CHECK_VALUE_INVALID_LENGTH);
        return INTEGRITY_CHECKER_ERROR_CHECK_VALUE_INVALID_LENGTH;
    }

    //if (((uintptr_t)value % INTEGRITY_CHECKER_REQUIRED_ALIGNMENT) != 0
    //       || (value_size % INTEGRITY_CHECKER_REQUIRED_ALIGNMENT) != 0) {
        for (int idx = 0; idx < value_size / sizeof(uint32_t); idx++) {
            temp_val[idx] = value[idx];
        }
        value_ptr = temp_val;
    //}

SCB_CleanDCache_by_Addr((void *)temp_val, 32);

    init_integrity_checker(dev, &iccval);

    /* Set algorithm */
    iccval |= (mode & 0b111) << 1;

    /* Configure input data. Size is in words */
    p_integrity_checker->icda = remap_addr(dev, (uintptr_t)data);
    p_integrity_checker->icdl = size / INTEGRITY_CHECKER_REQUIRED_ALIGNMENT;

    /* Set compare address */
    p_integrity_checker->iceva = remap_addr(dev, (uintptr_t)value_ptr);

    /* Start integrity checker */
    iccval |= 1;

    p_integrity_checker->icc = iccval;

    /* Poll for any interrupts */
    while(!p_integrity_checker->icis) {}

    /* Check for any unusual error interrupts */
    if (p_integrity_checker->icis & (~0b11)) {
        FATAL_ERR(INTEGRITY_CHECKER_ERROR_CHECK_VALUE_OPERATION_FAILED);
        return INTEGRITY_CHECKER_ERROR_CHECK_VALUE_OPERATION_FAILED;
    } else if (p_integrity_checker->icis & (0b10)) {
        /* Check for comparison failure */
        NONFATAL_ERR(INTEGRITY_CHECKER_ERROR_CHECK_VALUE_COMPARISON_FAILED);
        return INTEGRITY_CHECKER_ERROR_CHECK_VALUE_COMPARISON_FAILED;
    }

    return INTEGRITY_CHECKER_ERROR_NONE;
}