mirror of
https://github.com/fosslinux/live-bootstrap.git
synced 2026-03-18 01:05:24 +01:00
Add fletcher16-gen developer util
1. I'm not convinced our fletcher16 implementation is proper 2. It is not in coreutils So we add some basic code to do that. This is also the first dev-util, so add some documentation to DEVEL.md.
This commit is contained in:
parent
71505bc8b9
commit
192221af22
10 changed files with 400 additions and 0 deletions
8
dev-utils/fletcher16-gen/.gitignore
vendored
Normal file
8
dev-utils/fletcher16-gen/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# SPDX-FileCopyrightText: 2021 fosslinux <fosslinux@aussies.space>
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
fletcher16.M1
|
||||
fletcher16-footer.M1
|
||||
fletcher16.hex2
|
||||
fletcher16-gen
|
||||
42
dev-utils/fletcher16-gen/compile-fletcher16-gen.sh
Executable file
42
dev-utils/fletcher16-gen/compile-fletcher16-gen.sh
Executable file
|
|
@ -0,0 +1,42 @@
|
|||
#!/bin/sh
|
||||
|
||||
# SPDX-FileCopyrightText: 2021 fosslinux <fosslinux@aussies.space>
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
set -ex
|
||||
|
||||
M2-Planet \
|
||||
--architecture x86 \
|
||||
-f ../m2-functions/in_set.c \
|
||||
-f ../m2-functions/file_print.c \
|
||||
-f ../m2-functions/numerate_number.c \
|
||||
-f ../m2-functions/string.c \
|
||||
-f ../../sysa/mescc-tools-seed/src/mescc-tools-seed/M2-Planet/test/common_x86/functions/file.c \
|
||||
-f ../../sysa/mescc-tools-seed/src/mescc-tools-seed/M2-Planet/test/common_x86/functions/exit.c \
|
||||
-f ../m2-functions/require.c \
|
||||
-f ../../sysa/mescc-tools-seed/src/mescc-tools-seed/M2-Planet/test/common_x86/functions/malloc.c \
|
||||
-f ../../sysa/mescc-tools-seed/src/mescc-tools-seed/M2-Planet/functions/calloc.c \
|
||||
-f fletcher16-gen.c \
|
||||
-o fletcher16.M1 \
|
||||
--debug
|
||||
|
||||
blood-elf -f fletcher16.M1 -o fletcher16-footer.M1
|
||||
|
||||
M1 \
|
||||
-f ../../sysa/mescc-tools-seed/src/mescc-tools-seed/M2-Planet/test/common_x86/x86_defs.M1 \
|
||||
-f ../../sysa/mescc-tools-seed/src/mescc-tools-seed/M2-Planet/test/common_x86/libc-core.M1 \
|
||||
-f fletcher16.M1 \
|
||||
-f fletcher16-footer.M1 \
|
||||
--LittleEndian \
|
||||
--architecture x86 \
|
||||
-o fletcher16.hex2
|
||||
|
||||
hex2 \
|
||||
-f ../../sysa/mescc-tools-seed/src/mescc-tools-seed/M2-Planet/test/common_x86/ELF-i386-debug.hex2 \
|
||||
-f fletcher16.hex2 \
|
||||
--LittleEndian \
|
||||
--architecture x86 \
|
||||
--BaseAddress 0x8048000 \
|
||||
-o fletcher16-gen \
|
||||
--exec_enable
|
||||
40
dev-utils/fletcher16-gen/fletcher16-gen.c
Normal file
40
dev-utils/fletcher16-gen/fletcher16-gen.c
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 fosslinux <fosslinux@aussies.space>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define BUF_SIZE 1024
|
||||
// CONSTANT BUF_SIZE 1024
|
||||
#define PATH_MAX 512
|
||||
// CONSTANT PATH_MAX 512
|
||||
|
||||
int fletch16(FILE* fp)
|
||||
{
|
||||
long sum1 = 0;
|
||||
long sum2 = 0;
|
||||
int index;
|
||||
int c = fgetc(fp);
|
||||
while(c != EOF)
|
||||
{
|
||||
sum1 = (sum1 + c) % 255;
|
||||
sum2 = (sum2 + sum1) % 255;
|
||||
c = fgetc(fp);
|
||||
}
|
||||
|
||||
return (sum2 << 8) | sum1;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
/* Open the file containing the checksums */
|
||||
FILE* fp = fopen(argv[1], "r");
|
||||
require(fp != NULL, prepend_string(
|
||||
prepend_string("Error opening checksum file ", argv[1]), "\n"));
|
||||
int csum = fletch16(fp);
|
||||
file_print(prepend_string(prepend_string(prepend_string(
|
||||
numerate_number(csum), " "), argv[1]), "\n"), stdout);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue