jslinux的kernel的重新编译

这里是原创哦
被引用的
http://www.programering.com/a/MTM2gzNwATc.html

图片都木有换


硬盘的挂载和修改参考
http://haoningabc.iteye.com/blog/2142532
今天说一下jslinux内核的编译
环境:再linode的64位的centos7下
gcc版本
[root@#localhost linux-2.6.20]# gcc --version
gcc (GCC) 4.8.2 20140120 (Red Hat 4.8.2-16)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

修改自带的Makefile为

注意加了 make ARCH=i386 -C $(KERNEL_PATH) -j4 >log.txt 2>error.txt
root@#localhost linuxstart-20120111]# pwd
/data/qemu/linuxstart-20120111
[root@#localhost linuxstart-20120111]# cat Makefile 
LD=ld -m elf_i386
CC=gcc -m32
CFLAGS= -O2 -Wall -fno-builtin -fno-stack-protector #-march=i386 
HOST_CFLAGS=-O2 -Wall
# modify to set the kernel path
KERNEL_PATH=../linux-2.6.20

all: linuxstart.bin

linuxstart.out: linuxstart_head.o linuxstart.o libc.o
        $(LD) -o $@ -N -Ttext 0x00010000 $^

linuxstart.bin: linuxstart.out
        objcopy -O binary $< $@
        cp /data/qemu/linuxstart-20120111/linuxstart.bin /data/qemu/backup/jslinux_debug/jslinux

%.o: %.c
        $(CC) $(CFLAGS)  -c -o $@ $<

%.o: %.S
        $(CC) -m32 -D__ASSEMBLY__ -c -o $@ $<

# target to generate kernel
kernel:
        #make ARCH=i386 -C $(KERNEL_PATH) -j4 
        make ARCH=i386 -C $(KERNEL_PATH) -j4 >log.txt 2>error.txt
        objcopy -O binary $(KERNEL_PATH)/vmlinux vmlinux26.bin

clean:
        rm -f linuxstart.bin linuxstart.out *.o *~ 

[root@#localhost linuxstart-20120111]# 


[root@#localhost linux-2.6.20]# pwd
/data/qemu/linux-2.6.20
cp ../linuxstart-20120111/config* .config
 patch -p1 <../linuxstart-20120111/patch_linux-2.6.20 
注意只有打了这个patch才能正常使用jslinux的剪切板

---------------------------------------------
错误0:
Makefile:1442: *** mixed implicit and normal rules.
参考http://blog.csdn.net/fengyaqi123/article/details/7873940
解决:
在Makefile中
将420行代码:
config %config: scripts_basic outputmakefile FORCE
改为:
%config: scripts_basic outputmakefile FORCE
将1268行代码:
/ %/: prepare scripts FORCE
改为:
%/: prepare scripts FORCE

即可编译通过!
------------------------------------------
错误1
scripts/mod/sumversion.c:384: error: ‘PATH_MAX’ undeclared 错误
scripts/mod/sumversion.c, and adding #include <limits.h>

参考 http://blog.csdn.net/livingpark/article/details/3732679

modifying linux-2.6.x/scripts/mod/sumversion.c, and adding #include <limits.h>
----------------------------------------------
错误2:
gcc: error: elf_i386: No such file or directory
gcc: error: unrecognized command line option ‘-m’

这个问题是由于 gcc 4.6 不再支持 linker-style 架构
需要 gcc -m elf_i386 改成gcc  -m32
但是ld不改
参考http://blog.sina.com.cn/s/blog_8f9cdbbd01014lxj.html
解决:
查找所有的文件 grep -nR "\-m elf_i386" *
开始想这样做,但是这个方法不行
执行多文件替换
#sed -i "s/\-m elf_i386 \-m elf_i386/\-m elf_i386/g" `grep "\-m elf_i386" -rl  .` 
#sed -i "s/m elf_i386/m32/g" `grep "m elf_i386" -rl  .` 
只改vim arch/i386/kernel/Makefile 中的 -m elf_i386 变-m32 注意只改gcc后面的,ld的不修改

错误3:
如果是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去掉


修改完了之后去make kernel
linux-2.6.20和linuxstart-20120111同级目录
运行效果
把vmlinux26.bin考到和index.html相同的位置
然后修改jslinux.js
    //pc.load_binary("vmlinux-2.6.20.bin", 0x00100000, start2);
    pc.load_binary("vmlinux26.bin", 0x00100000, start2);




jslinux.js中start3
 block_list = [ 0, 7, 3, 643, 720, 256, 336, 644, 781, 387, 464, 475, 131, 589, 468, 472, 474, 776, 777, 778, 779, 465, 466, 473, 467, 469, 470, 512, 592, 471, 691, 697, 708, 792, 775, 769 ];

为啥要选这些数字?
用emeditor搜索“Welcome to JS/Linux”
grep不行哦,会发现hda0000000781.bin里面有个echo "Welcome to JS/linux"
惊天秘密么?why,系统文件中怎么找这个?
文件时随机写的,但是某个文件写的时候是连续的吧
不要改呀 改了就起不来了,比如我们改了JS/linux为JJ/linux则会

原来是/sbin/init 有问题了
恢复文件后
vi /sbin/init
果然在这里啊
cat </sbin/init >/dev/clipboard 输出出来
#!/bin/sh

export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
export HOME=/var/root
export TERM=vt100

mount -a

mkdir /var/tmp
mkdir /var/root

ifconfig lo 127.0.0.1

# allow running DOS .COM executables with the small 'runcom' utility
echo ':DOSCOM:E::com::/usr/bin/runcom:' > /proc/sys/fs/binfmt_misc/register

stty -F /dev/ttyS0 rows 30

show_boot_time

cd $HOME
cp /root/hello.c $HOME
ln -sf /root/dos $HOME

echo "Welcome to JS/Linux"

while /bin/true; do

  setsid sh -c 'exec sh </dev/ttyS0 >/dev/ttyS0 2>&1'

done


猜你喜欢

转载自haoningabc.iteye.com/blog/2148555