Customizing LGMOD

From Openlgtv
Jump to: navigation, search

Customizing LGMOD

LGMOD is delivered now as epk for easy update of your TV. For one interested in modifying it/contribute to it there are several steps.

From epk to flash image(s)

An epk is just an archive with header and crc containing several flash partition images to be updated on TV, official epk contain several partition images (kernel, u-boot, rootfs, lgapp (RELEASE), fonts, etc...), while LGMOD epk contains only the rootfs for now (later should kernel be included).

To unpack an epk (official of LGMOD) simply use the python script un_epk.py I have done based on lucas work.

arno1@VM4 :> ls
LGMOD142.epk un_epk.py
arno1@VM4 :> ./un_epk.py LGMOD142.epk
pak 0 starts at 0x000000d0, length: 0x0013a084
EPK file: LGMOD142.epk, type: epak, size of packs: 0x0013a084, version: 00031400, contains 1 paks, tv model: HE_DTV_GP_M_AAAAABAA
saving root.pak, version: 00010402, date: 20100609, mode: 0, modelname: DVB-SATURN6
arno1@VM4 :> ls
LGMOD142.epk LGMOD142.epk_header LGMOD142.epk_root.mtd  LGMOD142.epk_root.pak_header un_epk.py
arno1@VM4 :> ./un_epk.py
Usage: un_epk

extract epk to epk header and pak files (full pak, pak header and pak data (mtd content))


See topic here on lg-hack forum : [1]


On the example above we have 4 files generated :

LGMOD142.epk_header => the epk header

LGMOD142.epk_root.pak => the rootfs pak image (rootfs flash image + header + crc)

LGMOD142.epk_root.pak_header => the rootfs pak header

LGMOD142.epk_root.mtd => the rootfs flash image (what we are interested in for next step)

From rootfs image to file structure

rootfs on LG TV firmware is squashfs (read-only and compressed file system very often used in embeded systems), you'll need squashfs tools installed on your linux system and being root (or sudo command implemented) to unpak it.

If you do not have unsquashfs and mksquashfs commands, you'll have to install squashfs-tools : Take care to use a 3.x version, 4.0 version does not work

>sudo apt-get install squashfs-tools

Deflate the to be modified rootfs under linux like this, for exemple with rootfs flash image taken from example above :

>sudo unsquashfs LGMOD142.epk_root.mtd

You'll get a directory "squashfs-root" with the content of the rootfs.

It's important to do this as root (sudo) else you won't have rights to create /dev devices file structure

Modify LGMOD

Now you can modify the rootfs (LGMOD or other), in squashfs-root directory, some examples :

Recompile busybox with new version and/or features enabled

Add modules

Customize init script :

The first script launched at init is /etc/init.d/rcS which call other scripts, just follow ;-)

Customize webui (internal http server) :

The web pages of webui are in /var/www directory

What ever is your modification, please modify the version file in /var/www/cgi-bin/version so that if your distribute your image one can track the version installed on TV set by webui.

From modified file structre to rootfs image

Happy with your modification ? it is now time to build a rootfs flash image.

From outside your modified squashfs-root directory do :

>sudo mksquashfs squashfs-root

Take care on saturn6 based TV the flash partition for rootfs is limited to 1,5 Mbytes (1 572 864) your resulting image should be less or equal to that size.

