libubootenv: adapt patches to v0.3.5

https://onedigi.atlassian.net/browse/DEL-8885

Signed-off-by: Gabriel Valcazar <gabriel.valcazar@digi.com>
This commit is contained in:
Gabriel Valcazar 2023-12-26 14:24:34 +01:00
parent 5457c89a9e
commit 148b4974a4
5 changed files with 128 additions and 132 deletions

View File

@ -28,10 +28,10 @@ Signed-off-by: Gabriel Valcazar <gabriel.valcazar@digi.com>
create mode 100644 src/md5.h create mode 100644 src/md5.h
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4b71bc588827..d7e38a12feed 100644 index ababe0f..fb1efa2 100644
--- a/src/CMakeLists.txt --- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt +++ b/src/CMakeLists.txt
@@ -1,6 +1,8 @@ @@ -4,6 +4,8 @@
cmake_minimum_required (VERSION 2.6) cmake_minimum_required (VERSION 2.6)
# Sources and private headers # Sources and private headers
SET(libubootenv_SOURCES SET(libubootenv_SOURCES
@ -42,7 +42,7 @@ index 4b71bc588827..d7e38a12feed 100644
) )
diff --git a/src/caam_keyblob.h b/src/caam_keyblob.h diff --git a/src/caam_keyblob.h b/src/caam_keyblob.h
new file mode 100644 new file mode 100644
index 000000000000..e313e87a3854 index 0000000..e313e87
--- /dev/null --- /dev/null
+++ b/src/caam_keyblob.h +++ b/src/caam_keyblob.h
@@ -0,0 +1,42 @@ @@ -0,0 +1,42 @@
@ -90,7 +90,7 @@ index 000000000000..e313e87a3854
+#endif /* CAAM_KEYBLOB_H */ +#endif /* CAAM_KEYBLOB_H */
diff --git a/src/md5.c b/src/md5.c diff --git a/src/md5.c b/src/md5.c
new file mode 100644 new file mode 100644
index 000000000000..47ae8bf34a4d index 0000000..47ae8bf
--- /dev/null --- /dev/null
+++ b/src/md5.c +++ b/src/md5.c
@@ -0,0 +1,275 @@ @@ -0,0 +1,275 @@
@ -371,7 +371,7 @@ index 000000000000..47ae8bf34a4d
+} +}
diff --git a/src/md5.h b/src/md5.h diff --git a/src/md5.h b/src/md5.h
new file mode 100644 new file mode 100644
index 000000000000..02a9a9d23e34 index 0000000..02a9a9d
--- /dev/null --- /dev/null
+++ b/src/md5.h +++ b/src/md5.h
@@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
@ -400,13 +400,13 @@ index 000000000000..02a9a9d23e34
+ +
+#endif /* _MD5_H */ +#endif /* _MD5_H */
diff --git a/src/uboot_env.c b/src/uboot_env.c diff --git a/src/uboot_env.c b/src/uboot_env.c
index 30c39ebf6fa9..2fd08f5a07db 100644 index ae85c7e..750b736 100644
--- a/src/uboot_env.c --- a/src/uboot_env.c
+++ b/src/uboot_env.c +++ b/src/uboot_env.c
@@ -33,11 +33,21 @@ @@ -34,11 +34,21 @@
#include <sys/wait.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <zlib.h> #include <zlib.h>
#include <yaml.h>
+#include <arpa/inet.h> +#include <arpa/inet.h>
#include <mtd/mtd-user.h> #include <mtd/mtd-user.h>
#include <mtd/ubi-user.h> #include <mtd/ubi-user.h>
@ -425,8 +425,8 @@ index 30c39ebf6fa9..2fd08f5a07db 100644
#define UBI_MAX_VOLUME 128 #define UBI_MAX_VOLUME 128
#define DEVICE_MTD_NAME "/dev/mtd" #define DEVICE_MTD_NAME "/dev/mtd"
@@ -844,6 +854,105 @@ static int set_obsolete_flag(struct uboot_flash_env *dev) @@ -1028,6 +1038,105 @@ const struct uboot_version_info *libuboot_version_info(void)
return ret; return &libinfo;
} }
+static int is_env_encrypted(void) +static int is_env_encrypted(void)
@ -531,7 +531,7 @@ index 30c39ebf6fa9..2fd08f5a07db 100644
int libuboot_env_store(struct uboot_ctx *ctx) int libuboot_env_store(struct uboot_ctx *ctx)
{ {
struct var_entry *entry; struct var_entry *entry;
@@ -919,6 +1028,15 @@ int libuboot_env_store(struct uboot_ctx *ctx) @@ -1103,6 +1212,15 @@ int libuboot_env_store(struct uboot_ctx *ctx)
((struct uboot_env_redund *)image)->flags = flags; ((struct uboot_env_redund *)image)->flags = flags;
} }
@ -547,7 +547,7 @@ index 30c39ebf6fa9..2fd08f5a07db 100644
*(uint32_t *)image = crc32(0, (uint8_t *)data, ctx->size - offsetdata); *(uint32_t *)image = crc32(0, (uint8_t *)data, ctx->size - offsetdata);
copy = ctx->redundant ? (ctx->current ? 0 : 1) : 0; copy = ctx->redundant ? (ctx->current ? 0 : 1) : 0;
@@ -984,6 +1102,13 @@ static int libuboot_load(struct uboot_ctx *ctx) @@ -1167,6 +1285,13 @@ static int libuboot_load(struct uboot_ctx *ctx)
} }
crc = *(uint32_t *)(buf[i] + offsetcrc); crc = *(uint32_t *)(buf[i] + offsetcrc);
dev->crc = crc32(0, (uint8_t *)data, usable_envsize); dev->crc = crc32(0, (uint8_t *)data, usable_envsize);
@ -561,7 +561,7 @@ index 30c39ebf6fa9..2fd08f5a07db 100644
crcenv[i] = dev->crc == crc; crcenv[i] = dev->crc == crc;
if (ctx->redundant) if (ctx->redundant)
dev->flags = *(uint8_t *)(buf[i] + offsetflags); dev->flags = *(uint8_t *)(buf[i] + offsetflags);
@@ -1264,6 +1389,11 @@ int libuboot_read_config(struct uboot_ctx *ctx, const char *config) @@ -1773,6 +1898,11 @@ int libuboot_read_config_ext(struct uboot_ctx **ctxlist, const char *config)
break; break;
} }
} }
@ -573,7 +573,7 @@ index 30c39ebf6fa9..2fd08f5a07db 100644
if (ndev == 0) if (ndev == 0)
retval = -EINVAL; retval = -EINVAL;
@@ -1461,6 +1591,7 @@ int libuboot_initialize(struct uboot_ctx **out, @@ -2042,6 +2172,7 @@ int libuboot_initialize(struct uboot_ctx **out,
return -ENOMEM; return -ENOMEM;
ctx->valid = false; ctx->valid = false;
@ -582,10 +582,10 @@ index 30c39ebf6fa9..2fd08f5a07db 100644
if (ret < 0) { if (ret < 0) {
diff --git a/src/uboot_private.h b/src/uboot_private.h diff --git a/src/uboot_private.h b/src/uboot_private.h
index 4b7a9f9602a6..22c8c14ce8cc 100644 index 40e5446..ee2d305 100644
--- a/src/uboot_private.h --- a/src/uboot_private.h
+++ b/src/uboot_private.h +++ b/src/uboot_private.h
@@ -111,10 +111,14 @@ LIST_HEAD(vars, var_entry); @@ -114,10 +114,14 @@ LIST_HEAD(vars, var_entry);
struct uboot_ctx { struct uboot_ctx {
/** true if the environment is redundant */ /** true if the environment is redundant */
bool redundant; bool redundant;

View File

@ -18,10 +18,10 @@ Signed-off-by: Gabriel Valcazar <gabriel.valcazar@digi.com>
2 files changed, 119 insertions(+) 2 files changed, 119 insertions(+)
diff --git a/src/libuboot.h b/src/libuboot.h diff --git a/src/libuboot.h b/src/libuboot.h
index bfcaeb1d609f..b15969f89174 100644 index 3ed3244..e83b3a5 100644
--- a/src/libuboot.h --- a/src/libuboot.h
+++ b/src/libuboot.h +++ b/src/libuboot.h
@@ -159,6 +159,29 @@ const char *libuboot_getname(void *entry); @@ -201,6 +201,29 @@ const char *libuboot_getname(void *entry);
*/ */
const char *libuboot_getvalue(void *entry); const char *libuboot_getvalue(void *entry);
@ -52,11 +52,11 @@ index bfcaeb1d609f..b15969f89174 100644
} }
#endif #endif
diff --git a/src/uboot_env.c b/src/uboot_env.c diff --git a/src/uboot_env.c b/src/uboot_env.c
index 2fd08f5a07db..87f831b0cdc7 100644 index 750b736..b7ad4c4 100644
--- a/src/uboot_env.c --- a/src/uboot_env.c
+++ b/src/uboot_env.c +++ b/src/uboot_env.c
@@ -1632,3 +1632,99 @@ void libuboot_close(struct uboot_ctx *ctx) { @@ -2234,3 +2234,99 @@ void libuboot_exit(struct uboot_ctx *ctx)
void libuboot_exit(struct uboot_ctx *ctx) {
free(ctx); free(ctx);
} }
+ +

View File

@ -27,10 +27,10 @@ Signed-off-by: Gabriel Valcazar <gabriel.valcazar@digi.com>
2 files changed, 90 insertions(+), 2 deletions(-) 2 files changed, 90 insertions(+), 2 deletions(-)
diff --git a/src/uboot_env.c b/src/uboot_env.c diff --git a/src/uboot_env.c b/src/uboot_env.c
index 87f831b0cdc7..539e22f9a8ac 100644 index b7ad4c4..924a6cf 100644
--- a/src/uboot_env.c --- a/src/uboot_env.c
+++ b/src/uboot_env.c +++ b/src/uboot_env.c
@@ -431,6 +431,73 @@ static int check_env_device(struct uboot_ctx *ctx, struct uboot_flash_env *dev) @@ -591,6 +591,73 @@ static int check_env_device(struct uboot_flash_env *dev)
return 0; return 0;
} }
@ -104,7 +104,7 @@ index 87f831b0cdc7..539e22f9a8ac 100644
static bool check_compatible_devices(struct uboot_ctx *ctx) static bool check_compatible_devices(struct uboot_ctx *ctx)
{ {
if (!ctx->redundant) if (!ctx->redundant)
@@ -442,6 +509,12 @@ static bool check_compatible_devices(struct uboot_ctx *ctx) @@ -602,6 +669,12 @@ static bool check_compatible_devices(struct uboot_ctx *ctx)
return false; return false;
if (ctx->envdevs[0].envsize != ctx->envdevs[1].envsize) if (ctx->envdevs[0].envsize != ctx->envdevs[1].envsize)
return false; return false;
@ -117,7 +117,7 @@ index 87f831b0cdc7..539e22f9a8ac 100644
return true; return true;
} }
@@ -488,7 +561,7 @@ static int fileread(struct uboot_flash_env *dev, void *data) @@ -648,7 +721,7 @@ static int fileread(struct uboot_flash_env *dev, void *data)
return ret; return ret;
} }
@ -126,7 +126,7 @@ index 87f831b0cdc7..539e22f9a8ac 100644
{ {
size_t count; size_t count;
size_t blocksize; size_t blocksize;
@@ -507,6 +580,17 @@ static int mtdread(struct uboot_flash_env *dev, void *data) @@ -667,6 +740,17 @@ static int mtdread(struct uboot_flash_env *dev, void *data)
ret = read(dev->fd, data, dev->envsize); ret = read(dev->fd, data, dev->envsize);
break; break;
case MTD_NANDFLASH: case MTD_NANDFLASH:
@ -144,7 +144,7 @@ index 87f831b0cdc7..539e22f9a8ac 100644
if (dev->offset) if (dev->offset)
if (lseek(dev->fd, dev->offset, SEEK_SET) < 0) { if (lseek(dev->fd, dev->offset, SEEK_SET) < 0) {
ret = -EIO; ret = -EIO;
@@ -582,7 +666,7 @@ static int devread(struct uboot_ctx *ctx, unsigned int copy, void *data) @@ -742,7 +826,7 @@ static int devread(struct uboot_ctx *ctx, unsigned int copy, void *data)
ret = fileread(dev, data); ret = fileread(dev, data);
break; break;
case DEVICE_MTD: case DEVICE_MTD:
@ -154,10 +154,10 @@ index 87f831b0cdc7..539e22f9a8ac 100644
case DEVICE_UBI: case DEVICE_UBI:
ret = ubiread(dev, data); ret = ubiread(dev, data);
diff --git a/src/uboot_private.h b/src/uboot_private.h diff --git a/src/uboot_private.h b/src/uboot_private.h
index 22c8c14ce8cc..591df20d6936 100644 index ee2d305..84bd1bc 100644
--- a/src/uboot_private.h --- a/src/uboot_private.h
+++ b/src/uboot_private.h +++ b/src/uboot_private.h
@@ -113,10 +113,14 @@ struct uboot_ctx { @@ -116,10 +116,14 @@ struct uboot_ctx {
bool redundant; bool redundant;
/** true if the environment is encrypted */ /** true if the environment is encrypted */
bool encrypted; bool encrypted;

View File

@ -21,10 +21,10 @@ https://onedigi.atlassian.net/browse/DEL-8444
1 file changed, 52 insertions(+), 2 deletions(-) 1 file changed, 52 insertions(+), 2 deletions(-)
diff --git a/src/uboot_env.c b/src/uboot_env.c diff --git a/src/uboot_env.c b/src/uboot_env.c
index 539e22f9a8ac..86f9b9ebfec2 100644 index 924a6cf..d507cac 100644
--- a/src/uboot_env.c --- a/src/uboot_env.c
+++ b/src/uboot_env.c +++ b/src/uboot_env.c
@@ -945,6 +945,32 @@ static int is_env_encrypted(void) @@ -1129,6 +1129,32 @@ static int is_env_encrypted(void)
return access(dt_prop, F_OK) != -1; return access(dt_prop, F_OK) != -1;
} }
@ -57,7 +57,7 @@ index 539e22f9a8ac..86f9b9ebfec2 100644
#define MAX_HWID_WORDS 4 #define MAX_HWID_WORDS 4
static int env_caam_get_keymod(unsigned char output[16]) static int env_caam_get_keymod(unsigned char output[16])
{ {
@@ -953,12 +979,11 @@ static int env_caam_get_keymod(unsigned char output[16]) @@ -1137,12 +1163,11 @@ static int env_caam_get_keymod(unsigned char output[16])
int fd; int fd;
uint32_t ocotp_hwid[MAX_HWID_WORDS]; uint32_t ocotp_hwid[MAX_HWID_WORDS];
char dt_prop[32]; char dt_prop[32];
@ -71,7 +71,7 @@ index 539e22f9a8ac..86f9b9ebfec2 100644
fd = open(dt_prop, O_RDONLY); fd = open(dt_prop, O_RDONLY);
if (fd < 0) if (fd < 0)
return fd; return fd;
@@ -969,6 +994,31 @@ static int env_caam_get_keymod(unsigned char output[16]) @@ -1153,6 +1178,31 @@ static int env_caam_get_keymod(unsigned char output[16])
} }
ocotp_hwid[i] = ntohl(*(uint32_t *)buf); ocotp_hwid[i] = ntohl(*(uint32_t *)buf);
close(fd); close(fd);

View File

@ -1,4 +1,3 @@
From 768cac09ee47729e3ef38b477c7a69e5b3d10c60 Mon Sep 17 00:00:00 2001
From: Mike Engel <Mike.Engel@digi.com> From: Mike Engel <Mike.Engel@digi.com>
Date: Fri, 26 May 2023 11:21:43 +0200 Date: Fri, 26 May 2023 11:21:43 +0200
Subject: [PATCH] Implement support for environment encryption for CCMP1 Subject: [PATCH] Implement support for environment encryption for CCMP1
@ -32,10 +31,10 @@ Signed-off-by: Mike Engel <Mike.Engel@digi.com>
create mode 100644 src/teec_trace.h create mode 100644 src/teec_trace.h
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d7e38a1..15dad7a 100644 index fb1efa2..04353e9 100644
--- a/src/CMakeLists.txt --- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt +++ b/src/CMakeLists.txt
@@ -1,6 +1,10 @@ @@ -4,6 +4,10 @@
cmake_minimum_required (VERSION 2.6) cmake_minimum_required (VERSION 2.6)
# Sources and private headers # Sources and private headers
SET(libubootenv_SOURCES SET(libubootenv_SOURCES
@ -48,7 +47,7 @@ index d7e38a1..15dad7a 100644
uboot_env.c uboot_env.c
diff --git a/src/ta_ccmp1_aes.h b/src/ta_ccmp1_aes.h diff --git a/src/ta_ccmp1_aes.h b/src/ta_ccmp1_aes.h
new file mode 100644 new file mode 100644
index 0000000..9110cda index 0000000..ceab07d
--- /dev/null --- /dev/null
+++ b/src/ta_ccmp1_aes.h +++ b/src/ta_ccmp1_aes.h
@@ -0,0 +1,84 @@ @@ -0,0 +1,84 @@
@ -2576,10 +2575,10 @@ index 0000000..b1e37ec
+ +
+#endif +#endif
diff --git a/src/uboot_env.c b/src/uboot_env.c diff --git a/src/uboot_env.c b/src/uboot_env.c
index 86f9b9e..45b356f 100644 index d507cac..aa33930 100644
--- a/src/uboot_env.c --- a/src/uboot_env.c
+++ b/src/uboot_env.c +++ b/src/uboot_env.c
@@ -41,6 +41,9 @@ @@ -42,6 +42,9 @@
#include "md5.h" #include "md5.h"
#include "uboot_private.h" #include "uboot_private.h"
@ -2589,7 +2588,7 @@ index 86f9b9e..45b356f 100644
/* /*
* The BLOB includes a random AES-256 key (32 bytes) and a * The BLOB includes a random AES-256 key (32 bytes) and a
* Message Authentication Code (MAC) (16 bytes) * Message Authentication Code (MAC) (16 bytes)
@@ -972,7 +975,7 @@ static bool machine_is_compatible(char *machine) @@ -1156,7 +1159,7 @@ static bool machine_is_compatible(char *machine)
} }
#define MAX_HWID_WORDS 4 #define MAX_HWID_WORDS 4
@ -2598,7 +2597,7 @@ index 86f9b9e..45b356f 100644
{ {
int i; int i;
int len; int len;
@@ -1040,7 +1043,7 @@ static int env_caam_crypt(char *data, unsigned int size, const int enc) @@ -1224,7 +1227,7 @@ static int env_caam_crypt(char *data, unsigned int size, const int enc)
char *buffer; char *buffer;
unsigned char key_modifier[16]; unsigned char key_modifier[16];
@ -2607,7 +2606,7 @@ index 86f9b9e..45b356f 100644
if (ret) if (ret)
return ret; return ret;
@@ -1087,6 +1090,165 @@ free: @@ -1271,6 +1274,165 @@ free:
return ret; return ret;
} }
@ -2773,7 +2772,7 @@ index 86f9b9e..45b356f 100644
int libuboot_env_store(struct uboot_ctx *ctx) int libuboot_env_store(struct uboot_ctx *ctx)
{ {
struct var_entry *entry; struct var_entry *entry;
@@ -1163,7 +1325,12 @@ int libuboot_env_store(struct uboot_ctx *ctx) @@ -1347,7 +1509,12 @@ int libuboot_env_store(struct uboot_ctx *ctx)
} }
if (ctx->encrypted) { if (ctx->encrypted) {
@ -2787,7 +2786,7 @@ index 86f9b9e..45b356f 100644
if (ret) { if (ret) {
fprintf(stderr, fprintf(stderr,
"Error: can't encrypt env for flash\n"); "Error: can't encrypt env for flash\n");
@@ -1237,7 +1404,12 @@ static int libuboot_load(struct uboot_ctx *ctx) @@ -1420,7 +1587,12 @@ static int libuboot_load(struct uboot_ctx *ctx)
crc = *(uint32_t *)(buf[i] + offsetcrc); crc = *(uint32_t *)(buf[i] + offsetcrc);
dev->crc = crc32(0, (uint8_t *)data, usable_envsize); dev->crc = crc32(0, (uint8_t *)data, usable_envsize);
if (ctx->encrypted) { if (ctx->encrypted) {
@ -2801,6 +2800,3 @@ index 86f9b9e..45b356f 100644
if (ret) { if (ret) {
fprintf(stderr, "Error: can't decrypt environment\n"); fprintf(stderr, "Error: can't decrypt environment\n");
return ret; return ret;
--
2.34.1