MultiFiles

UDP 멀티캐스트 상의 파일(펌웨어) 분배를 위한 시스템

다운로드 multifiles v0.5

라이센스: GPLv2, GPLv3.

MultiFiles 운영 원리

분배된 파일은 지정된 멀티캐스트 주소(기본적으로 224.2.2.4 포트 2222)에 따라 UDP 멀티캐스트 스트림에 있는 네트워크로 주기적으로 전송됩니다. 펌웨어를 받으려면 클라이언트는 IGMP 요청을 보내서 멀티캐스트 그룹에 참여하고 파일을 다운로드해야 합니다. 다운로드가 완료되면 클라이언트는 그룹과 분리되며 파일의 무결성을 확인합니다. 확인을 성공적으로 끝내면, 파일(형식은 .tar.gz)의 압축을 풀고 다운로드 받은 폴더에 있는 customup.sh 스크립트를 시작합니다. 이 스크립트는 필요한 파일을 업데이트하고 업데이트에 필요한 기타 작업을 실행합니다.

멀티캐스트를 통하여 하나의 스트림만을 사용하는 임의의 동적 IP 셋톱박스를 업데이트할 수 있습니다.

기존의 펌웨어 버전이 스트림에 배포된 것과 같거나 보다 새로운 것이라면 클라이언트는 업데이트를 실행하지 않습니다. 그러나, 서버에 "force update" 옵션이 지정되어 있으면, 소프트웨어 버전에 상관없이 업데이트가 항상 실행됩니다.

Multifiles scheme
그림 1. 멀티파일을 가진 네트워크 구성도

스트림 사양

스트림은 다음 형식의 헤더를 가진 UDP 패킷으로 구성되어 있습니다:

struct mulfiles_header{
    uint32_t message_type;
    uint32_t flags;
    uint32_t data_size;
    uint32_t sequence_no;
    uint32_t file_offset;
};

message_type은 다음 두 값 중 하나를 가질 수 있습니다:

#define MF_MTYPE_INFO 0x04030201
#define MF_MTYPE_DATA 0x04030202

MF_MTYPE_INFO 형식의 패킷은 정보용 패킷이고 분배된 파일의 정보를 담고 있으며 다음 데이터를 포함합니다:

struct mulfiles_message_info{
    uint32_t file_size;
    uint32_t fw_version;
    unsigned char md5sum[16];
    char filename[1024];
};

무결성 확인을 위해 파일 크기, 펌웨어 버전, 파일 이름 및 MD5 요약. 정보용 패킷은 기본적으로 매 2초마다 전송됩니다.

MF_MTYPE_DATA 형식의 패킷은 분배된 파일의 콘텐츠를 담고 있습니다. 헤더는 파일 시작에 관한 패킷에 들어 있는 데이터의 오프셋 상의 정보를 담고 있습니다. 클라이언트는 시작할 다음 주기를 기다리지 않고 항상 파일의 다운로드를 시작할 수 있습니다. 이런 원리를 통해 파일의 시작과 끝을 탐색하기 위해 발생하는 추가 지연없이 파일을 다운로드할 수 있습니다.

네트워크 상의 데이터 전송 속도는 서버 애플리케이션의 명령줄 옵션을 통해 조절할 수 있습니다. 기본적으로 속도는 100Kb/s입니다.

서버 애플리케이션 사양

서버의 명령줄 옵션:

multifiles # ./mfsrv -h
NetUP's multicast file upload utility (server). Copyright (c) 2001-2008 NetUP Inc.
www.netup.tv. Compile date: Nov  3 2008 13:22:49
 Use this utility at your own risk.
usage:
options
 [-i IP]          Multicast IP address to use. Default: 224.2.2.4
 [-p port]                UDP port to use. Default: 2222
 [-d]             Enable debug messages. Default: disabled
 [-f file]                Name of the file to send. Default: testfile.bin
 [-s speed]               Upload speed Kbytes/sec. Default: 100 Kbytes/sec
 [-t delay]               Prophylactic info messages delay, sec. Default: 2 sec
 [-u]             Setting force update flag. Default: force update flag not set
 [-a version]             Firmware version. Default: 0
 [-h]             This help

서버 시작의 예:

multifiles # ./mfsrv  -i 224.5.6.7 -p 1111 -f ./netup.tgz -s 100 -a 1104 -t 6
Using file:./netup.tgz file name:netup.tgz prophylactic_delay:6
Speed:102400 bytes/sec psleep: 13513
+ Sending file:netup.tgz sequence:1
o    Prophylactic info: 1068 bytes from 1068 send to socket:3
o    Prophylactic info: 1068 bytes from 1068 send to socket:3
o    Prophylactic info: 1068 bytes from 1068 send to socket:3
o    Prophylactic info: 1068 bytes from 1068 send to socket:3
o    Prophylactic info: 1068 bytes from 1068 send to socket:3
o    Prophylactic info: 1068 bytes from 1068 send to socket:3
o    Prophylactic info: 1068 bytes from 1068 send to socket:3
o    Prophylactic info: 1068 bytes from 1068 send to socket:3
o    File:netup.tgz successfully sent
+ Sending file:netup.tgz sequence:2

