[opentitantool]: Adapt heuristics for Ti50 images

As part of the "rescue" protocol for Ti50 updates, OpenTitan tool needs
to recognize the "RW" part of the given image file.  This is done
through heuristics that recognize the header of each section, and
relying on the order in which sections appear.

Recent images happen to have the header signature in more places in the
image, causing mis-identification of the RW section.  This CL improves
the heuristics.

Signed-off-by: Jes B. Klinke <jbk@chromium.org>
Change-Id: I3f9e0003ecf71b3967d25af88db962b87d041b0f
diff --git a/sw/host/opentitanlib/src/bootstrap/rescue.rs b/sw/host/opentitanlib/src/bootstrap/rescue.rs
index ddf4198..8739b4c 100644
--- a/sw/host/opentitanlib/src/bootstrap/rescue.rs
+++ b/sw/host/opentitanlib/src/bootstrap/rescue.rs
@@ -46,6 +46,7 @@
     const FLASH_BUFFER_MASK: usize = Self::FLASH_BUFFER_SIZE - 1;
     const DATA_LEN: usize = 1024 - std::mem::size_of::<FrameHeader>();
     const HASH_LEN: usize = 32;
+    const HEADER_ALIGNMENT: usize = 0x1000;
     const MAGIC_HEADER: [u8; 4] = [0xfd, 0xff, 0xff, 0xff];
     const CRYPTOLIB_TELL: [u8; 4] = [0x53, 0x53, 0x53, 0x53];
 
@@ -85,20 +86,20 @@
 
         // Find second occurrence of magic value, not followed by signature of encrypted
         // cryptolib.
-        let min_addr = match payload[256..]
-            .chunks(256)
+        let min_addr = match payload[Self::HEADER_ALIGNMENT..]
+            .chunks(Self::HEADER_ALIGNMENT)
             .position(|c| &c[0..4] == &Self::MAGIC_HEADER && &c[4..8] != &Self::CRYPTOLIB_TELL)
         {
-            Some(n) => (n + 1) * 256,
+            Some(n) => (n + 1) * Self::HEADER_ALIGNMENT,
             None => bail!(RescueError::ImageFormatError),
         };
 
         // Find third occurrence of magic value.
-        let max_addr = match payload[min_addr + 256..]
-            .chunks(256)
+        let max_addr = match payload[min_addr + Self::HEADER_ALIGNMENT..]
+            .chunks(Self::HEADER_ALIGNMENT)
             .position(|c| &c[0..4] == &Self::MAGIC_HEADER)
         {
-            Some(n) => (n + 1) * 256 + min_addr,
+            Some(n) => (n + 1) * Self::HEADER_ALIGNMENT + min_addr,
             None => payload.len(),
         };