layout: Show a warning if no region is included

This seems better than a plain success message for a (probably
accidental) no-op run.

Change-Id: I53b749ce42ecc6c267b6cbe71413d536ec3965c5
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/313
Reviewed-by: Felix Singer <felixsinger@posteo.net>
diff --git a/cli_classic.c b/cli_classic.c
index 26253dc..a49e045 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -567,6 +567,9 @@
 	if (ret)
 		goto out_shutdown;
 
+	if (layout && layout_num_regions_included(layout) == 0)
+		msg_gwarn("Warning: Layout specified but no region included!\n");
+
 	flashprog_layout_set(fill_flash, layout);
 	flashprog_flag_set(fill_flash, FLASHPROG_FLAG_FORCE, force);
 #if CONFIG_INTERNAL == 1
diff --git a/include/layout.h b/include/layout.h
index 356ca25..c64dc01 100644
--- a/include/layout.h
+++ b/include/layout.h
@@ -56,6 +56,7 @@
 
 int register_include_arg(struct layout_include_args **, char *arg);
 int process_include_args(struct flashprog_layout *, const struct layout_include_args *);
+unsigned int layout_num_regions_included(const struct flashprog_layout *);
 void cleanup_include_args(struct layout_include_args **);
 
 const struct romentry *layout_next_included_region(const struct flashprog_layout *, chipoff_t);
diff --git a/layout.c b/layout.c
index ef4ebe9..24e25e7 100644
--- a/layout.c
+++ b/layout.c
@@ -186,6 +186,19 @@
 	return 0;
 }
 
+unsigned int layout_num_regions_included(const struct flashprog_layout *const l)
+{
+	const struct romentry *entry = NULL;
+	unsigned int count = 0;
+
+	while ((entry = layout_next(l, entry))) {
+		if (entry->included)
+			++count;
+	}
+
+	return count;
+}
+
 void cleanup_include_args(struct layout_include_args **args)
 {
 	struct layout_include_args *tmp;