프로그램 사용/u-boot2009. 12. 30. 12:26
당연한것 일수도 있지만, u-boot에서 kernel로 argument를 날려주고
그 인자들 중, NIC 관련 변수들을 파싱하여 자동으로 네트워크를 설정하게 되는데
인자를 ' '(홀따옴표)로 감싸주어 커널에서 파싱하도록 할 수 있다.

물론, bootargs에 한번에 넣어서는 불가능하며,
run 명령어를 통해서 인자를 생성후 넘겨주는 방식을 취한다.

We can use U-Boot environment variables to store all necessary configuration parameters:

=> setenv ipaddr 192.168.100.6
=> setenv serverip 192.168.1.1
=> setenv netmask 255.255.0.0
=> setenv hostname canyonlands
=> setenv rootpath /opt/eldk-4.2/ppc_4xx
=> saveenv

Then you can use these variables to build the boot arguments to be passed to the Linux kernel:

=> setenv nfsargs 'root=/dev/nfs rw nfsroot=${serverip}:${rootpath}'


Note: You cannot use this method directly to define for example the "bootargs" environment variable, as the implicit usage of this variable by the "bootm" command will not trigger variable expansion - this happens only when using the "setenv" command.

[링크 : http://www.denx.de/wiki/DULG/LinuxBootArgs]


사용예
setenv nfsargs 'setenv bootargs console=ttyAS0,115200 root=/dev/mtdblock2 rootfstype=cramfs'
setenv addip 'setenv bootargs ${bootargs} nwhwconf=device:eth0,hwaddr:${ethaddr}
                    ip=${ipaddr}::${gateway}:${netmask}:${histname}::off'
setenv bootcmd 'run nfsargs addip\; tftp 0x84400000 uImage\; bootm'

아무튼, bootcmd 에 'run' 을 통해서 bootargs를 생성후 임시 변수를 커널로 넘겨주는 방식이다.
(실제로 bootargs 변수는 uboot에 존재하지 않는다.)
Posted by 구차니
프로그램 사용/u-boot2009. 8. 19. 17:20
fw_printenv는 uboot에 포함된 tool이다
uboot/tool/env 에 존재하는 녀석인데
ethaddr을 값을 변경하려고 하니 에러가 발생하였다.

fw_setenv()의 리턴값은 30인데 아마도 EROFS가 30인듯 하다(errno.h에서는 발견하지 못한 변수이다.)
눈에 들어온 부분은 아래의 strcmp() 이다.
	/*
	 * Delete any existing definition
	 */
	if (oldval) {
		/*
		 * Ethernet Address and serial# can be set only once
		 */
		if ((strcmp (name, "ethaddr") == 0) ||
			(strcmp (name, "serial#") == 0)) {
			fprintf (stderr, "Can't overwrite \"%s\"\n", name);
			return (EROFS);
		}

		if (*++nxt == '\0') {
			*env = '\0';
		} else {
			for (;;) {
				*env = *nxt++;
				if ((*env == '\0') && (*nxt == '\0'))
					break;
				++env;
			}
		}
		*++env = '\0';
	}

아무튼, uboot에서 기본적으로 ethaddr과 serial#을 지원하고
이값들은, 한번만 write되고 수정되서는 안되기 때문에 제약사항으로 묶어놓은 듯 하다.
Posted by 구차니
프로그램 사용/u-boot2009. 8. 17. 18:34
busybox에서 라고 해야 하나,
아무튼, busybox의 경우에는 커널에서 부팅시에 ip를 설정한다.

TCP bic registered
NET: Registered protocol family 1
NET: Registered protocol family 17
stmmaceth_open: MAC address 00:fa:e0:fa:e0:59
stmmac_init_phy: phy_id=0:03, phy_addr=0x3
IP-Config: Complete:
      device=eth0, addr=192.168.10.116, mask=255.255.255.0, gw=192.168.10.1,
     host=hmp_7109, domain=, nis-domain=(none),
     bootserver=255.255.255.255, rootserver=192.168.10.10, rootpath=
Looking up port of RPC 100003/2 on 192.168.10.10
PHY: 0:03 - Link is Up - 100/Full
Looking up port of RPC 100005/1 on 192.168.10.10
VFS: Mounted root (nfs filesystem) readonly.
Freeing unused kernel memory: 100k freed
  Vendor: AXXEN     Model: SKYMIRROR         Rev: 1.00
  Type:   Direct-Access                      ANSI SCSI revision: 02
SCSI device sda: 4016128 512-byte hdwr sectors (2056 MB)
sda: assuming Write Enabled
sda: assuming drive cache: write through
SCSI device sda: 4016128 512-byte hdwr sectors (2056 MB)
sda: assuming Write Enabled
sda: assuming drive cache: write through
 sda: sda1
sd 1:0:0:0: Attached scsi removable disk sda
Welcome to STLinux BusyBox system

머.. 이건 중요한게 아니고, 아무튼, ifdown을 통해서 죽이고
ifup을 통해서 올리려고 하는데, ifup시 static ip가 설정이 되지 않고
초기 kernel argument로 넘긴 값으로 부팅이 되는 문제가 있다.

검색을 해보니

Re: ETH0 already configured durring boot
The U-boot uses its own network driver and only the MAC address set up by the U-boot affects the network driver under Linux.

The network is started by the script /etc/init.d/networking in Debian/Emdebian distribution.  The soft links are used in each run level start up directories /etc/rcX.d, where X is run level 0, 1, 2, etc.  The normal run level is 3.  You can remove the link in the directory to disable the network start up.

The text file /etc/network/interfaces configures the network interfaces.  It should be something like,

auto eth0
iface eth0 inet dhcp

You can also just remove everything in this file to disable the automatic start up of the network.

[링크 : http://glomation.net/smf/index.php?topic=111.0]

라고 되어있는데, 일단 커널레벨에서 설정하는 것과는 별개의 문제이다.

# cat /etc/network/interfaces
######################################################################
# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)
#
# A "#" character in the very first column makes the rest of the line
# be ignored. Blank lines are ignored. Lines may be indented freely.
# A "\" character at the very end of the line indicates the next line
# should be treated as a continuation of the current one.
#
# The "pre-up", "up", "down" and "post-down" options are valid for all
# interfaces, and may be specified multiple times. All other options
# may only be specified once.
#
# See the interfaces(5) manpage for information on what options are
# available.
######################################################################

# We always want the loopback interface.
#
# auto lo
# iface lo inet loopback

# An example ethernet card setup: (broadcast and gateway are optional)
#
# auto eth0
# iface eth0 inet static
#     address 192.168.0.42
#     network 192.168.0.0
#     netmask 255.255.255.0
#     broadcast 192.168.0.255
#     gateway 192.168.0.1

# A more complicated ethernet setup, with a less common netmask, and a downright
# weird broadcast address: (the "up" lines are executed verbatim when the
# interface is brought up, the "down" lines when it's brought down)
#
# auto eth0
# iface eth0 inet static
#     address 192.168.1.42
#     network 192.168.1.0
#     netmask 255.255.255.128
#     broadcast 192.168.1.0
#     up route add -net 192.168.1.128 netmask 255.255.255.128 gw 192.168.1.2
#     up route add default gw 192.168.1.200
#     down route del default gw 192.168.1.200
#     down route del -net 192.168.1.128 netmask 255.255.255.128 gw 192.168.1.2

# A more complicated ethernet setup with a single ethernet card with
# two interfaces.
# Note: This happens to work since ifconfig handles it that way, not because
# ifup/down handles the ':' any differently.
# Warning: There is a known bug if you do this, since the state will not
# be properly defined if you try to 'ifdown eth0' when both interfaces
# are up. The ifconfig program will not remove eth0 but it will be
# removed from the interfaces state so you will see it up until you execute:
# 'ifdown eth0:1 ; ifup eth0; ifdown eth0'
# BTW, this is "bug" #193679 (it's not really a bug, it's more of a
# limitation)
#
# auto eth0 eth0:1
# iface eth0 inet static
#     address 192.168.0.100
#     network 192.168.0.0
#     netmask 255.255.255.0
#     broadcast 192.168.0.255
#     gateway 192.168.0.1
# iface eth0:1 inet static
#     address 192.168.0.200
#     network 192.168.0.0
#     netmask 255.255.255.0

# "pre-up" and "post-down" commands are also available. In addition, the
# exit status of these commands are checked, and if any fail, configuration
# (or deconfiguration) is aborted. So:
#
# auto eth0
# iface eth0 inet dhcp
#     pre-up [ -f /etc/network/local-network-ok ]
#
# will allow you to only have eth0 brought up when the file
# /etc/network/local-network-ok exists.

# Two ethernet interfaces, one connected to a trusted LAN, the other to
# the untrusted Internet. If their MAC addresses get swapped (because an
# updated kernel uses a different order when probing for network cards,
# say), then they don't get brought up at all.
#
# auto eth0 eth1
# iface eth0 inet static
#     address 192.168.42.1
#     netmask 255.255.255.0
#     pre-up /path/to/check-mac-address.sh eth0 11:22:33:44:55:66
#     pre-up /usr/local/sbin/enable-masq
# iface eth1 inet dhcp
#     pre-up /path/to/check-mac-address.sh eth1 AA:BB:CC:DD:EE:FF
#     pre-up /usr/local/sbin/firewall

# Two ethernet interfaces, one connected to a trusted LAN, the other to
# the untrusted Internet, identified by MAC address rather than interface
# name:
#
# auto eth0 eth1
# mapping eth0 eth1
#     script /path/to/get-mac-address.sh
#     map 11:22:33:44:55:66 lan
#     map AA:BB:CC:DD:EE:FF internet
# iface lan inet static
#     address 192.168.42.1
#     netmask 255.255.255.0
#     pre-up /usr/local/sbin/enable-masq $IFACE
# iface internet inet dhcp
#     pre-up /usr/local/sbin/firewall $IFACE

# A PCMCIA interface for a laptop that is used in different locations:
# (note the lack of an "auto" line for any of these)
#
# mapping eth0
#    script /path/to/pcmcia-compat.sh
#    map home,*,*,*                  home
#    map work,*,*,00:11:22:33:44:55  work-wireless
#    map work,*,*,01:12:23:34:45:50  work-static
#
# iface home inet dhcp
# iface work-wireless bootp
# iface work-static static
#     address 10.15.43.23
#     netmask 255.255.255.0
#     gateway 10.15.43.1
#
# Note, this won't work unless you specifically change the file
# /etc/pcmcia/network to look more like:
#
#     if [ -r ./shared ] ; then . ./shared ; else . /etc/pcmcia/shared ; fi
#     get_info $DEVICE
#     case "$ACTION" in
#         'start')
#             /sbin/ifup $DEVICE
#             ;;
#         'stop')
#             /sbin/ifdown $DEVICE
#             ;;
#     esac
#     exit 0

# An alternate way of doing the same thing: (in this case identifying
# where the laptop is is done by configuring the interface as various
# options, and seeing if a computer that is known to be on each particular
# network will respond to pings. The various numbers here need to be chosen
# with a great deal of care.)
#
# mapping eth0
#    script /path/to/ping-places.sh
#    map 192.168.42.254/24 192.168.42.1 home
#    map 10.15.43.254/24 10.15.43.1 work-wireless
#    map 10.15.43.23/24 10.15.43.1 work-static
#
# iface home inet dhcp
# iface work-wireless bootp
# iface work-static static
#     address 10.15.43.23
#     netmask 255.255.255.0
#     gateway 10.15.43.1
#
# Note that the ping-places script requires the iproute package installed,
# and the same changes to /etc/pcmcia/network are required for this as for
# the previous example.


# Set up an interface to read all the traffic on the network. This
# configuration can be useful to setup Network Intrusion Detection
# sensors in 'stealth'-type configuration. This prevents the NIDS
# system to be a direct target in a hostile network since they have
# no IP address on the network. Notice, however, that there have been
# known bugs over time in sensors part of NIDS (for example see
# DSA-297 related to Snort) and remote buffer overflows might even be
# triggered by network packet processing.
#
# auto eth0
# iface eth0 inet manual
#     up ifconfig $IFACE 0.0.0.0 up
#       up ip link set $IFACE promisc on
#       down ip link set $IFACE promisc off
#       down ifconfig $IFACE down

# Set up an interface which will not be allocated an IP address by
# ifupdown but will be configured through external programs. This
# can be useful to setup interfaces configured through other programs,
# like, for example, PPPOE scripts.
#
# auto eth0
# iface eth0 inet manual
#       up ifconfig $IFACE 0.0.0.0 up
#       up /usr/local/bin/myconfigscript
#       down ifconfig $IFACE down

/etc/network/interfaces는 ifup / ifdown 에서 사용하는 내용으로 저러면 된다는데...
결국 미궁이다.. 후우...

[링크 : http://www.annodex.net/cgi-bin/man/man2html?interfaces]
[링크 : http://www.annodex.net/cgi-bin/man/man2html?8+ifup]
[링크 : http://www.annodex.net/cgi-bin/man/man2html?8+ifdown]


Posted by 구차니
프로그램 사용/u-boot2009. 7. 18. 13:09
u-boot/tools/env 에 있는 README 파일 번역입니다.

이것은 U-boot의 환경 변수를 읽어오는 리눅스 명령행 프로그램의 적용예제 입니다.

run-time 유틸리티 설정을 위해서 다음의 줄을 주석처리 합니다.
fw_env.h 파일의
    #define CONFIG_FILE  "/etc/fw_env.config"

특정 타겟 보드를 위한 define들은 fw_env.confg 파일의 주석을  보시기 바랍니다.

화경설정은 fw_env.h 파일의 #define들을 통해 할 수 있습니다.
아래의 내용을 수정하시면 됩니다.

    #define HAVE_REDUND     /* 환경변수 영역이 2개일 경우 */
    #define DEVICE1_NAME    "/dev/mtd1"
    #define DEVICE2_NAME    "/dev/mtd2"
    #define DEVICE1_OFFSET    0x0000
    #define ENV1_SIZE         0x4000
    #define DEVICE1_ESIZE     0x4000
    #define DEVICE2_OFFSET    0x0000
    #define ENV2_SIZE         0x4000
    #define DEVICE2_ESIZE     0x4000

현재의 설정은 TRAB 보드에 맞추어져 있습니다.

백업용 환경변수 영역을 사용하지 않는다면 HAVE_REFUND를 주석처리합니다.
HAVE_REDUND 가 주석처리 되면 DEVICE2_NAME, ENV2_SIZE, DEVICE2_ESIZE 를 무시합니다.

DEVICEx_NAME 에는 환경변수가 저장되어 있는 MTD 캐릭터 디바이스를 지정합니다.
DEVICEx_OFFSET 에는 MTD 캐릭터 디바이스 범위 안의 환경변수의 offset을 지정합니다.
ENVx_SIZE 에는 (만약에 환경변수가 하나의 섹터크기 보다 적다면 플래시 섹터보다 작은 값을 지닐) 환경변수에 의해 사용되는 크기를 지정합니다.
DEVICEx_ESIZE 환경변수가 위치하는 플래시 파티션의 첫 섹터의 크기를 지정합니다.


Posted by 구차니
프로그램 사용/u-boot2009. 3. 25. 18:51

14.3.27. How can I access U-Boot environment variables in Linux?

Question:
I would like to access U-Boot's environment variables from my Linux application. Is this possible?

Answer:
Yes, you can. The environment variables must be stored in flash memory, and your Linux kernel must support flash access through the MTD layer. In the U-Boot source tree you can find the environment tools in the directory tools/env, which can be built with command:

make env

For building against older versions of the MTD headers (meaning before v2.6.8-rc1) it is required to pass the argument "MTD_VERSION=old" to make:

make MTD_VERSION=old env

The resulting binary is called fw_printenv, but actually includes support for setting environment variables too. To achieve this, the binary behaves according to the name it is invoked as, so you will have to create a link called fw_setenv to fw_printenv.

These tools work exactly like the U-Boot commands printenv resp. setenv You can either build these tools with a fixed configuration selected at compile time, or you can configure the tools using the /etc/fw_env.config configuration file in your target root filesystem.

[링크 : http://www.denx.de/wiki/view/DULG/HowCanIAccessUBootEnvironmentVariablesInLinux]

2010.03.11 추가
간단하게 말하자면 eboot 소스트리에서
u-boot/tools/env 에서
fw_env를 컴파일 하게 되면
fw_setenv
fw_getenv 파일이 생성된다. (물론 하나는 심볼릭 링크이다)

2009/07/18 - [프로그램 사용/u-boot] - U-Boot 환경변수 읽어오기 (u-boot environment variable)

Posted by 구차니