summaryrefslogtreecommitdiff
path: root/rbutil/jztool/src/identify_file.c
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/jztool/src/identify_file.c')
-rw-r--r--rbutil/jztool/src/identify_file.c50
1 files changed, 16 insertions, 34 deletions
diff --git a/rbutil/jztool/src/identify_file.c b/rbutil/jztool/src/identify_file.c
index 3bf4a9ced7..e735075687 100644
--- a/rbutil/jztool/src/identify_file.c
+++ b/rbutil/jztool/src/identify_file.c
@@ -81,6 +81,14 @@ static uint8_t crc7(const uint8_t* buf, size_t len)
81 return crc; 81 return crc;
82} 82}
83 83
84/** \brief Identify a file as an SPL for X1000 CPUs
85 * \param data File data buffer
86 * \param len Length of file
87 * \return JZ_SUCCESS if file looks correct, or one of the following errors
88 * \retval JZ_IDERR_WRONG_SIZE file too small or size doesn't match header
89 * \retval JZ_IDERR_BAD_HEADER missing magic bytes from header
90 * \retval JZ_IDERR_BAD_CHECKSUM CRC7 mismatch
91 */
84int jz_identify_x1000_spl(const void* data, size_t len) 92int jz_identify_x1000_spl(const void* data, size_t len)
85{ 93{
86 /* Use <= check because a header-only file is not really valid, 94 /* Use <= check because a header-only file is not really valid,
@@ -115,6 +123,14 @@ static const struct scramble_model_info {
115 {NULL, 0}, 123 {NULL, 0},
116}; 124};
117 125
126/** \brief Identify a file as a Rockbox `scramble` image
127 * \param data File data buffer
128 * \param len Length of file
129 * \return JZ_SUCCESS if file looks correct, or one of the following errors
130 * \retval JZ_IDERR_WRONG_SIZE file too small to be valid
131 * \retval JZ_IDERR_UNRECOGNIZED_MODEL unsupported/unknown model type
132 * \retval JZ_IDERR_BAD_CHECKSUM checksum mismatch
133 */
118int jz_identify_scramble_image(const void* data, size_t len) 134int jz_identify_scramble_image(const void* data, size_t len)
119{ 135{
120 /* 4 bytes checksum + 4 bytes player model */ 136 /* 4 bytes checksum + 4 bytes player model */
@@ -143,37 +159,3 @@ int jz_identify_scramble_image(const void* data, size_t len)
143 159
144 return JZ_SUCCESS; 160 return JZ_SUCCESS;
145} 161}
146
147int jz_identify_fiiom3k_bootimage(const void* data, size_t len)
148{
149 /* The bootloader image is simply a dump of the first NAND eraseblock,
150 * so it has a fixed 128 KiB size */
151 if(len != 128*1024)
152 return JZ_IDERR_WRONG_SIZE;
153
154 /* We'll verify the embedded SPL, but we have to drag out the correct
155 * length from the header. Length should be more than 12 KiB, due to
156 * limitations of the hardware */
157 const struct x1000_spl_header* spl_header;
158 spl_header = (const struct x1000_spl_header*)data;
159 if(spl_header->length > 12 * 1024)
160 return JZ_IDERR_BAD_HEADER;
161
162 int rc = jz_identify_x1000_spl(data, spl_header->length);
163 if(rc < 0)
164 return rc;
165
166 const uint8_t* dat = (const uint8_t*)data;
167
168 /* Check the partition table is present */
169 if(memcmp(&dat[0x3c00], "nand", 4))
170 return JZ_IDERR_OTHER;
171
172 /* Check first bytes of PDMA firmware. It doesn't change
173 * between OF versions, and Rockbox doesn't modify it. */
174 static const uint8_t pdma_fw[] = {0x54, 0x25, 0x42, 0xb3, 0x70, 0x25, 0x42, 0xb3};
175 if(memcmp(&dat[0x4000], pdma_fw, sizeof(pdma_fw)))
176 return JZ_IDERR_OTHER;
177
178 return JZ_SUCCESS;
179}