CHG: [kernel] use new devicetree/descriptor format on netbird only

SVN commit 23561@trunk
This commit is contained in:
Stefan Eichenberger 2017-03-01 15:04:21 +00:00 committed by Moritz Rosenthal
parent 5ee94ef1fe
commit c6da2089ea
15 changed files with 441 additions and 3192 deletions

View File

@ -112,6 +112,7 @@ static const BD_Info bd_info[] = {
{ BD_Hmac_Sha1_4 , BD_Type_HMAC , "hmac-sha1" },
{ BD_Ui_Adapter_Type , BD_Type_UInt16 , "ui_adapter_type" },
{ PD_Dev_Tree , BD_Type_String , "pd_dev_tree" },
/* Guard entry, must be last in array (don't remove) */
{ BD_End , BD_Type_End , 0 },

View File

@ -160,6 +160,15 @@ typedef enum _BD_Tags
BD_Ui_Adapter_Type = 4096, /**< "UInt16" -> IV OG2 UI adapterboard type (0 = not present) */
BD_Pd_Module0 = 4100,
BD_Pd_Module1 = 4101,
BD_Pd_Module2 = 4102,
BD_Pd_Module3 = 4103,
BD_Pd_Module4 = 4104,
BD_Pd_Module5 = 4105,
BD_Pd_Sim = 4122,
PD_Dev_Tree = 4125, /**< "String" -> Devicetree file name */
/* project specific tags */
BD_BootPart = 32768, /**< "UInt8" */

View File

@ -0,0 +1,272 @@
/******************************************************************************
* (c) COPYRIGHT 2010 by NetModule AG, Switzerland. All rights reserved.
*
* 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
*
* ABSTRACT:
* Implements functions for settings
*
* HISTORY:
* Date Author Description
* 20100421 SMA created
* 20100903 rs reading carrier board descriptor from EEPROM at 54.
* code cleanup (tabs/indentation)
* 20110211 rs partition table handling
*
*****************************************************************************/
#include <common.h>
#include <i2c.h>
#include <malloc.h>
#include "bdparser.h" /* tlv parser */
#define MAX_PARTITION_ENTRIES 4
static const BD_Context *bdctx_list; /* The board descriptor context */
static size_t bdctx_count = 0;
void bd_register_context_list(const BD_Context *list, size_t count) {
bdctx_list = list;
bdctx_count = count;
}
int bd_get_context(BD_Context *bdctx, uint32_t i2caddress, uint32_t offset)
{
bd_bool_t rc;
uint8_t bdHeader[8];
void* pBdData = NULL;
/* Read header bytes from beginning of EEPROM */
if (i2c_read( i2caddress, offset, 2, bdHeader, BD_HEADER_LENGTH )) {
debug("%s() Can't read BD header from EEPROM\n", __func__);
goto exit1;
}
/* Check whether this is a valid board descriptor (or empty EEPROM) */
rc = BD_CheckHeader( bdctx, bdHeader );
if (!rc) {
debug("%s() No valid board descriptor found\n", __func__);
goto exit1;
}
/* Allocate memory for descriptor data and .. */
pBdData = malloc( bdctx->size );
if ( pBdData == NULL ) {
debug("%s() Can't allocate %d bytes\n", __func__, bdctx->size);
goto exit1;
}
/* .. read data from EEPROM */
if (i2c_read(i2caddress, offset+BD_HEADER_LENGTH, 2, pBdData, bdctx->size)) {
debug("%s() Can't read data from EEPROM\n", __func__);
goto exit1;
}
/*
* Import data into board descriptor context
*/
rc = BD_ImportData( bdctx, pBdData );
if (!rc) {
debug("%s() Invalid board descriptor data\n", __func__);
goto exit1;
}
return 0;
exit1:
if (pBdData != NULL)
{
free(pBdData);
pBdData = NULL;
}
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_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) ) {
debug("%s() Product name not found\n", __func__);
return -1;
}
return 0;
}
void bd_get_hw_version(int* ver, int* rev)
{
static uint8_t hwver;
static uint8_t hwrev;
if ( !_get_uint8( BD_Hw_Ver, 0, &hwver) )
debug("%s() no Hw Version found\n", __func__);
if ( !_get_uint8( BD_Hw_Rel, 0, &hwrev) )
debug("%s() no Hw Release found\n", __func__);
*ver = hwver;
*rev = hwrev;
}
int bd_get_mac(int index, uint8_t *macaddr, size_t len)
{
if (len != 6) {
debug("macaddr size must be 6 (is %d)", len);
return -1;
}
/* MAC address */
if ( !_get_mac( BD_Eth_Mac, index, macaddr) ) {
debug("%s() MAC addresss %d not found\n", __func__, index);
return -1;
}
return 0;
}
u32 bd_get_fpgainfo(void)
{
uint32_t fpgainfo = 0xFFFFFFFF;
if ( !_get_uint32( BD_Fpga_Info, 0, &fpgainfo) )
debug("%s() no Fpga Info found\n", __func__);
return fpgainfo;
}
int bd_get_pd_module(int 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",
__func__, slot);
return -1;
}
return 0;
}
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__);
return -1;
}
return 0;
}
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__);
return -1;
}
return 0;
}
static u8 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;
}
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 (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();
}

View File

@ -11,7 +11,11 @@
int bd_read(int bus_addr, int dev_addr);
u8 bd_get_boot_partition(void);
int bd_get_mac_address(uint index, u8 *mac_address, u32 len);
int bd_get_mac(uint index, u8 *mac_address, u32 len);
int bd_get_hw_version(int* pVer, int* pRev);
int bd_get_devicetree(char* devicetreename, size_t len);
int bd_get_context(BD_Context *bdctx, uint32_t i2caddress, uint32_t offset);
void bd_register_context_list(const BD_Context *list, size_t count);
u8 bd_get_boot_partition(void);
#endif /* __BOARD_DESCRIPTOR_H */

View File

@ -10,4 +10,4 @@ ifeq ($(CONFIG_SKIP_LOWLEVEL_INIT),)
obj-y := mux.o
endif
obj-y += board.o bdparser.o board_descriptor.o
obj-y += board.o ../common/bdparser.o ../common/board_descriptor.o

View File

