return -1;
}
- ret = rom_add(rom, name, buffer, size, type);
+ ret = rom_add(rom, name, buffer, 0, size, type);
free(buffer);
return ret;
}
static int add_blob(struct rom *rom, const char *filename,
- const char *name, int type)
+ const char *name, unsigned long address, int type)
{
void *ptr;
struct stat s;
return -1;
}
- ret = rom_add(rom, name, ptr, s.st_size, type);
+ ret = rom_add(rom, name, ptr, address, s.st_size, type);
munmap(ptr, s.st_size);
close(fd);
void add_usage(void)
{
- printf("add [FILE] [NAME] [TYPE]\tAdd a component\n");
+ printf("add FILE NAME TYPE [base address]\tAdd a component\n");
}
void add_stage_usage(void)
{
- printf("add-stage [FILE] [NAME] [OPTIONS]\tAdd a stage to the ROM\n");
+ printf("add-stage FILE NAME [OPTIONS]\tAdd a stage to the ROM\n");
}
void add_payload_usage(void)
{
printf
- ("add-payload [FILE] [NAME] [OPTIONS]\tAdd a payload to the ROM\n");
+ ("add-payload FILE NAME [OPTIONS]\tAdd a payload to the ROM\n");
+}
+
+int select_component_type(char *s)
+{
+ int i = 0;
+ char *accepted_strings[] = {
+ "stage",
+ "payload",
+ "optionrom",
+ "deleted",
+ "free",
+ };
+ for (i=0; i < 5; i++)
+ if (!strcmp(s, accepted_strings[i]))
+ return i;
+ return -1;
}
int add_handler(struct rom *rom, int argc, char **argv)
{
unsigned int type = CBFS_COMPONENT_NULL;
+ unsigned long address = 0;
- if (argc < 2) {
+ if ((argc < 3) || (argc > 4)) {
add_usage();
return -1;
}
+ if (argc > 3) {
+ address = strtoul(argv[3], 0, 0);
+ }
+
if (!rom_exists(rom)) {
ERROR("You need to create the ROM before adding files to it\n");
return -1;
}
+ int component_type;
+
/* There are two ways to specify the type - a string or a number */
- if (argc == 3) {
- if (isdigit(*(argv[2])))
- type = strtoul(argv[2], 0, 0);
+ if (isdigit(*(argv[2])))
+ type = strtoul(argv[2], 0, 0);
+ else {
+ switch( component_type = select_component_type(argv[2])) {
+ case 0:
+ type = CBFS_COMPONENT_STAGE;
+ break;
+ case 1:
+ type = CBFS_COMPONENT_PAYLOAD;
+ break;
+ case 2:
+ type = CBFS_COMPONENT_OPTIONROM;
+ break;
+ case 3:
+ type = CBFS_COMPONENT_DELETED;
+ break;
+ case 4:
+ type = CBFS_COMPONENT_NULL;
+ break;
+ default:
+ ERROR("Unrecognized component type %s.\nValid options are: stage, payload, optionrom, deleted, free.\n", argv[2]);
+ return -1;
+ }
}
- if (type == CBFS_COMPONENT_NULL)
- WARN("No file type was given for %s - using default\n",
- argv[0]);
-
- return add_blob(rom, argv[0], argv[1], type);
+ return add_blob(rom, argv[0], argv[1], address, type);
}
char *find_tool(char *tool)
return toolpath;
}
-/* Invoke the rom-mkpayload utility */
+/* Invoke the cbfs-mkpayload utility */
int add_payload_handler(struct rom *rom, int argc, char **argv)
{
return -1;
}
- return fork_tool_and_add(rom, find_tool("rom-mkpayload"), argv[0],
+ return fork_tool_and_add(rom, find_tool("cbfs-mkpayload"), argv[0],
argv[1], CBFS_COMPONENT_PAYLOAD, argc - 2,
argc > 2 ? &argv[2] : NULL);
}
-/* Invoke the rom-mkstage utility */
+/* Invoke the cbfs-mkstage utility */
int add_stage_handler(struct rom *rom, int argc, char **argv)
{
return -1;
}
- return fork_tool_and_add(rom, find_tool("rom-mkstage"), argv[0],
+ return fork_tool_and_add(rom, find_tool("cbfs-mkstage"), argv[0],
argv[1], CBFS_COMPONENT_STAGE, argc - 2,
argc > 2 ? &argv[2] : NULL);
}