Location>code7788 >text

Old Thing Utilization - Converting a set-top box into a Linux development machine!

Popularity:920 ℃/2024-08-11 16:45:20

preamble

Set-top box modelMobile Magic Box CM201-2(CH), chipset: hi3798mv300(hi3798mv3dmm), other models similar

Theoretically applicable to the following SOCs: Hi3798Mv100 / Hi3798Cv200 / Hi3798Mv200 / Hi3798Mv300

preliminary

1. Prepare the Linux system as the compilation environment, and use the Windows system to burn in the HiTool software (Windows can also be used without, refer to the official document of HIS).

Therefore, it is recommended to install WSL on Windows platform

2. Prepare HiTool (Windows software), Hess's burn-in software

image

3. Prepare to burn the firmware required to pass the USB serial TTL line, the blogger is using the CH340G, which only needs to be connected to the board TXD, RXD, GND three, and prepare a network cable for the set-top box to send the firmware program quickly!

The CH340G requires drivers that need to go to theOfficial Website Download

4. Preparation of set-top box source code

Source link: /martixjohn/HiSTBLinuxV100R005C00SPC050

Blogger modified part of the configuration to fit hi3798mv3dmm

5. Download the required toolchain for compilation in advance, using Ubuntu as an example.

sudo apt install gcc make gettext bison flex bc zlib1g-dev libncurses5-dev lzma

6. Ubuntu Rootfs Image

The Ubuntu reference steps are as follows

  • Download the Ubuntu base that matches the set-top box architecture from the ubuntu website or mirror source

  • Create a new empty file, at least 800M is recommended, and use it as a loopback file.

    dd if=/dev/zero of= bs=400M count=1
    
  • Format the loopback file to create the ext4 file system

    mkfs.ext4 
    
  • Mounting a loopback file

    # Create a mounted partition
    mkdir -p /mnt/loopback
    
    # Virtualize as a block device
    losetup --find --show
    
    # Mount the block device to a partition, e.g. /dev/loop0
    mount /dev/loop0 /mnt/loopback
    
  • Unzip the Ubuntu base

    tar -xzf  -C /mnt/loopback
    
  • Switching root directories

    It is recommended to use arch-chroot, which does a lot of the mounting, etc., and doesn't need to concern itself with extra steps

    arch-chroot /mnt/loopback
    
  • Customize your rootfs

    Install common software, note that Ubuntu base does not have systemdNetwork Manager installed, you need to install it yourself.

    apt install systemd network-manager ssh
    

    Important: you need to change the root password or create a new user and specify the passwordYou can only log in after you've swiped and booted

    passwd
    

Compiling the source SDK in a Linux environment

1. Copy the pre-configuration and overwrite it in the home directory.

Pre-configured files are in the configs directory

cp configs/hi3798mv300/hi3798mv3dmm_hi3798mv300_cfg.mak 

2. Preloaded environment

. ./
make tools

3. Customized configuration of compilation options (optional), as in the Linux kernel, the configuration system used is KConfig

make menuconfig

A few of the more important configuration options

  • Base->Chip Type: Select Chipset

  • Base->Out DIR: Output path, in the out directory

  • Board->Boot Regfile Config List: boot regfile, change the first one to the profile name that matches your own set-top box
    image

    This file is stored in source/boot/sysreg/xxx/*.reg
    image

    Hardware such as memory particles may vary from set-top box to set-top box, cf.connection testSelect the Reg Name displayed.
    image

4. Source code compilation

make build

You can turn on multi-core compilation, e.g. the blogger uses 16 cores for compilation

make build -j 16

Wait for the compilation to complete, the output is placed in the out directory, and the files required for burning are shown in the figure below

image

After adding the ubuntu rootfs image, the burn should be prepared with the files shown below

image

Modify the partition configuration file emmc_partitions.xml, change the SelectFile in the last item to the filename of the ubuntu image, and change the Length attribute to - to indicate that it occupies the remaining space in the memory.
image

Burning firmware to EMMC using HiTool software in Windows environment

1. Connect the TTL cable to the main board of the set-top box

  • If the CH340 driver is installed correctly, you will see the following in the device manager
    image

  • Connection Schematic
    image

  • Main board wiring as shown, from left to right connected to the adapter board GND, TXD, RXD, different boards may vary, you can try to adjust the TXD, RXD order!

image

2. Connection testing

  • Open HiTool software, select the chip, the first time you use it may pop up to show the

image

  • Click on Connection Manager

image

Configure the port, it will be recognized automatically, select the port of CH340, the baud rate is 115200
image

  • Open the Terminal tool
    image

  • The set-top box is connected to the power supply and switched on by pressing the set-top box power button

If the connection is correct, a startup message similar to the following will be displayed in the terminal
image

  • Turn off the power switch of the set-top box and click Disconnect on the terminal page.

image

3. Start burning

  • Load partition configuration and firmware: select HiBurn->Burn EMMC->Browse in order (select partition configuration file emmc_paritions.xml)
    image

  • Take a network cable to connect the motherboard of the set-top box to the router, make sure that the PC and the set-top box can interoperate, and configure the IP information (using thenetwork transmission(The reason for burning is that the serial port transfer rate is too slow)

    • The PC and Board Side Configuration tab is shown in Figure

    image

    • Under Local PC Configuration, click Refresh to get the corresponding port and the IP address of the PC

    • In the board configuration, the gateway is generally set to the router intranet IP, the general router default 192.168.1.1, the subnet mask needs to be configured in accordance with the router, the default home router is 255.255.255.0, the IP configured arbitrarily to ensure that the router and the router in the same subnet, such as 192.168.1.200, the physical address is arbitrarily set up!

    Note: The purpose of the above configuration is to allow the set-top box to fix the IP address so that the firmware can be transferred to the set-top box via Ethernet, and the set-top box will automatically set the corresponding IP according to the configuration to establish communication with the PC.

  • Click to burn

image

  • Turn on the set-top box power switch and start writing automatically

  • Burning is complete, pop-up window indicates success

4. Validation results

  • The set-top box may restart automatically, turn off the set-top box switch first

  • Open the HiTool terminal tool
    image

  • Right-click Clear Terminal to clear previous messages
    image

  • grout
    image

  • Turn on the set-top box switch, after first printing bootloader and other startup information, until a string of green OK is displayed, indicating that Ubuntu has been successfully flashed!

image

Just log in
image

Replacing or customizing a Linux distribution

Follow the burning steps, just replace the files corresponding to the last partition, make sure to select only that partition, and then click on Flush
image
image

Any partition can be customized similarly, happy DIYing everyone!

Welcome to the conversation, blogger.GitHub: /martixjohn/