Project: Taurus
Product: 2-bay NAS ( Network Attached Storage )
Solution: Oxford OXE810DSE BSP
Features:
- Seamless interface to 2 integrated SATA ports, expandable using PCI SATA bridge chips
- Accessible from multiple clients using Ethernet (integrated 10/100/1000 Ethernet MAC) with GMII support, or IEEE 802.11 Wi.Fi (via PCI Wi.Fi chips)
- 367 MHz ARM926EJ.S processor with 32.Kbyte caches & MMU
- Network coprocessor with TCP / IP acceleration
- Supports multiple software architectures: Linux OS, TCP/IP & CIFS, EXT3 or XFS
- Integrated fan tachometer/thermistor controller and pulse width modulators
- Hardware AES.based encryption supports multiple
- authentication methods & devices for secure storage of user data
- 5 channel DMA controller
- USB 2.0 (high.speed) and USB 1.1 (full.speed) host controllers
- 128 Kbyte on.chip SRAM
- DDR1 & DDR2 SDRAM controller 16.bit interface supports combinations up to 256 Mbytes addressable storage
- 16 bit static memory interface (optional—device boots from HDD) supports up to 4 Mbytes addressable storage per chipselect
- 90 nm CMOS process with 1.0 V core
- 19 mm × 19 mm 272 pin PBGA (1 mm ball pitch)

