• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/cfe/cfe/arch/mips/board/bcm9635x/src/
1/*  *********************************************************************
2    *  Broadcom Common Firmware Environment (CFE)
3    *
4    *  bcm635x_board.c   utility functions for bcm635X board
5    *
6    *  Created on :  09/25/2002  seanl
7    *
8    *********************************************************************
9
10<:copyright-broadcom
11
12 Copyright (c) 2002 Broadcom Corporation
13 All Rights Reserved
14 No portions of this material may be reproduced in any form without the
15 written permission of:
16          Broadcom Corporation
17          16215 Alton Parkway
18          Irvine, California 92619
19 All information contained in this document is Broadcom Corporation
20 company private, proprietary, and trade secret.
21
22:>
23*/
24
25#include "bcm63xx_util.h"
26extern NVRAM_DATA nvramData;
27extern int readNvramData(void);
28
29static int parsePsiSize(char *psiStr)
30{
31    int psiSize = atoi(psiStr);
32
33    if (psiSize >= 1 && psiSize <= NVRAM_PSI_MAX_SIZE)
34        return 0;
35    else
36        return 1;
37}
38
39static int parseMemConfig(char *memSizeStr)
40{
41    int memSize = atoi(memSizeStr);
42
43    if (memSize >= MEMORY_635X_16MB_1_CHIP && memSize <= MEMORY_635X_64MB_2_CHIP)
44        return 0;
45    else
46        return 1;
47}
48
49static PARAMETER_SETTING gBoardParam[] =
50{
51    // prompt name                      Error Prompt Define Param  Validation function
52    {"Board Id String(max 16 char) :", BOARDID_STR_PROMPT, "", "", parseBoardIdStr},
53    {"Psi size in KB (default:127) :", PSI_SIZE_PROMPT, "", "", parsePsiSize},
54    {"Number of MAC Addresses(1-32):", MAC_CT_PROMPT, "", "", parseMacAddrCount},
55    {"Base MAC Address             :", MAC_ADDR_PROMPT, "", "", parseMacAddr},
56    {"Memory size:   Range 0-2\n\
5716MB (1 chip)  ------- 0\n\
5832MB (2 chips) ------- 1\n\
5964MB (2 chips) ------- 2     :", MEM_CONFIG_PROMPT, "", "", parseMemConfig},
60    {NULL}
61};
62
63
64// getBoardParam:  convert the board param data and put them in the gBoardParam struct
65//
66void getBoardParam(void)
67{
68    int memType;
69
70    if (nvramData.szBoardId[0] != (char)0xff)
71        memcpy(gBoardParam[0].parameter, nvramData.szBoardId, NVRAM_BOARD_ID_STRING_LEN);
72    else
73        memset(gBoardParam[0].parameter, 0, NVRAM_BOARD_ID_STRING_LEN);
74
75    if (nvramData.ulPsiSize == 0xffffffff)
76        nvramData.ulPsiSize = NVRAM_PSI_DEFAULT_635X;
77    sprintf(gBoardParam[1].parameter, "%d", nvramData.ulPsiSize);
78
79    if (nvramData.ulNumMacAddrs == 0xffffffff)
80        nvramData.ulNumMacAddrs = NVRAM_MAC_COUNT_DEFAULT_635X;
81    sprintf(gBoardParam[2].parameter, "%d", nvramData.ulNumMacAddrs);
82
83    if (nvramData.ucaBaseMacAddr[0] == 0xff && nvramData.ucaBaseMacAddr[1] == 0xff &&
84        nvramData.ucaBaseMacAddr[2] == 0xff && nvramData.ucaBaseMacAddr[3] == 0xff)
85        memset(gBoardParam[3].parameter, 0, NVRAM_MAC_ADDRESS_LEN);
86    else
87        macNumToStr(nvramData.ucaBaseMacAddr, gBoardParam[3].parameter);
88
89    memType = kerSysMemoryTypeGet();
90
91    if (!(memType >= MEMORY_635X_16MB_1_CHIP && memType <= MEMORY_635X_64MB_2_CHIP))
92        memType = MEMORY_635X_16MB_1_CHIP;
93    sprintf(gBoardParam[4].parameter, "%d", memType);
94}
95
96
97// setBoardParam: Set the board Id string, mac addresses, psi size, etc...
98//
99int setBoardParam(void)
100{
101    int bChange = FALSE;
102    int count = 0;
103    PPARAMETER_SETTING tmpPtr = gBoardParam;
104    int memType;
105
106    while (tmpPtr->promptName !=  NULL)
107    {
108        count++;
109        tmpPtr++;
110    }
111
112    getBoardParam();
113
114    while (1)
115    {
116        bChange = processPrompt(gBoardParam, count);
117        if (strlen(gBoardParam[3].parameter) != 0)
118            break;
119        printf("Base Mac address is not entered.  Try it again!\n");
120    }
121
122    if (bChange)
123    {
124        // fill in board id string, psi and mac count
125        nvramData.ulVersion = NVRAM_VERSION_NUMBER;
126        nvramData.ulEnetModeFlag = 0xffffffff;          // all ffs for enet mode flag
127        memset(nvramData.szBoardId, 0, NVRAM_BOARD_ID_STRING_LEN);
128        memcpy(nvramData.szBoardId, gBoardParam[0].parameter, NVRAM_BOARD_ID_STRING_LEN);
129        nvramData.ulPsiSize = atoi(gBoardParam[1].parameter);
130        nvramData.ulNumMacAddrs = atoi(gBoardParam[2].parameter);
131        parsehwaddr(gBoardParam[3].parameter, nvramData.ucaBaseMacAddr);
132
133        // set memory type thing
134        memType = atoi(gBoardParam[4].parameter);
135        kerSysMemoryTypeSet((int) FLASH63XX_ADDR_BOOT_ROM, (char *)&memType, sizeof(int));
136
137        if (nvramData.ulPsiSize != NVRAM_PSI_DEFAULT_635X)
138        {
139            printf("Are you REALLY sure persistent storage size is %d?", nvramData.ulPsiSize);
140            if (yesno())
141            {
142                nvramData.ulPsiSize = NVRAM_PSI_DEFAULT_635X;
143                sprintf(gBoardParam[1].parameter, "%d", nvramData.ulPsiSize);
144                return 0;
145            }
146        }
147        // save the buf to nvram
148        writeNvramData();
149
150        printf("Press any key to reset the board: \n");
151        while (1)
152            if (console_status())
153                kerSysMipsSoftReset();
154    }
155
156    return 0;
157
158}  // setBoardParam
159
160
161void displayBoardParam(void)
162{
163    PPARAMETER_SETTING tmpPtr = gBoardParam;
164    int count = 0;
165    int i;
166    int memType;
167    char memoryStr[] = "Memory size                  :";
168    char megaByte[30];
169
170    while (tmpPtr->promptName !=  NULL)
171    {
172        count++;
173        tmpPtr++;
174    }
175
176    getBoardParam();
177    for (i = 0; i < (count-1); i++)
178        printf("%s %s  \n", gBoardParam[i].promptName, gBoardParam[i].parameter);
179    // print last memory type seperately
180    memType = kerSysMemoryTypeGet();
181    switch (memType)
182    {
183    case MEMORY_635X_16MB_1_CHIP:
184        strcpy(megaByte, "16MB");
185        break;
186    case MEMORY_635X_32MB_2_CHIP:
187        strcpy(megaByte, "32MB");
188        break;
189    case MEMORY_635X_64MB_2_CHIP:
190        strcpy(megaByte, "64MB");
191        break;
192    default:
193        strcpy(megaByte, "***Not defined?***");
194        break;
195    }
196    printf("%s %s\n\n", memoryStr, megaByte);
197}
198
199
200void setDefaultBootline(void)
201{
202    memset(nvramData.szBootline, 0, NVRAM_BOOTLINE_LEN);
203    strncpy(nvramData.szBootline, DEFAULT_BOOTLINE_635X, strlen(DEFAULT_BOOTLINE_635X));
204    printf("Use default boot line parameters: %s\n", DEFAULT_BOOTLINE_635X);
205    writeNvramData();
206    readNvramData();
207    convertBootInfo();
208}
209