PowerPC VxWorks BSP Analysis 7 -- Image Compression

Source: Internet
Author: User
1. Image Compression

In embedded systems, we usually require that the VxWorks file be as small as possible. For example, when loading VxWorks through a serial port, floppy disk or tffs, if the file is too large, it may not be stored, or the loading fails. The following describes a technique to compress and decompress VxWorks files by using the deflate and inflate built-in tornado and VxWorks.

1. Use Tornado to create a bootable project, including applications. Perform proper reduction and configuration for VxWorks.

2. If you want to store VxWorks on a hard disk, floppy disk, or tffs, you should use usrnetenddevstart and usrnetifconfig in usrappinit to start the network interface. If it is stored on tffs, modify usrnetboot. C:

If (strncmp (sysbootparams. bootdev, "SCSI", 4) = 0)

| (Strncmp (sysbootparams. bootdev, "ide", 3) = 0)

| (Strncmp (sysbootparams. bootdev, "ata", 3) = 0)

| (Strncmp (sysbootparams. bootdev, "FD", 2) = 0 ))

Is:

If (strncmp (sysbootparams. bootdev, "SCSI", 4) = 0)

| (Strncmp (sysbootparams. bootdev, "ide", 3) = 0)

| (Strncmp (sysbootparams. bootdev, "ata", 3) = 0)

| (Strncmp (sysbootparams. bootdev, "tffs", 4) = 0)

| (Strncmp (sysbootparams. bootdev, "FD", 2) = 0 ))

3. Run tornado/host/x86-win32/bin/torvars in DOS.

4. Go to the directory where VxWorks is located and run:

Deflate VxWorks. Z. Here, the default. Z file is a compressed file.

5. If you want to store VxWorks. Z on a hard disk, floppy disk, or tffs, you must first create a device and initialize it with dosfs. If you load VxWorks. Z through a serial port or network, you need to initialize the corresponding interface.

6. Modify the bootconfig. c file:

A. Add the following at the end of the Code Section tftpxfer and ftpxfer of the local status netload function:

If (strstr (filename, ". Z") | strstr (filename, ". Z "))

{

Printf ("file % s is compressed, now begin Uncompressing...", filename );

If (bootloadmoduleinflate (FD, pentry )! = OK)

Goto readerr;

}

Else if (bootloadmodule (FD, pentry )! = OK)

Goto readerr;

B. Add the following code at the end of the usrtffsconfig and open sections of the local status tffsload function:

If (strstr (filename, ". Z") | strstr (filename, ". Z "))

{

Printf ("file % s is compressed, now begin Uncompressing...", filename );

If (bootloadmoduleinflate (FD, pentry )! = OK)

Goto readerr;

}

Else if (bootloadmodule (FD, pentry )! = OK)

Goto readerr;

C. Define the prototype of the function bootloadmoduleinflate before the local status bootload function:

# Define decomp_buf_size (ram_high_adrs-ram_low_adrs)

# Define comp_buf_size (decomp_buf_size/3)

Status bootloadmoduleinflate (INT zfd, funcptr * pentry)

{

Char * imagebuf = NULL;

Char * compbuf = NULL;

Int FD =-1;

Int Rv = error;

Int compsize, R;

Extern status inflate (char * SRC, char * DST, int src_size );

If (compbuf = malloc (comp_buf_size) = NULL)

{

Printerr ("no enough memory for image buffer ");

Goto done;

}

Compsize = 0;

While (r = read (zfd, compbuf + compsize, comp_buf_size-compsize) & gt; 0)

Compsize + = R;

If (r <0)

{

Printerr ("read failed: errno = % d", errnoget ());

Goto done;

}

If (compsize = comp_buf_size)

{

Printerr ("compressed image too large ");

Goto done;

}

Printerr ("Uncompressing % d bytes...", compsize );

If (imagebuf = malloc (decomp_buf_size) = NULL)

{

Printerr ("not enough memory for decompression buffer ");

Goto done;

}

If (r = inflate (compbuf, imagebuf, compsize) & lt; 0)

{

Printerr ("uncompress failed ");

Goto done;

}

Printerr ("loading image ...");

Memdrv ();

Memdevcreate ("mem:", imagebuf, decomp_buf_size );

If (FD = open ("mem: 0", o_rdonly, 0) & lt; 0)

{

Printerr ("cannot open memory device .");

Goto done;

}

If (bootloadmodule (FD, pentry )! = OK)

{

Printerr ("error loading: errno = % d", errnoget ());

Goto done;

}

Printerr ("");

Rv = OK;

Done: If (FD> = 0)

Close (FD );

If (imagebuf)

Free (imagebuf );

If (compbuf)

Free (compbuf );

Return RV;

}

D. If the load fails, read the previous Code and adjust the sizes of ram_high_adrs and ram_low_adrs.

7. Modify the startup parameters in config. H, for example, the Startup Device is tffs = (), the file name is/tffs0/VxWorks. Z, and so on. re-create bootrom and write it to flash.

8. When starting, modify the startup parameters so that the system still loads VxWorks from the network. This VxWorks should implement the ftp or TFTP function.

These functions write the VxWorks. Z file into the storage medium such as tffs.

9. Restart and load VxWorks from the tffs or hard disk on a floppy disk.

10. You can first start through the network and change the Startup File name to VxWorks. Z to verify compression and decompression.

11. the above only considers loading VxWorks from the network and tffs. Z compressed file. If it is loaded from FD, ATA, etc., you only need to add and 6 in the corresponding place. the same Code in.

12. This method is applicable to ppc850 and is verified by tffs and network loading.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.