Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Unified Diff: set.c

Issue 6579034: Add the device type/parameters support for cbootimage tool. (Closed) Base URL: http://git.chromium.org/git/cbootimage.git@master
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « set.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: set.c
diff --git a/set.c b/set.c
index 14fe2149a8f05bad9e3da65ee45936e2a157dd9a..e8ea25962432e2e05895ab418623397ca166b0b6 100644
--- a/set.c
+++ b/set.c
@@ -24,6 +24,7 @@
* set.c - State setting support for the cbootimage tool
*/
+#include <math.h>
#include "set.h"
#include "cbootimage.h"
#include "crypto.h"
@@ -39,6 +40,22 @@
* A SetXXX() function may not call any parseing functions.
*/
+#define NV_MAX(a, b) (((a) > (b)) ? (a) : (b))
+
+#define CASE_DEVICE_VALUE(prefix, id) \
+ case token_##id: \
+ (void)context->bctlib.setdev_param(index, \
+ nvbct_lib_id_##prefix##_##id, \
+ value, \
+ context->bct); \
+ break
+
+#define DEFAULT() \
+ default: \
+ printf("Unexpected token %d at line %d\n", \
+ token, __LINE__); \
+ return 1
+
int
read_from_image(char *filename,
u_int32_t page_size,
@@ -59,7 +76,7 @@ read_from_image(char *filename,
if (stat(filename, &stats) != 0) {
printf("Error: Unable to query info on bootloader path %s\n",
- filename);
+ filename);
result = 1;
goto cleanup;
}
@@ -147,7 +164,14 @@ context_set_array(build_image_context *context,
context->bct);
break;
- DEFAULT();
+ case token_dev_type:
+ (void)context->bctlib.setdev_param(index,
+ nvbct_lib_id_dev_type,
+ value,
+ context->bct);
+ break;
+
+ DEFAULT();
}
return 0;
}
@@ -166,8 +190,41 @@ int context_set_value(build_image_context *context,
context->newbl_attr = value;
break;
+ case token_block_size:
+ context->block_size = value;
+ context->block_size_log2 = log2(value);
+
+ if (context->memory != NULL) {
+ printf("Error: Too late to change block size.\n");
+ return 1;
+ }
+
+ if (value != (u_int32_t)(1 << context->block_size_log2)) {
+ printf("Error: Block size must be a power of 2.\n");
+ return 1;
+ }
+ context->pages_per_blk= 1 << (context->block_size_log2-
+ context->page_size_log2);
+ SET_VALUE(block_size_log2, context->block_size_log2);
+ break;
+
+ case token_partition_size:
+ if (context->memory != NULL) {
+ printf("Error: Too late to change block size.\n");
+ return 1;
+ }
+
+ context->partition_size= value;
+ SET_VALUE(partition_size, value);
+ break;
+
case token_page_size:
context->page_size = value;
+ context->page_size_log2 = log2(value);
+ context->pages_per_blk= 1 << (context->block_size_log2-
+ context->page_size_log2);
+
+ SET_VALUE(page_size_log2, context->page_size_log2);
break;
case token_redundancy:
context->redundancy = value;
@@ -304,3 +361,60 @@ set_other_field(build_image_context *context,
}
+static void
+update_num_param_sets(build_image_context *context, u_int32_t index)
+{
+ u_int32_t num_params;
+
+ GET_VALUE(num_param_sets, &num_params);
+ num_params = NV_MAX(num_params, index + 1);
+ SET_VALUE(num_param_sets, num_params);
+}
+
+/*
+ * set_sdmmc_param(): Processes commands to set MoviNand parameters.
+ */
+int
+set_sdmmc_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(sdmmc, clock_divider);
+ CASE_DEVICE_VALUE(sdmmc, data_width);
+ CASE_DEVICE_VALUE(sdmmc, max_power_class_supported);
+ DEFAULT();
+ }
+
+ return 0;
+}
+
+/*
+ * set_spiflash_param(): Processes commands to set SpiFlash parameters.
+ */
+int
+set_spiflash_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(spiflash, clock_divider);
+ CASE_DEVICE_VALUE(spiflash, clock_source);
+ CASE_DEVICE_VALUE(spiflash, read_command_type_fast);
+ DEFAULT();
+ }
+
+ return 0;
+}
« no previous file with comments | « set.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698