위의 예에서 보여진 것처럼, netup.tgz 파일이 100Kb/s의 속도로 멀티캐스트 그룹 224.5.6.7:1111에 전송되고 있습니다. 펌웨어 버전은 1104입니다.

클라이언트 애플리케이션 사양

클라이언트의 명령줄 옵션:

multifiles # ./mfcln -h
NetUP's multicast file upload utility (client). Copyright (c) 2001-2008 NetUP Inc.
www.netup.tv. Compile date: Nov  3 2008 01:22:48
 Use this utility at your own risk.
usage:
options
 [-i IP]          Multicast IP address to use. Default: 224.2.2.4
 [-p port]                UDP port to use. Default: 2222
 [-t socket wait timeout]       UDP socket timeout, sec. Default: 10 sec.
 [-d]             Enable debug messages. Default: disabled
 [-f file]        Name of the file to save. Default using filename coming from server
 [-s stat_file]   Name of the file to save stats in. Default: /tmp/mfstat.log
 [-a fw_version]  Current fw version. Download is started only if 
                  the received version is newer than current. Default: 0
 [-h]             This help

클라이언트 시작의 예:

multifiles # ./mfcln -i 224.5.6.7 -p 1111 -a 1100
Waiting for incoming data ...
Info message received. sequence:9240 filename:netup.tgz outfilename:netup.tgz.9240 
size:5741931 bytes
Receiving data ...
Filling file to required 5741931 bytes, blocks size is:1048576
File filled. Size is:5741931 requested size is:5741931. Starting write into
First offset:1379
Prophylactic info message received. filename:netup.tgz offset:208380 size:5741931 bytes 
force update:0 fw_version:1104
Prophylactic info message received. filename:netup.tgz offset:615480 size:5741931 bytes 
force update:0 fw_version:1104
Prophylactic info message received. filename:netup.tgz offset:1022580 size:5741931 bytes 
force update:0 fw_version:1104
Prophylactic info message received. filename:netup.tgz offset:1431060 size:5741931 bytes 
force update:0 fw_version:1104
Prophylactic info message received. filename:netup.tgz offset:1838160 size:5741931 bytes 
force update:0 fw_version:1104
Prophylactic info message received. filename:netup.tgz offset:2245260 size:5741931 bytes 
force update:0 fw_version:1104
Prophylactic info message received. filename:netup.tgz offset:2653740 size:5741931 bytes 
force update:0 fw_version:1104
Prophylactic info message received. filename:netup.tgz offset:3060840 size:5741931 bytes 
force update:0 fw_version:1104
Prophylactic info message received. filename:netup.tgz offset:3467940 size:5741931 bytes 
force update:0 fw_version:1104
Prophylactic info message received. filename:netup.tgz offset:3875040 size:5741931 bytes 
force update:0 fw_version:1104
Prophylactic info message received. filename:netup.tgz offset:4283520 size:5741931 bytes 
force update:0 fw_version:1104
Prophylactic info message received. filename:netup.tgz offset:4690620 size:5741931 bytes 
force update:0 fw_version:1104
Prophylactic info message received. filename:netup.tgz offset:5097720 size:5741931 bytes 
force update:0 fw_version:1104
Prophylactic info message received. filename:netup.tgz offset:5506200 size:5741931 bytes 
force update:0 fw_version:1104
Prophylactic info message received. filename:netup.tgz offset:69000 size:5741931 bytes 
force update:0 fw_version:1104
File 'netup.tgz.9240' received. Checking ...
e7a646426d66b5df3318ba09f1ae33d2 - our file md5. size:5741931
e7a646426d66b5df3318ba09f1ae33d2 - received md5
MD5 check success
File 'netup.tgz.9240' checked. Success.

위의 예에서 보여진 것처럼, netup.tgz 파일을 멀티캐스트 그룹 224.5.6.7:1111에서 받고 있습니다. 현재 파일 버전은 1100이지만 서버가 제공한 버전은 1104입니다.

펌웨어 만들기

스크립트 디렉토리 목록:

multifiles # ls -al scripts/
total 16
drwxr-xr-x 4 root root   84 Oct 27 13:51 .
drwxr-xr-x 5 root root 4096 Oct 27 15:36 ..
-rwxr-xr-x 1 root root  115 Oct 27 13:51 createfw.sh
-rwxr-xr-x 1 root root  187 Oct 27 13:42 customup.sh
drwxr-xr-x 3 root root   35 Oct 27 13:51 firmware
-rwxr-xr-x 1 root root  889 Oct 27 13:39 update.sh

