Uclinux under the SQLite database transplant full Raiders (PHOTOS)

Source: Internet
Author: User
Tags add define file system sqlite sqlite database strlen version usleep
Introduction | data | Database This article discusses the more popular embedded development combination arm+uclinux, namely the target Development Board for Samsung S3C4510, complete SQLite on its uclinux transplant.

This article assumes that you have the ability to properly compile uclinux kernel, that is, the ability to complete make Menuconfig;makedep;makelib_only;make user_only;makeromfs;makeimage ; make. You can also add your own similar HelloWorld program to the user-defined application, which means you can complete the "custom user program" described in "Uclinux-dist/documentation/adding-user-apps-howto".


Most developers who need to migrate SQLite to Uclinux should already have the ability to do so, but are not sure how to modify SQLite to complete their uclinux compilation. If you are still unable to complete the above requirements, then do some preparatory work, because this example involves mainly with the SQLite in the uclinux of the transplant, the other in the process of problems, developers need to deal with themselves.

The uclinux used in this example is uclinux-dist-20030522.tar.gz, and you can get the package that fits you from http://www.uclinux.org.

The cross-compile tool is arm-elf-tools-20030314.sh, and you can also find it in http://www.uclinux.org.

The SQLite used in this example is sqlite-2.8.15.tar.gz, and the method in this article is also suitable for the SQLite of the 2.8.x series; there may be some content that does not apply to the SQLite of the 3.0.x series, because the source code in 3.0.x is greatly changed.

1, download SQLite: You can go to http://www.sqlite.org/download.html, download sqlite-2.8.15.tar.gz software package;

2, will download the package solution to the Uclinux-dist/user directory;

Command:

$tar ZXVF sqlite-2.8.15.tar.gz-c uclinux-dist/user/

Now in the Uclinux user directory, you should be able to see the SQLite directory. The solution to this user directory is primarily to compile sqlite into a common user application.

3, the user application of the relevant settings:

As mentioned in the Uclinux-dist/documentation/adding-user-apps-howto document, add SQLite as a user application and make it into a shell, similar to Uclinux's own PS command.

Edit File

Uclinux-dist/user/makefile

Uclinux-dist/config/configure.help

Uclinux-dist/config/config.in

I'm looking for "CPU" in these files, and then underneath it, plus my own sqlite, this process is not complicated.

After the above modification, you can now run Uclinux makemenuconfig, select "Customizevendor/usersettings", and then select "Miscellaneousapplications", You can see that it now appears a new "SQLite", which is the SQLite item we just added.

In a later Makeromfs, Uclinux will compile your sqlite as part of the ROMFS because you have added uclinux-dist/user/makefile to the SQLite. This will allow you to execute the SQLite command in the/bin after the transplant uclinux.

OK, now we're going to change the SQLite to do the transplant work.

In the description below, we will add and modify some of the following files to complete the SQLite under Uclinux:

SQLITE/MAIN.MK modification

Sqlite/makefile add

SQLITE/SRC/OS.C modification

SQLITE/SRC/SHELL.C modification

When you make changes to these files, make a backup of the files yourself, for example, you can copy them and rename them with a filename. bak. This is important to prevent you from being able to revert to a problem in the process of modification.

   I. Modification of SQLITE/MAIN.MK

1, TCCX

Will

TCCX = $ (TCC) $ (OPTS) $ (threadsafe) $ (USLEEP)-i.-i$ (top)/SRC

Amended to

TCCX = $ (TCC) $ (OPTS) $ (threadsafe) $ (USLEEP)-i.-i$ (top)/src$ (cflags)

The $ (cflags) tag is added.

2, Libobj

Find the # Object files for the SQLite library.

Remove the TCLSQLITE.O. That is to remove the TCL related things.

If there is no tclsqlite.o, then do not have to deal with it.

3, sqlite$ (EXE)

Find a sentence similar to sqlite$ (EXE) that will:

sqlite$ (EXE): $ (top)/src/shell.c libsqlite.a sqlite.h

