Add the nand device support for cbootimage tool.

Change-Id: Ic24dd4c971c16d00742d90830be168b41483be7a

BUG=None.
TEST=Test with the config file.

Review URL: http://codereview.chromium.org/6611009
Patch from Peer Chen <pchen@nvidia.com>.
This commit is contained in:
Peer Chen
2011-03-03 10:12:58 -08:00
committed by Anton Staaf
parent 8f49024db8
commit 053d578f2b
10 changed files with 93 additions and 17 deletions

View File

@@ -176,6 +176,8 @@ main(int argc, char *argv[])
/* Generate the new bct file */
if (context.generate_bct != 0) {
/* Update the BCT */
begin_update(&context);
/* Signing the bct. */
e = sign_bct(&context, context.bct);
if (e != 0)

View File

@@ -35,12 +35,10 @@
#include <errno.h>
#define NVBOOT_AES_BLOCK_SIZE_LOG2 4
#define KEY_LENGTH (128/8)
#define MAX_BUFFER 200
#define MAX_STR_LEN 20
#define MAX_BOOTLOADER_SIZE (16 * 1024 * 1024)
#define NVBOOT_BOOTDATA_VERSION(a, b) ((((a)&0xffff) << 16) | ((b)&0xffff))
/*
* Enumerations

View File

@@ -79,7 +79,6 @@ set_bl_data(build_image_context *context,
static int write_bootloaders(build_image_context *context);
static void find_new_journal_blk(build_image_context *context);
static int begin_update (build_image_context *context);
static int finish_update(build_image_context *context);
static u_int32_t
iceil_log2(u_int32_t a, u_int32_t b)
@@ -871,7 +870,7 @@ find_new_journal_blk(build_image_context *context)
* - Write the good BCT to slot 0 of the journal block.
* - Erase block 0
*/
static int
int
begin_update(build_image_context *context)
{
u_int32_t pages_per_bct;
@@ -896,6 +895,7 @@ begin_update(build_image_context *context)
block_size_log2, page_size_log2);
}
SET_VALUE(boot_data_version, NVBOOT_BOOTDATA_VERSION(2, 1));
GET_VALUE(bct_size, &bct_size);
GET_VALUE(hash_size, &hash_size);
GET_VALUE(reserved_size, &reserved_size);

View File

@@ -53,4 +53,7 @@ update_addon_item(struct build_image_context_rec *context);
int
write_block_raw(struct build_image_context_rec *context);
int
begin_update(build_image_context *context);
#endif /* #ifndef INCLUDED_DATA_LAYOUT_H */

View File

