/*
- * Copyright (c) 2015-2019, Renesas Electronics Corporation. All rights reserved.
+ * Copyright (c) 2015-2021, Renesas Electronics Corporation. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <drivers/io/io_driver.h>
#include <drivers/io/io_storage.h>
-#include "io_common.h"
-#include "io_emmcdrv.h"
-#include "io_private.h"
#include "emmc_config.h"
+#include "emmc_def.h"
#include "emmc_hal.h"
#include "emmc_std.h"
-#include "emmc_def.h"
+#include "io_common.h"
+#include "io_emmcdrv.h"
+#include "io_private.h"
static int32_t emmcdrv_dev_open(const uintptr_t spec __attribute__ ((unused)),
io_dev_info_t **dev_info);
static int32_t emmcdrv_block_seek(io_entity_t *entity, int32_t mode,
signed long long offset)
{
- if (mode != IO_SEEK_SET)
+ if (mode != IO_SEEK_SET) {
return IO_FAIL;
+ }
((file_state_t *) entity->info)->file_pos = offset;
current_file.partition, current_file.file_pos,
sector_add, length, sector_num);
- if ((buffer + length - 1U) <= (uintptr_t)UINT32_MAX)
+ if ((buffer + length - 1U) <= (uintptr_t)UINT32_MAX) {
emmc_dma = LOADIMAGE_FLAGS_DMA_ENABLE;
+ }
if (emmc_read_sector((uint32_t *) buffer, sector_add, sector_num,
- emmc_dma) != EMMC_SUCCESS)
+ emmc_dma) != EMMC_SUCCESS) {
result = IO_FAIL;
+ }
*length_read = length;
fp->file_pos += (signed long long)length;
if (emmcdrv_bootpartition == PARTITION_ID_USER) {
emmcdrv_bootpartition = mmc_drv_obj.boot_partition_en;
- if ((PARTITION_ID_BOOT_1 == emmcdrv_bootpartition) ||
- (PARTITION_ID_BOOT_2 == emmcdrv_bootpartition)) {
+ if ((emmcdrv_bootpartition == PARTITION_ID_BOOT_1) ||
+ (emmcdrv_bootpartition == PARTITION_ID_BOOT_2)) {
current_file.partition = emmcdrv_bootpartition;
NOTICE("BL2: eMMC boot from partition %d\n",
return IO_FAIL;
}
- if ((PARTITION_ID_USER == block_spec->partition) ||
- (PARTITION_ID_BOOT_1 == block_spec->partition) ||
- (PARTITION_ID_BOOT_2 == block_spec->partition))
+ if ((block_spec->partition == PARTITION_ID_USER) ||
+ (block_spec->partition == PARTITION_ID_BOOT_1) ||
+ (block_spec->partition == PARTITION_ID_BOOT_2)) {
current_file.partition = block_spec->partition;
- else
+ } else {
current_file.partition = emmcdrv_bootpartition;
+ }
done:
- if (emmc_select_partition(current_file.partition) != EMMC_SUCCESS)
+ if (emmc_select_partition(current_file.partition) != EMMC_SUCCESS) {
return IO_FAIL;
+ }
entity->info = (uintptr_t) ¤t_file;
int32_t rc;
rc = io_register_device(&emmcdrv_dev_info);
- if (rc == IO_SUCCESS)
+ if (rc == IO_SUCCESS) {
*dev_con = &emmcdrv_dev_connector;
+ }
return rc;
}
/*
- * Copyright (c) 2015-2019, Renesas Electronics Corporation. All rights reserved.
+ * Copyright (c) 2015-2021, Renesas Electronics Corporation. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <drivers/io/io_storage.h>
#include "io_common.h"
-#include "io_private.h"
#include "io_memdrv.h"
+#include "io_private.h"
#include "rcar_def.h"
extern void rcar_dma_exec(uintptr_t dst, uint32_t src, uint32_t len);
io_dev_info_t **dev_info);
static int32_t memdrv_dev_close(io_dev_info_t *dev_info);
-/* As we need to be able to keep state for seek, only one file can be open
+/*
+ * As we need to be able to keep state for seek, only one file can be open
* at a time. Make this a structure and point to the entity->info. When we
* can malloc memory we can change this to support more open files.
*/
{
const io_drv_spec_t *block_spec = (io_drv_spec_t *) spec;
- /* Since we need to track open state for seek() we only allow one open
+ /*
+ * Since we need to track open state for seek() we only allow one open
* spec at a time. When we have dynamic memory we can malloc and set
* entity->info.
*/
- if (current_file.in_use != 0U)
+ if (current_file.in_use != 0U) {
return IO_RESOURCES_EXHAUSTED;
+ }
/* File cursor offset for seek and incremental reads etc. */
current_file.base = block_spec->offset;
static int32_t memdrv_block_seek(io_entity_t *entity, int32_t mode,
signed long long offset)
{
- if (mode != IO_SEEK_SET)
+ if (mode != IO_SEEK_SET) {
return IO_FAIL;
+ }
((file_state_t *) entity->info)->file_pos = offset;
int32_t result;
result = io_register_device(&memdrv_dev_info);
- if (result == IO_SUCCESS)
+ if (result == IO_SUCCESS) {
*dev_con = &memdrv_dev_connector;
+ }
return result;
}
/*
- * Copyright (c) 2015-2018, Renesas Electronics Corporation. All rights reserved.
+ * Copyright (c) 2015-2021, Renesas Electronics Corporation. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdint.h>
#include <string.h>
-#include <platform_def.h>
-
#include <arch_helpers.h>
#include <common/bl_common.h>
#include <common/debug.h>
#include "io_rcar.h"
#include "io_common.h"
#include "io_private.h"
+#include <platform_def.h>
extern int32_t plat_get_drv_source(uint32_t id, uintptr_t *dev,
uintptr_t *image_spec);
} plat_rcar_name_offset_t;
typedef struct {
- /* Put position above the struct to allow {0} on static init.
+ /*
+ * Put position above the struct to allow {0} on static init.
* It is a workaround for a known bug in GCC
* http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119
*/
#define RCAR_ATTR_SET_ISNOLOAD(a) (((a) & 0x1) << 16U)
#define RCAR_ATTR_SET_CERTOFF(a) (((a) & 0xF) << 8U)
#define RCAR_ATTR_SET_ALL(a, b, c) ((uint32_t)(RCAR_ATTR_SET_CALCADDR(a) |\
- RCAR_ATTR_SET_ISNOLOAD(b) | \
+ RCAR_ATTR_SET_ISNOLOAD(b) |\
RCAR_ATTR_SET_CERTOFF(c)))
#define RCAR_ATTR_GET_CALCADDR(a) ((a) & 0xFU)
{
#if TRUSTED_BOARD_BOOT
int32_t i;
+
for (i = 0; i < ARRAY_SIZE(cert_offset); i++) {
- if (name != cert_offset[i].name)
+ if (name != cert_offset[i].name) {
continue;
+ }
*cert = RCAR_CERT_SIZE;
*cert *= RCAR_ATTR_GET_CERTOFF(cert_offset[i].attr);
int32_t i;
for (i = 0; i < ARRAY_SIZE(name_offset); i++) {
- if (name != name_offset[i].name)
+ if (name != name_offset[i].name) {
continue;
+ }
addr = RCAR_ATTR_GET_CALCADDR(name_offset[i].attr);
- if (rcar_image_number + 2 < addr)
+ if (rcar_image_number + 2U < addr) {
continue;
+ }
*offset = rcar_image_header[addr];
*cert = RCAR_CERT_SIZE;
#if TRUSTED_BOARD_BOOT
for (i = 0; i < ARRAY_SIZE(cert_offset); i++) {
- if (name != cert_offset[i].name)
+ if (name != cert_offset[i].name) {
continue;
+ }
*no_load = RCAR_ATTR_GET_ISNOLOAD(cert_offset[i].attr);
*partition = 0U;
result = IO_FAIL;
}
done:
- if (result == IO_FAIL)
+ if (result == IO_FAIL) {
ERROR("BL2: Out of range : dst=0x%lx len=0x%lx\n", dst, len);
+ }
return result;
}
BL338_IMAGE_ID
};
- if (loaded != IO_NOT_SUPPORTED)
+ if (loaded != IO_NOT_SUPPORTED) {
return loaded;
+ }
for (i = 1; i < rcar_image_number; i++) {
rc = file_to_offset(img[i], &offset, &cert, &noload,
&partition);
if (rc != IO_SUCCESS) {
- WARN("load_bl33x: failed to get offset\n");
+ WARN("%s: failed to get offset\n", __func__);
loaded = IO_FAIL;
return loaded;
}
rc = io_open(rcar_handle, rcar_spec, &handle);
if (rc != IO_SUCCESS) {
- WARN("Failed to open FIP (%i)\n", rc);
+ WARN("%s: Failed to open FIP (%i)\n", __func__, rc);
loaded = IO_FAIL;
return loaded;
}
rc = io_seek(handle, IO_SEEK_SET, offset);
if (rc != IO_SUCCESS) {
- WARN("load_bl33x: failed to seek\n");
+ WARN("%s: failed to seek\n", __func__);
loaded = IO_FAIL;
return loaded;
}
rc = check_load_area(dst, len);
if (rc != IO_SUCCESS) {
- WARN("load_bl33x: check load area\n");
+ WARN("%s: check load area\n", __func__);
loaded = IO_FAIL;
return loaded;
}
rc = io_read(handle, dst, len, &cnt);
if (rc != IO_SUCCESS) {
- WARN("load_bl33x: failed to read\n");
+ WARN("%s: failed to read\n", __func__);
loaded = IO_FAIL;
return loaded;
}
#if TRUSTED_BOARD_BOOT
rc = auth_mod_verify_img(img[i], (void *)dst, len);
- if (rc) {
+ if (rc != 0) {
memset((void *)dst, 0x00, len);
loaded = IO_FAIL;
return loaded;
static int32_t rcar_dev_init(io_dev_info_t *dev_info, const uintptr_t name)
{
- uint64_t header[64] __aligned(FLASH_TRANS_SIZE_UNIT) = {
- 0};
+ uint64_t header[64] __aligned(FLASH_TRANS_SIZE_UNIT) = {0UL};
uintptr_t handle;
ssize_t offset;
uint32_t i;
return IO_FAIL;
}
- if (RCAR_CERT_LOAD == rcar_cert_load)
+ if (rcar_cert_load == RCAR_CERT_LOAD) {
return IO_SUCCESS;
+ }
rc = io_open(rcar_handle, rcar_spec, &handle);
if (rc != IO_SUCCESS) {
return IO_FAIL;
}
- /* get start address list */
- /* [0] address num */
- /* [1] BL33-1 image address */
- /* [2] BL33-2 image address */
- /* [3] BL33-3 image address */
- /* [4] BL33-4 image address */
- /* [5] BL33-5 image address */
- /* [6] BL33-6 image address */
- /* [7] BL33-7 image address */
- /* [8] BL33-8 image address */
+ /*
+ * get start address list
+ * [0] address num
+ * [1] BL33-1 image address
+ * [2] BL33-2 image address
+ * [3] BL33-3 image address
+ * [4] BL33-4 image address
+ * [5] BL33-5 image address
+ * [6] BL33-6 image address
+ * [7] BL33-7 image address
+ * [8] BL33-8 image address
+ */
offset = name == EMMC_DEV_ID ? RCAR_EMMC_CERT_HEADER :
RCAR_FLASH_CERT_HEADER;
rc = io_seek(handle, IO_SEEK_SET, offset);
rcar_cert_load = RCAR_CERT_LOAD;
error:
- if (rc != IO_SUCCESS)
+ if (rc != IO_SUCCESS) {
rc = IO_FAIL;
+ }
io_close(handle);
uint32_t noload, cert, len;
int32_t rc;
- /* Only one file open at a time. We need to track state (ie, file
- * cursor position). Since the header lives at * offset zero, this entry
+ /*
+ * Only one file open at a time. We need to track state (ie, file
+ * cursor position). Since the header lives at offset zero, this entry
* should never be zero in an active file.
* Once the system supports dynamic memory allocation we will allow more
- * than one open file at a time. */
+ * than one open file at a time.
+ */
if (current_file.offset != 0U) {
- WARN("rcar_file_open : Only one open file at a time.\n");
+ WARN("%s: Only one open file at a time.\n", __func__);
return IO_RESOURCES_EXHAUSTED;
}
return IO_FAIL;
}
- if (noload) {
+ if (noload != 0U) {
current_file.offset = 1;
current_file.dst = 0;
current_file.size = 1;
rcar_read_certificate((uint64_t) cert, &len, &dst);
- /*----------------*
- * Baylibre: HACK *
- *----------------*/
- if (BL31_IMAGE_ID == spec->offset && len < RCAR_TRUSTED_SRAM_SIZE) {
- WARN("r-car ignoring the BL31 size from certificate,"
- "using RCAR_TRUSTED_SRAM_SIZE instead\n");
+ /* Baylibre: HACK */
+ if (spec->offset == BL31_IMAGE_ID && len < RCAR_TRUSTED_SRAM_SIZE) {
+ WARN("%s,%s\n", "r-car ignoring the BL31 size from certificate",
+ "using RCAR_TRUSTED_SRAM_SIZE instead");
len = RCAR_TRUSTED_SRAM_SIZE;
}
#else
static uint32_t load_bl33x_counter;
#endif
- if (current_file.no_load) {
+ if (current_file.no_load != 0U) {
*cnt = length;
return IO_SUCCESS;
}
rc = io_seek(handle, IO_SEEK_SET, offset);
if (rc != IO_SUCCESS) {
- WARN("rcar_file_read: failed to seek\n");
+ WARN("%s: failed to seek\n", __func__);
goto error;
}
if (load_bl33x_counter == RCAR_COUNT_LOAD_BL33) {
rc = check_load_area(buffer, length);
if (rc != IO_SUCCESS) {
- WARN("rcar_file_read: load area err\n");
+ WARN("%s: load area err\n", __func__);
goto error;
}
}
io_close(handle);
load_bl33x_counter += 1;
- if (load_bl33x_counter == RCAR_COUNT_LOAD_BL33X)
+ if (load_bl33x_counter == RCAR_COUNT_LOAD_BL33X) {
return load_bl33x();
+ }
return IO_SUCCESS;
error:
static int32_t rcar_file_close(io_entity_t *entity)
{
- if (current_file.offset)
+ if (current_file.offset != 0U) {
memset(¤t_file, 0, sizeof(current_file));
+ }
entity->info = 0U;
int32_t result;
result = io_register_device(&rcar_dev_info);
- if (result == IO_SUCCESS)
+ if (result == IO_SUCCESS) {
*dev_con = &rcar_dev_connector;
+ }
return result;
}