$ (TCCX) $ (readline_flags)-O sqlite$ (EXE) $ (top)/src/shell.c\\\\\\\\\\\\\\\\

Libsqlite.a $ (libreadline) $ (threadlib)

To be replaced by:

SHELL.O: $ (top)/SRC/SHELL.C sqlite.h

$ (TCCX) $ (readline_flags)-C $ (top)/SRC/SHELL.C

sqlite$ (EXE): SHELL.O libsqlite.a

$ (TCC) $ (ldflags)-O $@ shell.o \\\\\\\\\\\\\\\\

Libsqlite.a $ (libreadline) $ (threadlib) $ (ldlibs)

That is, on the sqlite$ (EXE) line plus the SHELL.O, followed by the $ (ldlibs) tag. This is the modification of the/SRC/SHELL.C compilation method.

4, Romfs

Will:

Install:sqlite Libsqlite.a sqlite.h

MV Sqlite/usr/bin

MV Libsqlite.a/usr/lib

MV Sqlite.h/usr/include

To be replaced by:

Romfs:sqlite

$ (romfsinst)/bin/sqlite

That is, remove the make install item, plus the MAKEROMFS item. This is important, and this will generate SQLite in the Romfs/bin directory.

5, clean

Will:

Clean

Rm-f *.o sqlite libsqlite.a sqlite.h opcodes.*

Rm-f Lemon lempar.c parse.* sqlite*.tar.gz

Rm-f $ (PUBLISH)

Rm-f *.da *.bb *.BBG gmon.out

RM-RF Tsrc replaced by:

Clean

Rm-f *.o sqlite libsqlite.a sqlite.h opcodes.*

Rm-f $ (PUBLISH)

Rm-f *.da *.bb *.BBG gmon.out

RM-RF TSRC

Distclean:clean

Rm-f Lemon lempar.c parse.* sqlite*.tar.gz

Rm-f config.h

The Make Distclean item is added. Popular recommendations: Suping concept and Method 2004 Top ten most popular graphics card overclocking King

1 2 3

   Ii. Adding makefile documents under SQLite

There should be no Makefile files in the SQLite directory, but only one SQLITE/MAKEFILE.LINUX-GCC file. We want to transplant SQLite to uclinux, then we must write a suitable makefile.

The contents are as follows:

===========makefile Content started ===========

#!/usr/make

#

# Makefile for SQLITE

#

# This is a template makefile for SQLite. Most Peoplepreferto

# Use the autoconf generated configure script togeneratethe

# makefile automatically. But that does not work foreverybody

# and in every situation. If you are have problems with the

# Configure script, you might want to try this Makefileasan

# Alternative. Create a copy of this file, edit Theparameters

# below and type make.

#

# # # TopLevel Directory of the source tree. This isthedirectory

# That's contains this makefile.in and Theconfigure.inscript.

#

top =.

# C Compiler and options in Buildingexecutablesthat

# would run on the platform the ' is doing ' build.

#

BCC = Gcc-g-o2

#BCC =/opt/ancic/bin/c89-0

# # IF The target operating system supports THEUSLEEP () system

# call, then define the Have_usleep macro to all C modules.

#

#USLEEP =

USLEEP =-dhave_usleep=1

# If You are want the SQLite library to is safe for Usewithina

# multi-threaded program, then define the following macro

# appropriately:

#

#THREADSAFE =-dthreadsafe=1

Threadsafe =-dthreadsafe=0

# # Specify any extra linker options needed to Makethelibrary

# thread safe

#

#THREADLIB =-lpthread

Threadlib =

# # # Leave memory_debug undefined for maximum speed. Usememory_debug=1

# to check for memory leaks. Use memory_debug=2 to print a logofall

# malloc () s and free () s in order to track down memory leaks.

#

# SQLite uses some expensive ASSERT () statements in Theinnerloop.

# you can make the library go almost twice as fast Ifyoucompile

# with-dndebug=1

