summaryrefslogtreecommitdiffstats
path: root/utils/samsungtools/samsung.c
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2012-12-06 12:16:57 +0100
committerAmaury Pouly <amaury.pouly@gmail.com>2012-12-06 12:17:50 +0100
commitfb43a137e72d1f428efef00047a416497463edfb (patch)
tree5d933a0240418967cf85e17da48949d4ec24748b /utils/samsungtools/samsung.c
parent8666e83aaadfa7f334431da697b82963d649acc6 (diff)
downloadrockbox-fb43a137e72d1f428efef00047a416497463edfb.tar.gz
rockbox-fb43a137e72d1f428efef00047a416497463edfb.tar.bz2
rockbox-fb43a137e72d1f428efef00047a416497463edfb.zip
samsungtool: allow firmware creation
The new tool fwcrypt can create a firmware image with a specified model, version, region and so on. Change-Id: I0e90e9ab905398a3e7ae3f4fb8b8bbfb2d12d703
Diffstat (limited to 'utils/samsungtools/samsung.c')
-rw-r--r--utils/samsungtools/samsung.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/utils/samsungtools/samsung.c b/utils/samsungtools/samsung.c
index decf34f208..2d45b6f068 100644
--- a/utils/samsungtools/samsung.c
+++ b/utils/samsungtools/samsung.c
@@ -117,6 +117,57 @@ struct samsung_firmware_t *samsung_read(samsung_read_t read,
return fw;
}
+enum samsung_error_t samsung_write(samsung_write_t write, samsung_printf_t printf,
+ void *user, struct samsung_firmware_t *fw)
+{
+ struct yp_header_t yp_hdr;
+ struct yp_md5_t yp_md5;
+
+ // write header
+ strncpy(yp_hdr.signature, YP_SIGNATURE, sizeof(yp_hdr.signature));
+ strncpy(yp_hdr.version, fw->version, sizeof(yp_hdr.version));
+ strncpy(yp_hdr.region, fw->region, sizeof(yp_hdr.region));
+ strncpy(yp_hdr.extra, fw->extra, sizeof(yp_hdr.extra));
+ strncpy(yp_hdr.model, fw->model, sizeof(yp_hdr.model));
+ yp_hdr.datasize = fw->data_size;
+
+ printf(user, false, "Model: %s\n", yp_hdr.model);
+ printf(user, false, "Version: %s %s %s\n", yp_hdr.version, yp_hdr.region, yp_hdr.extra);
+
+ if(write(user, 0, &yp_hdr, sizeof(yp_hdr)) != sizeof(yp_hdr))
+ {
+ printf(user, true, "Cannot write header\n");
+ return SAMSUNG_WRITE_ERROR;
+ }
+
+ // encrypt data
+ cyclic_xor(fw->data, fw->data_size, g_yp_key, sizeof(g_yp_key));
+ // compute MD5
+ MD5_CTX c;
+ MD5_Init(&c);
+ MD5_Update(&c, fw->data, fw->data_size);
+ MD5_Final(yp_md5.md5, &c);
+
+ // write data
+ if(write(user, sizeof(yp_hdr), fw->data, fw->data_size) != fw->data_size)
+ {
+ // decrypt data so that the firmware data is the same after the call
+ cyclic_xor(fw->data, fw->data_size, g_yp_key, sizeof(g_yp_key));
+ printf(user, true, "Cannot write data\n");
+ return SAMSUNG_WRITE_ERROR;
+ }
+ // decrypt data so that the firmware data is the same after the call
+ cyclic_xor(fw->data, fw->data_size, g_yp_key, sizeof(g_yp_key));
+ // write md5
+ if(write(user, sizeof(yp_hdr) + fw->data_size, &yp_md5, sizeof(yp_md5)) != sizeof(yp_md5))
+ {
+ printf(user, true, "Cannot write md5\n");
+ return SAMSUNG_WRITE_ERROR;
+ }
+
+ return SAMSUNG_SUCCESS;
+}
+
void samsung_free(struct samsung_firmware_t *fw)
{
if(fw)