Customizing_LGMOD - openlgtv/wiki GitHub Wiki
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 :
>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 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
No at the end add CRC in INSERT MODE so in little endian here 0x1a 0xa3 0x78 0x29.
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.
That's it, we have our epk, and finally cross fingers and test ;-)
--Arno1 15:08, 10 February 2011 (MSK)