#

#OPTS =-dmemory_debug=2

#OPTS =-dmemory_debug=1

#OPTS =-dndebug=1

OPTS =-dmemory_debug=1

# # # # # suffix to add to executable files. . exeforwindows.

# Nothing for UNIX.

#

#EXE =. exe

EXE =

# C Compile and options in Buildingexecutablesthat

# would run on the target platform. This is usually the same

# as BCC, unless you are cross-compiling.

#

TCC = $ (CROSS) gcc

Fltflags = s 12000

#TCC = Gcc-g-o0-wall

#TCC = Gcc-g-o0-wall-fprofile-arcs-ftest-coverage

#TCC =/opt/mingw/bin/i386-mingw32-gcc-o6

#TCC =/opt/ansic/bin/c89-o +z-wl,-a,archive

# Tools used to build a static library.

#

AR = $ (CROSS) AR cr

#AR =/opt/mingw/bin/i386-mingw32-ar cr

Ranlib = $ (CROSS) Ranlib

#RANLIB =/opt/mingw/bin/i386-mingw32-ranlib

# # Extra compiler options needed for programs ' use Thetcllibrary.

#

#TCL_FLAGS =

#TCL_FLAGS =-dstatic_build=1

#TCL_FLAGS =-i/home/drh/tcltk/8.4linux

#TCL_FLAGS =-i/home/drh/tcltk/8.4win-dstatic_build=1

#TCL_FLAGS =-i/home/drh/tcltk/8.3hpux

# # Linker options needed to link against the TCL library.

#

#LIBTCL =-LTCL-LM-LDL

#LIBTCL =/HOME/DRH/TCLTK/8.4LINUX/LIBTCL8.4G.A-LM-LDL

#LIBTCL =/home/drh/tcltk/8.4win/libtcl84s.a-lmsvcrt

#LIBTCL =/HOME/DRH/TCLTK/8.3HPUX/LIBTCL8.3.A-LDLD-LM-LC

# Compiler options needed for programs the use Thereadline () library.

#

Readline_flags =

#READLINE_FLAGS =-dhave_readline=1-i/usr/include/readline

# Linker options needed by programs using ReadLine () mustlinkagainst.

#

#LIBREADLINE =

#LIBREADLINE =-static-lreadline-ltermcap

# Should The database engine assume text is coded as utf-8oriso8859?

#

# ENCODING = UTF8

ENCODING = ISO8859

# You should the have to change anything below the This line

###############################################################################

Include $ (top)/main.mk

===========makefile Content End ===========

Note:

1, in the uclinux under the SQLite makefile will not be used to the TCL-related library.

2. The makefile of the SQLite under Uclinux will not be used to ReadLine ().

There is a description of makefile in the Sqlite/readme:

The Configure script uses autoconf 2.50 and Libtool. Iftheconfigure script does not work out for you, there is agenericmakefile named to the top directory O Fthesource tree, can copy and edit to suite yourneeds. Comments on the generic makefile show what changes areneeded.

You can use SQLITE/MAKEFILE.LINUX-GCC as a blueprint to modify your own Makefile.

If you are interested, you can compare the above Makefile content and SQLITE/MAKEFILE.LINUX-GCC content diff, see the uclinux under the SQLite compiled what different places.

   iii. modification of SQLITE/SRC/OS.C

If your SQLite package includes os.c files then modify them, no os.c file may be your SQLite version is newer, so there is no need to modify.

Will all you find:

Use:

Replace. Popular recommendations: Suping concept and Method 2004 Top ten most popular graphics card overclocking King

1 2 3

   iv. modification of SQLITE/SRC/SHELL.C

1, struct PREVIOUS_MODE_DATA structure definition item:

the int colWidth100;

with int colWidth20;

Replace.

2, struct CALLBACK_DATA structure definition item

Will:

int colWidth100;

int actualWidth100;

Char Outfilefilename_max;

Use:

int colWidth20;

int actualWidth20;

