diff --git a/src/barebox-state/backend_format_dtb.c b/src/barebox-state/backend_format_dtb.c index d7b0172..55fa1fc 100644 --- a/src/barebox-state/backend_format_dtb.c +++ b/src/barebox-state/backend_format_dtb.c @@ -40,7 +40,7 @@ static int state_backend_format_dtb_verify(struct state_backend_format *format, uint32_t magic, const void * buf, - ssize_t *lenp) + ssize_t *lenp, enum state_flags flags) { struct state_backend_format_dtb *fdtb = get_format_dtb(format); struct device_node *root; @@ -81,7 +81,7 @@ int ret; if (!fdtb->root) { - state_backend_format_dtb_verify(format, 0, buf, &len); + state_backend_format_dtb_verify(format, 0, buf, &len, 0); } ret = state_from_node(state, fdtb->root, 0); diff --git a/src/barebox-state/backend_format_raw.c b/src/barebox-state/backend_format_raw.c index 43a5523..232856a 100644 --- a/src/barebox-state/backend_format_raw.c +++ b/src/barebox-state/backend_format_raw.c @@ -96,7 +96,7 @@ static int backend_format_raw_verify(struct state_backend_format *format, uint32_t magic, const void * buf, - ssize_t *lenp) + ssize_t *lenp, enum state_flags flags) { uint32_t crc; struct backend_raw_header *header; @@ -127,7 +127,7 @@ return -EINVAL; } - if (backend_raw->algo) { + if (backend_raw->algo && !(flags & STATE_FLAG_NO_AUTHENTIFICATION)) { ret = backend_raw_digest_init(backend_raw); if (ret) return ret; @@ -153,7 +153,7 @@ *lenp = header->data_len + sizeof(*header); - if (backend_raw->algo) { + if (backend_raw->algo && !(flags & STATE_FLAG_NO_AUTHENTIFICATION)) { const void *hmac = data + header->data_len; /* hmac over header and data */ diff --git a/src/barebox-state/backend_storage.c b/src/barebox-state/backend_storage.c index 2edc755..53fe829 100644 --- a/src/barebox-state/backend_storage.c +++ b/src/barebox-state/backend_storage.c @@ -128,6 +128,7 @@ * @param magic state magic value * @param buf The newly allocated data area will be stored in this pointer * @param len The resulting length of the buffer + * @param flags flags controlling how to load state * @return 0 on success, -errno otherwise. buf and len will be set to valid * values on success. * @@ -138,7 +139,8 @@ */ int state_storage_read(struct state_backend_storage *storage, struct state_backend_format *format, - uint32_t magic, void **buf, ssize_t *len) + uint32_t magic, void **buf, ssize_t *len, + enum state_flags flags) { struct state_backend_storage_bucket *bucket, *bucket_used = NULL; int ret; @@ -158,7 +160,7 @@ * Verify the buffer crcs. The buffer length is passed in the len argument, * .verify overwrites it with the length actually used. */ - ret = format->verify(format, magic, bucket->buf, &bucket->len); + ret = format->verify(format, magic, bucket->buf, &bucket->len, flags); if (!ret && !bucket_used) bucket_used = bucket; } diff --git a/src/barebox-state/state.c b/src/barebox-state/state.c index dc26259..8bd3ecb 100644 --- a/src/barebox-state/state.c +++ b/src/barebox-state/state.c @@ -77,14 +77,14 @@ * we read is checked for integrity by the formatter. After that we unpack the * data into our state. */ -int state_load(struct state *state) +static int state_do_load(struct state *state, enum state_flags flags) { void *buf; ssize_t len; int ret; ret = state_storage_read(&state->storage, state->format, - state->magic, &buf, &len); + state->magic, &buf, &len, flags); if (ret) { dev_err(&state->dev, "Failed to read state with format %s, %d\n", state->format->name, ret); @@ -105,6 +105,16 @@ return ret; } +int state_load(struct state *state) +{ + return state_do_load(state, 0); +} + +int state_load_no_auth(struct state *state) +{ + return state_do_load(state, STATE_FLAG_NO_AUTHENTIFICATION); +} + static int state_format_init(struct state *state, const char *backend_format, struct device_node *node, const char *state_name) { diff --git a/src/barebox-state/state.h b/src/barebox-state/state.h index a2737ab..5e240c4 100644 --- a/src/barebox-state/state.h +++ b/src/barebox-state/state.h @@ -5,6 +5,10 @@ struct state; struct mtd_info_user; +enum state_flags { + STATE_FLAG_NO_AUTHENTIFICATION = (1 << 0), +}; + /** * state_backend_storage_bucket - This class describes a single backend storage * object copy @@ -53,7 +57,7 @@ */ struct state_backend_format { int (*verify) (struct state_backend_format * format, uint32_t magic, - const void * buf, ssize_t *lenp); + const void * buf, ssize_t *lenp, enum state_flags flags); int (*pack) (struct state_backend_format * format, struct state * state, void ** buf, ssize_t * len); int (*unpack) (struct state_backend_format * format, @@ -223,7 +227,8 @@ const void * buf, ssize_t len); int state_storage_read(struct state_backend_storage *storage, struct state_backend_format *format, - uint32_t magic, void **buf, ssize_t *len); + uint32_t magic, void **buf, ssize_t *len, + enum state_flags flags); static inline struct state_uint32 *to_state_uint32(struct state_variable *s) { diff --git a/src/state.h b/src/state.h index bc9a574..ce420d1 100644 --- a/src/state.h +++ b/src/state.h @@ -19,6 +19,7 @@ int state_get_name(const struct state *state, char const **name); int state_load(struct state *state); +int state_load_no_auth(struct state *state); int state_save(struct state *state); void state_info(void);