boot_serial: Allow direct image upload

The commit provides support for "image" parameter in mcumgr image
update frame, that is used to select image number to be updated;
for the purpose, the option MCUBOOT_SERIAL_DIRECT_IMAGE_UPLOAD
that enables the feature.
Platform that enables the feature needs, to provide an implementation
of the flash_area_id_from_direct_image function that will match
the image number to flash area to upload to.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
diff --git a/boot/boot_serial/src/boot_serial.c b/boot/boot_serial/src/boot_serial.c
index baff764..8168d93 100644
--- a/boot/boot_serial/src/boot_serial.c
+++ b/boot/boot_serial/src/boot_serial.c
@@ -288,7 +288,11 @@
         goto out_invalid_data;
     }
 
+#if !defined(MCUBOOT_SERIAL_DIRECT_IMAGE_UPLOAD)
     rc = flash_area_open(flash_area_id_from_multi_image_slot(img_num, 0), &fap);
+#else
+    rc = flash_area_open(flash_area_id_from_direct_image(img_num), &fap);
+#endif
     if (rc) {
         rc = MGMT_ERR_EINVAL;
         goto out;
diff --git a/boot/boot_serial/src/boot_serial_priv.h b/boot/boot_serial/src/boot_serial_priv.h
index f17a2fc..5e0211c 100644
--- a/boot/boot_serial/src/boot_serial_priv.h
+++ b/boot/boot_serial/src/boot_serial_priv.h
@@ -69,6 +69,19 @@
 void boot_serial_input(char *buf, int len);
 extern const struct boot_uart_funcs *boot_uf;
 
+/**
+ * @brief Selects direct image to upload according to the "image"
+ * parameter of the mcumgr update frame.
+ *
+ * @param[in] image_id  the value of the "image" parameter of the
+ *                      mcumgr update frame to be translated.
+ *
+ * @return flash area ID for the image if defined;
+ *         -EINVAL when flash area for given image number has not been
+ *         defined.
+ */
+extern int flash_area_id_from_direct_image(int image_id);
+
 #ifdef __cplusplus
 }
 #endif