@ -1,558 +0,0 @@
#ifndef _BDPARSER_H
#define _BDPARSER_H
/******************************************************************************
* (c) COPYRIGHT 2009-2011 by NetModule AG, Switzerland. All rights reserved.
*
* 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 : Board descriptor
*
* ABSTRACT:
* This package implements board descriptor manipulation functions.
*
* HISTORY:
* Date Author Description
* 20091106 rb RFE-FB18392: created
* 20100119 rs Minor cleanup, tags defined
* 20100301 rs Tags redefined
* 20100302 sma RFE-FB18392: created (partition)
* 20100322 th Adaptation WinCE and Win32 (assert)
* Added get bd info (type and name for standard entries)
* Adjusted bd tags
* Added scan entries (init and get next)
* Added partition info (flags and types)
* Added uint64 and partition64
* Changed boolean value true (BD_TRUE to 1)
* 20110104 rs General code cleanup (style guide), added new tags/types
* Added bufLen parameter for BD_GetInfo()
* Fixed wrong sizeof type in GetPartition()
* Changed 64 bit type to "long long" from struct
* Added BD_VerifySha1Hmac() function
*****************************************************************************/
/**
* @file
* Board descriptor parser.
* Get() functions are implemented for all supported basis data types:
* - 8/16/32 bits unsigned integers
* - void
* - string
* - IPv4 addresses
* - Ethernet MAC addresses
*/
/**
\mainpage
\section description Description
This is the generated documentation for the <b>Board Descriptor utilities</b>.
For more details see the Board Descriptor Design Description.
**/
/*--- component configuration ------------------------------------------------*/
/** Select a target or operating system (just one of course) **/
#undef BD_TARGET_WIN32
#undef BD_TARGET_WINCE
#define BD_TARGET_UBOOT
#undef BD_TARGET_LINUX
#undef BD_TARGET_VXWORKS
#undef BD_CONF_UNIT_TESTS /**< define this to include unit test functions */
#undef BD_CONF_WANT_ASSERT /**< define this to use assert functions */
#undef BD_CONF_HAS_HASH /**< set to include hash check functions in parser */
/** Define external hmac-sha1 function to use */
#ifdef BD_CONF_HAS_HASH
extern int hmac_sha1(const void* key, unsigned int keylen, const void* data, unsigned int dataLen, void* hash);
#define BD_SHA1_HASH_FUNC(key, keylen, data, dataLen, hash) \
hmac_sha1 (key, keylen, data, dataLen, hash)
#endif
/** Define desired assert function */
#ifdef BD_CONF_WANT_ASSERT
#ifdef BD_TARGET_WINCE
#define BD_ASSERT(test) ASSERT(test)
#elif defined(BD_TARGET_WIN32) && !defined(_DEBUG)
/* Win32 Release build */
#include <stdio.h>
#include <stdlib.h>
#define BD_ASSERT(test) { if(!(test)) { printf("BD_ASSERT(%s)\n- file <%s>\n- line <%d>\n", #test, __FILE__, __LINE__ ); exit(1); } }
#elif defined(BD_TARGET_LINUX)
#include <linux/kernel.h>
#define BD_ASSERT(test) { if(!(test)) { printk(KERN_NOTICE "BD_ASSERT(%s) %s:%d\n", #test, __FILE__, __LINE__ ); } }
#else
#include <assert.h>
#define BD_ASSERT(test) assert(test)
#endif
#else
/* No assertions wanted */
#define BD_ASSERT(test) ((void) 0)
#endif /* BD_CONF_WANT_ASSERT */
/*--- defines ----------------------------------------------------------------*/
#define BD_MAX_LENGTH (4096) /**< Maximum length of a board descriptor's payload */
#define BD_MAX_ENTRY_LEN (512) /**< Maximum length of a tag value */
#define BD_HEADER_LENGTH (8) /**< Header is 8 bytes long */
#define BD_MAX_PARTITION_NAME (16) /**< Name of partition is at most 16 chars long*/
/*--- types ------------------------------------------------------------------*/
/**
* Board Descriptor Tags
*/
typedef enum _BD_Tags
{
BD_End = 0, /**< "Void" -> End tag */
BD_Serial = 1, /**< "String" -> Serial number of the equipment */
BD_Production_Date = 2, /**< "Date" -> Production date of the board */
BD_Hw_Ver = 3, /**< "UInt8" -> Hardware version of the equipment (Major HW changes, potentionally SW relevant) */
BD_Hw_Rel = 4, /**< "UInt8" -> Hardware release of the equipment (Minor HW changes, not SW relevant) */
BD_Prod_Name = 5, /**< "String" -> Human readable product name */
BD_Prod_Variant = 6, /**< "UInt16" -> Product variant */
BD_Prod_Compatibility = 7, /**< "String" -> Product compatibility name */
BD_Eth_Mac = 8, /**< "MAC" -> MAC address of the ethernet interface */
BD_Ip_Addr = 9, /**< "IPV4" -> IP V4 address (0.0.0.0 = DHCP) */
BD_Ip_Netmask = 10, /**< "IPV4" -> IP V4 address mask */
BD_Ip_Gateway = 11, /**< "IPV4" -> IP V4 address of the default gateway */
BD_Usb_Device_Id = 12, /**< "UInt16" -> USB device ID */
BD_Usb_Vendor_Id = 13, /**< "UInt16" -> USB vendor ID */
BD_Ram_Size = 14, /**< "UInt32" -> Available RAM size in bytes */
BD_Ram_Size64 = 15, /**< "UInt64" -> Available RAM size in bytes */
BD_Flash_Size = 16, /**< "UInt32" -> Available flash size in bytes */
BD_Flash_Size64 = 17, /**< "UInt64" -> Available flash size in bytes */
BD_Eeeprom_Size = 18, /**< "UInt32" -> Available EEPROM size in bytes */
BD_Nv_Rram_Size = 19, /**< "UInt32" -> Available EEPROM size in bytes */
BD_Cpu_Base_Clk = 20, /**< "UInt32" -> Base clock of the CPU in Hz = external clock input */
BD_Cpu_Core_Clk = 21, /**< "UInt32" -> Core clock of the CPU in Hz */
BD_Cpu_Bus_Clk = 22, /**< "UInt32" -> Bus clock of the CPU in Hz */
BD_Ram_Clk = 23, /**< "UInt32" -> RAM clock in Hz */
BD_Partition = 24, /**< "Partition" -> Offset of 1st Uboot partition in the 1st flash device in bytes */
BD_Partition64 = 25, /**< "Partition64" -> Offset of 1st Uboot partition in the 1st flash device in bytes */
BD_Lcd_Type = 26, /**< "UInt16" -> LCD type -> 0 = not present (interpretation can be project specific) */
BD_Lcd_Backlight = 27, /**< "UInt8" -> LCD backlight setting (0 = off; 100=max) */
BD_Lcd_Contrast = 28, /**< "UInt8" -> LCD contrast setting (0 = min; 100=max) */
BD_Touch_Type = 29, /**< "UInt16" -> Touch Screen type --> 0 = not present/defined */
BD_Manufacturer_Id = 30, /**< "String" -> Manufacturer id of the produced equipment (i.e. barcode) */
BD_Hmac_Sha1_4 = 31, /**< "Hash" -> SHA1 HMAC with 4 byte result */
BD_Fpga_Info = 32, /**< "UInt32" -> FPGA type/location (0xTTPPRRRR TT=FPGA type, PP=Population location, RRRR=Reserved allways 0000) */
BD_Ui_Adapter_Type = 4096, /**< "UInt16" -> IV OG2 UI adapterboard type (0 = not present) */
/* project specific tags */
BD_BootPart = 32768, /**< "UInt8" */
BD_None_Type = 65535, /**< "Void" -> None */
}
BD_Tags;
/**
* Board Descriptor Tag Types
*/
typedef enum _BD_Type
{
BD_Type_End = 0x00000000,
BD_Type_Void = 0x00000001,
BD_Type_UInt8 = 0x00000002,
BD_Type_UInt16 = 0x00000003,
BD_Type_UInt32 = 0x00000004,
BD_Type_UInt64 = 0x00000005,
BD_Type_String = 0x00000010,
BD_Type_Date = 0x00000020,
BD_Type_MAC = 0x00000030,
BD_Type_IPV4 = 0x00000040,
BD_Type_Partition = 0x00000050,
BD_Type_Partition64 = 0x00000051,
BD_Type_HMAC = 0x00000060,
BD_Type_None = 0xFFFFFFFF,
}
BD_Type;
typedef unsigned int bd_uint_t; /**< Generic UInt */
typedef unsigned int bd_size_t; /**< Size type */
typedef unsigned char bd_uint8_t; /**< 8 Bit unsigned integer */
typedef unsigned short bd_uint16_t; /**< 16 Bit unsigned integer */
typedef unsigned int bd_uint32_t; /**< 32 Bit unsigned integer */
#if defined(BD_TARGET_WIN32) || defined (BD_TARGET_WINCE)
typedef unsigned __int64 bd_uint64_t; /**< 64 Bit unsigned integer */
#else
typedef unsigned long long bd_uint64_t; /**< 64 Bit unsigned integer */
#endif
typedef int bd_bool_t; /**< Boolean */
#define BD_FALSE 0 /**< Boolean FALSE */
#define BD_TRUE 1 /**< Boolean TRUE */
typedef struct _BD_Info
{
BD_Tags tag;
BD_Type type;
const char* pName;
}
BD_Info;
typedef struct _BD_Entry
{
bd_uint16_t tag; /**< Tag of entry */
bd_size_t len; /**< Length of entry */
bd_uint_t entry; /**< Number of entry */
const bd_uint8_t* pData; /**< Pointer to descriptor data of entry */
}
BD_Entry;
/**
* Board Descriptor Context
*
* This structure is passed to all calls of a Board Descriptor function.
* It stores the required context information.
* The entries are solely used by the Board Descriptor functions.
* They must not be accessed by the user.
*/
typedef struct _BD_Context
{
bd_bool_t headerOk; /**< True if header check passed else false */
bd_bool_t initialized; /**< True if data imported (and checked) */
bd_uint_t size; /**< Size of descriptor data */
bd_uint_t entries; /**< Number of entries found */
bd_uint16_t checksum; /**< Payload checksum contained in the header */
const bd_uint8_t* pData; /**< Pointer to descriptor data (not header) */
const bd_uint8_t* pDataEnd; /**< Pointer to end of data */
}
BD_Context;
/*
* Partition Flags
*/
typedef enum _BD_Partition_Flags
{
BD_Partition_Flags_None = 0x00, /**< No special flags */
BD_Partition_Flags_Active = 0x80, /**< Partition is active */
}
BD_Partition_Flags;
/*
* Partition Type
*/
typedef enum _BD_Partition_Type
{
BD_Partition_Type_Raw = 0, /**< Unspecified type */
BD_Partition_Type_Raw_BootLoader = 1, /**< Linear bootloader image */
BD_Partition_Type_Raw_BBT = 2, /**< Bad Block Table */
BD_Partition_Type_FS_YAFFS2 = 3, /**< YAFFS2 Partition */
BD_Partition_Type_FS_JFFS2 = 4, /**< JFFS2 Partition */
BD_Partition_Type_FS_FAT16 = 5, /**< FAT16 Partition */
BD_Partition_Type_FS_FAT32 = 6, /**< FAT32 Partition */
BD_Partition_Type_FS_EXFAT = 7, /**< EXFAT Partition */
BD_Partition_Type_Max = 8, /**< For error checks */
}
BD_Partition_Type;
/*
* Partition Options (Partition64 element only)
*/
typedef enum _BD_Partition_Options
{
BD_Partition_Opts_None = 0x00, /***< No special options */
BD_Partition_Opts_ReadOnly = 0x01, /***< Partition should be mounted read only */
BD_Partition_Opts_OS = 0x02, /***< Partition contains operating system (OS) */
}
BD_Partition_Options;
/**
* Board descriptor type to describe filesystem partitions
*
* The function BD_GetPartition will directly fill such a structure.
*/
typedef struct _BD_PartitionEntry
{
BD_Partition_Flags flags;
BD_Partition_Type type;
bd_uint32_t offset;
bd_uint32_t size;
char name[BD_MAX_PARTITION_NAME+1];
}
BD_PartitionEntry;
/**
* Board descriptor type to describe filesystem partitions
*
* Extended version with 64 bit addresses and options field.
* The function BD_GetPartition64 will directly fill such a structure.
*/
typedef struct _BD_PartitionEntry64
{
BD_Partition_Flags flags;
BD_Partition_Type type;
BD_Partition_Options options;
bd_uint64_t offset;
bd_uint64_t size;
char name[BD_MAX_PARTITION_NAME+1];
}
BD_PartitionEntry64;
/*--- function prototypes ----------------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif
/**
* Checks a BD header's validity and updates the BD context.
*
* @param[in,out] pCtx The context of the BD being checked.
* @param[in] pHeader Pointer to the BD header
* @return True if the header is valid and the context was updated.
* False if the header s not valid.
*/
bd_bool_t BD_CheckHeader( BD_Context* pCtx, const void* pHeader );
/**
* Imports BD data from a buffer into a BD context.
*
* @param[in,out] pCtx The context into which data is imported.
* @param[in] pData Pointer to the buffer containing the BD entries.
* @return True if BD entries could be succesfuly imported.
* False if there is an error in the buffer data structure.
*/
bd_bool_t BD_ImportData( BD_Context* pCtx, const void* pData );
/**
* Checks the existence of a tag in the BD
*
* @param[in,out] pCtx The context in which the tag is searched.
* @param[in] tag Tag being checked.
* @param[in] index Index of the tag (0=first index).
* @return True if the entry exists in the BD else False.
*/
bd_bool_t BD_ExistsEntry( const BD_Context* pCtx, bd_uint16_t tag, bd_uint_t index );
/**
* Get type and name of a tag in the BD info table
*
* @param[in] tag Tag reference.
* @param[out] pType Type of the tag (0 if not used).
* @param[out] pName Name of the tag (0 if not used).
* @param[in] bufLen Length of the pName buffer.
* If required the returned string for pName will be truncated.
* @return True if the tag in the BD info table exists else False.
*/
bd_bool_t BD_GetInfo( bd_uint16_t tag, BD_Type* pType, char* pName, bd_size_t bufLen );
/**
* Initialize the entry before use BD_GetNextEntry
*
* @param[out] pEntry BD entry to be initalized.
* @return True if the entry was initialized, fasle otherwise.
*/
bd_bool_t BD_InitEntry( BD_Entry* pEntry);
/**
* Get type and name of a tag in the BD info table
*
* @param[in] pCtx The context from which the value is read.
* @param[out] pEntry BD entry (use BD_InitEntry, not 0 for first ).
* @return True if the tag in the BD info table exists else False.
*/
bd_bool_t BD_GetNextEntry( const BD_Context* pCtx, BD_Entry* pEntry );
/**
* Gets a void value from a BD.
*
* @param[in] pCtx The context from which the value is read.
* @param[in] tag Tag Id.
* @param[in] index Index of the tag (0=first occurance).
* @param[out] pResult True if the value could be found else False.
* @return False if something went wrong dring the parsing else True.
*/
bd_bool_t BD_GetVoid( const BD_Context* pCtx, bd_uint16_t tag, bd_uint_t index, bd_bool_t* pResult );
/**
* Gets an 8 bits unsigned integer value from a BD.
*
* @param[in] pCtx The context from which the value is read.
* @param[in] tag Tag Id.
* @param[in] index Index of the tag (0=first occurance).
* @param[out] pResult Placeholder for the read value.
* @return True if the value in pResult is valid else False.
*/
bd_bool_t BD_GetUInt8( const BD_Context* pCtx, bd_uint16_t tag, bd_uint_t index, bd_uint8_t* pResult );
/**
* Gets a 16 bits unsigned integer value from a BD.
*
* @param[in] pCtx The context from which the value is read.
* @param[in] tag Tag Id.
* @param[in] index Index of the tag (0=first occurance).
* @param[out] pResult Placeholder for the read value.
* @return True if the value in pResult is valid else False.
*/
bd_bool_t BD_GetUInt16( const BD_Context* pCtx, bd_uint16_t tag, bd_uint_t index, bd_uint16_t* pResult );
/**
* Gets a 32 bits unsigned integer value from a BD.
*
* @param[in] pCtx The context from which the value is read.
* @param[in] tag Tag Id.
* @param[in] index Index of the tag (0=first occurance).
* @param[out] pResult Placeholder for the read value.
* @return True if the value in pResult is valid else False.
*/
bd_bool_t BD_GetUInt32( const BD_Context* pCtx, bd_uint16_t tag, bd_uint_t index, bd_uint32_t* pResult );
/**
* Gets a 64 bits unsigned integer value from a BD.
*
* @param[in] pCtx The context from which the value is read.
* @param[in] tag Tag Id.
* @param[in] index Index of the tag (0=first occurance).
* @param[out] pResult Placeholder for the read value.
* @return True if the value in pResult is valid else False.
*/
bd_bool_t BD_GetUInt64( const BD_Context* pCtx, bd_uint16_t tag, bd_uint_t index, bd_uint64_t* pResult );
/**
* Gets a string value from a BD.
*
* @param[in] pCtx The context from which the value is read.
* @param[in] tag Tag Id.
* @param[in] index Index of the tag (0=first occurance).
* @param[out] pResult Placeholder for the read value.
* @param[in] bufLen Length of the pResult buffer.
* @return True if the value in pResult is valid else False.
*
* @note @li The returned string in pResult is null-terminated.
* @li If the buffer is too.small to hold the value the returned string is truncated.
*/
bd_bool_t BD_GetString( const BD_Context* pCtx, bd_uint16_t tag, bd_uint_t index, char* pResult, bd_size_t bufLen );
/**
* Gets a binary large object (blob) value from a BD.
*
* @param[in] pCtx The context from which the value is read.
* @param[in] tag Tag Id.
* @param[in] index Index of the tag (0=first occurance).
* @param[out] pResult Placeholder for the read value.
* @param[in] bufLen Length of the pResult buffer.
* @param[out] pReadLen The actual number of bytes read.
* @return True if the complete tag value could be read in pResult else False.
*/
bd_bool_t BD_GetBlob( const BD_Context* pCtx, bd_uint16_t tag, bd_uint_t index,
char* pResult, bd_size_t bufLen, bd_size_t* pReadLen );
/**
* Gets an IPv4 address from a BD.
*
* The IP address is returned as a 32 bits unsigned integer with the most
* significant byte first. E.g. 192.168.2.1 is stored as 0xC0A80201
*
* @param[in] pCtx The context from which the IP address is read.
* @param[in] tag Tag Id.
* @param[in] index Index of the tag (0=first occurance).
* @param[out] pResult Placeholder for the read IP address.
* @return True if the value in pResult is valid else False.
*/
bd_bool_t BD_GetIPv4( const BD_Context* pCtx, bd_uint16_t tag, bd_uint_t index, bd_uint32_t* pResult );
/**
* Gets an Ethernet MAC address from a BD.
*
* @param[in] pCtx The context from which the MAC address is read.
* @param[in] tag Tag Id.
* @param[in] index Index of the tag (0=first occurance).
* @param[out] pResult Placeholder for the read MAC address.
* @return True if the value in pResult is valid else False.
*/
bd_bool_t BD_GetMAC( const BD_Context* pCtx, bd_uint16_t tag, bd_uint_t index, bd_uint8_t pResult[6] );
/**
* Gets a partition entry from a BD.
*
* @param[in,out] pCtx The context from which the MAC address is read.
* @param[in] tag Tag Id.
* @param[in] index Index of the tag (0=first occurance).
* @param[out] pResult Placeholder for the partition entry
* @return True if the value in pResult is valid else False.
*/
bd_bool_t BD_GetPartition( const BD_Context* pCtx, bd_uint16_t tag, bd_uint_t index, BD_PartitionEntry* pResult );
/**
* Gets a partition64 entry from a BD.
*
* @param[in,out] pCtx The context from which the MAC address is read.
* @param[in] tag Tag Id.
* @param[in] index Index of the tag (0=first occurance).
* @param[out] pResult Placeholder for the partition entry
* @return True if the value in pResult is valid else False.
*/
bd_bool_t BD_GetPartition64( const BD_Context* pCtx, bd_uint16_t tag, bd_uint_t index, BD_PartitionEntry64* pResult );
#ifdef BD_CONF_HAS_HASH
/**
* Verifies the SHA1-HMAC checksum.
*
* The checksum is computed with the specified key over the area defined
* by the hash tag. The key must match the one used to generate the descriptor.
*
* @param[in] pCtx The context from which the MAC address is read.
* @param[in] tag Tag Id.
* @param[in] index Index of the tag (0=first occurance).
* @param[in] pKey Pointer to key for HMAC initialization.
* @param[in] keyLen Size of the key.
* @return True if the protected data is unmodified. False in any other case.
*/
bd_bool_t BD_VerifySha1Hmac( const BD_Context* pCtx, bd_uint16_t tag, bd_uint_t index, const void* pKey, bd_size_t keyLen );
#endif
#ifdef BD_CONF_UNIT_TESTS
/**
* Runs unit tests
*
* If an error occurs an assert is triggered
*/
void BD_UnitTest(void);
#endif /* BD_CONF_UNIT_TESTS */
#ifdef __cplusplus
} /*end extern c*/
#endif
#endif /* _BDPARSER_H */

