jslinux重新编译内核3.19

阅读更多
一个日本的编3.8.5的:
http://d.hatena.ne.jp/cupnes/comment/20130403/1364974831

使用的系统版本是
Red Hat Enterprise Linux Server release 6.5 (Santiago)
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4)
测试如下:

本地跑的jslinux参考
http://haoningabc.iteye.com/blog/1397960
这个版本是用的2.6.20
其实可以编译3.19的版本的内核
http://bellard.org/jslinux/
下载官网的
linuxstart-20120111
里面的文件config_linux-2.6.20 是编译内核用的
比如在
linuxstart-20120111同级目录下下载内核
http://www.linux-mips.org/pub/linux/mips/kernel/v2.6/
linux-2.6.20.tar.bz2
[root@node11 tmp]# cat run26.sh 
#!/bin/sh
tar -jxvf linux-2.6.20.tar.bz2
cp ./linuxstart-20120111/config_linux-2.6.20 ./linux-2.6.20/.config
cd ./linux-2.6.20/
patch -p1 <../linuxstart-20120111/patch_linux-2.6.20 
echo "vim linux-2.6.20/scripts/mod/sumversion.c "
echo "adding #include "
echo "if this is centos7 and gcc 4.8.3 ,something must
do "
echo "time make ARCH=i386 -j16 "


如果是centos7的
gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9)

可能编译遇到问题
-------------------------centos7可能出现问题开始---------------------
Makefile:1439: *** mixed implicit and normal rules
config %config: scripts_basic outputmakefile FORCE
改成
%config: scripts_basic outputmakefile FORCE
将1279行代码:
/ %/: prepare scripts FORCE(错)
改为:
%/: prepare scripts FORCE(对)

参考
http://blog.csdn.net/simonjay2007/article/details/7796390
如果遇到问题
gcc: error: elf_i386: No such file or directory  
gcc: error: unrecognized command line option ‘-m’ 

#sed -i "s/m elf_i386/m32/g" `grep "m elf_i386" -rl  .` 

只改vim arch/i386/kernel/Makefile 中的 -m elf_i386 变-m32 注意只改gcc后面的,ld的不修改
如果出现错误
kernel/built-in.o: In function `mutex_lock':
(.sched.text+0xe25): undefined reference to `__mutex_lock_slowpath'
kernel/built-in.o: In function `mutex_unlock':
(.sched.text+0xe35): undefined reference to `__mutex_unlock_slowpath'
make: *** [.tmp_vmlinux1] Error 1

如果是mutex相关的错误
未定义什么mutex加锁和解锁
kernel/mutex.c
这个好使,其他的都是扯淡,什么该config参数,什么加__used都不行,需要把static去掉,加锁和解锁的
https://github.com/socketpair/jslinux_reversed/blob/master/contrib/patches/2.6.20_common_fixes.patch
__mutex_lock_slowpath的两个方法的static去掉
__mutex_unlock_slowpath的两个方法的static去掉
-------------------------centos7可能出现问题结束----------------------


1.由于gcc的版本问题,linux-2.6.20/scripts/mod/sumversion.c加了一行#include
2.使用config_linux-2.6.20作为linux内核的.config配置文件
3.patch_linux-2.6.20 增加了1个文件jsclipboard.c,修改了4个文件
patching file drivers/char/Kconfig
patching file drivers/char/Makefile
patching file drivers/char/jsclipboard.c
patching file drivers/serial/8250.c
patching file drivers/ide/ide-probe.c

jsclipboard是剪切板交互的功能
8250是串口
ide-probe是加速的一行代码
[root@node11 linux-2.6.20]# vim drivers/ide/ide-probe.c

865         for (unit = 0; unit < MAX_DRIVES; ++unit) {
866                 ide_drive_t *drive = &hwif->drives[unit];
867 
868                 if (hwif->no_io_32bit)
869                         drive->no_io_32bit = 1;
870                 else
871                         drive->no_io_32bit = drive->id->dword_io ? 1 : 0;
add 872                 drive->io_32bit = 1; 
873         }

这个补丁如果不打的话也是可以加载的只是不能用剪切板的交互


我们下载
linux-3.19.tar.gz
tar zxvf linux-3.19.tar.gz
cd linux-3.19
cp ../linuxstart-20120111/config_linux-2.6.20 .config
make  ARCH=i386  -j16 
一路回车下来
编译好的内核
参考linuxstart-20120111中的Makefile文件
objcopy -O binary ../linux-3.19/vmlinux  vmlinux319.bin
生成js使用的内核
vmlinux319.bin
把vmlinux319.bin复制到
bellard.org/jslinux的目录,我们下载的可以跑jslinux的目录

修改jslinux.js
    pc = new PCEmulator(params);

    init_state.params = params;

    //pc.load_binary("vmlinux-2.6.20.bin", 0x00100000, start2);
    pc.load_binary("vmlinux319.bin", 0x00100000, start2);
}

function start2(ret)
{
    if (ret < 0)
        return;
    init_state.start_addr = 0x10000;
    pc.load_binary("linuxstart.bin", init_state.start_addr, start3);
}

加载重新生成的内核

jslinux重新编译内核3.19_第1张图片

以上直接编译的内核不带剪切板从linux到浏览器交互的功能
如果想交互
看patch文件
多一个
drivers/char/jsclipboard.c
由于内核的3.19的版本
注释掉一行
//#include
/* 
 *    JS clipboard support for JS/Linux
 *       (c) 2011 Fabrice Bellard
 *       */
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#include 
#include 
//#include 

#define JSCLIPBOARD_MINOR 231

#define JSCLIPBOARD_PORT 0x3c0

