From e5e72b240defe26b864a8cb58e4f58d58411c35f Mon Sep 17 00:00:00 2001 From: Javier Viguera Date: Wed, 28 Nov 2012 17:00:57 +0100 Subject: [PATCH] meta-digi-del: add libdigi Signed-off-by: Javier Viguera --- meta-digi-del/recipes-core/libdigi/libdigi.bb | 36 ++ .../recipes-core/libdigi/libdigi/cmdopt.c | 366 ++++++++++++++++++ .../recipes-core/libdigi/libdigi/cmdopt.h | 54 +++ .../recipes-core/libdigi/libdigi/crc32.c | 86 ++++ .../recipes-core/libdigi/libdigi/crc32.h | 24 ++ .../libdigi/libdigi/digi-platforms.h | 104 +++++ .../recipes-core/libdigi/libdigi/log.c | 129 ++++++ .../recipes-core/libdigi/libdigi/log.h | 34 ++ .../recipes-core/libdigi/libdigi/mem.c | 90 +++++ .../recipes-core/libdigi/libdigi/mem.h | 23 ++ .../libdigi/libdigi/misc_helper.h | 51 +++ .../recipes-core/libdigi/libdigi/platform.c | 69 ++++ 12 files changed, 1066 insertions(+) create mode 100644 meta-digi-del/recipes-core/libdigi/libdigi.bb create mode 100644 meta-digi-del/recipes-core/libdigi/libdigi/cmdopt.c create mode 100644 meta-digi-del/recipes-core/libdigi/libdigi/cmdopt.h create mode 100644 meta-digi-del/recipes-core/libdigi/libdigi/crc32.c create mode 100644 meta-digi-del/recipes-core/libdigi/libdigi/crc32.h create mode 100644 meta-digi-del/recipes-core/libdigi/libdigi/digi-platforms.h create mode 100644 meta-digi-del/recipes-core/libdigi/libdigi/log.c create mode 100644 meta-digi-del/recipes-core/libdigi/libdigi/log.h create mode 100644 meta-digi-del/recipes-core/libdigi/libdigi/mem.c create mode 100644 meta-digi-del/recipes-core/libdigi/libdigi/mem.h create mode 100644 meta-digi-del/recipes-core/libdigi/libdigi/misc_helper.h create mode 100644 meta-digi-del/recipes-core/libdigi/libdigi/platform.c diff --git a/meta-digi-del/recipes-core/libdigi/libdigi.bb b/meta-digi-del/recipes-core/libdigi/libdigi.bb new file mode 100644 index 000000000..170f2eee7 --- /dev/null +++ b/meta-digi-del/recipes-core/libdigi/libdigi.bb @@ -0,0 +1,36 @@ +SUMMARY = "Digi's utilities library" +SECTION = "libs" +LICENSE = "GPL-2.0" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/GPL-2.0;md5=801f80980d171dd6425610833a22dbe6" + +PR = "r1" + +SRC_URI = "file://cmdopt.c \ + file://cmdopt.h \ + file://crc32.c \ + file://crc32.h \ + file://digi-platforms.h \ + file://log.c \ + file://log.h \ + file://mem.c \ + file://mem.h \ + file://misc_helper.h \ + file://platform.c \ + " + +S = "${WORKDIR}" + +do_compile() { + ${CC} -O2 -Wall -c -o log.o log.c + ${CC} -O2 -Wall -c -o cmdopt.o cmdopt.c + ${CC} -O2 -Wall -c -o mem.o mem.c + ${CC} -O2 -Wall -c -o crc32.o crc32.c + ${CC} -O2 -Wall -c -o platform.o platform.c + ${AR} -rcs libdigi.a log.o cmdopt.o mem.o crc32.o platform.o +} + +do_install() { + mkdir -p ${D}/usr/include/libdigi ${D}/usr/lib + install -m 0644 libdigi.a ${D}/usr/lib + install -m 0644 cmdopt.h crc32.h digi-platforms.h log.h mem.h misc_helper.h ${D}/usr/include/libdigi +} diff --git a/meta-digi-del/recipes-core/libdigi/libdigi/cmdopt.c b/meta-digi-del/recipes-core/libdigi/libdigi/cmdopt.c new file mode 100644 index 000000000..5deadbe5b --- /dev/null +++ b/meta-digi-del/recipes-core/libdigi/libdigi/cmdopt.c @@ -0,0 +1,366 @@ +/*********************************************************************** + * + * Copyright 2001,2002 by FS-Forth Systeme GmbH. + * All rights reserved. + * + * $Id: cmdopt.c,v 1.4 2007-01-23 15:13:27 mpietrek Exp $ + * @Author: Markus Pietrek + * @Descr: Provides some helper functions to access the command line + * options. The results are stored in global variables. + * This file is not thread safe. + * + ********************************************************************** */ +/*********************************************************************** * + * @History: + * 2002/10/21 : Purified for splint. Changed to new variable + * naming convention. + * + *********************************************************************** */ + +#include +#include // toupper +#include // getopt +#include +#include // atoi +#include // strlen + +#include "cmdopt.h" +#include "log.h" +#include "misc_helper.h" + +#define BUFFER_SIZE 1024 +#define MAX_ENTRIES 32 + +/*@observer@*/ +void (*fnCmdOptExtendedUsage) (char bCmdLine) = NULL; +const char* szCmdOptVersion = "$Revision: 1.4 $"; // if not + // overwritten take + // at least the + // revision of cmdopt + +static CmdOptEntry cmdOptEntries[ MAX_ENTRIES ]; // to avoid malloc we + // use a static buffer +/*@noreturn@*/ +static void usageAndExit( int argc, + char* argv[], + const CmdOptEntry entries[], + const char* szDescr, + char cWrongNumber ); +static void updateVar( const CmdOptEntry entries[], + int nOptIndex, + const char* szStr ); + + +/*********************************************************************** + * @Function: cmdOptParse + * @Return: only if command line could be parsed otherwise ends + * the application. Result is only set if COT_MORE is specified + * and points to the first unprocessed entry + * @Descr: reads the command line and sets the variables. Displays a usage + * if values are wrong. + ***********************************************************************/ + +int cmdOptParse( int argc, + char* argv[], + const CmdOptEntry entries[], + const char* szDescr ) +{ + char szOptLine[ BUFFER_SIZE ]; + struct option axLongOptions[ MAX_ENTRIES ]; + int nOptIndex = 0; + int nSize = 0; + int nSizeLong = 0; + signed char cOptChar; + int nOptIndexStatic = 0; + int nOptLongIndex = 0; + char cPrintVersion = 0; + char cPrintHelp = 0; + + CmdOptEntry coePrintVersion = + {COT_BOOL, -1, &cPrintVersion, "version", "print version and exit" }; + CmdOptEntry coePrintHelp = + {COT_BOOL, 'h', &cPrintHelp, "help", "print help" }; + CmdOptEntry coeLogLevel = + {COT_INT, 'l', &logLevel, "log-level", "log level for messages" }; + + CLEAR( axLongOptions ); + + // add global default command line arguments + cmdOptEntries[ nOptIndexStatic++ ] = coePrintVersion; + cmdOptEntries[ nOptIndexStatic++ ] = coePrintHelp; + cmdOptEntries[ nOptIndexStatic++ ] = coeLogLevel; + + // copy default command line entries + // will break when all entries are copied to global area + // or too much arguments + while( 1 ) + { + if( nOptIndexStatic == MAX_ENTRIES ) + { + logMsg( LOG_ERR, "cmdOptParse: too many command line options" ); + exit( EXIT_FAILURE ); + } + + cmdOptEntries[ nOptIndexStatic ] = entries[ nOptIndex ]; + if( entries[ nOptIndex ].type == COT_NONE ) + // no more entries + break; + + nOptIndexStatic++; + nOptIndex++; + } + + // create parameter list for getopt + + nOptIndex = 0; + szOptLine[ nOptIndex ] = 0; + + while( cmdOptEntries[ nSize ].type != COT_NONE ) + { + if( ( cmdOptEntries[ nSize ].type != COT_MORE ) && + ( cmdOptEntries[ nSize ].type != COT_MORE_OPT ) ) { + axLongOptions[ nSizeLong ].name = cmdOptEntries[ nSize ].szLabelStr; + axLongOptions[ nSizeLong ].has_arg = + ((cmdOptEntries[ nSize ].type != COT_BOOL ) ? required_argument : no_argument); + axLongOptions[ nSizeLong ].flag = NULL; + axLongOptions[ nSizeLong ].val = -2 - nSize; + nSizeLong++; + } + + if( NULL != cmdOptEntries[ nSize ].pbPresent ) + *cmdOptEntries[ nSize ].pbPresent = 0; + if( !cmdOptEntries[ nSize ].cOptChar ) + { + // parameter is not mandatory + nSize++; + continue; + } + + if( nOptIndex >= BUFFER_SIZE - 2 ) + { + logMsg( LOG_ERR, + "cmdOptParse: too long command line" ); + exit( EXIT_FAILURE ); + } + + if( -1 != cmdOptEntries[ nSize ].cOptChar ) { + szOptLine[ nOptIndex++ ] = cmdOptEntries[ nSize ].cOptChar; + if( cmdOptEntries[ nSize ].type != COT_BOOL ) + szOptLine[ nOptIndex++ ] = ':'; + } + + szOptLine[ nOptIndex ] = 0; + + nSize++; + } + + // parse optional command line options + + while( ( cOptChar = getopt_long( argc, argv, szOptLine, axLongOptions, &nOptLongIndex ) ) != -1 ) + { + char cFound = 0; + + if( cOptChar < 0 ) { + cFound = 1; + updateVar( cmdOptEntries, -2 - cOptChar, optarg ); + } else { + for( nOptIndex = 0; nOptIndex < nSize; nOptIndex++ ) + { + if( cmdOptEntries[ nOptIndex ].cOptChar == cOptChar ) + { + // optional arguments only + cFound = 1; + updateVar( cmdOptEntries, nOptIndex, optarg ); + } + } + } + + if( !cFound ) + usageAndExit( argc, argv, cmdOptEntries, szDescr, 0 ); + } + + if( cPrintVersion ) + { + fprintf( stdout, "%s %s\n", + argv[ 0 ], + szCmdOptVersion ); + exit( EXIT_SUCCESS ); + } + + if( cPrintHelp ) + usageAndExit( argc, argv, cmdOptEntries, szDescr, 0 ); + + // parse mandatory command line options + + nOptIndex = 0; + for( nOptIndex = 0; nOptIndex < nSize; nOptIndex++ ) + if( !cmdOptEntries[ nOptIndex ].cOptChar ) + { + if( cmdOptEntries[ nOptIndex ].type == COT_MORE_OPT ) + // don't parse the following arguments as they + // can't be covered by this lib yet + return optind; + + if( !( argc - optind ) ) + usageAndExit( argc, argv, cmdOptEntries, szDescr, 1 ); + + if( cmdOptEntries[ nOptIndex ].type == COT_MORE ) + // don't parse the following arguments as they + // can't be covered by this lib yet + return optind; + + updateVar( cmdOptEntries, nOptIndex, argv[ optind++ ] ); + } + + if( argc - optind ) + // COT_MORE is aborted before + usageAndExit( argc, argv, cmdOptEntries, szDescr, 1 ); + + return 0; +} + +void cmdOptUsageAndExit( + int argc, + char* argv[], + const CmdOptEntry entries[], + const char* szDescr ) +{ + usageAndExit( argc, argv, entries, szDescr, 0 ); +} + + +/*********************************************************************** + * @Function: usageAndExit + * @Return: never + * @Descr: displays usage and exits with EXIT_FAILURE. If wrongNumber is 1, + * a message "too many arguments is displayed". + ***********************************************************************/ + +static void usageAndExit( /*@unused@*/ int argc, + char* argv[], + const CmdOptEntry entries[], + const char* szDescr, + char cWrongNumber ) +{ + int nOptIndex = 0; + size_t maxStrLen = 0; + + fprintf( stdout, "Usage: %s ", argv[ 0 ] ); + + // print command line arguments + while( entries[ nOptIndex ].type != COT_NONE ) + { + if( entries[ nOptIndex ].szLabelStr != NULL ) + { + // determine max len of labelStr for formatted output + size_t strLen = strlen( entries[ nOptIndex ].szLabelStr ); + + if( strLen > maxStrLen ) + maxStrLen = strLen; + } + + switch( entries[ nOptIndex ].type ) + { + case COT_BOOL: + case COT_INT: + case COT_STRING: + fprintf( stdout, "[--%s] ", entries[ nOptIndex ].szLabelStr ); + break; + case COT_MORE: + case COT_MORE_OPT: + fprintf( stdout, + "%s ", + entries[ nOptIndex ].szLabelStr ); + break; + case COT_NONE: + // will never happen but satisfies compiler + break; + } + nOptIndex++; + } + if( NULL != fnCmdOptExtendedUsage ) + fnCmdOptExtendedUsage( 1 ); + + fprintf( stdout, "\n" ); + + // explain command line options + nOptIndex = 0; + while( entries[ nOptIndex ].type != COT_NONE ) + { + fprintf( stdout, " " ); + fprintf( stdout, " %-*s", + (int) maxStrLen, + entries[ nOptIndex ].szLabelStr ); + + if( entries[ nOptIndex ].cOptChar > 0) + fprintf( stdout, " [-%c]", entries[ nOptIndex ].cOptChar ); + else + fprintf( stdout, " " ); + /*@+matchanyintegral*/ // maxStrLen is size_t. We shall + // unrestrict for this case the + // behaviour of splint because the + // compiler should do some + // checking, too + /*@-matchanyintegral*/ + + if( entries[ nOptIndex ].szHelpStr != NULL ) + fprintf( stdout, " : %s", entries[ nOptIndex ].szHelpStr ); + + fprintf( stdout, "\n" ); + nOptIndex++; + } + + if( NULL != fnCmdOptExtendedUsage ) + fnCmdOptExtendedUsage( 0 ); + + fprintf( stdout, "\n%s\n", szDescr ); + + // explain failure + if( cWrongNumber ) + fprintf( stderr, "\n*** Wrong # arguments ***\n" ); + + exit( EXIT_FAILURE ); +} + + +/*********************************************************************** + * @Function: updateVar + * @Return: nothing + * @Descr: sets the variable in entries[ index ] to the value in str + * and does conversion if necessary + ***********************************************************************/ + +static void updateVar( const CmdOptEntry entries[], + int nOptIndex, + const char* szStr ) +{ + switch( entries[ nOptIndex ].type ) + { + case COT_BOOL: + *((char*) entries[ nOptIndex ].vValuePtr) = 1; + break; + case COT_INT: + if( (int) strlen( szStr ) > 2 && + ((szStr[ 0 ] == '0' && (toupper( szStr[ 1 ] ) == 'X' )))) + { + sscanf( &szStr[ 2 ], + "%x", + ((int*) entries[ nOptIndex ].vValuePtr ) ); + break; + } + *((int*) entries[ nOptIndex ].vValuePtr) = atoi( szStr ); + break; + case COT_STRING: + *((const char**) entries[ nOptIndex ].vValuePtr) = szStr; + break; + case COT_MORE: + case COT_MORE_OPT: + case COT_NONE: + // will never happen but satisfies compiler + break; + } + + if( NULL != entries[ nOptIndex ].pbPresent ) + *entries[ nOptIndex ].pbPresent = 1; +} + diff --git a/meta-digi-del/recipes-core/libdigi/libdigi/cmdopt.h b/meta-digi-del/recipes-core/libdigi/libdigi/cmdopt.h new file mode 100644 index 000000000..7f9ca2ab5 --- /dev/null +++ b/meta-digi-del/recipes-core/libdigi/libdigi/cmdopt.h @@ -0,0 +1,54 @@ +/* + * libdigi/cmdopt.h + * + * Copyright (C) 2001,2002 by Digi International Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * Description: Helper functions to access command line options. + * The results are stored in global variables. + * + */ + +#ifndef DG_CMDOPT_H +#define DG_CMDOPT_H + +typedef enum { + COT_BOOL, // if present,bool is set 1, otherwise unchanged + COT_INT, // sets *valuePtr to the int value + // with conversions (if 0x + // prefix is present) + COT_STRING, // sets *valuePtr to the string + COT_MORE, // to end the array. Any additional arguments + // are allowed + COT_MORE_OPT, // to end the array. Any optional arguments + // are allowed + COT_NONE // to end the array. Any additional arguments + // are considered as failures +} CmdOptTypes; + +typedef struct { + CmdOptTypes type; // type of option to be read + signed char cOptChar; // character to identify that option, if 0, then + // no option is used but parameter is required + void *vValuePtr; // ptr to the variable where value is stored + const char *szLabelStr; // label displayed in command line + const char *szHelpStr; // displays this help string for the variable + char *pbPresent; // will be set to if this option is present +} CmdOptEntry; + +/* can be set to display additional usage */ +extern void (*fnCmdOptExtendedUsage) (char bCmdLine); + +extern const char *szCmdOptVersion; // overwrite it before calling cmdOptParse to + // define version of application + +int cmdOptParse(int argc, char *argv[], const CmdOptEntry entries[], const char *szDescr); + +void cmdOptUsageAndExit(int argc, + char *argv[], const CmdOptEntry entries[], const char *szDescr); + +#endif /* DG_CMDOPT_H */ diff --git a/meta-digi-del/recipes-core/libdigi/libdigi/crc32.c b/meta-digi-del/recipes-core/libdigi/libdigi/crc32.c new file mode 100644 index 000000000..52d7aa710 --- /dev/null +++ b/meta-digi-del/recipes-core/libdigi/libdigi/crc32.c @@ -0,0 +1,86 @@ +/* + * crc32.c + * + * Copyright (C) 2006 by Digi International Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * Description: Flash Test Util + * + */ + +#include "crc32.h" + +static const crc32_t crc32_table[256] = { + 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, + 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L, + 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, + 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL, + 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L, + 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L, + 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L, + 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL, + 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L, + 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL, + 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, + 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L, + 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L, + 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL, + 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL, + 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L, + 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL, + 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L, + 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L, + 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L, + 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL, + 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L, + 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L, + 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL, + 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L, + 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L, + 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L, + 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L, + 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L, + 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL, + 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL, + 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L, + 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L, + 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL, + 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL, + 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L, + 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL, + 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L, + 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL, + 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L, + 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL, + 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L, + 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L, + 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL, + 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L, + 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L, + 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L, + 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L, + 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L, + 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L, + 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL, + 0x2d02ef8dL +}; + +crc32_t crc32(crc32_t uiCRC, const void *pvBuf, size_t iLen) +{ + const unsigned char *pcBuf = (const unsigned char *)pvBuf; + + /* uiCRC starts with 0 on first block. If run on a block, undoes the + previous uiCRC ^ 0xffffffff. */ + uiCRC ^= 0xffffffff; + + while (iLen-- > 0) + uiCRC = crc32_table[(uiCRC ^ *pcBuf++) & 0xff] ^ (uiCRC >> 8); + + /* if last block, this is the result. Otherwise this will be undone + on next crc32 call */ + return uiCRC ^ 0xffffffff; +} diff --git a/meta-digi-del/recipes-core/libdigi/libdigi/crc32.h b/meta-digi-del/recipes-core/libdigi/libdigi/crc32.h new file mode 100644 index 000000000..6cf7e1197 --- /dev/null +++ b/meta-digi-del/recipes-core/libdigi/libdigi/crc32.h @@ -0,0 +1,24 @@ +/* + * libdigi/crc32.h + * + * Copyright (C) 2006 by Digi International Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * Description: CRC32 functions + * + */ + +#ifndef DG_CRC32_H +#define DG_CRC32_H + +#include /* uint32_t */ +#include /* size_t */ + +typedef uint32_t crc32_t; +extern crc32_t crc32(crc32_t uiCRC, const void *pvBuf, size_t iLen); + +#endif /* DG_CRC32_H */ diff --git a/meta-digi-del/recipes-core/libdigi/libdigi/digi-platforms.h b/meta-digi-del/recipes-core/libdigi/libdigi/digi-platforms.h new file mode 100644 index 000000000..f594d2827 --- /dev/null +++ b/meta-digi-del/recipes-core/libdigi/libdigi/digi-platforms.h @@ -0,0 +1,104 @@ +/* + * libdigi/digi-platforms.h + * + * Copyright (C) 2011 by Digi International Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * Description: Digi platforms + * + */ + +#ifndef DIGI_PLATFORMS_H +#define DIGI_PLATFORMS_H + +#define PLATFORM_NAME(x) x ## _NAME + +#define MACH_TYPE_CC7U 1017 +#define MACH_TYPE_CC7U_NAME "cc7u" +#define MACH_TYPE_CWIEM 1033 +#define MACH_TYPE_CWIEM_NAME "cwiem" +#define MACH_TYPE_CCW9C 1110 +#define MACH_TYPE_CCW9C_NAME "ccw9c" +#define MACH_TYPE_CC9P9360DEV 1114 +#define MACH_TYPE_CC9P9360DEV_NAME "cc9p9360dev" +#define MACH_TYPE_CC9P9750DEV 1115 +#define MACH_TYPE_CC9P9750DEV_NAME "cc9p9750dev" +#define MACH_TYPE_CC9P9360VAL 1116 +#define MACH_TYPE_CC9P9360VAL_NAME "cc9p9360val" +#define MACH_TYPE_CC9P9750VAL 1117 +#define MACH_TYPE_CC9P9750VAL_NAME "cc9p9750val" +#define MACH_TYPE_CC9P9360JS 1264 +#define MACH_TYPE_CC9P9360JS_NAME "cc9p9360js" +#define MACH_TYPE_CC9P9215 1445 +#define MACH_TYPE_CC9P9215_NAME "cc9p9215" +#define MACH_TYPE_CC9P9210 1446 +#define MACH_TYPE_CC9P9210_NAME "cc9p9210" +#define MACH_TYPE_CC9P9215JS 1447 +#define MACH_TYPE_CC9P9215JS_NAME "cc9p9215js" +#define MACH_TYPE_CC9P9210JS 1448 +#define MACH_TYPE_CC9P9210JS_NAME "cc9p9210js" +#define MACH_TYPE_CC7UCAMRY 1493 +#define MACH_TYPE_CC7UCAMRY_NAME "cc7ucamry" +#define MACH_TYPE_CC9M2443JS 1663 +#define MACH_TYPE_CC9M2443JS_NAME "cc9m2443js" +#define MACH_TYPE_CME9210 1712 +#define MACH_TYPE_CME9210_NAME "cme9210" +#define MACH_TYPE_CCW9P9215JS 1811 +#define MACH_TYPE_CCW9P9215JS_NAME "ccw9p9215js" +#define MACH_TYPE_CC9M2443 1815 +#define MACH_TYPE_CC9M2443_NAME "cc9m2443" +#define MACH_TYPE_CME9210JS 1854 +#define MACH_TYPE_CME9210JS_NAME "cme9210js" +#define MACH_TYPE_CC9P9360 1855 +#define MACH_TYPE_CC9P9360_NAME "cc9p9360" +#define MACH_TYPE_CCW9P9215 2137 +#define MACH_TYPE_CCW9P9215_NAME "ccw9p9215" +#define MACH_TYPE_CCW9M2443 2145 +#define MACH_TYPE_CCW9M2443_NAME "ccw9m2443" +#define MACH_TYPE_CCW9M2443JS 2146 +#define MACH_TYPE_CCW9M2443JS_NAME "ccw9m2443js" +#define MACH_TYPE_CC9P9215_3G 2397 +#define MACH_TYPE_CC9P9215_3G_NAME "cc9p9215_3g" +#define MACH_TYPE_CC9P9215_3GJS 2398 +#define MACH_TYPE_CC9P9215_3GJS_NAME "cc9p9215_3gjs" +#define MACH_TYPE_CCMX51 2516 +#define MACH_TYPE_CCMX51_NAME "ccmx51" +#define MACH_TYPE_CCMX51JS 2517 +#define MACH_TYPE_CCMX51JS_NAME "ccmx51js" +#define MACH_TYPE_CCWMX51 2518 +#define MACH_TYPE_CCWMX51_NAME "ccwmx51" +#define MACH_TYPE_CCWMX51JS 2519 +#define MACH_TYPE_CCWMX51JS_NAME "ccwmx51js" +#define MACH_TYPE_CWME9210 3320 +#define MACH_TYPE_CWME9210_NAME "cwme9210" +#define MACH_TYPE_CWME9210JS 3321 +#define MACH_TYPE_CWME9210JS_NAME "cwme9210js" +#define MACH_TYPE_CCMX53 3346 +#define MACH_TYPE_CCMX53_NAME "ccmx53" +#define MACH_TYPE_CCMX53JS 3347 +#define MACH_TYPE_CCMX53JS_NAME "ccmx53js" +#define MACH_TYPE_CCWMX53 3348 +#define MACH_TYPE_CCWMX53_NAME "ccwmx53" +#define MACH_TYPE_CCWMX53JS 3349 +#define MACH_TYPE_CCWMX53JS_NAME "ccwmx53js" +#define MACH_TYPE_CPX2 3419 +#define MACH_TYPE_CPX2_NAME "cpx2" +#define MACH_TYPE_WR21 3737 +#define MACH_TYPE_WR21_NAME "wr21" +#define MACH_TYPE_CCARDWMX28 3893 +#define MACH_TYPE_CCARDWMX28_NAME "ccardwmx28" +#define MACH_TYPE_CCARDMX28 3894 +#define MACH_TYPE_CCARDMX28_NAME "ccardmx28" +#define MACH_TYPE_CCARDWMX28JS 3917 +#define MACH_TYPE_CCARDWMX28JS_NAME "ccardwmx28js" +#define MACH_TYPE_CCARDMX28JS 3918 +#define MACH_TYPE_CCARDMX28JS_NAME "ccardmx28js" + +int get_platform_id(void); +char is_nand_oob_atomic(void); + +#endif /* DIGI_PLATFORMS_H */ diff --git a/meta-digi-del/recipes-core/libdigi/libdigi/log.c b/meta-digi-del/recipes-core/libdigi/libdigi/log.c new file mode 100644 index 000000000..5aeebafc2 --- /dev/null +++ b/meta-digi-del/recipes-core/libdigi/libdigi/log.c @@ -0,0 +1,129 @@ +/* + * log.c + * + * Copyright (C) 2001,2002 by Digi International Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * Description: implements logging interface + * + */ + +#include // fprintf +#include // EXIT_FAILURE +#include // errno +#include // h_errno +#include // strerror +#include // vprintf + +#include "log.h" + +/* Globaly visible */ +LogLevel logLevel = LOG_STATUS; + + +/*********************************************************************** + * @Function: log + * @Return: nothing + * @Descr: format and arg1..arg3 are printed on stderr only if level + * is <= logLevel + * format may not contain any newline character. + ***********************************************************************/ +void logMsg(LogLevel level, const char *szFormat, ...) +{ + if (level <= logLevel) { + va_list ap; + + /*@-formatconst@ */ + va_start(ap, szFormat); + vfprintf(stderr, szFormat, ap); + va_end(ap); + /*@-formatconst@ */ + fputs("\n", stderr); + } +} + +/*********************************************************************** + * @Function: systemLog + * @Return: nothing + * @Descr: dumps the system error that happened just before + ***********************************************************************/ +void systemLog(const char *szFormat, ...) +{ + char *szError = NULL; + va_list ap; + + if (errno) + szError = strdup(strerror(errno)); + else if (h_errno) + szError = strdup(hstrerror(h_errno)); + + /*@-formatconst@ */ + va_start(ap, szFormat); + vfprintf(stderr, szFormat, ap); + va_end(ap); + /*@-formatconst@ */ + if (NULL != szError) + fprintf(stderr, " (%s)", szError); + + fputs("\n", stderr); + + if (NULL != szError) + free(szError); +} + +/*********************************************************************** + * @Function: error + * @Return: never + * @Descr: format and arg1..arg3 are printed on stderr only if level + * is <= logLevel + * format may not contain any newline character. + ***********************************************************************/ +void error(const char *szFormat, ...) +{ + va_list ap; + + fprintf(stderr, "*** Error: "); + /*@-formatconst@ */ + va_start(ap, szFormat); + vfprintf(stderr, szFormat, ap); + va_end(ap); + /*@-formatconst@ */ + fputs("\n", stderr); + + exit(EXIT_FAILURE); +} + +/*********************************************************************** + * @Function: systemError + * @Return: never + * @Descr: dumps the system error that happened just before and exits the + * application + ***********************************************************************/ +void systemError(const char *szFormat, ...) +{ + char *szError = NULL; + va_list ap; + + if (errno) + szError = strdup(strerror(errno)); + else if (h_errno) + szError = strdup(hstrerror(h_errno)); + + fprintf(stderr, "*** Error: "); + /*@-formatconst@ */ + va_start(ap, szFormat); + vfprintf(stderr, szFormat, ap); + va_end(ap); + /*@-formatconst@ */ + if (NULL != szError) + fprintf(stderr, " (%s)", szError); + + fputs("\n", stderr); + free(szError); + + exit(EXIT_FAILURE); +} diff --git a/meta-digi-del/recipes-core/libdigi/libdigi/log.h b/meta-digi-del/recipes-core/libdigi/libdigi/log.h new file mode 100644 index 000000000..26f573f64 --- /dev/null +++ b/meta-digi-del/recipes-core/libdigi/libdigi/log.h @@ -0,0 +1,34 @@ +/* + * libdigi/log.h + * + * Copyright (C) 2001,2002 by Digi International Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * Description: Logging facility for applications + * + */ + +#ifndef DG_LOG_H +#define DG_LOG_H + +typedef enum { + LOG_ERR = 0, + LOG_STATUS, + LOG_HARDWARE1, + LOG_HARDWARE2, + LOG_PACKET, + LOG_LAST +} LogLevel; + +extern LogLevel logLevel; + +extern void logMsg(LogLevel level, const char *szFormat, ...); +extern void systemLog(const char *szFormat, ...); +extern void error(const char *szFormat, ...); +extern void systemError(const char *szFormat, ...); + +#endif /* DG_LOG_H */ diff --git a/meta-digi-del/recipes-core/libdigi/libdigi/mem.c b/meta-digi-del/recipes-core/libdigi/libdigi/mem.c new file mode 100644 index 000000000..df4a853f9 --- /dev/null +++ b/meta-digi-del/recipes-core/libdigi/libdigi/mem.c @@ -0,0 +1,90 @@ +/* + * mem.c + * + * Copyright (C) 2006 by Digi International Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * Description: provides MemCmp() and MemDump() + * + */ + +#include /* printf */ + +#include "mem.h" + +/*********************************************************************** + * !Function: MemCmp + * !Descr: compares memory + * !Return: offset of failure or -1 if none + ***********************************************************************/ +loff_t MemCmp(const void *pvS1, const void *pvS2, size_t iSize) +{ + const char *pcS2 = (const char *)pvS2; + const char *pcS1 = (const char *)pvS1; + loff_t iOffset = 0; + + while (iOffset < iSize) { + if (*pcS2 != *pcS1) + return iOffset; + + pcS2++; + pcS1++; + iOffset++; + } + + return -1; +} + +/*********************************************************************** + * !Function: MemDump + * !Descr: Prints memory from pvbase + iOffset to pvBase + iOffset + iLen + ***********************************************************************/ +void MemDump(const void *pvBase, loff_t iOffset, size_t iLen) +{ + const unsigned char *pucBuf = (const unsigned char *)pvBase + iOffset; + const int COLUMN_COUNT = 16; + int i; + + for (i = 0; i < iLen; i += COLUMN_COUNT) { + /* print one row */ + int j, iRowLen; + + if ((i + COLUMN_COUNT) <= iLen) + iRowLen = COLUMN_COUNT; + else + iRowLen = iLen - i; + + printf("%08llx ", (long long)iOffset); + + /* print hexadecimal representation */ + for (j = 0; j < iRowLen; j++) { + printf("%02x ", *(pucBuf + j)); + if (((COLUMN_COUNT / 2) - 1) == j) + /* additional separator */ + printf(" "); + } + + printf(" "); + + /* print character representation row */ + for (j = 0; j < iRowLen; j++) { + unsigned char c = *(pucBuf + j); + if ((c < 32) || (c > 127)) + c = '.'; + + if (((COLUMN_COUNT / 2) - 1) == j) + /* additional separator */ + printf(" "); + + printf("%c", c); + } + + printf("\r\n"); + pucBuf += iRowLen; + iOffset += iRowLen; + } +} diff --git a/meta-digi-del/recipes-core/libdigi/libdigi/mem.h b/meta-digi-del/recipes-core/libdigi/libdigi/mem.h new file mode 100644 index 000000000..0316e6d56 --- /dev/null +++ b/meta-digi-del/recipes-core/libdigi/libdigi/mem.h @@ -0,0 +1,23 @@ +/* + * libdigi/mem.h + * + * Copyright (C) 2006 by Digi International Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * Description: provides MemCmp() and MemDump() + * + */ + +#ifndef DG_MEM_H +#define DG_MEM_H + +#include /* size_t */ + +extern loff_t MemCmp(const void *pvS1, const void *pvS2, size_t iSize); +extern void MemDump(const void *pvBase, loff_t iOffset, size_t iLen); + +#endif /* DG_MEM_H */ diff --git a/meta-digi-del/recipes-core/libdigi/libdigi/misc_helper.h b/meta-digi-del/recipes-core/libdigi/libdigi/misc_helper.h new file mode 100644 index 000000000..3bd170af9 --- /dev/null +++ b/meta-digi-del/recipes-core/libdigi/libdigi/misc_helper.h @@ -0,0 +1,51 @@ +/* + * libdigi/misc_helper.h + * + * Copyright (C) 2006 by Digi International Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * Description: miscellanous definitions that simplifies developing + * May require 'string.h' or 'log.h' + * + */ + +#ifndef DG_MISC_HELPER_H +#define DG_MISC_HELPER_H + +#include /* snprintf */ +#include /* memset */ + +#define ARRAY_SIZE(x) (sizeof(x)/sizeof(*(x))) +#define CLEAR(x) memset( &x, 0, sizeof( x ) ) + +/* round up to kB */ +#define TO_KiB(x) (((x) + 1023) / 1024) + +/* to bytes */ +#define KiB(x) ((x) * 1024) +#define MiB(x) (KiB(x) * 1024) + +#define MAX(a, b) ((a) < (b) ? (b) : (a)) +#define MIN(a, b) ((a) > (b) ? (b) : (a)) + +#define FREE(x) \ + do { \ + free((void *)x); \ + x = NULL; \ + } while (0) + +#define CLOSE(x) \ + do { \ + if (close(x)) \ + systemError("close"); \ + x = -1; \ + } while (0) + +#define SPRINTF(acStr, args...) \ + snprintf(acStr, sizeof(acStr), args) + +#endif /* DG_MISC_HELPER_H */ diff --git a/meta-digi-del/recipes-core/libdigi/libdigi/platform.c b/meta-digi-del/recipes-core/libdigi/libdigi/platform.c new file mode 100644 index 000000000..aeff846e1 --- /dev/null +++ b/meta-digi-del/recipes-core/libdigi/libdigi/platform.c @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2011 by Digi International Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version2 as published by + * the Free Software Foundation. +*/ + +#include +#include +#include + +#include "digi-platforms.h" +#include "log.h" + +/* + * Gets the platform ID from the file /proc/cpuinfo + * (the kernel needs to write the machine ID in this file). + * Returns the machine ID or -1 on error + */ +int get_platform_id(void) +{ + char buffer[80]; + FILE *fp; + long id = -1; + + fp = popen("cat /proc/cpuinfo | grep \"Machine ID\" | cut -f 2 -d :", "r"); + if (fp == NULL) + systemError("cannot access /proc/cpuinfo"); + + if (fgets(buffer, sizeof(buffer) - 1, fp)) { + errno = 0; /* to distinguish success/failure after call */ + id = strtol(buffer, NULL, 10); + if (errno != 0) + id = -1; /* don't care about the error code */ + } + fclose(fp); + return id; +} + +/* + * Checks whether platform requires an atomic access to NAND OOB + */ +char is_nand_oob_atomic(void) +{ + int platform_id; + + platform_id = get_platform_id(); + /* The following platforms require atomic access to NAND OOB */ + if (MACH_TYPE_CPX2 == platform_id || + MACH_TYPE_WR21 == platform_id || + MACH_TYPE_CCMX51 == platform_id || + MACH_TYPE_CCMX51JS == platform_id || + MACH_TYPE_CCWMX51 == platform_id || + MACH_TYPE_CCWMX51JS == platform_id || + MACH_TYPE_CCMX53 == platform_id || + MACH_TYPE_CCMX53JS == platform_id || + MACH_TYPE_CCWMX53 == platform_id || + MACH_TYPE_CCWMX53JS == platform_id || + MACH_TYPE_CCARDMX28 == platform_id || + MACH_TYPE_CCARDMX28JS == platform_id || + MACH_TYPE_CCARDWMX28 == platform_id || + MACH_TYPE_CCARDWMX28JS == platform_id) { + return 1; + } + + return 0; +}