@@ -62,9 +62,15 @@ typedef enum {
nvbct_lib_id_crypto_length,
nvbct_lib_id_max_bct_search_blks,
nvbct_lib_id_num_param_sets,
nvbct_lib_id_dev_type_nand,
nvbct_lib_id_dev_type_sdmmc,
nvbct_lib_id_dev_type_spi,
nvbct_lib_id_nand_clock_divider,
nvbct_lib_id_nand_nand_timing,
nvbct_lib_id_nand_nand_timing2,
nvbct_lib_id_nand_block_size_log2,
nvbct_lib_id_nand_page_size_log2,
nvbct_lib_id_sdmmc_clock_divider,
nvbct_lib_id_sdmmc_data_width,
nvbct_lib_id_sdmmc_max_power_class_supported,

View File

@@ -94,6 +94,12 @@ getdev_param(u_int32_t set,
return -ENODATA;
switch (id) {
CASE_GET_DEV_PARAM(nand, clock_divider);
CASE_GET_DEV_PARAM(nand, nand_timing);
CASE_GET_DEV_PARAM(nand, nand_timing2);
CASE_GET_DEV_PARAM(nand, block_size_log2);
CASE_GET_DEV_PARAM(nand, page_size_log2);
CASE_GET_DEV_PARAM(sdmmc, clock_divider);
CASE_GET_DEV_PARAM(sdmmc, data_width);
CASE_GET_DEV_PARAM(sdmmc, max_power_class_supported);
@@ -125,6 +131,12 @@ setdev_param(u_int32_t set,
return -ENODATA;
switch (id) {
CASE_SET_DEV_PARAM(nand, clock_divider);
CASE_SET_DEV_PARAM(nand, nand_timing);
CASE_SET_DEV_PARAM(nand, nand_timing2);
CASE_SET_DEV_PARAM(nand, block_size_log2);
CASE_SET_DEV_PARAM(nand, page_size_log2);
CASE_SET_DEV_PARAM(sdmmc, clock_divider);
CASE_SET_DEV_PARAM(sdmmc, data_width);
CASE_SET_DEV_PARAM(sdmmc, max_power_class_supported);
@@ -272,6 +284,7 @@ bct_get_value(nvbct_lib_id id, u_int32_t *data, u_int8_t *bct)
CASE_GET_CONST(max_bct_search_blks, NVBOOT_MAX_BCT_SEARCH_BLOCKS);
CASE_GET_CONST_PREFIX(dev_type_nand, nvboot);
CASE_GET_CONST_PREFIX(dev_type_sdmmc, nvboot);
CASE_GET_CONST_PREFIX(dev_type_spi, nvboot);
CASE_GET_CONST_PREFIX(sdmmc_data_width_4bit, nvboot);

41
parse.c
View File

@@ -87,8 +87,10 @@ static enum_item s_devtype_table[] =
{
{ "NvBootDevType_Sdmmc", nvbct_lib_id_dev_type_sdmmc },
{ "NvBootDevType_Spi", nvbct_lib_id_dev_type_spi },
{ "NvBootDevType_Nand", nvbct_lib_id_dev_type_nand },
{ "Sdmmc", nvbct_lib_id_dev_type_sdmmc },
{ "Spi", nvbct_lib_id_dev_type_spi },
{ "Nand", nvbct_lib_id_dev_type_nand },
{ NULL, 0 }
};
@@ -141,6 +143,19 @@ static enum_item s_spi_clock_source_table[] =
{ NULL, 0 }
};
static field_item s_nand_table[] =
{
{ "ClockDivider", token_clock_divider, field_type_u32, NULL },
/* Note: NandTiming2 must appear before NandTiming, because NandTiming
* is a prefix of NandTiming2 and would otherwise match first.
*/
{ "NandTiming2", token_nand_timing2, field_type_u32, NULL },
{ "NandTiming", token_nand_timing, field_type_u32, NULL },
{ "BlockSizeLog2", token_block_size_log2, field_type_u32, NULL },
{ "PageSizeLog2", token_page_size_log2, field_type_u32, NULL },
{ NULL, 0, 0, NULL }
};
static field_item s_sdmmc_table[] =
{
{ "ClockDivider", token_clock_divider, field_type_u32, NULL },
@@ -165,6 +180,8 @@ static field_item s_spiflash_table[] =
static parse_subfield_item s_device_type_table[] =
{
{ "NandParams.", token_nand_params,
s_nand_table, set_nand_param },
{ "SdmmcParams.", token_sdmmc_params,
s_sdmmc_table, set_sdmmc_param },
{ "SpiFlashParams.", token_spiflash_params,
@@ -175,18 +192,18 @@ static parse_subfield_item s_device_type_table[] =
static parse_item s_top_level_items[] =
{
{ "Bctfile=", token_bct_file, parse_bct_file },
{ "Attribute=", token_attribute, parse_value_u32 },
{ "Attribute[", token_attribute, parse_array },
{ "PageSize=", token_page_size, parse_value_u32 },
{ "BlockSize=", token_block_size, parse_value_u32 },
{ "PartitionSize=", token_partition_size, parse_value_u32 },
{ "DevType[", token_dev_type, parse_array },
{ "DeviceParam[", token_dev_param, parse_dev_param },
{ "BootLoader=", token_bootloader, parse_bootloader },
{ "Redundancy=", token_redundancy, parse_value_u32 },
{ "Version=", token_version, parse_value_u32 },
{ "AddOn[", token_addon, parse_addon },
{ "Bctfile=", token_bct_file, parse_bct_file },
{ "Attribute=", token_attribute, parse_value_u32 },
{ "Attribute[", token_attribute, parse_array },
{ "PageSize=", token_page_size, parse_value_u32 },
{ "BlockSize=", token_block_size, parse_value_u32 },
{ "PartitionSize=", token_partition_size, parse_value_u32 },
{ "DevType[", token_dev_type, parse_array },
{ "DeviceParam[", token_dev_param, parse_dev_param },
{ "BootLoader=", token_bootloader, parse_bootloader },
{ "Redundancy=", token_redundancy, parse_value_u32 },
{ "Version=", token_version, parse_value_u32 },
{ "AddOn[", token_addon, parse_addon },
{ NULL, 0, NULL } /* Must be last */
};

View File

@@ -53,6 +53,7 @@ typedef enum
token_version,
token_bct_file,
token_addon,
token_nand_params,
token_sdmmc_params,
token_spiflash_params,
token_data_width,
@@ -60,6 +61,10 @@ typedef enum
token_clock_source,
token_read_command_type_fast,
token_max_power_class_supported,
token_nand_timing2,
token_nand_timing,
token_block_size_log2,
token_page_size_log2,
token_force32 = 0x7fffffff
} parse_token;

26
set.c
View File

@@ -371,6 +371,32 @@ update_num_param_sets(build_image_context *context, u_int32_t index)
SET_VALUE(num_param_sets, num_params);
}
/*
* set_nand_param(): Processes commands to set Nand parameters.
*/
int
set_nand_param(build_image_context *context,
u_int32_t index,
parse_token token,
u_int32_t value)
{
assert(context != NULL);
assert(context->bct != NULL);
update_num_param_sets(context, index);
switch (token) {
CASE_DEVICE_VALUE(nand, clock_divider);
CASE_DEVICE_VALUE(nand, nand_timing);
CASE_DEVICE_VALUE(nand, nand_timing2);
CASE_DEVICE_VALUE(nand, block_size_log2);
CASE_DEVICE_VALUE(nand, page_size_log2);
DEFAULT();
}
return 0;
}
/*
* set_sdmmc_param(): Processes commands to set MoviNand parameters.
*/

6
set.h
View File

@@ -70,6 +70,12 @@ set_other_field(build_image_context *context,
int other,
int index);
int
set_nand_param(build_image_context *context,
u_int32_t index,
parse_token token,
u_int32_t value);
int
set_sdmmc_param(build_image_context *context,
u_int32_t index,