View File

@ -34,7 +34,8 @@
#include <environment.h>
#include <watchdog.h>
#include <environment.h>
#include "board_descriptor.h"
#include "../common/bdparser.h"
#include "../common/board_descriptor.h"
#include "board.h"
#include <console.h>
@ -66,12 +67,38 @@ DECLARE_GLOBAL_DATA_PTR;
static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
#endif
#define BD_EEPROM_ADDR (0x50) /* CPU BD EEPROM (8kByte) is at 50 (A0) */
#define BD_ADDRESS (0x0000) /* Board descriptor at beginning of EEPROM */
#define PD_ADDRESS (0x0200) /* Product descriptor */
#define PARTITION_ADDRESS (0x0600) /* Partition Table */
static BD_Context bdctx[3]; /* The descriptor context */
static int _bd_init(void)
{
if (bd_get_context(&bdctx[0], BD_EEPROM_ADDR, BD_ADDRESS) != 0) {
printf("%s() no valid bd found\n", __func__);
return -1;
}
if (bd_get_context(&bdctx[1], BD_EEPROM_ADDR, PD_ADDRESS) != 0) {
printf("%s() no valid pd found (legacy support)\n", __func__);
}
if (bd_get_context(&bdctx[2], BD_EEPROM_ADDR, PARTITION_ADDRESS) != 0) {
printf("%s() no valid partition table found\n", __func__);
}
bd_register_context_list(bdctx, ARRAY_SIZE(bdctx));
return 0;
}
/*
* Read header information from EEPROM into global structure.
*/
static inline int __maybe_unused read_eeprom(void)
{
return bd_read(-1, CONFIG_SYS_I2C_EEPROM_ADDR);
return _bd_init();
}
struct serial_device *default_serial_console(void)
@ -353,12 +380,40 @@ int board_init(void)
return 0;
}
#if !defined(CONFIG_SPL_BUILD)
static void set_devicetree_name(void)
{
char devicetreename[64];
/* add hardware versions to environment */
if (bd_get_devicetree(devicetreename, sizeof(devicetreename)) != 0) {
printf("Devicetree name not found, use legacy name\n");
strcpy(devicetreename, "am335x-nbhw16.dtb");
}
setenv("fdt_image", devicetreename);
}
static void get_hw_version(void)
{
int hw_ver, hw_rev;
char hw_versions[16];
char new_env[256];
/* add hardware versions to environment */
bd_get_hw_version(&hw_ver, &hw_rev);
printf("HW16: V%d.%d\n", hw_ver, hw_rev);
snprintf(hw_versions, sizeof(hw_versions), "CP=%d.%d", hw_ver, hw_rev);
snprintf(new_env, sizeof(new_env), "setenv bootargs $bootargs %s", hw_versions);
setenv("add_version_bootargs", new_env);
}
#endif
#ifdef CONFIG_BOARD_LATE_INIT
int board_late_init(void)
{
#if !defined(CONFIG_SPL_BUILD)
int hw_ver, hw_rev;
int boot_partition;
if (read_eeprom() < 0)
@ -373,17 +428,11 @@ int board_late_init(void)
/* mmcblk0p1 => root0, mmcblk0p2 => root1 so +1 */
setenv_ulong("root_part", boot_partition + 1);
/* add hardware versions to environment */
if (bd_get_hw_version(&hw_ver, &hw_rev)==0) {
char hw_versions[128];
char new_env[256];
snprintf(hw_versions, sizeof(hw_versions), "CP=%d.%d", hw_ver, hw_rev);
snprintf(new_env, sizeof(new_env), "setenv bootargs $bootargs %s", hw_versions);
setenv("add_version_bootargs", new_env);
}
check_reset_button();
get_hw_version();
set_devicetree_name();
#endif
#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
@ -481,10 +530,10 @@ int board_eth_init(bd_t *bis)
cpsw_data.mdio_div = 0x3E;
bd_get_mac_address(0, mac_addr0, sizeof(mac_addr0));
bd_get_mac(0, mac_addr0, sizeof(mac_addr0));
set_mac_address(0, mac_addr0);
bd_get_mac_address(1, mac_addr1, sizeof(mac_addr1));
bd_get_mac(1, mac_addr1, sizeof(mac_addr1));
set_mac_address(1, mac_addr1);
writel(RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE, &cdev->miisel);

View File

@ -1,240 +0,0 @@
/*
* Library to support early TI EVM EEPROM handling
*
* Copyright (C) 2015-2016 Texas Instruments Incorporated - http://www.ti.com/
* Lokesh Vutla
* Steve Kipisz
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <asm/omap_common.h>
#include <i2c.h>
#include <malloc.h>
#include <asm/io.h>
#include "board_descriptor.h"
#include "bdparser.h"
#define SYSINFO_ADDRESS 0x0000 /* Board descriptor at beginning of EEPROM */
#define SYSCONFIG_ADDRESS 0x0600 /* Board descriptor at beginning of EEPROM */
#define MAX_PARTITION_ENTRIES 4
static BD_Context *bd_board_info = 0;
static BD_Context *bd_system_config = 0;
static int i2c_eeprom_init(int i2c_bus, int dev_addr)
{
int rc;
if (i2c_bus >= 0) {
rc = i2c_set_bus_num(i2c_bus);
if (rc)
return rc;
}
return i2c_probe(dev_addr);
}
static int i2c_eeprom_read(int offset, void *data, size_t len)
{
return i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR,
offset,
CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
data,
len);
}
static int boardinfo_read(BD_Context **context, size_t start_addr)
{
char bd_header_buffer[8];
void *bd_data = NULL;
if(*context)
return 0;
*context = calloc(sizeof(BD_Context), 1);
if(!*context)
{
printf("Couldn't allocate memory for board information\n");
goto failed;
}
if (i2c_eeprom_read(start_addr, bd_header_buffer, sizeof(bd_header_buffer))) {
printf("%s() Can't read BD header from EEPROM\n", __FUNCTION__);
goto failed;
}
if (!BD_CheckHeader(*context, bd_header_buffer))
{
printf("Invalid board information header\n");
goto failed;
}
bd_data = malloc((*context)->size);
if (bd_data == NULL)
{
printf("Can not allocate memory for board info");
goto failed;
}
if (i2c_eeprom_read(start_addr + sizeof(bd_header_buffer), bd_data, (*context)->size))
{
printf("Can not read board information data");
goto failed;
}
if (!BD_ImportData(*context, bd_data))
{
printf("Invalid board information!\n");
goto failed;
}
return 0;
failed:
if (bd_data != NULL)
{
free(bd_data);
bd_data = NULL;
}
if (*context != NULL)
{
free(*context);
*context = NULL;
}
return -1;
}
static void read_sysinfo(void)
{
int err;
err = boardinfo_read(&bd_board_info, SYSINFO_ADDRESS);
if (err ) {
printf("Could not read sysinf boarddescriptor\n");
return;
}
return;
}
static void read_sysconfig(void)
{
int err;
err = boardinfo_read(&bd_system_config, SYSCONFIG_ADDRESS);
if (err ) {
printf("Could not read sysconfig boarddescriptor\n");
return;
}
}
int bd_read (int bus_addr, int dev_addr)
{
if (i2c_eeprom_init(bus_addr, dev_addr)) {
return -1;
}
read_sysinfo();
read_sysconfig();
return 0;
}
static u8 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 = BD_GetPartition64( bd_system_config, 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;
}
u8 bd_get_boot_partition(void)
{
u8 boot_part;
if ((bd_system_config == 0)) {
puts("System config not valid, can not get boot partition\n");
return 0;
}
/* If we have a new Bootpartition entry take this as boot part */
if ( BD_GetUInt8( bd_system_config, 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();
}
int bd_get_mac_address(uint index, u8 *mac, u32 len)
{
if (bd_board_info == 0) {
puts("Board info not valid, can not get mac address\n");
return -1;
}
if (len != 6) {
return -1;
}
if (BD_GetMAC( bd_board_info, BD_Eth_Mac, index, mac))
return 0;
else
return -1;
}
int bd_get_hw_version(int* pVer, int* pRev)
{
u8 bdCpHwVer = 0;
u8 bdCpHwRev = 0;
if (bd_board_info == 0) {
puts("Board info not valid, can not get hw version\n");
return -1;
}
/* Hardware version/revision */
if ( !BD_GetUInt8( bd_board_info, BD_Hw_Ver, 0, &bdCpHwVer) ) {
printf("no Hw version found\n");
return -1;
}
/* Hardware version/revision */
if ( !BD_GetUInt8( bd_board_info, BD_Hw_Rel, 0, &bdCpHwRev) ) {
printf("no Hw release found\n");
return -1;
}
*pVer = bdCpHwVer;
*pRev = bdCpHwRev;
return 0;
}

View File

@ -1,17 +0,0 @@
/*
* Library to support early TI EVM EEPROM handling
*
* Copyright (C) 2015-2016 Texas Instruments Incorporated - http://www.ti.com
*
* SPDX-License-Identifier: GPL-2.0+
*/
#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_address(uint index, u8 *mac_address, u32 len);
int bd_get_hw_version(int* pVer, int* pRev);
#endif /* __BOARD_DESCRIPTOR_H */

View File

@ -10,4 +10,4 @@ ifeq ($(CONFIG_SKIP_LOWLEVEL_INIT),)
obj-y := mux.o
endif
obj-y += board.o bdparser.o board_descriptor.o
obj-y += board.o ../common/bdparser.o ../common/board_descriptor.o

File diff suppressed because it is too large Load Diff

View File

@ -34,7 +34,8 @@
#include <environment.h>
#include <watchdog.h>
#include <environment.h>
#include "board_descriptor.h"
#include "../common/bdparser.h"
#include "../common/board_descriptor.h"
#include "board.h"
DECLARE_GLOBAL_DATA_PTR;
@ -59,6 +60,7 @@ DECLARE_GLOBAL_DATA_PTR;
#define NETBIRD_GPIO_LED_B GPIO_TO_PIN(1, 15)
#define NETBIRD_GPIO_RESET_BUTTON GPIO_TO_PIN(0, 2)
#define NETBIRD_GPIO_USB_PWR_EN GPIO_TO_PIN(1, 27)
#define NETBIRD_GPIO_USB_PWR_EN_2 GPIO_TO_PIN(2, 4) // On new version this gpio is used
#define DDR3_CLOCK_FREQUENCY (400)
@ -67,12 +69,38 @@ DECLARE_GLOBAL_DATA_PTR;
static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
#endif
#define BD_EEPROM_ADDR (0x50) /* CPU BD EEPROM (8kByte) is at 50 (A0) */
#define BD_ADDRESS (0x0000) /* Board descriptor at beginning of EEPROM */
#define PD_ADDRESS (0x0200) /* Product descriptor */
#define PARTITION_ADDRESS (0x0600) /* Partition Table */
static BD_Context bdctx[3]; /* The descriptor context */
static int _bd_init(void)
{
if (bd_get_context(&bdctx[0], BD_EEPROM_ADDR, BD_ADDRESS) != 0) {
printf("%s() no valid bd found\n", __func__);
return -1;
}
if (bd_get_context(&bdctx[1], BD_EEPROM_ADDR, PD_ADDRESS) != 0) {
printf("%s() no valid pd found (legacy support)\n", __func__);
}
if (bd_get_context(&bdctx[2], BD_EEPROM_ADDR, PARTITION_ADDRESS) != 0) {
printf("%s() no valid partition table found\n", __func__);
}
bd_register_context_list(bdctx, ARRAY_SIZE(bdctx));
return 0;
}
/*
* Read header information from EEPROM into global structure.
*/
static inline int __maybe_unused read_eeprom(void)
{
return bd_read(-1, CONFIG_SYS_I2C_EEPROM_ADDR);
return _bd_init();
}
struct serial_device *default_serial_console(void)
@ -304,6 +332,7 @@ int check_reset_button(void)
static void enable_ext_usb(void)
{
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_USB_PWR_EN);
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_USB_PWR_EN_2);
/* Disable LS2 */
if (tps65218_reg_write(TPS65218_PROT_LEVEL_2, TPS65218_ENABLE2, 0x00, 0x04)) {
puts ("tps65218_reg_write failure (LS2 enable)\n");
@ -317,6 +346,7 @@ static void enable_ext_usb(void)
mdelay(10);
gpio_set_value(NETBIRD_GPIO_USB_PWR_EN, 1);
gpio_set_value(NETBIRD_GPIO_USB_PWR_EN_2, 1);
mdelay(50);
@ -367,8 +397,8 @@ int board_init(void)
mdelay(1200);
gpio_set_value(NETBIRD_GPIO_PWR_GSM, 0);
REQUEST_AND_SET_GPIO(NETBIRD_GPIO_LED_A);
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_LED_B);
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_LED_A);
REQUEST_AND_SET_GPIO(NETBIRD_GPIO_LED_B);
REQUEST_AND_SET_GPIO(NETBIRD_GPIO_RST_PHY_N);
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_WLAN_EN);
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_BT_EN);
@ -438,11 +468,49 @@ static void enable_wlan_clock(void)
enable_pwm();
}
#if !defined(CONFIG_SPL_BUILD)
static void set_devicetree_name(void)
{
char devicetreename[64];
/* add hardware versions to environment */
if (bd_get_devicetree(devicetreename, sizeof(devicetreename)) != 0) {
printf("Devicetree name not found, use legacy name\n");
strcpy(devicetreename, "am335x-nbhw16-prod2.dtb");
}
setenv("fdt_image", devicetreename);
}
static void get_hw_version(void)
{
int hw_ver, hw_rev;
char hw_versions[16];
char new_env[256];
/* add hardware versions to environment */
bd_get_hw_version(&hw_ver, &hw_rev);
printf("HW16: V%d.%d\n", hw_ver, hw_rev);
snprintf(hw_versions, sizeof(hw_versions), "CP=%d.%d", hw_ver, hw_rev);
snprintf(new_env, sizeof(new_env), "setenv bootargs $bootargs %s", hw_versions);
setenv("add_version_bootargs", new_env);
}
static void check_fct(void)
{
/* If probe fails we are sure no eeprom is connected */
if (i2c_probe(0x51) == 0) {
printf("Entering fct mode\n");
setenv ("bootcmd", "");
}
}
#endif
#ifdef CONFIG_BOARD_LATE_INIT
int board_late_init(void)
{
#if !defined(CONFIG_SPL_BUILD)
int hw_ver, hw_rev;
int boot_partition;
if (read_eeprom() < 0)
@ -457,18 +525,11 @@ int board_late_init(void)
/* mmcblk0p1 => root0, mmcblk0p2 => root1 so +1 */
setenv_ulong("root_part", boot_partition + 1);
/* add hardware versions to environment */
if (bd_get_hw_version(&hw_ver, &hw_rev)==0) {
char hw_versions[128];
char new_env[256];
printf("HW16: V%d.%d\n", hw_ver, hw_rev);
snprintf(hw_versions, sizeof(hw_versions), "CP=%d.%d", hw_ver, hw_rev);
snprintf(new_env, sizeof(new_env), "setenv bootargs $bootargs %s", hw_versions);
setenv("add_version_bootargs", new_env);
}
check_reset_button();
get_hw_version();
set_devicetree_name();
#endif
#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
@ -480,6 +541,10 @@ int board_late_init(void)
enable_wlan_clock();
#if !defined(CONFIG_SPL_BUILD)
check_fct();
#endif
return 0;
}
#endif
@ -560,7 +625,6 @@ int board_eth_init(bd_t *bis)
{
int rv, n = 0;
uint8_t mac_addr0[6] = {02,00,00,00,00,01};
uint8_t mac_addr1[6] = {02,00,00,00,00,02};
__maybe_unused struct ti_am_eeprom *header;
#if !defined(CONFIG_SPL_BUILD)
@ -568,12 +632,9 @@ int board_eth_init(bd_t *bis)
cpsw_data.mdio_div = 0x3E;
bd_get_mac_address(0, mac_addr0, sizeof(mac_addr0));
bd_get_mac(0, mac_addr0, sizeof(mac_addr0));
set_mac_address(0, mac_addr0);
bd_get_mac_address(1, mac_addr1, sizeof(mac_addr1));
set_mac_address(1, mac_addr1);
writel(RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE, &cdev->miisel);
cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_RMII;
cpsw_slaves[1].phy_if = PHY_INTERFACE_MODE_RMII;

View File

@ -1,240 +0,0 @@
/*
* Library to support early TI EVM EEPROM handling
*
* Copyright (C) 2015-2016 Texas Instruments Incorporated - http://www.ti.com/
* Lokesh Vutla
* Steve Kipisz
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <asm/omap_common.h>
#include <i2c.h>
#include <malloc.h>
#include <asm/io.h>
#include "board_descriptor.h"
#include "bdparser.h"
#define SYSINFO_ADDRESS 0x0000 /* Board descriptor at beginning of EEPROM */
#define SYSCONFIG_ADDRESS 0x0600 /* Board descriptor at beginning of EEPROM */
#define MAX_PARTITION_ENTRIES 4
static BD_Context *bd_board_info = 0;
static BD_Context *bd_system_config = 0;
static int i2c_eeprom_init(int i2c_bus, int dev_addr)
{
int rc;
if (i2c_bus >= 0) {
rc = i2c_set_bus_num(i2c_bus);
if (rc)
return rc;
}
return i2c_probe(dev_addr);
}
static int i2c_eeprom_read(int offset, void *data, size_t len)
{
return i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR,
offset,
CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
data,
len);
}
static int boardinfo_read(BD_Context **context, size_t start_addr)
{
char bd_header_buffer[8];
void *bd_data = NULL;
if(*context)
return 0;
*context = calloc(sizeof(BD_Context), 1);
if(!*context)
{
printf("Couldn't allocate memory for board information\n");
goto failed;
}
if (i2c_eeprom_read(start_addr, bd_header_buffer, sizeof(bd_header_buffer))) {
printf("%s() Can't read BD header from EEPROM\n", __FUNCTION__);
goto failed;
}
if (!BD_CheckHeader(*context, bd_header_buffer))
{
printf("Invalid board information header\n");
goto failed;
}
bd_data = malloc((*context)->size);
if (bd_data == NULL)
{
printf("Can not allocate memory for board info");
goto failed;
}
if (i2c_eeprom_read(start_addr + sizeof(bd_header_buffer), bd_data, (*context)->size))
{
printf("Can not read board information data");
goto failed;
}
if (!BD_ImportData(*context, bd_data))
{
printf("Invalid board information!\n");
goto failed;
}
return 0;
failed:
if (bd_data != NULL)
{
free(bd_data);
bd_data = NULL;
}
if (*context != NULL)
{
free(*context);
*context = NULL;
}
return -1;
}
static void read_sysinfo(void)
{
int err;
err = boardinfo_read(&bd_board_info, SYSINFO_ADDRESS);
if (err ) {
printf("Could not read sysinf boarddescriptor\n");
return;
}
return;
}
static void read_sysconfig(void)
{
int err;
err = boardinfo_read(&bd_system_config, SYSCONFIG_ADDRESS);
if (err ) {
printf("Could not read sysconfig boarddescriptor\n");
return;
}
}
int bd_read (int bus_addr, int dev_addr)
{
if (i2c_eeprom_init(bus_addr, dev_addr)) {
return -1;
}
read_sysinfo();
read_sysconfig();
return 0;
}
static u8 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 = BD_GetPartition64( bd_system_config, 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;
}
u8 bd_get_boot_partition(void)
{
u8 boot_part;
if ((bd_system_config == 0)) {
puts("System config not valid, can not get boot partition\n");
return 0;
}
/* If we have a new Bootpartition entry take this as boot part */
if ( BD_GetUInt8( bd_system_config, 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();
}
int bd_get_mac_address(uint index, u8 *mac, u32 len)
{
if (bd_board_info == 0) {
puts("Board info not valid, can not get mac address\n");
return -1;
}
if (len != 6) {
return -1;
}
if (BD_GetMAC( bd_board_info, BD_Eth_Mac, index, mac))
return 0;
else
return -1;
}
int bd_get_hw_version(int* pVer, int* pRev)
{
u8 bdCpHwVer = 0;
u8 bdCpHwRev = 0;
if (bd_board_info == 0) {
puts("Board info not valid, can not get hw version\n");
return -1;
}
/* Hardware version/revision */
if ( !BD_GetUInt8( bd_board_info, BD_Hw_Ver, 0, &bdCpHwVer) ) {
printf("no Hw version found\n");
return -1;
}
/* Hardware version/revision */
if ( !BD_GetUInt8( bd_board_info, BD_Hw_Rel, 0, &bdCpHwRev) ) {
printf("no Hw release found\n");
return -1;
}
*pVer = bdCpHwVer;
*pRev = bdCpHwRev;
return 0;
}

View File

@ -58,7 +58,7 @@
"fdt_skip_update=yes\0" \
"ethprime=cpsw\0" \
"sdbringup=echo Try bringup boot && ext4load mmc 1:$root_part $kernel_addr /boot/zImage && " \
"ext4load mmc 1:$root_part $fdt_addr /boot/am335x-nbhw16.dtb && setenv bootargs $bootargs rw;\0" \
"ext4load mmc 1:$root_part $fdt_addr /boot/$fdt_image && setenv bootargs $bootargs rw;\0" \
"sdprod=ext4load mmc 1:$root_part $kernel_addr /boot/$kernel_image && " \
"ext4load mmc 1:$root_part $fdt_addr /boot/$fdt_image && setenv bootargs $bootargs ro;\0" \
"sdboot=if mmc dev 1; then echo Copying Linux from SD to RAM...; "\
@ -217,4 +217,7 @@
#define CONFIG_POWER_TPS65217
#define CONFIG_POWER_TPS62362
/* Never enable ISO it is broaken and can lead to a crash */
#undef CONFIG_ISO_PARTITION
#endif /* ! __CONFIG_AM335X_EVM_H */

View File

@ -54,7 +54,7 @@
"fdt_skip_update=yes\0" \
"ethprime=cpsw\0" \
"sdbringup=echo Try bringup boot && ext4load mmc 1:$root_part $kernel_addr /boot/zImage && " \
"ext4load mmc 1:$root_part $fdt_addr /boot/am335x-nbhw16-nb800.dtb && setenv bootargs $bootargs rw;\0" \
"ext4load mmc 1:$root_part $fdt_addr /boot/$fdt_image && setenv bootargs $bootargs rw;\0" \
"sdprod=ext4load mmc 1:$root_part $kernel_addr /boot/$kernel_image && " \
"ext4load mmc 1:$root_part $fdt_addr /boot/$fdt_image && setenv bootargs $bootargs ro;\0" \
"sdboot=if mmc dev 1; then echo Copying Linux from SD to RAM...; "\
@ -214,4 +214,7 @@
#undef CONFIG_CMD_PXE
/* Never enable ISO it is broaken and can lead to a crash */
#undef CONFIG_ISO_PARTITION
#endif /* ! __CONFIG_AM335X_NETBIRD_V2_H */