static int io_port = JSCLIPBOARD_PORT;
static int minor = JSCLIPBOARD_MINOR;
static struct semaphore open_sem;
static int need_cache_sync;

module_param(io_port, int, 0);
MODULE_PARM_DESC(io_port, "IO port");

module_param(minor, int, 0);
MODULE_PARM_DESC(minor, "minor number");

static ssize_t jsclipboard_read(struct file *file, char __user *buf,
                                size_t count1, loff_t *ppos)
{
        uint32_t pos, total_length, v;
        uint8_t b;
        size_t count, l;
        
        /* set read position */
        pos = *ppos;
        outl(pos, io_port + 4);
        total_length = inl(io_port + 0);
        
        if (!access_ok(VERIFY_WRITE, buf, count1))
                return -EFAULT;
        
        if (pos < total_length) 
                l = total_length - pos;
        else
                l = 0;
        if (count1 > l)
                count1 = l;
        count = count1;
        while (count >= 4) {
                v = inl(io_port + 8);
                if (__put_user(v, (uint32_t *)buf))
                        return -EFAULT;
                buf += 4;
                count -= 4;
        }
        
        while (count != 0) {
                b = inb(io_port + 8);
                if (__put_user(b, buf))
                        return -EFAULT;
                buf++;
                count--;
        }

        *ppos = pos + count1;

        return count1;
}

static ssize_t jsclipboard_write(struct file *file, const char *buf, 
                                 size_t count1, loff_t *ppos)
{
        size_t count;
        uint8_t b;
        uint32_t v;

        if (!access_ok(VERIFY_READ, buf, count1))
                return -EFAULT;
        if (*ppos == 0) {
                /* flush clipboard */
                outl(0, io_port);
        }

        need_cache_sync = 1;

        count = count1;
        while (count >= 4) {
                if (__get_user(v, (uint32_t *)buf))
                        return -EFAULT;
                outl(v, io_port + 8);
                buf += 4;
                count -= 4;
        }

        while (count != 0) {
                if (__get_user(b, buf))
                        return -EFAULT;
                outb(b, io_port + 8);
                buf++;
                count--;
        }
        *ppos += count1;
        return count1;
}

static int jsclipboard_open(struct inode *inode, struct file *file)
{
        if (down_trylock(&open_sem))
                return -EBUSY;
        need_cache_sync = 0;
        return 0;
}

static int jsclipboard_release(struct inode *inode, struct file *file)
{
        if (need_cache_sync) {
                outl(0, io_port + 12);
        }
        up(&open_sem);
        return 0;
}

static const struct file_operations jsclipboard_fops = {
        .owner          = THIS_MODULE,
        .read           = jsclipboard_read,
        .write          = jsclipboard_write,
        .open           = jsclipboard_open,
        .release        = jsclipboard_release,
};

static struct miscdevice jsclipboard_dev = {
        .minor          = JSCLIPBOARD_MINOR,
        .name           = "jsclipboard",
        .fops           = &jsclipboard_fops,
};

static int __init jsclipboard_init(void)
{
        if (!request_region(io_port, 16, "jsclipboard")) 
                return -ENODEV;
        sema_init(&open_sem, 1);
        if (misc_register(&jsclipboard_dev)) {
                return -ENODEV;
        }
        printk(KERN_INFO "JS clipboard: I/O at 0x%04x\n", io_port);
        return 0;
}

static void __exit jsclipboard_exit (void)
{
        misc_deregister(&jsclipboard_dev);
        release_region(io_port, 16);
}

module_init(jsclipboard_init);
module_exit(jsclipboard_exit);

MODULE_AUTHOR("Fabrice Bellard");
MODULE_LICENSE("GPL");

修改kconfig和Makefile文件
/drivers/char/Kconfig
在 files for controlling the behavior of this hardware
下面加

config JSCLIPBOARD
       tristate "Javascript clipboard support (JS/Linux device)"
       default n
       help
         Javascript clipboard support for JS/Linux

drivers/char/Makefile
 obj-$(CONFIG_HANGCHECK_TIMER)  += hangcheck-timer.o
 obj-$(CONFIG_TCG_TPM)          += tpm/
+obj-$(CONFIG_JSCLIPBOARD)      += jsclipboard.o
 


再重新
make ARCH=i386 -j16
生成vmlinux
再用objcopy
objcopy -O binary ../linux-3.19/vmlinux  vmlinux319.bin
生成bin给jslinux.js用


测试
在js跑的linux中
/var/root # echo "aaa" > /dev/clipboard

可以看到页面上的剪切板有了变化

如果不用jslinux,想用qemu直接启动

使用
 
cd jslinux/bin
cat cat hda000000*.bin > hda.bin
得到jslinux的硬盘hda.bin
/usr/libexec/qemu-kvm  -kernel linux-2.6.20/arch/i386/boot/bzImage -hda hda.bin -append "root=/dev/hda" -serial stdio -vnc 0.0.0.0:3 

注意使用 -serial stdio
vnc连到这个vm后只显示
Booting from ROM...
Uncompressing Linux... Ok, booting the kernel.

操作还在终端
参考
https://balau82.wordpress.com/2010/04/12/booting-linux-with-u-boot-on-qemu-arm/

如果使用官方的 linux-0.2.img
直接用
/usr/libexec/qemu-kvm  -hda linux-0.2.img   -vnc 0.0.0.0:3

把linux-0.2.img mount到硬盘上可以看到boot里面已经有2.6.20的内核了。
  • jslinux重新编译内核3.19_第2张图片
  • 大小: 20.5 KB
  • 查看图片附件

你可能感兴趣的:(jslinux)