summaryrefslogtreecommitdiffstats
path: root/utils/imxtools/sbtools
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2012-12-16 21:07:31 +0100
committerAmaury Pouly <amaury.pouly@gmail.com>2012-12-16 21:28:41 +0100
commit212cfdf771dc0059804cf817caaf2e43ef2b3f50 (patch)
tree48606c29d82efb075fff71789155719cab3dd6da /utils/imxtools/sbtools
parentf4f600fc52d38e4a287913050880647144d1873c (diff)
downloadrockbox-212cfdf771dc0059804cf817caaf2e43ef2b3f50.tar.gz
rockbox-212cfdf771dc0059804cf817caaf2e43ef2b3f50.tar.bz2
rockbox-212cfdf771dc0059804cf817caaf2e43ef2b3f50.zip
imxtools/sbtools: fix some instruction handling & crypto
Change-Id: I6530bdf27896d8325dec4e2ba31c7e6a0131a286
Diffstat (limited to 'utils/imxtools/sbtools')
-rw-r--r--utils/imxtools/sbtools/sb1.c20
-rw-r--r--utils/imxtools/sbtools/sb1.h5
2 files changed, 17 insertions, 8 deletions
diff --git a/utils/imxtools/sbtools/sb1.c b/utils/imxtools/sbtools/sb1.c
index 576196d5bd..6149ef37c2 100644
--- a/utils/imxtools/sbtools/sb1.c
+++ b/utils/imxtools/sbtools/sb1.c
@@ -59,6 +59,8 @@ static void fix_version(struct sb1_version_t *ver)
enum sb1_error_t sb1_write_file(struct sb1_file_t *sb, const char *filename)
{
+ if(sb->key.method != CRYPTO_XOR_KEY)
+ return SB1_NO_VALID_KEY;
/* compute image size (without userdata) */
uint32_t image_size = 0;
image_size += sizeof(struct sb1_header_t);
@@ -104,6 +106,7 @@ enum sb1_error_t sb1_write_file(struct sb1_file_t *sb, const char *filename)
for(int i = 0; i < sb->nr_insts; i++)
{
int bytes = 0;
+ int size = 0;
switch(sb->insts[i].cmd)
{
case SB1_INST_LOAD:
@@ -114,7 +117,8 @@ enum sb1_error_t sb1_write_file(struct sb1_file_t *sb, const char *filename)
bytes - sb->insts[i].size);
break;
case SB1_INST_FILL:
- bytes = 4;
+ bytes = sb->insts[i].size;
+ size = 2;
memcpy(cmd + 1, &sb->insts[i].pattern, 4);
cmd->addr = sb->insts[i].addr;
break;
@@ -125,7 +129,7 @@ enum sb1_error_t sb1_write_file(struct sb1_file_t *sb, const char *filename)
memcpy(cmd + 1, &sb->insts[i].argument, 4);
break;
case SB1_INST_MODE:
- bytes = 4;
+ bytes = 0;
cmd->addr = sb->insts[i].mode;
break;
case SB1_INST_SDRAM:
@@ -137,11 +141,15 @@ enum sb1_error_t sb1_write_file(struct sb1_file_t *sb, const char *filename)
bugp("Unknown SB instruction: %#x\n", sb->insts[i].cmd);
}
+ /* handle most common cases */
+ if(size == 0)
+ size = ROUND_UP(bytes, 4) / 4 + 1;
+
cmd->cmd = SB1_MK_CMD(sb->insts[i].cmd, sb->insts[i].datatype,
bytes, sb->insts[i].critical,
- ROUND_UP(bytes, 4) / 4 + 1);
+ size);
- cmd = (void *)cmd + 8 + ROUND_UP(bytes, 4);
+ cmd = (void *)cmd + 4 + size * 4;
}
/* move everything to prepare crypto marks (start at the end !) */
@@ -149,7 +157,7 @@ enum sb1_error_t sb1_write_file(struct sb1_file_t *sb, const char *filename)
memmove(buf + i * SECTOR_SIZE, buf + i * (SECTOR_SIZE - 4), SECTOR_SIZE - 4);
union xorcrypt_key_t key[2];
- memcpy(key, sb->key, sizeof(sb->key));
+ memcpy(key, sb->key.u.xor_key, sizeof(sb->key));
void *ptr = header + 1;
int offset = header->header_size;
for(unsigned i = 0; i < image_size / SECTOR_SIZE; i++)
@@ -354,7 +362,7 @@ struct sb1_file_t *sb1_read_memory(void *_buf, size_t filesize, void *u,
}
}
- memcpy(file->key, key, sizeof(key));
+ memcpy(file->key.u.xor_key, key, sizeof(key));
if(!valid_key)
fatal(SB1_NO_VALID_KEY, "No valid key found\n");
diff --git a/utils/imxtools/sbtools/sb1.h b/utils/imxtools/sbtools/sb1.h
index 0a0c9fe69c..1ee28978e1 100644
--- a/utils/imxtools/sbtools/sb1.h
+++ b/utils/imxtools/sbtools/sb1.h
@@ -58,7 +58,8 @@ struct sb1_cmd_header_t
uint32_t addr;
} __attribute__((packed));
-#define SB1_CMD_MAX_SIZE 0x1ff8
+#define SB1_CMD_MAX_LOAD_SIZE 0x1ff8
+#define SB1_CMD_MAX_FILL_SIZE 0x3fff
#define SB1_CMD_SIZE(cmd) ((cmd) >> 21)
#define SB1_CMD_CRITICAL(cmd) !!(cmd & (1 << 20))
@@ -125,7 +126,7 @@ struct sb1_file_t
struct sb1_inst_t *insts;
void *userdata;
int userdata_size;
- union xorcrypt_key_t key[2];
+ struct crypto_key_t key;
};
enum sb1_error_t