@@ -33,7 +33,7 @@ struct installer_handler supported_types[MAX_INSTALLER_HANDLER];
static unsigned long nr_installers = 0;
int register_handler(const char *desc,
- handler installer, void *data)
+ handler installer, HANDLER_MASK mask, void *data)
{
if (nr_installers > MAX_INSTALLER_HANDLER - 1)
@@ -43,6 +43,7 @@ int register_handler(const char *desc,
sizeof(supported_types[nr_installers].desc));
supported_types[nr_installers].installer = installer;
supported_types[nr_installers].data = data;
+ supported_types[nr_installers].mask = mask;
nr_installers++;
return 0;
@@ -63,6 +63,48 @@ static int check_missing_hash(struct imglist *list)
}
#endif
+static int check_handler(struct img_type *item, unsigned int mask, const char *desc)
+{
+ struct installer_handler *hnd;
+
+ hnd = find_handler(item);
+ if (!hnd) {
+ ERROR("feature '%s' required for "
+ "'%s' in %s is absent!",
+ item->type, item->fname,
+ SW_DESCRIPTION_FILENAME);
+ return -EINVAL;
+ }
+
+ if (!(hnd->mask & mask)) {
+ ERROR("feature '%s' is not allowed for "
+ "'%s' in %s is absent!",
+ item->type, desc,
+ SW_DESCRIPTION_FILENAME);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int check_handler_list(struct imglist *list, unsigned int allowedmask,
+ const char *desc)
+{
+ struct img_type *item;
+ int ret;
+ if (!LIST_EMPTY(list)) {
+ LIST_FOREACH(item, list, next)
+ {
+ ret = check_handler(item, allowedmask, desc);
+
+ if (ret < 0)
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
int parse(struct swupdate_cfg *sw, const char *descfile)
{
int ret = -1;
@@ -85,39 +127,26 @@ int parse(struct swupdate_cfg *sw, const char *descfile)
return ret;
}
- struct img_type *item;
- if (!LIST_EMPTY(&sw->scripts)) {
- LIST_FOREACH(item, &sw->scripts, next)
- {
- if (!find_handler(item)) {
- ERROR("feature '%s' required for script "
- "'%s' in %s is absent!",
- item->type, item->fname,
- SW_DESCRIPTION_FILENAME);
- return -1;
- }
- }
- }
- if (!LIST_EMPTY(&sw->images)) {
- LIST_FOREACH(item, &sw->images, next)
- {
- if (!find_handler(item)) {
- ERROR("feature '%s' required for image "
- "'%s' in %s is absent!",
- item->type, item->fname,
- SW_DESCRIPTION_FILENAME);
- return -1;
- }
- }
- }
+ ret = check_handler_list(&sw->scripts, SCRIPT_HANDLER, "scripts");
+ ret |= check_handler_list(&sw->images, IMAGE_HANDLER | FILE_HANDLER,
+ "images / files");
+ ret |= check_handler_list(&sw->partitions, PARTITION_HANDLER,
+ "partitions");
+ if (ret)
+ return -EINVAL;
+
+ /*
+ * Bootloader is slightly different, it has no image
+ * but a list of variables
+ */
struct img_type item_uboot = {.type = "uboot"};
struct img_type item_bootloader = {.type = "bootenv"};
if (!LIST_EMPTY(&sw->bootloader) &&
- (!find_handler(&item_uboot) &&
+ (!find_handler(&item_uboot) &&
!find_handler(&item_bootloader))) {
ERROR("bootloader support absent but %s has bootloader section!",
SW_DESCRIPTION_FILENAME);
- return -1;
+ return -EINVAL;
}
#ifdef CONFIG_SIGNED_IMAGES
@@ -463,7 +463,8 @@ static int l_register_handler( lua_State *L ) {
*l_func_ref = luaL_ref (L, LUA_REGISTRYINDEX);
/* pop the arguments from the stack */
lua_pop (L, 2);
- register_handler(handler_desc,l_handler_wrapper,l_func_ref);
+ register_handler(handler_desc, l_handler_wrapper,
+ ANY_HANDLER, l_func_ref);
return 0;
}
}
@@ -253,12 +253,14 @@ static int install_archive_image(struct img_type *img,
__attribute__((constructor))
void archive_handler(void)
{
- register_handler("archive", install_archive_image, NULL);
+ register_handler("archive", install_archive_image,
+ IMAGE_HANDLER | FILE_HANDLER, NULL);
}
/* This is an alias for the parsers */
__attribute__((constructor))
void untar_handler(void)
{
- register_handler("tar", install_archive_image, NULL);
+ register_handler("tar", install_archive_image,
+ IMAGE_HANDLER | FILE_HANDLER, NULL);
}
@@ -75,10 +75,12 @@ static int install_boot_environment(struct img_type *img,
__attribute__((constructor))
static void uboot_handler(void)
{
- register_handler("uboot", install_boot_environment, NULL);
+ register_handler("uboot", install_boot_environment,
+ BOOTLOADER_HANDLER, NULL);
}
__attribute__((constructor))
static void boot_handler(void)
{
- register_handler("bootloader", install_boot_environment, NULL);
+ register_handler("bootloader", install_boot_environment,
+ BOOTLOADER_HANDLER, NULL);
}
@@ -331,5 +331,6 @@ static int install_flash_hamming_image(struct img_type *img,
__attribute__((constructor))
void flash_1bit_hamming_handler(void)
{
- register_handler("flash-hamming1", install_flash_hamming_image, (void *)1);
+ register_handler("flash-hamming1", install_flash_hamming_image,
+ IMAGE_HANDLER | FILE_HANDLER, (void *)1);
}
@@ -349,5 +349,6 @@ static int install_flash_image(struct img_type *img,
__attribute__((constructor))
void flash_handler(void)
{
- register_handler("flash", install_flash_image, NULL);
+ register_handler("flash", install_flash_image,
+ IMAGE_HANDLER | FILE_HANDLER, NULL);
}
@@ -123,5 +123,5 @@ static int start_lua_script(struct img_type *img, void *data)
__attribute__((constructor))
static void lua_handler(void)
{
- register_handler("lua", start_lua_script, NULL);
+ register_handler("lua", start_lua_script, SCRIPT_HANDLER, NULL);
}
@@ -106,11 +106,13 @@ static int install_raw_file(struct img_type *img,
__attribute__((constructor))
void raw_handler(void)
{
- register_handler("raw", install_raw_image, NULL);
+ register_handler("raw", install_raw_image,
+ IMAGE_HANDLER, NULL);
}
__attribute__((constructor))
void raw_filecopy_handler(void)
{
- register_handler("rawfile", install_raw_file, NULL);
+ register_handler("rawfile", install_raw_file,
+ FILE_HANDLER, NULL);
}
@@ -211,5 +211,6 @@ cleanup:
__attribute__((constructor))
void remote_handler(void)
{
- register_handler("remote", install_remote_image, NULL);
+ register_handler("remote", install_remote_image,
+ IMAGE_HANDLER, NULL);
}
@@ -130,17 +130,20 @@ static int start_postinstall_script(struct img_type *img, void *data)
__attribute__((constructor))
static void shell_handler(void)
{
- register_handler("shellscript", start_shell_script, NULL);
+ register_handler("shellscript", start_shell_script,
+ SCRIPT_HANDLER, NULL);
}
__attribute__((constructor))
static void shell_preinstall_handler(void)
{
- register_handler("preinstall", start_preinstall_script, NULL);
+ register_handler("preinstall", start_preinstall_script,
+ SCRIPT_HANDLER, NULL);
}
__attribute__((constructor))
static void shell_postinstall_handler(void)
{
- register_handler("postinstall", start_postinstall_script, NULL);
+ register_handler("postinstall", start_postinstall_script,
+ SCRIPT_HANDLER, NULL);
}
@@ -251,6 +251,8 @@ static int adjust_volume(struct img_type *cfg,
__attribute__((constructor))
void ubi_handler(void)
{
- register_handler("ubivol", install_ubivol_image, NULL);
- register_handler("ubipartition", adjust_volume, NULL);
+ register_handler("ubivol", install_ubivol_image,
+ IMAGE_HANDLER, NULL);
+ register_handler("ubipartition", adjust_volume,
+ PARTITION_HANDLER, NULL);
}
@@ -29,15 +29,31 @@ typedef enum {
POSTINSTALL
} script_fn ;
+/*
+ * Use enum for mask to easy transfer to LUA
+ * scripts
+ */
+typedef enum {
+ IMAGE_HANDLER = 1,
+ FILE_HANDLER = 2,
+ SCRIPT_HANDLER = 4,
+ BOOTLOADER_HANDLER = 8,
+ PARTITION_HANDLER = 16
+} HANDLER_MASK;
+
+#define ANY_HANDLER (IMAGE_HANDLER | FILE_HANDLER | SCRIPT_HANDLER | \
+ BOOTLOADER_HANDLER | PARTITION_HANDLER)
+
typedef int (*handler)(struct img_type *img, void *data);
struct installer_handler{
char desc[64];
handler installer;
void *data;
+ unsigned int mask;
};
int register_handler(const char *desc,
- handler installer, void *data);
+ handler installer, HANDLER_MASK mask, void *data);
struct installer_handler *find_handler(struct img_type *img);
void print_registered_handlers(void);
Do not allow that handlers thought for a section can be defined in another section of sw-description. Scripts must be defined inside the "scripts" section and cannot be overridden. Up now, scripts could be defined even in the "files" and "images" by overriding the "type" argument. Signed-off-by: Stefano Babic <sbabic@denx.de> --- core/handler.c | 3 +- core/parser.c | 83 ++++++++++++++++++++++++++------------- corelib/lua_interface.c | 3 +- handlers/archive_handler.c | 6 ++- handlers/boot_handler.c | 6 ++- handlers/flash_hamming1_handler.c | 3 +- handlers/flash_handler.c | 3 +- handlers/lua_scripthandler.c | 2 +- handlers/raw_handler.c | 6 ++- handlers/remote_handler.c | 3 +- handlers/shell_scripthandler.c | 9 +++-- handlers/ubivol_handler.c | 6 ++- include/handler.h | 18 ++++++++- 13 files changed, 106 insertions(+), 45 deletions(-)