Too big ? then you have to remodify it and save room ;-(

You are now ready to flash it to your TV and test if you want with the u-boot loadz command !

If you want to flash it from usb you need to make an epk (next step)

From rootfs image to epk

First need to calculate crc of mtd (rootfs) flash image have script for that will share soon.

calculate flash image CRC :

> ./pak_crc.py LGMOD156.sqfs 
file: LGMOD156.sqfs, CRC: 0x2978a31a

Concatenate pak header (for example those of LGMOD1.5.5) and flash image :

> cat LGMOD155.epk_root.pak_header LGMOD156.sqfs > LGMOD156.pak_nocrc

No edit the pak file to edit header with an hex editor (here ghex2) : Change version at offset 0x48 to 0x4B (little endian again so 1.5.6 is 0x06 0x05 0x01 0x00) Change flash image size contained in pak at offset 0x04 to 0x07, here LGMOD156.sqfs is 1490944 bytes which in hex is 0x16C000

> ls -al LGMOD156.sqfs
-rwx------ 1 arno1 users 1490944 2011-02-04 18:03 LGMOD156.sqfs

So size is in little endian 0x00 0xC0 0x16 0x00

LGMOD156.pak nocrc.png

No at the end add CRC in INSERT MODE so in little endian here 0x1a 0xa3 0x78 0x29.

LGMOD156.pak.png

Save file as LGMOD156.pak

Now we have pak file, let's do the epk. Here it's quite simple we will include only one pak into epk.

First concatenate a header with pak file :

> cat LGMOD155.epk_header LGMOD156.pak > LGMOD156.epk

Then edit the file with hex editor to change epk version and pak offset and size. In epk header starting at offset 0x0C starts the pak table for each pak 2 infos, first offset in file (32 bits) then pak size (32 bits) as epk header is 0xD0 size length (208 bytes) first pak always starts at (little endian) 0xD0 0x00 0x00 0x00, here our flash partition has size 0x16C000, pak header size is 0x80 (128 bytes) and CRC 4 bytes so pak size is 0x16C000+0x80+0x04=0x16C084 so in little endian 0x84 0xC0 0x16 0x00 to be entered at offset 0x10 to 0x13.

At offset 0x04 to 0x07 is total size of paks here we have only one so same size as pak to be entered 0x84 0xC0 0x16 0x00.

At offset 0xAC is epk version, let's use 3.19 as it is recommended version of firmware to be used with LGMOD. That's 0x00 0x19 0x03 0x00.

LGMOD156.epk.png

That's it, we have our epk, and finally cross fingers and test ;-)

--Arno1 15:08, 10 February 2011 (MSK)

Another way

  1. Extracting the files from the firmware with unpacker "epk2extract by sirius" - see Firmware_unpack_tools#epk2extract_by_sirius.
  2. Edit the files as described above.
  3. Use the official packer LG - see Firmware_pack_tools.


How to compile BusyBox for LGMOD in any Linux-distro or under VMWare on Windows XP host

We will be working in the /root directory: cd /root

1. Install uClibc v0.9.30.1 cross-compiler toolchain:

wget http://www.uclibc.org/downloads/binaries/0.9.30.1/cross-compiler-mipsel.tar.bz2
tar -xvjf cross-compiler-mipsel.tar.bz2

2. Add compiler into PATH

export PATH=$PATH:/root/cross-compiler-mipsel/bin

3. Compile BusyBox

wget http://www.busybox.net/downloads/busybox-1.18.5.tar.bz2
tar -xvjf busybox-1.18.5.tar.bz2
cd busybox-1.18.5
wget http://openlgtv.org.ru/websvn/dl.php?repname=Repositary&path=/lgmod/trunk/busybox/.config&rev=393
cp config .config
make menuconfig

Go to Busybox Settings->Build Options->Cross Compiler prefix and set there:

/root/cross-compiler-mipsel/bin/mipsel- 

Also select other options you need, exit and save.

make 

4. Install BusyBox to LGMOD from WebSVN:

make CONFIG_PREFIX=/root/lgmod/trunk/rootfs install


How to compile Haserl for LGMOD in any Linux-distro or under VMWare on Windows XP host

We will be working in the /root directory: cd /root

1. Install uClibc v0.9.30.1 cross-compiler toolchain:

wget http://www.uclibc.org/downloads/binaries/0.9.30.1/cross-compiler-mipsel.tar.bz2
tar -xvjf cross-compiler-mipsel.tar.bz2

2. Add compiler into PATH

export PATH=$PATH:/root/cross-compiler-mipsel/bin

3. Compile Haserl

wget http://sourceforge.net/projects/haserl/files/haserl-0.9.29.tar.gz
tar -xvzf haserl-0.9.26.tar.gz
cd haserl-0.9.26
./configure --disable-luashell --disable-bash-extensions --host=mipsel CFLAGS="-static"
make
cd src
mipsel-strip haserl

To install Haserl to LGMOD from WebSVN:

cp haserl /root/lgmod/trunk/rootfs/usr/bin/

How to compile DJMount for LGMOD in any Linux-distro or under VMWare on Windows XP host

We will be working in the /root directory: cd /root

1. Install uClibc v0.9.30.1 cross-compiler toolchain:

wget http://www.uclibc.org/downloads/binaries/0.9.30.1/cross-compiler-mipsel.tar.bz2
tar -xvjf cross-compiler-mipsel.tar.bz2

2. Add compiler into PATH

export PATH=$PATH:/root/cross-compiler-mipsel/bin

3. Compile fuse:

wget http://sourceforge.net/projects/fuse/files/fuse-2.X/fuse-2.8.5.tar.gz
tar -xvzf fuse-2.8.5.tar.gz
cd fuse-2.8.5
./configure --host=mipsel --disable-example --prefix=/root/cross-compiler-mipsel
make
make install

4. Compile djmount

wget http://sourceforge.net/projects/djmount/files/djmount/djmount-0.71.tar.gz
tar -xvzf djmount-0.71.tar.gz
cd djmount-0.71

5. Compile libupnp 1.6.6

wget http://sourceforge.net/projects/pupnp/files/pupnp/libupnp-1.6.6.tar.bz2
tar -xvjf libupnp-1.6.6.tar.bz2
mv libupnp libupn_old
mv libupnp-1.6.6 libupnp
cd libupnp
ln -s build-aux config.aux

6. Apply >2Gbyte files support patch:

wget http://www.mediafire.com/file/wmnk2xz11ki/djmount-large5.zip
uzip djmount-large5.zip upnplib.patch -j
uzip djmount-large5.zip djmount.patch -j -d ../
patch -p1 -i libupnp.patch
./configure --host=mipsel --disable-debug --disable-samples
make
cd ..
patch -p1 -i djmount.patch
export FUSE_LIBS='-L/root/cross-compiler-mipsel/lib -lfuse -pthread -ldl'
export FUSE_CFLAGS='-I/root/cross-compiler-mipsel/include/fuse -D_FILE_OFFSET_BITS=64'
./configure --host=mipsel --disable-debug --disable-charset
make LDFLAGS+="-all-static"
cd djmount
mipsel-strip djmount

To install DJMount to LGMOD from WebSVN:

cp djmount /root/lgmod/trunk/rootfs/usr/bin/


How to compile kernel for Saturn 6 TV and corresponding network modules for LGMOD in any Linux-distro or under VMWare on Windows XP host

We will be working in the /root directory: cd /root

1. Install LG toolchain:

wget http://dl.dropbox.com/u/28364252/GP_toolchain.tar.bzip2
tar -xvjf GP_toolchain.tar.bzip2

2. Add compiler into PATH

export PATH=$PATH:/root/mips2_fp_le/bin

3. Compile kernel. At this step you need to get compilable sources of your firmware from LG. In my case the filename was lh7000_v3.55_OpenSrc.tgz and I put it in /root folder and continue:

tar -xvzf lh7000_v3.55_OpenSrc.tgz
cd GP_V3.55_openSRC/os/saturn6_linux/kernel/linux-2.6.26-saturn6

Here you can see some build scripts:

mk.sh - is for EU LCD/LED TVs (Saturn 6 = Venus_DVB codename)

mk-pdp.sh - is for EU PDP/Plasma TVs (Saturn 6 = PDP_DVB codename)

mk-s6-atsc.sh - is for US/KR LCD/LED TVs (Saturn 6 = Venus_ATSC codename)

mk-s5.sh - is for US/KR LCD/LED TVs (Saturn 5 = Mercury_ATSC codename)


So for EU LCD TV we do:

./mk.sh

After compilation you can find the image in obj-flash folder. It's called vmlinuz.lzo

If you want to change kernel options do:

cp config-flash .config
make menuconfig

Change options, save and do:

cp .config config-flash
./mk.sh

3. To compile all usb2net kernel modules:

cp config-flash .config
make menuconfig

Go to: Device Drivers, press Space on Network device support and press Enter. Go to: USB Network Adapters and select by Space every line there. Exit and save. And compile modules:

make modules

After compilation, you can find the modules in drivers/net and drivers/net/usb folders. To save space do:

cd drivers/net/usb
mips2_fp_le-strip --strip-unneeded *.ko

To update modules in LGMOD:

cp *.ko /root/lgmod/trunk/rootfs/modules