-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add checksum functionality
- Loading branch information
Showing
20 changed files
with
510 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* This file is the part of the STM32 secure bootloader | ||
* | ||
* Copyright ©2016 Dmitry Filimonchuk <dmitrystu[at]gmail[dot]com> | ||
* Copyright 2019 by Tsien (UK) Ltd. | ||
* | ||
* Author: Adrian Carpenter <tech[at]tsien[dot]com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
#ifndef _CHECKSUM_H_ | ||
#define _CHECKSUM_H_ | ||
#if defined(__cplusplus) | ||
extern "C" { | ||
#endif | ||
|
||
#include "config.h" | ||
|
||
const char *checksum_name; | ||
size_t append_checksum(void *data, uint32_t len); | ||
size_t validate_checksum(const void *data, uint32_t len); | ||
|
||
#if defined(__cplusplus) | ||
} | ||
#endif | ||
#endif // _CHECKSUM_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* A minimal POSIX getopt() implementation in ANSI C | ||
* | ||
* This is free and unencumbered software released into the public domain. | ||
* | ||
* This implementation supports the convention of resetting the option | ||
* parser by assigning optind to 0. This resets the internal state | ||
* appropriately. | ||
* | ||
* Ref: http://pubs.opengroup.org/onlinepubs/9699919799/functions/getopt.html | ||
*/ | ||
#ifndef GETOPT_H | ||
#define GETOPT_H | ||
|
||
#include <ctype.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
static int optind = 1; | ||
static int opterr = 1; | ||
static int optopt; | ||
static char *optarg; | ||
|
||
static int | ||
getopt(int argc, char *const argv[], const char *optstring) | ||
{ | ||
static int optpos = 1; | ||
const char *arg; | ||
(void)argc; | ||
|
||
/* Reset? */ | ||
if (optind == 0) | ||
{ | ||
optind = 1; | ||
optpos = 1; | ||
} | ||
|
||
arg = argv[optind]; | ||
if (arg && strcmp(arg, "--") == 0) | ||
{ | ||
optind++; | ||
return -1; | ||
} | ||
else if (!arg || arg[0] != '-' || !isalnum(arg[1])) | ||
{ | ||
return -1; | ||
} | ||
else | ||
{ | ||
const char *opt = strchr(optstring, arg[optpos]); | ||
optopt = arg[optpos]; | ||
if (!opt) | ||
{ | ||
if (opterr && *optstring != ':') | ||
fprintf(stderr, "%s: illegal option: %c\n", argv[0], optopt); | ||
return '?'; | ||
} | ||
else if (opt[1] == ':') | ||
{ | ||
if (arg[optpos + 1]) | ||
{ | ||
optarg = (char *)arg + optpos + 1; | ||
optind++; | ||
optpos = 1; | ||
return optopt; | ||
} | ||
else if (argv[optind + 1]) | ||
{ | ||
optarg = (char *)argv[optind + 1]; | ||
optind += 2; | ||
optpos = 1; | ||
return optopt; | ||
} | ||
else | ||
{ | ||
if (opterr && *optstring != ':') | ||
fprintf(stderr, | ||
"%s: option requires an argument: %c\n", | ||
argv[0], optopt); | ||
return *optstring == ':' ? ':' : '?'; | ||
} | ||
} | ||
else | ||
{ | ||
if (!arg[++optpos]) | ||
{ | ||
optind++; | ||
optpos = 1; | ||
} | ||
return optopt; | ||
} | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.