summaryrefslogtreecommitdiffstats
path: root/scripts/rkimage.c
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/rkimage.c')
-rw-r--r--scripts/rkimage.c93
1 files changed, 17 insertions, 76 deletions
diff --git a/scripts/rkimage.c b/scripts/rkimage.c
index dde9724886..551114ed82 100644
--- a/scripts/rkimage.c
+++ b/scripts/rkimage.c
@@ -9,62 +9,39 @@
#include <stdint.h>
#include <string.h>
#include <time.h>
-#include <openssl/sha.h>
+#include <openssl/evp.h>
#include <errno.h>
#include <stdbool.h>
+#include "common.h"
+#include "common.c"
+#include "rockchip.h"
+
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
static void sha256(const void *buf, int len, void *out)
{
- SHA256_CTX sha256;
+ EVP_MD_CTX *md_ctx;
- SHA256_Init(&sha256);
- SHA256_Update(&sha256, buf, len);
- SHA256_Final(out, &sha256);
+ md_ctx = EVP_MD_CTX_new();
+ EVP_DigestInit(md_ctx, EVP_sha256());
+ EVP_DigestUpdate(md_ctx, buf, len);
+ EVP_DigestFinal(md_ctx, out, NULL);
+ EVP_MD_CTX_free(md_ctx);
}
static void sha512(const void *buf, int len, void *out)
{
- SHA512_CTX sha512;
+ EVP_MD_CTX *md_ctx;
- SHA512_Init(&sha512);
- SHA512_Update(&sha512, buf, len);
- SHA512_Final(out, &sha512);
+ md_ctx = EVP_MD_CTX_new();
+ EVP_DigestInit(md_ctx, EVP_sha512());
+ EVP_DigestUpdate(md_ctx, buf, len);
+ EVP_DigestFinal(md_ctx, out, NULL);
+ EVP_MD_CTX_free(md_ctx);
}
-#define NEWIDB_MAGIC 0x534e4b52 /* 'RKNS' */
-
-struct newidb_entry {
- uint32_t sector;
- uint32_t unknown_ffffffff;
- uint32_t unknown1;
- uint32_t image_number;
- unsigned char unknown2[8];
- unsigned char hash[64];
-};
-
-struct newidb {
- uint32_t magic;
- unsigned char unknown1[4];
- uint32_t n_files;
- uint32_t hashtype;
- unsigned char unknown2[8];
- unsigned char unknown3[8];
- unsigned char unknown4[88];
- struct newidb_entry entries[4];
- unsigned char unknown5[40];
- unsigned char unknown6[512];
- unsigned char unknown7[16];
- unsigned char unknown8[32];
- unsigned char unknown9[464];
- unsigned char hash[512];
-};
-
-#define SECTOR_SIZE 512
-#define PAGE_SIZE 2048
-
typedef enum {
HASH_TYPE_SHA256 = 1,
HASH_TYPE_SHA512 = 2,
@@ -149,42 +126,6 @@ static void usage(const char *prgname)
prgname);
}
-static int read_full(int fd, void *buf, size_t size)
-{
- size_t insize = size;
- int now;
- int total = 0;
-
- while (size) {
- now = read(fd, buf, size);
- if (now == 0)
- return total;
- if (now < 0)
- return now;
- total += now;
- size -= now;
- buf += now;
- }
-
- return insize;
-}
-
-static int write_full(int fd, void *buf, size_t size)
-{
- size_t insize = size;
- int now;
-
- while (size) {
- now = write(fd, buf, size);
- if (now <= 0)
- return now;
- size -= now;
- buf += now;
- }
-
- return insize;
-}
-
int main(int argc, char *argv[])
{
int opt, i, fd;