createfw.sh 스크립트를 펌웨어 생성에 사용했습니다. 하나의 예로, 스트립트는 다음과 같습니다:

multifiles # cat scripts/createfw.sh
FWPATH="firmware"
FWNAME="mf_fw.tgz"

(cd $FWPATH; tar cvfz ../$FWNAME ./*)
echo "Firmware created. File: $FWNAME"

보여진 것처럼, 이 스크립트는 펌웨어 폴더의 목록을 mf_fw.tgz 파일에 보관합니다. 앞에서 설명한 것처럼, 이 파일은 멀티캐스트를 위해 제공됩니다.

scripts/firmware/ 디렉토리는 업데이트에 필요한 파일과 다운로드 후에 클라이언트 기기에서 필요한 작업을 실행하는 customup.sh 스크립트를 담고 있습니다. 이런 스크립트의 한 예가 다음에 보여집니다:

multifiles # cat scripts/firmware/customup.sh
echo "Running custom upgrade shell script ... Please, wait"
echo "Copying new files ... "
cp stb_client/bin/stb_client /netup/stb_client/bin/stb_client

echo "Updating config files ... "

보여진 것처럼, 이 스크립트는 새로운 파일을 복사하고 필요하다면 구성 파일을 업데이트합니다.

클라이언트에서 펌웨어로 작업하기

클라이언트 기기에서 펌웨어의 받기 및 처리를 구성하는 스크립트의 예(이것은 IP STB를 위해 제공된 것입니다):

multifiles # cat scripts/update.sh
MFPATH="/mfupdater"
NEPATH="/netup"
DSTPATH=$MFPATH/dst
STATFILE="/tmp/mfstat.log"

# Show update splash screen
cat $MFPATH/updatesp.bmp > /dev/fb0 2>/dev/null

# get current ver
if [ -f $NEPATH/version ]; then
    export CURVER=`cat $NEPATH/version`
else
    export CURVER=0
fi


$MFPATH/mfcln -s $STATFILE -t 3 -i 224.5.6.7 -p 1111 -f $MFPATH/download.bin -a $CURVER

if [ $? -eq 0 ]; then
    echo "Updating software ... "

    # Create dst path
    mkdir $DSTPATH 2>/dev/null

    # unbzip received file into /netup
    cd $DSTPATH
    cat $MFPATH/download.bin | tar -xz

    # run custom script in received file
    cd $DSTPATH
    sh customup.sh

    # save new version
    if [ -f $STATFILE ]; then
        cat $STATFILE > $NEPATH/version
    fi

    # cleanup dst dir if required. You can do this in customup.sh

    echo "Update done. New fw version:"
    cat $NEPATH/version
fi

위의 코드에서 보여진 것처럼, 이 스크립트는 다음 단계를 실행합니다:

  • 현재 펌웨어 버전을 불러옵니다. 버전 정보는 /netup/version 내에 저장됩니다.
  • 멀티캐스트 그룹에서 펌웨어 다운로드를 시작합니다.
  • 파일이 성공적으로 다운로드 되면, 압축을 풀고 해당 폴더에 들어있는 cutomup.sh 스크립트를 실행합니다. 이 스크립트는 필요한 작업(복사, 업데이트 설정 등)을 수행합니다.
  • 새로운 버전의 데이터는 /netup/version 파일에 저장됩니다. 새로운 펌웨어 버전이 서버에서 오거나 "force update" 옵션이 서버에 설정되어 있다면, 다음 업데이트가 실행됩니다.

바이너리 구축

보관 폴더는 아래의 플랫폼을 위해 준비된 바이너리 구축을 담고 있습니다:

  • SH-4
  • Mipsel uclibc
  • ARM9
  • PPC
  • x86

IP STB 제조업체를 위한 도움말

기본 IP STB 공급에 클라이언트 애플리케이션(mfcln)을 포함시키는 것을 권장합니다. 각각의 IP STB를 시작하면, 펌웨어를 가지는 멀티캐스트 스트림의 존재 여부를 확인하기 위해 애플리케이션을 실행하는 것이 요구됩니다. 확인하는데 2초 이상 걸리지 않으며, 멀티캐스트 스트림이 발견한 펌웨어가 없거나 더 오래된 펌웨어가 제공되면, 변경없이 일반적인 설치 및 시작이 진행됩니다. 새로운 펌웨어 버전이 얻어지면, 이것이 설치되고 다음 시작은 설치된 펌웨어가 제공한 다른 구성을 따르게 됩니다. 이런 과정으로 현재 네트워크를 위해 펌웨어를 상세 지정하는 것을 통해 방금 설치된 IP STB가 자동적으로 운영되는 것이 가능합니다.




Get Adobe Flash player