Char *outfilep;

Corresponds to the substitution.

Add below the structure:

#ifndef Filename_max

#define FILENAME_MAX 4095

#endif

Char Outfilenamefilename_max; /* Filename for *out * *

That

struct Callback_data

...

;

#ifndef Filename_max

#define FILENAME_MAX 4095

#endif

Char Outfilenamefilename_max; /* Filename for *out * *

3, Function Do_meta_command (...)

Find a sentence similar to this:

Sqlite_exec (p->db, PRAGMA database_list;, Callback,&data, &zerrmsg);

In front of it there is a sentence

memcpy (&data, p, sizeof (data));

Now add a line below memcpy

data.cnt = 0;

The value of CNT in the structure is assigned to 0;

Now the code will be modified to resemble:

OPEN_DB (P);

memcpy (&data, p, sizeof (data));

data.cnt = 0;

Go ahead.

Find a sentence similar to this:

strcmp (azarg1,stdout) ==0

In the parentheses below it:

Will strcpy (p->outfile,stdout);

with P->OUTFILEP = stdout;

To replace.

and 5-6 lines below it.

Will:

strcpy (P->OUTFILE,AZARG1);

Use:

strcpy (OUTFILENAME,AZARG1);

P->outfilep = Outfilename;

Replace.

Go ahead and find a sentence like this:

fprintf (p->out,%9.9s:%s\\\\\\\\\\\\\\\\n,output,

Will:

fprintf (p->out,%9.9s:%s\\\\\\\\\\\\\\\\n,output, strlen (p->outfile) p->outfile:stdout);

Use:

fprintf (p->out,%9.9s:%s\\\\\\\\\\\\\\\\n,output,p->outfilep&& strlen (p->outfilep)? p-> Outfilep:stdout);

Replace.

Complete the modification.

After all the changes to SQLite are done, you can make Dep;make lib_only;makeuser_only;makeromfs;make image.

If you change the SQLite, you can ignore the makedep;makelib_only command and make user_only;makeromfs;makeimage again, if there is an error in the making user_only process. Without having to repeat make Dep;make lib_only.

Makeimage will help you generate Romfs file system. There is now a compiled Romfs file system under Uclinux-dist/images. This is the ROMFS that we need to contain sqlite.

In the process above, you can not "make" after "makeimage" to generate kernel kernel, because you only need to generate ROMFS, it has sqlite.

Now you can download the Romfs that contains the SQLite application to run on the Development Board.

Welcome to

____ _ _

/ ___

_ __ ____ _ _ _ _

_ \\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\\\/ /

_ __ _ / \\\\\\\\\\\\\\\\

___\\\\\\\\\\\\\\\\____ __ _ _ \\\\\\\\\\\\\\\\____ \\\\\\\\\\\\\\\\_/\\\\\\\\\\\\\\\\_/

_

Gdb/armulator Support by

For further information check:

http://www.uclinux.org/

Command:/bin/ifconfig eth0 up 10.0.0.2

Execution finished, exiting

Init:booting to Single user mode

Sash Command shell (version 1.1.1)

/> CD Bin

/bin> Ls-l SQLite

-rwxr-xr-x 1 0 0 327072 to 00:00 sqlite

/bin >cd/tmp

/tmp>sqlite Test.sqlite

Sqlite> CREATE table my (name varchar, num smallint);

Sqlite> INSERT into my values (Yutao, 100);

Sqlite> INSERT into my values (uclinux, 99);

Sqlite> select * from I;

Yutao 100

Uclinux 99

Sqlite>. Tables

My

Sqlite>. Schema

CREATE table my (name varchar, num smallint);

Sqlite>. Q

/tmp>ls Cl Test.sqlite

You have to make sure that your/TMP is a writable directory.

OK, now your sqlite has been running in uclinux, how it feels, in the uclinux can also play "Select*from", feel very cool it. Popular recommendations: Suping concept and Method 2004 Top ten most popular graphics card overclocking King



Related Article

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.