nm: cleanup board descriptor library

- fix documentation/license information
- fix missing includes (dependancies, own header file)
- fix declaration mismatches
- fix data types
- fix parentheses
- fix order of functions in source/header
This commit is contained in:
Rene Straub 2019-03-30 11:07:39 +01:00
parent f6a10e8995
commit db067fefdd
2 changed files with 162 additions and 144 deletions

View File

@ -1,14 +1,14 @@
/******************************************************************************
* (c) COPYRIGHT 2010 by NetModule AG, Switzerland. All rights reserved.
* (c) COPYRIGHT 2010-2019 by NetModule AG, Switzerland.
*
* The program(s) may only be used and/or copied with the written permission
* from NetModule AG or in accordance with the terms and conditions stipulated
* in the agreement contract under which the program(s) have been supplied.
*
* PACKAGE : NetBox HW08
* PACKAGE : NetModule Common Hardware Abstraction
*
* ABSTRACT:
* Implements functions for settings
* Board descriptor library
*
* HISTORY:
* Date Author Description
@ -16,18 +16,128 @@
* 20100903 rs reading carrier board descriptor from EEPROM at 54.
* code cleanup (tabs/indentation)
* 20110211 rs partition table handling
* 20190330 rs cleanup after years of chaotic development
*
*****************************************************************************/
#include <common.h>
#include <i2c.h>
#include <malloc.h>
#include "bdparser.h" /* tlv parser */
#include "board_descriptor.h" /* own header file */
#define MAX_PARTITION_ENTRIES 4
static const BD_Context *bdctx_list; /* The board descriptor context */
static size_t bdctx_count = 0;
#define MAX_PARTITION_ENTRIES 4
static const BD_Context *bdctx_list;
static size_t bdctx_count = 0;
static bd_bool_t _get_string(bd_uint16_t tag, bd_uint_t index, char* pResult, bd_size_t bufLen)
{
int i;
for (i = 0; i < bdctx_count; i++) {
if (BD_GetString(&bdctx_list[i], tag, index, pResult, bufLen)) {
return BD_TRUE;
}
}
return BD_FALSE;
}
static bd_bool_t _get_mac(bd_uint16_t tag, bd_uint_t index, bd_uint8_t pResult[6])
{
int i;
for (i = 0; i < bdctx_count; i++) {
if (BD_GetMAC(&bdctx_list[i], tag, index, pResult)) {
return BD_TRUE;
}
}
return BD_FALSE;
}
static bd_bool_t _get_uint8(bd_uint16_t tag, bd_uint_t index, bd_uint8_t* pResult)
{
int i;
for (i = 0; i < bdctx_count; i++) {
if (BD_GetUInt8(&bdctx_list[i], tag, index, pResult)) {
return BD_TRUE;
}
}
return BD_FALSE;
}
static bd_bool_t _get_uint16(bd_uint16_t tag, bd_uint_t index, bd_uint16_t* pResult)
{
int i;
for (i = 0; i < bdctx_count; i++) {
if (BD_GetUInt16(&bdctx_list[i], tag, index, pResult)) {
return BD_TRUE;
}
}
return BD_FALSE;
}
static bd_bool_t _get_uint32(bd_uint16_t tag, bd_uint_t index, bd_uint32_t* pResult)
{
int i;
for (i = 0; i < bdctx_count; i++) {
if (BD_GetUInt32(&bdctx_list[i], tag, index, pResult)) {
return BD_TRUE;
}
}
return BD_FALSE;
}
static bd_bool_t _get_partition64(bd_uint16_t tag, bd_uint_t index, BD_PartitionEntry64 *pResult)
{
int i;
for (i = 0; i < bdctx_count; i++) {
if (BD_GetPartition64(&bdctx_list[i], tag, index, pResult)) {
return BD_TRUE;
}
}
return BD_FALSE;
}
static uint8_t _try_partition_read(void)
{
BD_PartitionEntry64 partition;
int i;
int rc;
int partition_count = 0;
int boot_partition = 0;
for (i = 0; i < MAX_PARTITION_ENTRIES; i++)
{
rc = _get_partition64(BD_Partition64, i, &partition);
if (rc) {
partition_count++;
if (((partition.flags & BD_Partition_Flags_Active) != 0) &&
(i > 0)) {
boot_partition = i;
}
}
}
if (partition_count < 1) {
printf("ERROR: Too few partitions defined, taking default 0\n");
}
return boot_partition;
}
void bd_register_context_list(const BD_Context *list, size_t count)
{
@ -79,8 +189,7 @@ int bd_get_context(BD_Context *bdctx, uint32_t i2caddress, uint32_t offset)
return 0;
exit1:
if (pBdData != NULL)
{
if (pBdData != NULL) {
free(pBdData);
pBdData = NULL;
}
@ -88,84 +197,6 @@ exit1:
return -1;
}
static bd_bool_t _get_string(bd_uint16_t tag, bd_uint_t index, char* pResult, bd_size_t bufLen )
{
int i;
for (i = 0; i < bdctx_count; i++) {
if (BD_GetString(&bdctx_list[i], tag, index, pResult, bufLen)) {
return BD_TRUE;
}
}
return BD_FALSE;
}
static bd_bool_t _get_mac( bd_uint16_t tag, bd_uint_t index, bd_uint8_t pResult[6] )
{
int i;
for (i = 0; i < bdctx_count; i++) {
if (BD_GetMAC(&bdctx_list[i], tag, index, pResult)) {
return BD_TRUE;
}
}
return BD_FALSE;
}
static bd_bool_t _get_uint8( bd_uint16_t tag, bd_uint_t index, bd_uint8_t* pResult )
{
int i;
for (i = 0; i < bdctx_count; i++) {
if (BD_GetUInt8(&bdctx_list[i], tag, index, pResult)) {
return BD_TRUE;
}
}
return BD_FALSE;
}
static bd_bool_t _get_uint16( bd_uint16_t tag, bd_uint_t index, bd_uint16_t* pResult )
{
int i;
for (i = 0; i < bdctx_count; i++) {
if (BD_GetUInt16(&bdctx_list[i], tag, index, pResult)) {
return BD_TRUE;
}
}
return BD_FALSE;
}
static bd_bool_t _get_uint32( bd_uint16_t tag, bd_uint_t index, bd_uint32_t* pResult )
{
int i;
for (i = 0; i < bdctx_count; i++) {
if (BD_GetUInt32(&bdctx_list[i], tag, index, pResult)) {
return BD_TRUE;
}
}
return BD_FALSE;
}
static bd_bool_t _get_partition64( bd_uint16_t tag, bd_uint_t index, BD_PartitionEntry64 *pResult)
{
int i;
for (i = 0; i < bdctx_count; i++) {
if (BD_GetPartition64(&bdctx_list[i], tag, index, pResult)) {
return BD_TRUE;
}
}
return BD_FALSE;
}
int bd_get_prodname(char *prodname, size_t len)
{
if ( !_get_string( BD_Prod_Name, 0, prodname, len) ) {
@ -176,11 +207,20 @@ int bd_get_prodname(char *prodname, size_t len)
return 0;
}
int bd_get_variantname(char *variantname, size_t len)
{
if ( !_get_string( BD_Prod_Variant_Name, 0, variantname, len) ) {
debug("%s() Variant name not found\n", __func__);
return -1;
}
return 0;
}
void bd_get_hw_version(int* ver, int* rev)
{
// TODO: Warum static?
static uint8_t hwver;
static uint8_t hwrev;
uint8_t hwver = 0;
uint8_t hwrev = 0;
if ( !_get_uint8( BD_Hw_Ver, 0, &hwver) )
debug("%s() no Hw Version found\n", __func__);
@ -194,7 +234,7 @@ void bd_get_hw_version(int* ver, int* rev)
void bd_get_hw_patch(int* patch)
{
uint8_t hwpatch;
uint8_t hwpatch = 0;
if ( !_get_uint8( BD_BOM_Patch, 0, &hwpatch) )
debug("%s() no Hw Patch found\n", __func__);
@ -204,7 +244,7 @@ void bd_get_hw_patch(int* patch)
int bd_get_mac(int index, uint8_t *macaddr, size_t len)
{
if (len != 6) {
if ( len != 6 ) {
debug("macaddr size must be 6 (is %d)", len);
return -1;
}
@ -218,17 +258,17 @@ int bd_get_mac(int index, uint8_t *macaddr, size_t len)
return 0;
}
u32 bd_get_fpgainfo(void)
uint32_t bd_get_fpgainfo(void)
{
uint32_t fpgainfo = 0xFFFFFFFF;
if ( !_get_uint32( BD_Fpga_Info, 0, &fpgainfo) )
debug("%s() no Fpga Info found\n", __func__);
debug("%s() no FGPA Info found\n", __func__);
return fpgainfo;
}
int bd_get_pd_module(int slot, char *config, size_t len)
int bd_get_pd_module(uint32_t slot, char *config, size_t len)
{
if ( !_get_string(BD_Pd_Module0 + slot, 0, config, len) ) {
debug("%s() could not read module configuration on slot %d\n",
@ -242,7 +282,7 @@ int bd_get_pd_module(int slot, char *config, size_t len)
int bd_get_sim_config(char* simconfig, size_t len)
{
if (!_get_string(BD_Pd_Sim, 0, simconfig, len)) {
debug("%s() No valid SIM Config found\n", __func__);
debug("%s() no valid SIM config found\n", __func__);
return -1;
}
@ -252,14 +292,14 @@ int bd_get_sim_config(char* simconfig, size_t len)
int bd_get_devicetree(char* devicetreename, size_t len)
{
if (!_get_string(PD_Dev_Tree, 0, devicetreename, len)) {
debug("%s() No valid Devicetree name found\n", __func__);
debug("%s() no valid devicetree name found\n", __func__);
return -1;
}
return 0;
}
int bd_get_shield(int shieldnr)
int bd_get_shield(uint32_t shieldnr)
{
bd_uint16_t shield = 0;
@ -271,46 +311,17 @@ int bd_get_shield(int shieldnr)
return shield;
}
static u8 try_partition_read(void)
uint8_t bd_get_boot_partition(void)
{
BD_PartitionEntry64 partition;
int i;
int rc;
int partition_count = 0;
int boot_partition = 0;
uint8_t boot_part;
for (i = 0; i < MAX_PARTITION_ENTRIES; i++)
{
rc = _get_partition64(BD_Partition64, i, &partition);
if (rc) {
partition_count++;
if (((partition.flags & BD_Partition_Flags_Active) != 0) &&
(i > 0)) {
boot_partition = i;
}
}
}
if (partition_count < 1)
{
printf("ERROR: Too few partitions defined, taking default 0\n");
}
return boot_partition;
}
int bd_get_boot_partition(void)
{
u8 boot_part;
/* If we have a new Bootpartition entry take this as boot part */
if ( _get_uint8( BD_BootPart, 0, &boot_part) ) {
/* If we have a Bootpartition entry take this as boot part */
if (_get_uint8( BD_BootPart, 0, &boot_part) ) {
if (boot_part >= 0 && boot_part <= 1) {
return boot_part;
}
}
/* If we not have a Bootpartition entry, perhaps we have a partition table */
return try_partition_read();
/* If we don't have a Bootpartition entry, perhaps we have a partition table */
return _try_partition_read();
}

View File

@ -1,7 +1,7 @@
/*
* Library to support early TI EVM EEPROM handling
* Board descriptor library
*
* Copyright (C) 2015-2016 Texas Instruments Incorporated - http://www.ti.com
* (c) COPYRIGHT 2010-2019 by NetModule AG, Switzerland.
*
* SPDX-License-Identifier: GPL-2.0+
*/
@ -9,15 +9,22 @@
#ifndef __BOARD_DESCRIPTOR_H
#define __BOARD_DESCRIPTOR_H
int bd_read(int bus_addr, int dev_addr);
u8 bd_get_boot_partition(void);
int bd_get_mac(uint index, u8 *mac_address, u32 len);
int bd_get_hw_version(int* ver, int* rev);
void bd_get_hw_patch(int* patch);
int bd_get_devicetree(char* devicetreename, size_t len);
int bd_get_context(BD_Context *bdctx, uint32_t i2caddress, uint32_t offset);
#include "bdparser.h" /* BD_Context */
void bd_register_context_list(const BD_Context *list, size_t count);
u8 bd_get_boot_partition(void);
int bd_get_shield(int shieldnr);
int bd_get_context(BD_Context *bdctx, uint32_t i2caddress, uint32_t offset);
int bd_get_prodname(char *prodname, size_t len);
int bd_get_variantname(char *variantname, size_t len);
void bd_get_hw_version(int* ver, int* rev);
void bd_get_hw_patch(int* patch);
int bd_get_mac(int index, uint8_t *macaddr, size_t len);
uint32_t bd_get_fpgainfo(void);
int bd_get_pd_module(uint32_t slot, char *config, size_t len);
int bd_get_sim_config(char* simconfig, size_t len);
int bd_get_devicetree(char* devicetreename, size_t len);
int bd_get_shield(uint32_t shieldnr);
uint8_t bd_get_boot_partition(void);
#endif /* __BOARD_DESCRIPTOR_H */