You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2023/01/06 15:25:33 UTC

[GitHub] [nuttx] acassis commented on a diff in pull request #8048: xtensa/esp32: ESP32 SPI Flash encryption supports 16-bytes align writing

acassis commented on code in PR #8048:
URL: https://github.com/apache/nuttx/pull/8048#discussion_r1063530118


##########
arch/xtensa/src/esp32/esp32_spiflash.c:
##########
@@ -1854,7 +1875,74 @@ static ssize_t esp32_bwrite_encrypt(struct mtd_dev_s *dev,
       return ret;
     }
 
-  ret = esp32_writedata_encrypted(priv, addr, buffer, size);
+  while (nbytes)
+    {
+      if (offset % SPI_FLASH_ENCRYPT_UNIT_SIZE)
+        {
+          wbuf = tmp_buf;
+          rbuf = tmp_buf;
+          addr = offset - SPI_FLASH_ENCRYPT_MIN_SIZE;
+
+          n = SPI_FLASH_ENCRYPT_MIN_SIZE;
+
+          ret = esp32_readdata_encrypted(priv, addr, rbuf, n);
+          if (ret < 0)
+            {
+              break;
+            }
+
+          memcpy(wbuf + n, buffer, n);
+        }
+      else if (nbytes % SPI_FLASH_ENCRYPT_UNIT_SIZE)
+        {
+          wbuf = tmp_buf;
+          if (offset % SPI_FLASH_ENCRYPT_UNIT_SIZE)
+            {
+              rbuf = tmp_buf;
+              addr = offset - SPI_FLASH_ENCRYPT_MIN_SIZE;
+            }
+          else
+            {
+              rbuf = tmp_buf + SPI_FLASH_ENCRYPT_MIN_SIZE;
+              addr = offset;
+            }
+
+          n = SPI_FLASH_ENCRYPT_MIN_SIZE;
+
+          ret = esp32_readdata_encrypted(priv, addr, rbuf, n);
+          if (ret < 0)
+            {
+              break;
+            }
+
+          if (offset % SPI_FLASH_ENCRYPT_UNIT_SIZE)
+            {
+              memcpy(wbuf + n, buffer, n);
+            }
+          else
+            {
+              memcpy(wbuf, buffer, n);
+            }
+        }
+      else
+        {
+          n = SPI_FLASH_ENCRYPT_UNIT_SIZE;
+          wbuf = (uint8_t *)buffer;
+          addr = offset;
+        }
+
+      ret = esp32_writedata_encrypted(priv, addr, wbuf,
+                                      SPI_FLASH_ENCRYPT_UNIT_SIZE);
+      if (ret < 0)
+        {
+          break;

Review Comment:
   Please include a ferr() saying that esp32_writedata_encrypted() failed



##########
arch/xtensa/src/esp32/esp32_spiflash.c:
##########
@@ -1854,7 +1875,74 @@ static ssize_t esp32_bwrite_encrypt(struct mtd_dev_s *dev,
       return ret;
     }
 
-  ret = esp32_writedata_encrypted(priv, addr, buffer, size);
+  while (nbytes)
+    {
+      if (offset % SPI_FLASH_ENCRYPT_UNIT_SIZE)
+        {
+          wbuf = tmp_buf;
+          rbuf = tmp_buf;
+          addr = offset - SPI_FLASH_ENCRYPT_MIN_SIZE;
+
+          n = SPI_FLASH_ENCRYPT_MIN_SIZE;
+
+          ret = esp32_readdata_encrypted(priv, addr, rbuf, n);
+          if (ret < 0)
+            {
+              break;

Review Comment:
   Please include a ferr() saying that esp32_readdata_encrypted() failed



##########
arch/xtensa/src/esp32/esp32_spiflash.c:
##########
@@ -1854,7 +1875,74 @@ static ssize_t esp32_bwrite_encrypt(struct mtd_dev_s *dev,
       return ret;
     }
 
-  ret = esp32_writedata_encrypted(priv, addr, buffer, size);
+  while (nbytes)
+    {
+      if (offset % SPI_FLASH_ENCRYPT_UNIT_SIZE)
+        {
+          wbuf = tmp_buf;
+          rbuf = tmp_buf;
+          addr = offset - SPI_FLASH_ENCRYPT_MIN_SIZE;
+
+          n = SPI_FLASH_ENCRYPT_MIN_SIZE;
+
+          ret = esp32_readdata_encrypted(priv, addr, rbuf, n);
+          if (ret < 0)
+            {
+              break;
+            }
+
+          memcpy(wbuf + n, buffer, n);
+        }
+      else if (nbytes % SPI_FLASH_ENCRYPT_UNIT_SIZE)
+        {
+          wbuf = tmp_buf;
+          if (offset % SPI_FLASH_ENCRYPT_UNIT_SIZE)
+            {
+              rbuf = tmp_buf;
+              addr = offset - SPI_FLASH_ENCRYPT_MIN_SIZE;
+            }
+          else
+            {
+              rbuf = tmp_buf + SPI_FLASH_ENCRYPT_MIN_SIZE;
+              addr = offset;
+            }
+
+          n = SPI_FLASH_ENCRYPT_MIN_SIZE;
+
+          ret = esp32_readdata_encrypted(priv, addr, rbuf, n);
+          if (ret < 0)
+            {
+              break;

Review Comment:
   Please include a ferr() saying that esp32_readdata_encrypted() failed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org