aboutsummaryrefslogtreecommitdiffstats
path: root/package/boot/uboot-oxnas/files/tools
diff options
context:
space:
mode:
authorJohn Crispin <john@openwrt.org>2014-11-26 09:00:17 +0000
committerJohn Crispin <john@openwrt.org>2014-11-26 09:00:17 +0000
commitc05048b0bb686bfa927d3a4848127b9052549fb1 (patch)
tree2c546927f7bdac026bfeda08e9856d5eef738b66 /package/boot/uboot-oxnas/files/tools
parent72b58f2eb12ad4aa0c59481d0911dc5e39180eb5 (diff)
downloadupstream-c05048b0bb686bfa927d3a4848127b9052549fb1.tar.gz
upstream-c05048b0bb686bfa927d3a4848127b9052549fb1.tar.bz2
upstream-c05048b0bb686bfa927d3a4848127b9052549fb1.zip
add uboot-oxnas
This adds support for the oxnas target in U-Boot 2014.04 History can be found at https://github.com/kref/u-boot-oxnas up to 2013.10 changes from 2013.10 to 2014.04 can be followed at https://gitorious.org/openwrt-oxnas Signed-off-by: Daniel Golle <daniel@makrotopia.org> SVN-Revision: 43389
Diffstat (limited to 'package/boot/uboot-oxnas/files/tools')
-rw-r--r--package/boot/uboot-oxnas/files/tools/mkox820crc.c123
1 files changed, 123 insertions, 0 deletions
diff --git a/package/boot/uboot-oxnas/files/tools/mkox820crc.c b/package/boot/uboot-oxnas/files/tools/mkox820crc.c
new file mode 100644
index 0000000000..d100191f2d
--- /dev/null
+++ b/package/boot/uboot-oxnas/files/tools/mkox820crc.c
@@ -0,0 +1,123 @@
+/* J J Larworthy 27 September 2006 */
+
+/* file to read the boot sector of a dis and the loaded image and report
+ * if the boot rom would accept the data as intact and suitable for use
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/errno.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+extern uint32_t crc32(uint32_t, const unsigned char *, unsigned int);
+
+#define NUMBER_VECTORS 12
+struct {
+ unsigned int start_vector[NUMBER_VECTORS];
+ char code[4];
+ unsigned int header_length;
+ unsigned int reserved[3];
+ unsigned int length;
+ unsigned int img_CRC;
+ unsigned int CRC;
+} img_header;
+
+void print_usage(void)
+{
+ printf("update_header file.bin\n");
+}
+
+void print_header(void)
+{
+ int i;
+
+ printf("vectors in header\n");
+ for (i = 0; i < NUMBER_VECTORS; i++) {
+ printf("%d:0x%08x\n", i, img_header.start_vector[i]);
+ }
+ printf("length:%8x\nimg_CRC:0x%08x\nHeader CRC:0x%08x\n",
+ img_header.length, img_header.img_CRC, img_header.CRC);
+}
+
+int main(int argc, char **argv)
+{
+ int in_file;
+ int status;
+ int unsigned crc;
+ int file_length;
+ int len;
+
+ struct stat file_stat;
+
+ void *executable;
+
+ in_file = open(argv[1], O_RDWR);
+
+ if (in_file < 0) {
+ printf("failed to open file:%s\n", argv[optind]);
+ return -ENOENT;
+ }
+
+ status = fstat(in_file, &file_stat);
+
+ /* read header and obtain size of image */
+ status = read(in_file, &img_header, sizeof(img_header));
+
+ file_length = file_stat.st_size - sizeof(img_header);
+
+ if (img_header.length != file_length) {
+ printf("size in header:%d, size of file: %d\n",
+ img_header.length, file_length);
+ }
+ img_header.length = file_length;
+
+ /* read working image and CRC */
+ executable = malloc(file_length);
+
+ status = read(in_file, executable, file_length);
+
+ if (status != file_length) {
+ printf("Failed to load image\n");
+ return -ENOENT;
+ }
+
+ /* verify image CRC */
+ crc = crc32(0, (const unsigned char *) executable, img_header.length);
+
+ if (crc != img_header.img_CRC) {
+ printf("New Image CRC:0x%08x, hdr:0x%08x\n", crc,
+ img_header.img_CRC);
+ img_header.img_CRC = crc;
+ }
+ memcpy(img_header.code, "BOOT", 4);
+ img_header.header_length = sizeof(img_header);
+
+ /* check header CRC */
+ crc = crc32(0, (const unsigned char *) &img_header,
+ sizeof(img_header) - sizeof(unsigned int));
+ if (crc != img_header.CRC) {
+ printf("New header CRC - crc:0x%08x hdr:0x%08x\n", crc,
+ img_header.CRC);
+ img_header.CRC = crc;
+ }
+
+ /* re-write the file */
+ status = lseek(in_file, 0, SEEK_SET);
+ if (status != 0) {
+ printf("failed to rewind\n");
+ return 1;
+ }
+ len = write(in_file, &img_header, sizeof(img_header));
+ assert(len == sizeof(img_header));
+ len = write(in_file, executable, file_length);
+ assert(len == file_length);
+ close(in_file);
+
+ return 0;
+}