Application
flk_alarm.c
/**+===========================================================================
File: flk_alarm.c
Description: main program used to control RTC alarm on OX810 platform
Revision: V1.0
History:
+------------------+-------------+--------------------------------------------+
| date | author | comments |
+------------------+-------------+--------------------------------------------+
| 2008/07/03 | Wade Chiu | Initial built |
+------------------+-------------+--------------------------------------------+
-------------------------------------------------------------------------------
** Cheng Uei Precision Industry CONFIDENTIAL
** Copyright(C) 2008 Uei Precision Industry Co., Ltd. All Rights Reserved.
**
** The source code contained or described herein and all documents related
** to the source code (Material) are owned by Cheng Uei.
** The Material is protected by worldwide copyright and trade secret laws and
** treaty provisions. No part of the Material may be used, copied, reproduced,
** modified, published, uploaded, posted, transmitted, distributed, or disclosed
** in any way without Cheng Uei prior express written permission.
============================================================================+*/
//====================================================================//
// header files //
//====================================================================//
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/time.h>
#include <linux/rtc.h>
#include <linux/ioctl.h>
//#include <asm/rtc.h>
#include "flk_comm_debug_api.h"
//====================================================================//
// definition of constant //
//====================================================================//
#define rtm_sec 0
#define rtm_min 50
#define rtm_hour 10
#define rtm_mday 4
#define rtm_mon 6
//====================================================================//
// functions protyping //
//====================================================================//
//====================================================================//
// functions definition //
//====================================================================//
int main(void)
{
struct rtc_wkalrm walrm;
struct rtc_wkalrm ralrm;
int fd;
int rvalue;
//open rtc device
fd = open("/dev/rtc",O_RDWR);
if( fd == -1 )
{
_FLK_PERROR("open /dev/rtc error.");
exit(-1);
}
//show write alarm
walrm.enabled = 1;
walrm.pending = 0;
walrm.time.tm_sec = rtm_sec;
walrm.time.tm_min = rtm_min;
walrm.time.tm_hour = rtm_hour;
walrm.time.tm_mday = rtm_mday;
walrm.time.tm_mon = rtm_mon;
//set alarm
rvalue = ioctl(fd,RTC_WKALM_SET,&walrm);
if( rvalue != 0 )
{
_FLK_PERROR("set rtc alarm error.");
close(fd);
exit(-1);
}
//read alarm
rvalue = ioctl(fd,RTC_WKALM_RD,&ralrm);
if( rvalue != 0 )
{
_FLK_PERROR("set read alarm error.");
close(fd);
exit(-1);
}
//show read alarm
printf("date:%d %d\n",ralrm.time.tm_mon+1,ralrm.time.tm_mday);
printf("time:%d %d %d\n",ralrm.time.tm_hour,ralrm.time.tm_min,ralrm.time.tm_sec);
//close device
close(fd);
exit(0);
}
flk_hw_reset.c
/**+===========================================================================
File: flk_hw_reset.c
Description: main program used to control LED status on OX810 platform
Revision: V1.0
History:
+------------------+-------------+--------------------------------------------+
| date | author | comments |
+------------------+-------------+--------------------------------------------+
| 2008/06/20 | Wade Chiu | Initial built |
+------------------+-------------+--------------------------------------------+
-------------------------------------------------------------------------------
** Cheng Uei Precision Industry CONFIDENTIAL
** Copyright(C) 2008 Uei Precision Industry Co., Ltd. All Rights Reserved.
**
** The source code contained or described herein and all documents related
** to the source code (Material) are owned by Cheng Uei.
** The Material is protected by worldwide copyright and trade secret laws and
** treaty provisions. No part of the Material may be used, copied, reproduced,
** modified, published, uploaded, posted, transmitted, distributed, or disclosed
** in any way without Cheng Uei prior express written permission.
============================================================================+*/
//====================================================================//
// header files //
//====================================================================//
#include "flk_gpio_ioctl_cmd.h"
#include "flk_comm_debug_api.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
//====================================================================//
// definition of constant //
//====================================================================//
//====================================================================//
// functions protyping //
//====================================================================//
//====================================================================//
// functions definition //
//====================================================================//
int main(void)
{
int fd;
int rvalue;
int wvalue;
//open gpio
fd = open("/dev/FLK_gpio",O_RDWR);
if( fd == -1 )
{
exit(-1);
}
//hardware reset
wvalue = 0;
rvalue = ioctl(fd,FLK_IOCTL_WRITE_GPIO_3,&wvalue);
if( rvalue != 0 )
{
exit(-1);
}
//close device
close(fd);
exit(0);
}
flk_common_debug_api.h
#ifndef _FLK_COMM_DEBUG_API_H
#define _FLK_COMM_DEBUG_API_H
/*=============================================================================
// Include files
//============================================================================*/
#ifdef __KERNEL__
#include <linux/kernel.h>
#else
#include <stdio.h>
#endif
/*=============================================================================
// Function used to print out error message
//============================================================================*/
#ifdef __KERNEL__
#define _FLK_PERROR(...) printk(KERN_CRIT "[Error][File::%s--Function::%s(%d)]--",__FILE__,__FUNCTION__,__LINE__); \
printk(KERN_CRIT __VA_ARGS__); \
printk(KERN_CRIT "\n\n")
#else
#define _FLK_PERROR(...) printf("[Error][File::%s--Function::%s(%d)]--",__FILE__,__FUNCTION__,__LINE__); \
printf(__VA_ARGS__); \
printf("\n\n")
#endif
/*=============================================================================
// Function used to print out debug message
//============================================================================*/
#undef _FLK_DEBUG_MODE
#define _FLK_DEBUG_MODE /* if you want to disable debug mode, please comment on this line. */
#ifdef _FLK_DEBUG_MODE
#ifdef __KERNEL__
#define _FLK_PDEBUG(...) printk(KERN_CRIT "[Debug][File::%s--Function::%s(%d)]--",__FILE__,__FUNCTION__,__LINE__); \
printk(KERN_CRIT __VA_ARGS__); \
printk(KERN_CRIT "\n\n")
#else
#define _FLK_PDEBUG(...) printf("[Debug][File::%s--Function::%s(%d)]--",__FILE__,__FUNCTION__,__LINE__); \
printf(__VA_ARGS__); \
printf("\n\n")
#endif /* end of #ifdef __KERNEL__ */
#else
#define _FLK_PDEBUG(...)
#endif /* end of #ifdef _FLK_DEBUG_MODE */
#undef _FLK_PDEBUGG
#define _FLK_PDEBUGG(...) /* When you want to disable separate debug function, please use this function. */
#endif /* end of #ifndef _FLK_COMM_DEBUG_API_H */
/*=============================================================================
// Trace Mode
//============================================================================*/
#define __TRACE_MODE 1 //trace function
#if __TRACE_MODE
#define TRC_MSG() \
printf("[Trace][File::%s--Function::%s(%d)]\n",__FILE__,__FUNCTION__,__LINE__)
#else
#define TRC_MSG(...)
#endif
/*=============================================================================
// Test Procedure Mode
//============================================================================*/
#define TEST_MSG(...) \
printf("[Test][File::%s--Function::%s(%d)]--",__FILE__,__FUNCTION__,__LINE__); \
printf(__VA_ARGS__); \
printf("\n")
flk_led.c
/**+===========================================================================
File: flk_led.c
Description: function implemented used to control LED status on OX810 platform
Revision: V1.0
History:
+------------------+-------------+--------------------------------------------+
| date | author | comments |
+------------------+-------------+--------------------------------------------+
| 2008/05/19 | Wade Chiu | Initial built |
+------------------+-------------+--------------------------------------------+
-------------------------------------------------------------------------------
** Cheng Uei Precision Industry CONFIDENTIAL
** Copyright(C) 2008 Uei Precision Industry Co., Ltd. All Rights Reserved.
**
** The source code contained or described herein and all documents related
** to the source code (Material) are owned by Cheng Uei.
** The Material is protected by worldwide copyright and trade secret laws and
** treaty provisions. No part of the Material may be used, copied, reproduced,
** modified, published, uploaded, posted, transmitted, distributed, or disclosed
** in any way without Cheng Uei prior express written permission.
============================================================================+*/
//====================================================================//
// header files //
//====================================================================//
#include "flk_led.h"
#include "flk_comm_debug_api.h"
//====================================================================//
// functions definition //
//====================================================================//
//class constructor
int Led_Constructor(LED_STATUS *ledObject)
{
ledObject->init_log_fp = &Init_LOG;
ledObject->get_logptr_fp = &Get_LOGPTR;
ledObject->run_daemon_fp = &Run_Daemon;
ledObject->open_gpio_fp = &Open_GPIO;
ledObject->disable_booting_pwm_fp = &Disable_Booting_PWM;
ledObject->get_fd_fp = &Get_fd;
ledObject->detect_reset_poweroff_fp = &Detect_Reset_Poweroff;
return 0;
}
//create a log and return file pointer
int Init_LOG(LED_STATUS *ledObject)
{
FILE *logptr = NULL;
logptr = fopen(logfile,"w+");
if( logptr == NULL )
{
_FLK_PERROR("open logfile fail.");
}
ledObject->logptr = logptr;
return 0;
}
//get log pointer
FILE *Get_LOGPTR(LED_STATUS *ledObject)
{
return ledObject->logptr;
}
//run daemon
int Run_Daemon(LED_STATUS *ledObject)
{
int max_tbl_sz;
struct stat fstatus;
int i;
pid_t pid;
int fd;
pid = fork();
if( pid == (-1) )
{
exit(-1);
}
if( pid != 0 )
{
//parent process
exit(0);
}
//child process
umask(0);
if( setsid() == (-1) )
{
exit(-1);
}
if( chdir("/") == (-1) )
{
exit(-1);
}
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
max_tbl_sz = getdtablesize();
for( fd = (STDERR_FILENO + 1); fd < (max_tbl_sz + 1); fd++)
{
if( fstat(fd, &fstatus) == 0 )
{
close(fd);
}
}
return 0;
}
int Open_GPIO(LED_STATUS *ledObject)
{
int fd;
fd = open("/dev/FLK_gpio",O_RDWR);
if( fd == -1 )
{
exit(-1);
}
ledObject->fd = fd;
return 0;
}
//get fd
int Get_fd(LED_STATUS *ledObject)
{
return ledObject->fd;
}
int Disable_Booting_PWM(LED_STATUS *ledObject)
{
FLK_ioctl_register_cmdT cmd;
int fd;
int rvalue;
int wvalue;
wvalue = 0;
fd = ledObject->get_fd_fp(ledObject);
rvalue = ioctl(fd,FLK_IOCTL_WRITE_GPIO_0,&wvalue);
if( rvalue != 0 )
{
exit(-1);
}
return 0;
}
int Detect_Reset_Poweroff(LED_STATUS *ledObject)
{
int fd;
int checkvalue;
int rvalue;
FILE *logptr;
logptr = ledObject->get_logptr_fp(ledObject);
fd = ledObject->get_fd_fp(ledObject);
fprintf(logptr,"== Detect_Reset_Poweroff. ==\n");
while(1)
{
rvalue = ioctl(fd,FLK_IOCTL_CHECK_RESET_EVENT,&checkvalue);
if( rvalue != 0 )
{
fprintf(logptr,"== reset event ioctl function fail. ==\n");
exit(-1);
}
if( checkvalue == 1 )
{
//close device
close(fd);
//halt os
system("reboot");
break;
}
rvalue = ioctl(fd,FLK_IOCTL_CHECK_PWR_EVENT,&checkvalue);
if( rvalue != 0 )
{
fprintf(logptr,"== power event ioctl function fail. ==\n");
exit(-1);
}
if( checkvalue == 1 )
{
//close device
close(fd);
//halt os
system("reboot");
break;
}
sleep(1);
}
return 0;
}
flk_led.h
/**+===========================================================================
File: flk_led.h
Description: main pogram used to control LED status on OX810 platform
Revision: V1.0
History:
+------------------+-------------+--------------------------------------------+
| date | author | comments |
+------------------+-------------+--------------------------------------------+
| 2008/06/03 | Wade Chiu | Initial built |
+------------------+-------------+--------------------------------------------+
-------------------------------------------------------------------------------
** Cheng Uei Precision Industry CONFIDENTIAL
** Copyright(C) 2008 Uei Precision Industry Co., Ltd. All Rights Reserved.
**
** The source code contained or described herein and all documents related
** to the source code (Material) are owned by Cheng Uei.
** The Material is protected by worldwide copyright and trade secret laws and
** treaty provisions. No part of the Material may be used, copied, reproduced,
** modified, published, uploaded, posted, transmitted, distributed, or disclosed
** in any way without Cheng Uei prior express written permission.
============================================================================+*/
//====================================================================//
// header file //
//====================================================================//
#include "flk_gpio_ioctl_cmd.h" //gpio
#include //fopen
#include
#include
#include
#include
#include //reboot
#include //reboot
//====================================================================//
// type definition //
//====================================================================//
typedef struct _led_status LED_STATUS;
typedef int (*fp_led_status)(LED_STATUS *ledObject);
typedef int (*fp_init_log)(LED_STATUS *ledObject);
typedef FILE * (*fp_get_logptr)(LED_STATUS *ledObject);
typedef int (*fp_run_daemon)(LED_STATUS *ledObject);
typedef int (*fp_open_gpio)(LED_STATUS *ledObject);
typedef int (*fp_disable_booting_pwm)(LED_STATUS *ledObject);
typedef int (*fp_get_fd)(LED_STATUS *ledObject);
typedef int (*fp_detect_reset_poweroff)(LED_STATUS *ledObject);
//====================================================================//
// class definition //
//====================================================================//
struct _led_status
{
//private attribute
FILE *logptr;
int fd;
//public function pointer
//constructor pointer
fp_led_status led_constructor_fp;
//log file pointer
fp_init_log init_log_fp;
//get log pointer
fp_get_logptr get_logptr_fp;
//run deamon
fp_run_daemon run_daemon_fp;
//open gpio
fp_open_gpio open_gpio_fp;
//disable booting pwm
fp_disable_booting_pwm disable_booting_pwm_fp;
//get fd
fp_get_fd get_fd_fp;
//detect reset thread
fp_detect_reset_poweroff detect_reset_poweroff_fp;
};
//====================================================================//
// functions protyping //
//====================================================================//
//constructor
int Led_Constructor(LED_STATUS *ledObject);
//log file
int Init_LOG(LED_STATUS *ledObject);
//get log pointer
FILE *Get_LOGPTR(LED_STATUS *ledObject);
//run daemon
int Run_Daemon(LED_STATUS *ledObject);
//open gpio
int Open_GPIO(LED_STATUS *ledObject);
//disable boting pwm
int Disable_Booting_PWM(LED_STATUS *ledObject);
//get fd
int Get_fd(LED_STATUS *ledObject);
//detect reset poweroff
int Detect_Reset_Poweroff(LED_STATUS *ledObject);
//====================================================================//
// define const //
//====================================================================//
#define logfile "/etc/init.d/flk_led.log"
flk_led_daemon.c
/**+===========================================================================
File: flk_led_main.c
Description: main program used to control LED status on OX810 platform
Revision: V1.0
History:
+------------------+-------------+--------------------------------------------+
| date | author | comments |
+------------------+-------------+--------------------------------------------+
| 2008/06/03 | Wade Chiu | Initial built |
+------------------+-------------+--------------------------------------------+
-------------------------------------------------------------------------------
** Cheng Uei Precision Industry CONFIDENTIAL
** Copyright(C) 2008 Uei Precision Industry Co., Ltd. All Rights Reserved.
**
** The source code contained or described herein and all documents related
** to the source code (Material) are owned by Cheng Uei.
** The Material is protected by worldwide copyright and trade secret laws and
** treaty provisions. No part of the Material may be used, copied, reproduced,
** modified, published, uploaded, posted, transmitted, distributed, or disclosed
** in any way without Cheng Uei prior express written permission.
============================================================================+*/
//====================================================================//
// header files //
//====================================================================//
#include "flk_led.h"
#include "flk_comm_debug_api.h"
//====================================================================//
// definition of constant //
//====================================================================//
//====================================================================//
// functions protyping //
//====================================================================//
static int Run_LED_Daemon(void);
//====================================================================//
// functions definition //
//====================================================================//
static int Run_LED_Daemon(void)
{
//declare variable
int error_code;
LED_STATUS LEDObject;
FILE * logptr;
int rvalue;
//init variable
error_code = 0;
rvalue = 0;
//constructor
LEDObject.led_constructor_fp = &Led_Constructor;
LEDObject.led_constructor_fp(&LEDObject);
//run deamon
LEDObject.run_daemon_fp(&LEDObject);
//init log
LEDObject.init_log_fp(&LEDObject);
logptr = LEDObject.get_logptr_fp(&LEDObject);
fprintf(logptr,"== init log. ==\n");
//open gpio
rvalue = LEDObject.open_gpio_fp(&LEDObject);
if(rvalue == -1)
{
fprintf(logptr,"== open gpio fail. ==\n");
}
fprintf(logptr,"== open gpio. ==\n");
//disable booting pwm
rvalue = LEDObject.disable_booting_pwm_fp(&LEDObject);
if(rvalue == -1)
{
fprintf(logptr,"== disable booting pwm fail. ==\n");
}
fprintf(logptr,"== disable booting pwm. ==\n");
//detect reset and power off
rvalue = LEDObject.detect_reset_poweroff_fp(&LEDObject);
if(rvalue == -1)
{
fprintf(logptr,"== reset event ioctl function fail. ==\n");
}
//de-constructor
exit(0);
}
int main(void)
{
printf("[Foxlink]--Run LED Daemon\n");
Run_LED_Daemon();
exit(0);
}
flk_reg.c
/**+===========================================================================
File: flk_reg.c
Description: manipulate gpio of Oxford 810
Revision: V0.01
History:
+------------------+-------------+--------------------------------------------+
| date | author | comments |
+------------------+-------------+--------------------------------------------+
| 2008/05/05 | Wade Chiu | Initial built |
+------------------+-------------+--------------------------------------------+
-------------------------------------------------------------------------------
** Cheng Uei Precision Industry CONFIDENTIAL
** Copyright(C) 2008 Uei Precision Industry Co., Ltd. All Rights Reserved.
**
** The source code contained or described herein and all documents related
** to the source code (Material) are owned by Cheng Uei.
** The Material is protected by worldwide copyright and trade secret laws and
** treaty provisions. No part of the Material may be used, copied, reproduced,
** modified, published, uploaded, posted, transmitted, distributed, or disclosed
** in any way without Cheng Uei prior express written permission.
============================================================================+*/
//====================================================================//
// Begin of include header files //
//====================================================================//
#include <unistd.h> //getopt()
#include <stdio.h> //printf()
#include <string.h> //strdup() strcmp() strchr() strtok()
#include <sys/mman.h> //mmap()
#include <fcntl.h> //open()
#include <sys/types.h> //open()
#include <sys/stat.h> //open()
#include <stdlib.h> //sscanf()
#include <ctype.h> //isxdigit()
#include <errno.h>
#define _GNU_SOURCE
#include <getopt.h>
//====================================================================//
// End of include header files //
//====================================================================//
//====================================================================//
// Begin of definition of constant //
//====================================================================//
#define __TEST_PROCEDURE_MODE 0 //execute test procedure
#define __TRACE_MODE 0 //trace function call
#if __TRACE_MODE
#define TRC_MSG() \
printf("[Trace][File::%s--Function::%s(%d)]\n",__FILE__,__FUNCTION__,__LINE__);
#else
#define TRC_MSG(...)
#endif
#define __DEBUG_MODE 1 //execute debug mode
#if __DEBUG_MODE
#define DBG_MSG(...) \
printf("[Debug][File::%s--Function::%s(%d)]--",__FILE__,__FUNCTION__,__LINE__); \
printf(__VA_ARGS__); \
printf("\n");
#else
#define DBG_MSG(...)
#endif
#define GPIOA_BASE (0x44000000)
#define GPIO_Input_offset (0x0000 >> 2)
#define GPIO_OE_offset (0x0004 >> 2)
#define GPIO_Output_offset (0x0010 >> 2)
#define GPIOA_BASE_VA (0xE0000000)
#define rgpiotable_size 1
#define wgpiotable_size 6
#define gpiovaluetable_size 2
#define map_size 0x1000
//====================================================================//
// End of definition of constant //
//====================================================================//
//====================================================================//
// Begin of functions protyping //
//====================================================================//
//--------------------------------------------------------------------//
// All external functions are declared in this header file //
//--------------------------------------------------------------------//
//#include "comm/s4_pcyc_test_comm_msg.h"
//-------------------------------------------------------------------
// All private functions are declared here. //
//--------------------------------------------------------------------//
static int test_print_optioninfo(int opt);
static int print_usage(void);
static int CheckArgument(void);
static int AccessGPIO(void);
static int InitPhys(void);
static int CheckGPIOformat(const char *gpioarg,const char *mode); //mode:"read","write"
static int ChoiceError(const char *mode);
static void ReadGPIOn(int n);
static void AddressReadGPIO(void);
static void WriteGPIOn(int n);
static void AddressWriteGPIO(void);
static int IsPlatformLittleEndian(void);
static unsigned long *SetBitn(unsigned long *gpiovalue,int bitn);
static unsigned long *ClearBitn(unsigned long *gpiovalue,int bitn);
static unsigned long GetBitn(unsigned long gpiovalue,int bitn);
//====================================================================//
// End of functions protyping //
//====================================================================//
//====================================================================//
// Begin of variable declaration //
//====================================================================//
//--------------------------------------------------------------------//
// All static variables are declared here //
//--------------------------------------------------------------------//
static char *readgpio = NULL; //read gpio
static char *writegpio = NULL; //write gpio: gpio=value
static char *ProgramName = NULL; //the c file name
static int showbinary = 0; //default zero 1:show binary format
static int memfd = -1; //filedescripter of /dev/mem
static char *writegpiovalue = NULL; //gpio string
static char *writegpiogpio = NULL; //value sring
static unsigned long *gpio_base = NULL; //kernel gpio mem map tp usr space pointer
const char *rgpiotable[] =
{
"GPIO5"
};
const char *wgpiotable[] =
{
"GPIO0","GPIO1","GPIO2","GPIO3","GPIO9","GPIO10"
};
const char *gpiovaluetable[] =
{
"0x0","0x1"
};
//====================================================================//
// End of variable declaration //
//====================================================================//
//===================================================================
// Begin of functions definition //
//====================================================================//
static ChoiceError(const char *mode)
{
int error_code = 0;
if( strcmp(mode,"read") == 0 )
{
error_code = 3;
}
else if( strcmp(mode,"write") == 0 )
{
error_code = 4;
}
return error_code;
}
static int CheckGPIOformat(const char *gpioarg,const char *mode)
{
TRC_MSG();
int error_code = 0;
int arglen = 0;
if( gpioarg != NULL )
{
//judge which type
arglen = strlen(gpioarg);
if( arglen > 1 )
{
if( gpioarg[0] == '0' )
{
//judge if read of write
if( strcmp(mode,"read") == 0 )
{
if( gpioarg[1] == 'x' || gpioarg[1] == 'X')
{
int len = arglen;
int index = 2;
while( index < len )
{
if(!isxdigit( gpioarg[index]) )
{
error_code = 8;
goto ERROR_AREA;
}
index++;
}
}
else
{
error_code = 3;
goto ERROR_AREA;
}
}
else
{
char *p = NULL;
if( (p = strchr(gpioarg,'=')) != NULL )
{
char *dupwritegpio;
char *tok;
dupwritegpio = strdup(gpioarg);
tok = strtok(dupwritegpio,"=");
if( tok != NULL )
{
writegpiogpio = strdup(tok);
tok = strtok(NULL,"=");
if( tok != NULL )
{
writegpiovalue = strdup(tok);
tok = strtok(NULL,"=");
if(tok != NULL)
{
error_code = 4;
goto ERROR_AREA;
}
}
else
{
error_code = 4;
goto ERROR_AREA;
}
}
else
{
error_code = 4;
goto ERROR_AREA;
}
}
else
{
error_code = 4;
goto ERROR_AREA;
}
//check gpio format
if( writegpiogpio[1] == 'x' || writegpiogpio[1] == 'X')
{
int len = strlen(writegpiogpio);
int index = 2;
while( index < len )
{
if(!isxdigit( writegpiogpio[index]) )
{
error_code = 8;
goto ERROR_AREA;
}
index++;
}
}
else
{
error_code = 4;
goto ERROR_AREA;
}
//check value format
if( writegpiovalue[0] == '0' && (writegpiovalue[1] == 'x' || writegpiovalue[1] == 'X') )
{
int len = strlen(writegpiovalue);
int index = 2;
while( index < len )
{
if( !isxdigit(writegpiovalue[index]) )
{
error_code = 8;
goto ERROR_AREA;
}
index++;
}
}
else
{
error_code = 4;
goto ERROR_AREA;
}
}
}
else if(gpioarg[0] == 'G')
{
//judge if read of write
if( strcmp(mode,"read") == 0 )
{
int isfind = -1;
int i;
for(i = 0; i < rgpiotable_size; i++)
{
DBG_MSG("rgpiotable[%d] = %s",i,rgpiotable[i]);
if( strcmp(gpioarg,rgpiotable[i]) == 0 )
{
isfind = 0;
break;
}
}
if( isfind != 0 )
{
error_code = 3;
goto ERROR_AREA;
}
}
else
{
char *p = NULL;
if( (p = strchr(gpioarg,'=')) != NULL )
{
char *dupwritegpio;
char *tok;
dupwritegpio = strdup(gpioarg);
tok = strtok(dupwritegpio,"=");
if( tok != NULL )
{
writegpiogpio = strdup(tok);
tok = strtok(NULL,"=");
if( tok != NULL )
{
writegpiovalue = strdup(tok);
tok = strtok(NULL,"=");
if(tok != NULL)
{
error_code = 4;
goto ERROR_AREA;
}
}
else
{
error_code = 4;
goto ERROR_AREA;
}
}
else
{
error_code = 4;
goto ERROR_AREA;
}
}
else
{
error_code = 4;
goto ERROR_AREA;
}
//check gpio format
int isfind = -1;
int i;
for(i = 0; i < wgpiotable_size; i++)
{
DBG_MSG("%s",wgpiotable[i]);
if( strcmp(writegpiogpio,wgpiotable[i]) == 0 )
{
isfind = 0;
break;
}
}
if( isfind != 0 )
{
error_code = 4;
goto ERROR_AREA;
}
//check value format
isfind = -1;
for(i = 0; i < gpiovaluetable_size; i++)
{
DBG_MSG("%s",gpiovaluetable[i]);
if( strcmp(writegpiovalue,gpiovaluetable[i]) == 0 )
{
isfind = 0;
break;
}
}
if( isfind != 0 )
{
error_code = 4;
goto ERROR_AREA;
}
}
}
else
{
error_code = ChoiceError(mode);
goto ERROR_AREA;
}
}
else
{
error_code = ChoiceError(mode);
goto ERROR_AREA;
}
}
else
{
error_code = 5;
goto ERROR_AREA;
}
ERROR_AREA:
TRC_MSG();
return error_code;
}
static int CheckArgument(void)
{
TRC_MSG();
int error_code = 0;
if( readgpio != NULL )
{
//chcek read gpio format
DBG_MSG("readgpio = %s",readgpio);
if( (error_code = CheckGPIOformat(readgpio,"read")) != 0 )
{
goto ERROR_AREA;
}
}
else if( writegpio != NULL )
{
//chcek write gpio format
DBG_MSG("write %s\n",writegpio);
if( (error_code = CheckGPIOformat(writegpio,"write")) != 0 )
{
goto ERROR_AREA;
}
}
ERROR_AREA:
TRC_MSG();
return error_code;
}
static int InitPhys(void)
{
TRC_MSG();
int error_code = 0;
int offset = 0;
int input = 0;
int inputbase = 0; //user輸入的page整部倍的部份
int inputoffset = 0; //user輸入的page之外 offset部分
memfd = open("/dev/mem",O_RDWR);
if( memfd < 0 )
{
error_code = 2;
goto ERROR_AREA;
}
if( readgpio != NULL )
{
if( readgpio[0] == '0' ) //read usr specified address
{
sscanf(readgpio,"%10x",&input);
DBG_MSG("read gpio address = %s(str) --> %08x(hex)",readgpio,input);
inputbase = input & 0xfffff000;
inputoffset = input & 0x00000fff;
DBG_MSG("inputbase = %08x , inputoffset = %08x",inputbase,inputoffset);
offset = inputbase;
}
else //read defined GPIOx
{
offset = GPIOA_BASE;
}
}
else if( writegpiogpio != NULL )
{
if( writegpiogpio[0] == '0' ) //write usr specified address
{
sscanf(writegpiogpio,"%10x",&input);
DBG_MSG("read gpio address = %s(str) --> %08x(hex)",writegpiogpio,input);
inputbase = input & 0xfffff000;
inputoffset = input & 0x00000fff;
DBG_MSG("inputbase = %08x , inputoffset = %08x",inputbase,inputoffset);
offset = inputbase;
}
else //write defined GPIOx
{
offset = GPIOA_BASE;
}
}
else
{
error_code = 6;
}
DBG_MSG("map_size = %08x",(map_size/* - userdefbase*/));
gpio_base = (unsigned long *)mmap(0,
(map_size/* - userdefbase*/),
PROT_READ|PROT_WRITE,
MAP_SHARED,
memfd,
offset);
if( gpio_base != (unsigned long *)0xffffffff )
{
gpio_base += ( inputoffset >> 2 );
DBG_MSG("gpio_base = %08x",gpio_base);
}
else
{
DBG_MSG("errno = %s",strerror(errno))
error_code = 7;
goto ERROR_AREA;
}
ERROR_AREA:
TRC_MSG();
return error_code;
}
static int IsPlatformLittleEndian(void)
{
const int n = 1;
return *((char *)&n) ? 1 : 0;
}
static unsigned long* SetBitn(unsigned long *gpiovalue,int bitn)
{
unsigned long *value = gpiovalue;
*value |= (1 << bitn);
return value;
}
static unsigned long* ClearBitn(unsigned long *gpiovalue,int bitn)
{
unsigned long *value = gpiovalue;
*value &= ~(1 << bitn);
return value;
}
static unsigned long GetBitn(unsigned long gpiovalue,int bitn)
{
unsigned long value;
value = (gpiovalue >> bitn) & 1;
return value;
}
static void WriteGPIOn(int n)
{
TRC_MSG();
int error_code = 0;
unsigned long *gpio_oe = NULL;
unsigned long *gpio_output = NULL;
int islittleendian = -1; //0:big 1:little
unsigned long gpiovaluedup = 0;
unsigned long bitn = 0;
//GPIO_OE bit 0 to be set to 1
gpio_oe = gpio_base + GPIO_OE_offset;
DBG_MSG("gpio_oe_offset = %08x",GPIO_OE_offset);
DBG_MSG("gpio_oe = %08x",gpio_oe);
DBG_MSG("gpio_oe_value = %08x",*gpio_oe);
gpio_oe = SetBitn(gpio_oe,n);
//gpio_oe = ClearBitn(gpio_oe,0);
DBG_MSG("after set bit %d gpio_oe_value = %08x",n,*gpio_oe);
//set GPIO_Input bit 0
gpio_output = gpio_base + GPIO_Output_offset;
DBG_MSG("gpio_input_value = %08x",*gpio_output);
if( strcmp(writegpiovalue,"0x0") == 0 )
{
gpio_output = ClearBitn(gpio_output,n);
}
else
{
gpio_output = SetBitn(gpio_output,n);
}
DBG_MSG("after set value gpio_input_value = %08x",*gpio_output);
//get GPIO_Input bit 0
gpiovaluedup = *gpio_output;
bitn = GetBitn(gpiovaluedup,n);
printf("0X%d\n",bitn);
TRC_MSG();
}
static void AddressReadGPIO()
{
TRC_MSG();
printf("%s:0X%08x\n",readgpio,*gpio_base);
TRC_MSG();
}
static void AddressWriteGPIO(void)
{
TRC_MSG();
int value;
sscanf(writegpiovalue,"%10x",&value);
DBG_MSG("write gpio value = %s(str) --> %08x(hex)",writegpiovalue,value);
*gpio_base = (unsigned long)value;
printf("%s:0X%08x\n",writegpiogpio,*gpio_base);
TRC_MSG();
}
static void ReadGPIOn(int n)
{
TRC_MSG();
int error_code = 0;
unsigned long *gpio_oe = NULL;
unsigned long *gpio_input = NULL;
int islittleendian = -1; //0:big 1:little
unsigned long gpiovaluedup = 0;
unsigned long bitn = 0;
//GPIO_OE bit 3 to be set to 0
gpio_oe = gpio_base + GPIO_OE_offset;
DBG_MSG("gpio_oe_offset = %08x",GPIO_OE_offset);
DBG_MSG("gpio_oe = %08x",gpio_oe);
DBG_MSG("gpio_oe_value = %08x",*gpio_oe);
gpio_oe = ClearBitn(gpio_oe,n);
DBG_MSG("after set bit %d gpio_oe_value = %08x",n,*gpio_oe);
//verify big little edian
islittleendian = IsPlatformLittleEndian();
DBG_MSG("your system is %s", islittleendian?"little endian":"big endian");
//get GPIO_Input bit 3
gpio_input = gpio_base + GPIO_Input_offset;
DBG_MSG("gpio_input_value = %08x",*gpio_input);
gpiovaluedup = *gpio_input;
bitn = GetBitn(gpiovaluedup,n);
printf("0X%d\n",bitn);
TRC_MSG();
}
static int AccessGPIO(void)
{
TRC_MSG();
int error_code = 0;
unsigned long gpiovalue = 0;
//init & open & mmap gpio
if( (error_code = InitPhys()) != 0)
{
goto ERROR_AREA;
}
if( readgpio != NULL )
{
DBG_MSG("readgpio = %s",readgpio);
if( strcmp(readgpio,"GPIO3") == 0 ) //read GPIO3
{
ReadGPIOn(3);
}
else if( readgpio[0] == '0' ) //read address
{
AddressReadGPIO();
}
else
{
error_code = 6;
goto ERROR_AREA;
}
}
else if( writegpio != NULL )
{
DBG_MSG("write %s\n",writegpio);
if(strcmp(writegpiogpio,"GPIO0") == 0 ) //write GPIO0
{
WriteGPIOn(0);
}
else if( strcmp(writegpiogpio,"GPIO1") == 0 ) //write GPIO1
{
WriteGPIOn(1);
}
else if( strcmp(writegpiogpio,"GPIO2") == 0 ) //write GPIO2
{
WriteGPIOn(2);
}
else if( strcmp(writegpiogpio,"GPIO5") == 0 ) //write GPIO5
{
WriteGPIOn(5);
}
else if( strcmp(writegpiogpio,"GPIO9") == 0 ) //write GPIO9
{
WriteGPIOn(9);
}
else if( strcmp(writegpiogpio,"GPIO10") == 0 ) //write GPIO10
{
WriteGPIOn(10);
}
else if( writegpiovalue[0] == '0' ) //write address
{
AddressWriteGPIO();
}
else
{
error_code = 6;
goto ERROR_AREA;
}
}
ERROR_AREA:
if( gpio_base != NULL )
{
munmap(gpio_base,map_size /*- userdefbase*/);
}
if( memfd != -1 )
{
close(memfd);
}
TRC_MSG();
return error_code;
}
static int print_usage(void)
{
TRC_MSG();
printf("[%s usage]:\n",ProgramName);
printf("%s [-r (GPIO) or (address)] [-w (GPIO or address)=(value)] [-h] [-v] [-b]\n\n",ProgramName);
printf("-r ==>> read just GPIO3 or usr specified address\n");
printf("-w ==>> write GPIO0,1,2,5,9,10 or usr specified address\n");
printf("-h ==>> show help\n");
printf("-v ==>> show version\n");
printf("-b ==>> show binary format\n");
TRC_MSG();
return 0;
}
int main(int argc, char *argv[])
{
TRC_MSG();
int opt; //return value of getopt()
int error_code = 0; //error_message
int reg_mutex_lock = 0; //r:1 w:2 no_arg:3
ProgramName = argv[0];
//DBG_MSG("start...get_opt()...");
//opion loop
while( (opt = getopt(argc,argv,":r:w:vhb")) != -1 )
{
switch(opt)
{
case 'r': // --reg_read
DBG_MSG("get_opt()...'-r'");
if( reg_mutex_lock == 0 )
{
test_print_optioninfo(opt);
reg_mutex_lock = 1;
}
else
{
error_code = 1;
goto ERROR_AREA;
}
readgpio = strdup(optarg);
break;
case 'w': // --reg_write
DBG_MSG("get_opt()...'-w'");
if( reg_mutex_lock == 0 )
{
test_print_optioninfo(opt);
reg_mutex_lock = 2;
}
else
{
error_code = 1;
goto ERROR_AREA;
}
writegpio = strdup(optarg);
break;
case 'v': // --version
DBG_MSG("get_opt()...'-v'");
test_print_optioninfo(opt);
printf("version 0.01\n");
break;
case 'h': // --help message
DBG_MSG("get_opt()...'-h'");
test_print_optioninfo(opt);
print_usage();
break;
case 'b': // --show binary value
DBG_MSG("get_opt()...'-b'");
test_print_optioninfo(opt);
showbinary = 1;
break;
case ':': // --find no argument
DBG_MSG("get_opt()...':'");
if( reg_mutex_lock == 0 )
{
test_print_optioninfo(opt);
reg_mutex_lock = 3;
}
else
{
error_code = 1;
goto ERROR_AREA;
}
break;
case '?': //invalid option
default:
DBG_MSG("get_opt()...'?'");
test_print_optioninfo(opt);
break;
}
}
//DBG_MSG("end...get_opt()...");
//check gpio argument
if( (error_code = CheckArgument()) != 0 )
{
goto ERROR_AREA;
}
else
{
//execute gpio access
if( (error_code = AccessGPIO()) != 0 )
{
goto ERROR_AREA;
}
}
ERROR_AREA:
if( error_code == 1 )
{
printf("[error %d]::just allow read('-r') or write('-w') at the same time once\n",error_code);
}
else if( error_code == 2 )
{
printf("[error %d]::open /dev/men fail\n",error_code);
}
else if( error_code == 3 )
{
printf("[error %d]::argument %s is a wrong format\n",error_code,readgpio);
}
else if( error_code == 4 )
{
printf("[error %d]::argument %s is a wrong format\n",error_code,writegpio);
}
else if( error_code == 5 )
{
printf("[error %d]::gpio argument is null\n",error_code);
}
else if( error_code == 6 )
{
printf("[error %d]::no such gpio to access\n",error_code);
}
else if( error_code == 7 )
{
printf("[error %d]::mmap failed!!maybe u enter a wrong address\n",error_code);
}
else if( error_code == 8 )
{
printf("[error %d]::a wrong number format\n",error_code);
}
TRC_MSG();
return 0;
}
// test function for test getopt value
static int test_print_optioninfo(int opt)
{
if( __TEST_PROCEDURE_MODE )
{
TRC_MSG();
if( (opt != ':') && (opt != '?') )
{
DBG_MSG("no error");
if( optarg != NULL )
{
printf("option: '-%c' -- argument: %s\n",opt,optarg);
}
else
{
printf("option: '-%c'\n",opt);
}
}
else
{
DBG_MSG("meet an error");
if( opt == ':' )
{
printf("option: '-%c' requires an argument\n",optopt);
}
else
{
printf("invalid option: '-%c'\n",optopt);
}
}
TRC_MSG();
}
return 0;
}
inittab
# /etc/inittab
#
# Copyright (C) 2001 Erik Andersen
#
# Note: BusyBox init doesn't support runlevels. The runlevels field is
# completely ignored by BusyBox init. If you want runlevels, use
# sysvinit.
#
# Format for each entry: :::
#
# id == tty to run on, or empty for /dev/console
# runlevels == ignored
# action == one of sysinit, respawn, askfirst, wait, and once
# process == program to run
# Startup the system
::sysinit:/bin/mount /proc
::sysinit:/bin/mount -a
::sysinit:/bin/mount -o remount,rw,noatime /
::sysinit:/bin/ln -s /proc/mounts /etc/mtab
::sysinit:/sbin/swapon -a
# Mount and repair if necessary the user data partition
::sysinit:/bin/sh /etc/init.d/mount-internal-shares.sh
::sysinit:/bin/chown www-data:www-data /shares/internal
::sysinit:/bin/chmod 755 /shares/internal
::sysinit:/bin/chown www-data:www-data /shares/external
::sysinit:/bin/chmod 755 /shares/external
::sysinit:/bin/chown www-data:www-data /shares/internal/PUBLIC
# Update ownership and modes for cups and samba
::sysinit:/bin/chgrp sys /var/spool/cups
::sysinit:/bin/chmod g+rws /var/spool/cups
::sysinit:/bin/chmod 1777 /var/spool/samba
::sysinit:/bin/chgrp users /var/spool/samba
::sysinit:/bin/chmod 4555 /usr/bin/sudo
# Give lighttpd ownership of it's log directory
::sysinit:/bin/chown -R www-data:www-data /var/log/lighttpd
# Give the WebUI ownership of /etc/smb.conf
::sysinit:/bin/chown -R www-data:www-data /etc/smb.conf
# Load kernel modules
# Temperature control
# Temperature control
::sysinit:/sbin/modprobe thermAndFan
# RTC
::sysinit:/bin/ln -s /dev/rtc0 /dev/rtc > /dev/null 2>&1
#::sysinit:/sbin/modprobe rtc-ds1307
::sysinit:/sbin/modprobe isl1208
::sysinit:/sbin/modprobe i2c-oxnas-bitbash
# USB
::sysinit:/sbin/modprobe ehci-hcd
::sysinit:/sbin/modprobe usb-storage
# Code Page for VFAT
::sysinit:/sbin/modprobe nls_cp437
# Power Button
::sysinit:/bin/sh /etc/init.d/load_power_button_module.sh
# Mount the USB filesystem
::sysinit:/bin/mount -t usbfs usbfs /proc/bus/usb
# Run any rc scripts
::sysinit:/etc/init.d/rcS
::sysinit:/bin/sh /etc/init.d/rc.myinit
::sysinit:/etc/init.d/led_daemon
# Set up a couple of getty's
#tty1::respawn:/sbin/getty 38400 tty1
#tty2::respawn:/sbin/getty 38400 tty2
# Put a getty on the serial port
ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100
#ttyS1::respawn:/sbin/getty -L ttyS1 115200 vt100
#ttyS2::respawn:/sbin/getty -L ttyS2 115200 vt100
# Logging junk
::sysinit:/bin/touch /var/log/messages
::respawn:/sbin/syslogd -n -m 0
::respawn:/sbin/klogd -n
#tty3::respawn:/usr/bin/tail -f /var/log/messages
# Stuff to do for the 3-finger salute
::ctrlaltdel:/sbin/reboot
# Stuff to do before rebooting
# tidy up using start scripts.
::shutdown:/bin/sh /etc/init.d/rc.myexit
::shutdown:/etc/init.d/rcK
# make sure everything else stops.
::shutdown:/bin/sync
::shutdown:/usr/bin/killall klogd
::shutdown:/usr/bin/killall syslogd
::shutdown:/sbin/swapoff -a
::shutdown:/bin/umount -a -r
#send hardware reset
::shutdown:/etc/init.d/hardware_reset
rc.myinit
#!/bin/bash
#/**+===========================================================================
#File: rc.myinit
#
#Description: start main program to read/write gpio and registers on
# OX810 platform
#
#Revision: V0.01
#
#History:
#+------------------+-------------+--------------------------------------------+
#| date | author | comments |
#+------------------+-------------+--------------------------------------------+
#| 2008/05/15 | Wade Chiu | Initial built |
#+------------------+-------------+--------------------------------------------+
#
#-------------------------------------------------------------------------------
#** Cheng Uei Precision Industry CONFIDENTIAL
#** Copyright(C) 2008 Uei Precision Industry Co., Ltd. All Rights Reserved.
#**
#** The source code contained or described herein and all documents related
#** to the source code (Material) are owned by Cheng Uei.
#** The Material is protected by worldwide copyright and trade secret laws and
#** treaty provisions. No part of the Material may be used, copied, reproduced,
#** modified, published, uploaded, posted, transmitted, distributed, or disclosed
#** in any way without Cheng Uei prior express written permission.
#============================================================================+*/
#//inittial part
Module_Name="flk_gpio_driver"
MyinitLog_Name="rc.myinit.log"
Node_Name="FLK_gpio"
PWD="/etc/init.d"
#//test if inittab work
if [ -f $PWD/$MyinitLog_Name ]
then
rm $PWD/$MyinitLog_Name
fi
#//create a log file to record insert procedure
touch $PWD/$MyinitLog_Name
if [ -f $PWD/$MyinitLog_Name ]
then
echo "create $PWD/$MyinitLog_Name success."
else
echo "create $PWD/$MyinitLog_Name fail."
exit 0
fi
#//check if module exist already
echo "check module if exist:$Module_Name." >> $PWD/$MyinitLog_Name
lsmod > listmodule_tmp.txt
RVALUE=$(grep -c $Module_Name listmodule_tmp.txt)
if [ $RVALUE -ne 0 ]
then
rmmod $Module_Name
echo "remove existed module:$Module_Name" >> $PWD/$MyinitLog_Name
fi
rm listmodule_tmp.txt
#//insert module
echo "insert module:$PWD/$Module_Name.ko." >> $PWD/$MyinitLog_Name
insmod $PWD/$Module_Name.ko
lsmod > listmodule_tmp.txt
RVALUE=$(grep -c $Module_Name listmodule_tmp.txt)
if [ $RVALUE -eq 0 ]
then
echo "insert module:$PWD/$Module_Name.KO fail." >> $PWD/$MyinitLog_Name
rm listmodule_tmp.txt
exit 0
fi
rm listmodule_tmp.txt
#//check node if exist
echo "check node if exist:/dev/$Node_Name." >> $PWD/$MyinitLog_Name
#ls /dev/$Node_Name > listnode_tmp.txt
ls /dev > listnode_tmp.txt
RVALUE=$(grep -c $Node_Name listnode_tmp.txt)
if [ $RVALUE -ne 0 ]
then
rm /dev/$Node_Name
echo "remove existed module:/dev/$Node_Name" >> $PWD/$MyinitLog_Name
fi
rm listnode_tmp.txt
#get major id
major=$(awk "\$2==\"$Node_Name\" {print \$1}" /proc/devices)
#//make a device node
echo "make a device node:/dev/$Node_Name." >> $PWD/$MyinitLog_Name
mknod /dev/$Node_Name c $major 0
ls /dev/$Node_Name > node_tmp.txt
RVALUE=$(grep -c /dev/$Node_Name node_tmp.txt)
if [ $RVALUE -eq 0 ]
then
echo "make a device node:/dev/$Node_Name fail." >> $PWD/$MyinitLog_Name
rm node_tmp.txt
exit 0
fi
rm node_tmp.txt
Web GUI
nasMaster.pl
#!/usr/bin/env perl
#!/usr/bin/perl
#
# Routes the request
#
#
# Ian Steel
# September 2006
#
use strict;
use CGI::Fast;
use Config::IniFiles;
use nasCommon;
use nasCore;
use Service::Shares;
#use Permission;
# Load the individual page modules
#
use nas::home;
use nas::driveman;
use nas::fileshare;
use nas::gensetup;
use nas::initsetup;
use nas::home_update;
use nas::home_status;
=for dynamic loading
use nas::chgdatetime;
use nas::chgdevicename;
use nas::chgusername;
use nas::fs_addshare;
use nas::fs_chgaccesstype;
use nas::fs_deluser;
use nas::fs_newuser;
use nas::fs_getSharePerms;
use nas::fs_removeshare;
use nas::fs_renameshare;
use nas::fs_updsecurity;
use nas::fs_userman;
use nas::language;
use nas::updnetwork;
=cut
# Pre run checks.
#
# Write paths to nbin/setupPaths.sh
# ( This means that nasCommon should be the only place that (most) paths
# need to be changed.)
#
if (! -w nasCommon->nas_paths ) {
sudo("$nbin/touch.sh ".nasCommon->nas_paths );
sudo("$nbin/chown.sh www-data:www-data ".nasCommon->nas_paths);
sudo("$nbin/chmod.sh 0644 ".nasCommon->nas_paths);
}
my $fdPaths = new IO::File( ">".nasCommon->nas_paths );
if ($fdPaths) {
print( $fdPaths "# Auto generated by nasMaster.pl on ".gmtime(time())."\n" );
print( $fdPaths "export SMB_PATH=" . nasCommon->smb_lib . "\n");
print( $fdPaths "export SMB_HOME=" . nasCommon->smb_home . "\n");
print( $fdPaths "export SMB_CONF=" . nasCommon->smb_conf . "\n");
print( $fdPaths "export SMB_PASSWD=" . nasCommon->smbpasswd . "\n");
print( $fdPaths "export SHARES_HOME=" . nasCommon->nas_shares. "\n");
print( $fdPaths "export OXSEMI_HOME=" . nasCommon->nas_home. "\n");
print( $fdPaths "export PERL5LIB=" . join(':',$ENV{PERL5LIB},nasCommon->nas_lib). "\n");
print( $fdPaths "export NETWORK_SETTINGS=" . nasCommon->network_settings. "\n");
$fdPaths->close();
}
# Remove any locks
#
# This file is typically used to signal that a process is in progress.
unlink( nasCommon->nas_lock ) if ( -r nasCommon->nas_lock );
=for future
Permission->path( nasCommon->nas_nbin ); # Where to find the scripts
Permission->new( nasCommon->nas_home, '0775','root','www-data' )->ensure();
Permission->new( nasCommon->shares_inc, '0644','www-data','www-data' )->ensure();
Permission->new( nasCommon->senvid_inc, '0644','www-data','www-data' )->ensure();
Permission->new( nasCommon->nas_ini, '0666','www-data','www-data' )->ensure();
Permission->new( nasCommon->smb_lib, '0775','www-data','www-data' )->ensure();
Permission->new( nasCommon->smbpasswd, '0664','www-data','www-data' )->ensure();
Permission->new( nasCommon->smb_conf, '0664','www-data','www-data' )->ensure();
=cut
#
# TODO: bruce - I am working on Permissions.pm to simplify this bit of code.
# BUG#2889 bruce - Web UI: No initial shares.inc or senvid.inc files
if (! -w nasCommon->TZ ) {
sudo("$nbin/touch.sh ".nasCommon->TZ );
sudo("$nbin/chown.sh root:www-data ".nasCommon->TZ );
sudo("$nbin/chmod.sh g+w ".nasCommon->TZ );
}
if (! -w nasCommon->network_settings ) {
sudo("$nbin/chown.sh root:www-data ".nasCommon->network_settings );
sudo("$nbin/chmod.sh g+w ".nasCommon->network_settings );
}
if (! -w nasCommon->nas_home ) {
sudo("$nbin/mkdir.sh ".nasCommon->nas_home);
sudo("$nbin/chown.sh root:www-data ".nasCommon->nas_home);
sudo("$nbin/chmod.sh 775 ".nasCommon->nas_home);
}
if (! -w nasCommon->shares_inc ) {
sudo("$nbin/touch.sh ".nasCommon->shares_inc );
sudo("$nbin/chown.sh www-data:www-data ".nasCommon->shares_inc);
sudo("$nbin/chmod.sh 0644 ".nasCommon->shares_inc);
}
if (! -w nasCommon->senvid_inc ) {
sudo("$nbin/touch.sh ".nasCommon->senvid_inc );
sudo("$nbin/chown.sh www-data:www-data ".nasCommon->senvid_inc);
sudo("$nbin/chmod.sh 0644 ".nasCommon->senvid_inc);
}
if (! -w nasCommon->nfs_exports ) {
sudo("$nbin/touch.sh ".nasCommon->nfs_exports );
sudo("$nbin/chown.sh www-data:www-data ".nasCommon->nfs_exports);
sudo("$nbin/chmod.sh 0644 ".nasCommon->nfs_exports);
}
# BUG#2890 bruce - /var/oxsemi/nas.ini should be owned by www-data
# Also moved the chmod up to befor the Config::IniFiles
sudo("$nbin/chown.sh www-data:www-data ".nasCommon->nas_ini);
sudo("$nbin/chmod.sh 0666 ".nasCommon->nas_ini);
# BUG#2894 bruce - Check that smbpasswd exists and create if not
if (! -w nasCommon->smbpasswd ) {
sudo("$nbin/touch.sh ".nasCommon->smbpasswd );
sudo("$nbin/chown.sh www-data:www-data ".nasCommon->smbpasswd);
sudo("$nbin/chmod.sh 0664 ".nasCommon->smbpasswd);
sudo("$nbin/fs_addUser.sh 'www-data' 'blank'" );
}
# BUG#2890 bruce - smb.conf and /usr/local/samba/lib/ should be owned by www-data
# Also moved the chmod up to befor the Config::IniFiles
sudo("$nbin/chown.sh root:www-data ".nasCommon->smb_conf);
sudo("$nbin/chmod.sh 0664 ".nasCommon->smb_conf);
sudo("$nbin/chown.sh root:www-data ".nasCommon->smb_lib);
sudo("$nbin/chmod.sh 0775 ".nasCommon->smb_lib);
# Create the default shares for NFS and Samba
#
Service::Shares->createDefault();
# Open nas.ini
my $config = new Config::IniFiles( -file => nasCommon->nas_ini );
# Extract some data from default-settings and put in nas.ini
if (my $dfs=Config::Tiny->read( nasCommon->default_settings )) {
my $type = $dfs->{_}->{default_system_type};
for ($type) {
# Map the default_system_type names to our internal type name.
/1nc/i && ($type='1NC',last);
/2nc/i && ($type='2NC',last);
}
# Store the type in config for later use
$config->newval( 'general','system_type', $type );
}
# Main FCGI Loop
while (my $cgi = new CGI::Fast)
{
#print $cgi->header(-type => 'text/html; charset=UTF-8',
# -cache-control => 'no-cache',
# );
#printf("mainloop--start
");
my $language = $config->val('general', 'language');
my $func = $ENV{SCRIPT_NAME};
my $auth = ($func=~/auth/);
# Ensure that pages that require authorization do so
if ( !$auth && ($func !~ /home|mio_update/)) {
$func="home"; # Just display the home page
}
#printf("File:%s--Line:%d--
\$ENV\{SCRIPT_NAME\}=\$func=%s
",__FILE__,__LINE__,$func);
my $auth = ($func=~/auth/);
$func =~ s/.*?([^\/]+)\.pl$/$1/;
$func = 'home' if $func =~ /nasMaster/;
$func = 'home' unless $func; # bruce - Added default if blank
# Ensure that the user visits, and completes, the initial setup page(s) - exception is that
# they can change language before completing the initial setup.
#
if ( ($func ne 'initsetup') &&
($func ne 'language') &&
($func ne 'home_update') &&
($func ne 'home_status') &&
($func ne 'mio_update_reg') &&
($func ne 'mio_update_share') &&
($func ne 'language')
) {
if ($config->val('general', 'initial_config_done') ne 'y') {
$func = 'initsetup';
}
}
# Use cookies cookies if usecookie is set
my $usecookie=$config->val( 'general','usecookie');
if ( ($func =~/^mio_update/) || # Ignore mionet
($func =~/hold/) || # and holding pages
($func =~/networkstatus/) || # and network status ajax
($func =~/ajax/) || # and anything ajax
($func =~/dm_progress/) # and dm_progress ajax
) {
# Flag to ignore cookies
$usecookie=0;
}
# Check that the network has finished starting up before we display any page
#
if ( ( $func!~/mio_update/) &&
( $func!~/networkstatus/) &&
(! -r nasCommon->network_lock)
) {
# Not mio and no lock and not the network status report
# Go to the hold page and store originalPage if locked
$func = "hold";
}
# Create a new object based on the $func name being the same name
# as a class in nas/*.pm
# bruce - perhaps enclose in eval() to trap potential errors
$func = "home" unless eval( "use nas::$func;1" );
$func = "nas::$func";
eval {
# Try executing the page
my $ss = new $func($language,$cgi,$config,$usecookie);
#printf("File:%s--Line:%d
\$ss=%s
\$func=%s
",__FILE__,__LINE__,$ss,$func);
#printf("File:%s
\$ss = new \$func(lan.cgi.config.cookie)
",__FILE__);
#printf("File:%s
\$ss->processRequest()
",__FILE__);
$ss->processRequest(); ## ($cgi, $config);
1;
} || do {
# Display the fatal error page
my $ss = new nasCore( $language,$cgi,$config );
$ss->fatalError( $config, 'f00000', $!.$@ );
};
#printf("mainloop--end
");
}
主要工作小結
1. 架設版本控制平台 SVN
2. 專案版本控制管理
3. 專案開發環境架設 fedora8及其BSP環境
4. 管理與整合BSP
5.
build image與release版本
6. 應用程式與GUI開發
心得
1.
對嵌入式系統有初步的認識
2.
對Linux的操作與shell script有初步認識
3.
了解embedded linux的系統管理
4.
對cross toolchain kernel rootfilesystem有初步的認識
5.
對 lighted 與 perl有初步認識
6.
對 Linux程式設計有初步的了解