CC312: Allow OTP reads to be more flexible

Allow partial reads of OTP items. Also, fix a minor bug with reading and
writing larger OTP items.

Change-Id: I3e037dbff1e59e9c0b0df347b350de0fffdb2a57
Signed-off-by: Raef Coles <raef.coles@arm.com>
diff --git a/platform/ext/common/template/otp_flash.c b/platform/ext/common/template/otp_flash.c
index 56ffce7..df630f4 100644
--- a/platform/ext/common/template/otp_flash.c
+++ b/platform/ext/common/template/otp_flash.c
@@ -125,14 +125,16 @@
         return err;
     }
 
-    copy_size = in_len < value_size ? in_len : value_size;
+    if (in_len > value_size) {
+        return TFM_PLAT_ERR_INVALID_INPUT;
+    }
 
-    err = read_otp_nv_counters_flash(offset, buffer, copy_size);
+    err = read_otp_nv_counters_flash(offset, buffer, in_len);
     if (err != TFM_PLAT_ERR_SUCCESS) {
         return err;
     }
 
-    for (idx = 0; idx < copy_size; idx++) {
+    for (idx = 0; idx < in_len; idx++) {
         if ((buffer[idx] | in[idx]) != in[idx]) {
             return TFM_PLAT_ERR_INVALID_INPUT;
         }
@@ -140,7 +142,7 @@
         buffer[idx] |= in[idx];
     }
 
-    err = write_otp_nv_counters_flash(offset, buffer, copy_size);
+    err = write_otp_nv_counters_flash(offset, buffer, in_len);
     if (err != TFM_PLAT_ERR_SUCCESS) {
         return err;
     }