最近有空呼吸新鲜空气,重新拿起来了eCos,做点东西共享给大家。
rt-thread最近很火,在mini2440的qemu平台上发表了测试和代码,这无疑给更多的爱好者以新的学习机会。
这段时间一直在研究ecos,所以有了把ecos移植到mini2440的qemu平台的想法。经过几天的折腾,终于可以在qemu的上面看到redboot的命令了。
先看看成果,然后进入枯燥的coding历程
现在开始看代码,:-)
1. 获得代码
git clone git://repo.or.cz/qemu/mini2440.git qemu
修改启动部分为ram的最小地址直接启动
ricky@ricky-laptop:~/ecos/projects/mini2440-qemu/mini2440$ git diff diff --git a/hw/mini2440.c b/hw/mini2440.c index 5decf4b..7a70aae 100644 --- a/hw/mini2440.c +++ b/hw/mini2440.c @@ -258,46 +258,15 @@ static void mini2440_reset(void *opaque) struct mini2440_board_s *s = (struct mini2440_board_s *) opaque; uint32_t image_size; - /* - * Normally we would load 4 KB of nand to SRAM and jump there, but - * it is not working perfectly as expected, so we cheat and load - * it from nand directly relocated to 0x33f80000 and jump there - */ - if (mini2440_load_from_nand(s->nand, 0, S3C_RAM_BASE | 0x03f80000, 256*1 - mini2440_printf("loaded default u-boot from NAND/n"); - s->cpu->env->regs[15] = S3C_RAM_BASE | 0x03f80000; /* start addr - } -#if 0 && defined(LATER) - if (mini2440_load_from_nand(s->nand, 0, S3C_SRAM_BASE_NANDBOOT, S3C_SRAM - s->cpu->env->regs[15] = S3C_SRAM_BASE_NANDBOOT; /* start address - mini2440_printf("4KB SteppingStone loaded from NAND/n"); - } -#endif : diff --git a/hw/mini2440.c b/hw/mini2440.c index 5decf4b..7a70aae 100644 --- a/hw/mini2440.c +++ b/hw/mini2440.c @@ -258,46 +258,15 @@ static void mini2440_reset(void *opaque) struct mini2440_board_s *s = (struct mini2440_board_s *) opaque; uint32_t image_size; - /* - * Normally we would load 4 KB of nand to SRAM and jump there, but - * it is not working perfectly as expected, so we cheat and load - * it from nand directly relocated to 0x33f80000 and jump there - */ - if (mini2440_load_from_nand(s->nand, 0, S3C_RAM_BASE | 0x03f80000, 256*10 - mini2440_printf("loaded default u-boot from NAND/n"); - s->cpu->env->regs[15] = S3C_RAM_BASE | 0x03f80000; /* start addre - } -#if 0 && defined(LATER) - if (mini2440_load_from_nand(s->nand, 0, S3C_SRAM_BASE_NANDBOOT, S3C_SRAM_ - s->cpu->env->regs[15] = S3C_SRAM_BASE_NANDBOOT; /* start address, - mini2440_printf("4KB SteppingStone loaded from NAND/n"); - } -#endif - /* : diff --git a/hw/mini2440.c b/hw/mini2440.c index 5decf4b..7a70aae 100644 --- a/hw/mini2440.c +++ b/hw/mini2440.c @@ -258,46 +258,15 @@ static void mini2440_reset(void *opaque) struct mini2440_board_s *s = (struct mini2440_board_s *) opaque; uint32_t image_size; - /* - * Normally we would load 4 KB of nand to SRAM and jump there, but - * it is not working perfectly as expected, so we cheat and load - * it from nand directly relocated to 0x33f80000 and jump there - */ - if (mini2440_load_from_nand(s->nand, 0, S3C_RAM_BASE | 0x03f80000, 256*102 - mini2440_printf("loaded default u-boot from NAND/n"); - s->cpu->env->regs[15] = S3C_RAM_BASE | 0x03f80000; /* start addres - } -#if 0 && defined(LATER) - if (mini2440_load_from_nand(s->nand, 0, S3C_SRAM_BASE_NANDBOOT, S3C_SRAM_S - s->cpu->env->regs[15] = S3C_SRAM_BASE_NANDBOOT; /* start address, - mini2440_printf("4KB SteppingStone loaded from NAND/n"); - } -#endif - /* - * if a u--boot is available as a file, we always use it : diff --git a/hw/mini2440.c b/hw/mini2440.c index 5decf4b..7a70aae 100644 --- a/hw/mini2440.c +++ b/hw/mini2440.c @@ -258,46 +258,15 @@ static void mini2440_reset(void *opaque) struct mini2440_board_s *s = (struct mini2440_board_s *) opaque; uint32_t image_size; - /* - * Normally we would load 4 KB of nand to SRAM and jump there, but - * it is not working perfectly as expected, so we cheat and load - * it from nand directly relocated to 0x33f80000 and jump there - */ - if (mini2440_load_from_nand(s->nand, 0, S3C_RAM_BASE | 0x03f80000, 256*1024)> - mini2440_printf("loaded default u-boot from NAND/n"); - s->cpu->env->regs[15] = S3C_RAM_BASE | 0x03f80000; /* start address, - } -#if 0 && defined(LATER) - if (mini2440_load_from_nand(s->nand, 0, S3C_SRAM_BASE_NANDBOOT, S3C_SRAM_SIZE - s->cpu->env->regs[15] = S3C_SRAM_BASE_NANDBOOT; /* start address, u-b - mini2440_printf("4KB SteppingStone loaded from NAND/n"); - } -#endif - /* - * if a u--boot is available as a file, we always use it - */ - { - image_size = load_image("mini2440/u-boot.bin", qemu_get_ram_ptr(0x03f8000 : diff --git a/hw/mini2440.c b/hw/mini2440.c index 5decf4b..7a70aae 100644 --- a/hw/mini2440.c +++ b/hw/mini2440.c @@ -258,46 +258,15 @@ static void mini2440_reset(void *opaque) struct mini2440_board_s *s = (struct mini2440_board_s *) opaque; uint32_t image_size; - /* - * Normally we would load 4 KB of nand to SRAM and jump there, but - * it is not working perfectly as expected, so we cheat and load - * it from nand directly relocated to 0x33f80000 and jump there - */ - if (mini2440_load_from_nand(s->nand, 0, S3C_RAM_BASE | 0x03f80000, 256*1024)> 0) - mini2440_printf("loaded default u-boot from NAND/n"); - s->cpu->env->regs[15] = S3C_RAM_BASE | 0x03f80000; /* start address, u-b - } -#if 0 && defined(LATER) - if (mini2440_load_from_nand(s->nand, 0, S3C_SRAM_BASE_NANDBOOT, S3C_SRAM_SIZE) > - s->cpu->env->regs[15] = S3C_SRAM_BASE_NANDBOOT; /* start address, u-boot - mini2440_printf("4KB SteppingStone loaded from NAND/n"); - } -#endif - /* - * if a u--boot is available as a file, we always use it - */ - { - image_size = load_image("mini2440/u-boot.bin", qemu_get_ram_ptr(0x03f80000)) - if (image_size < 0) - image_size = load_image("u-boot.bin", qemu_get_ram_ptr(0x03f80000)); - if (image_size > 0) { : diff --git a/hw/mini2440.c b/hw/mini2440.c index 5decf4b..7a70aae 100644 --- a/hw/mini2440.c +++ b/hw/mini2440.c @@ -258,46 +258,15 @@ static void mini2440_reset(void *opaque) struct mini2440_board_s *s = (struct mini2440_board_s *) opaque; uint32_t image_size; - /* - * Normally we would load 4 KB of nand to SRAM and jump there, but - * it is not working perfectly as expected, so we cheat and load - * it from nand directly relocated to 0x33f80000 and jump there - */ - if (mini2440_load_from_nand(s->nand, 0, S3C_RAM_BASE | 0x03f80000, 256*1024)> 0) { - mini2440_printf("loaded default u-boot from NAND/n"); - s->cpu->env->regs[15] = S3C_RAM_BASE | 0x03f80000; /* start address, u-boot - } -#if 0 && defined(LATER) - if (mini2440_load_from_nand(s->nand, 0, S3C_SRAM_BASE_NANDBOOT, S3C_SRAM_SIZE) > 0) - s->cpu->env->regs[15] = S3C_SRAM_BASE_NANDBOOT; /* start address, u-boot rel - mini2440_printf("4KB SteppingStone loaded from NAND/n"); - } -#endif - /* - * if a u--boot is available as a file, we always use it - */ - { - image_size = load_image("mini2440/u-boot.bin", qemu_get_ram_ptr(0x03f80000)); - if (image_size < 0) - image_size = load_image("u-boot.bin", qemu_get_ram_ptr(0x03f80000)); - if (image_size > 0) { - if (image_size & (512 -1)) /* round size to a NAND block size * - image_size = (image_size + 512) & ~(512-1); - mini2440_printf("loaded override u-boot (size %x)/n", image_size); : diff --git a/hw/mini2440.c b/hw/mini2440.c index 5decf4b..7a70aae 100644 --- a/hw/mini2440.c +++ b/hw/mini2440.c @@ -258,46 +258,15 @@ static void mini2440_reset(void *opaque) struct mini2440_board_s *s = (struct mini2440_board_s *) opaque; uint32_t image_size; - /* - * Normally we would load 4 KB of nand to SRAM and jump there, but - * it is not working perfectly as expected, so we cheat and load - * it from nand directly relocated to 0x33f80000 and jump there - */ - if (mini2440_load_from_nand(s->nand, 0, S3C_RAM_BASE | 0x03f80000, 256*1024)> 0) { - mini2440_printf("loaded default u-boot from NAND/n"); - s->cpu->env->regs[15] = S3C_RAM_BASE | 0x03f80000; /* start address, u-boot alrea - } -#if 0 && defined(LATER) - if (mini2440_load_from_nand(s->nand, 0, S3C_SRAM_BASE_NANDBOOT, S3C_SRAM_SIZE) > 0) { - s->cpu->env->regs[15] = S3C_SRAM_BASE_NANDBOOT; /* start address, u-boot relocati - mini2440_printf("4KB SteppingStone loaded from NAND/n"); - } -#endif - /* - * if a u--boot is available as a file, we always use it - */ - { - image_size = load_image("mini2440/u-boot.bin", qemu_get_ram_ptr(0x03f80000)); - if (image_size < 0) - image_size = load_image("u-boot.bin", qemu_get_ram_ptr(0x03f80000)); - if (image_size > 0) { - if (image_size & (512 -1)) /* round size to a NAND block size */ - image_size = (image_size + 512) & ~(512-1); - mini2440_printf("loaded override u-boot (size %x)/n", image_size); - s->cpu->env->regs[15] = S3C_RAM_BASE | 0x03f80000; /* start address, u-boot - } - } : diff --git a/hw/mini2440.c b/hw/mini2440.c index 5decf4b..7a70aae 100644 --- a/hw/mini2440.c +++ b/hw/mini2440.c @@ -258,46 +258,15 @@ static void mini2440_reset(void *opaque) struct mini2440_board_s *s = (struct mini2440_board_s *) opaque; uint32_t image_size; - /* - * Normally we would load 4 KB of nand to SRAM and jump there, but - * it is not working perfectly as expected, so we cheat and load - * it from nand directly relocated to 0x33f80000 and jump there - */ - if (mini2440_load_from_nand(s->nand, 0, S3C_RAM_BASE | 0x03f80000, 256*1024)> 0) { - mini2440_printf("loaded default u-boot from NAND/n"); - s->cpu->env->regs[15] = S3C_RAM_BASE | 0x03f80000; /* start address, u-boot already relo - } -#if 0 && defined(LATER) - if (mini2440_load_from_nand(s->nand, 0, S3C_SRAM_BASE_NANDBOOT, S3C_SRAM_SIZE) > 0) { - s->cpu->env->regs[15] = S3C_SRAM_BASE_NANDBOOT; /* start address, u-boot relocating code - mini2440_printf("4KB SteppingStone loaded from NAND/n"); - } -#endif - /* - * if a u--boot is available as a file, we always use it - */ - { - image_size = load_image("mini2440/u-boot.bin", qemu_get_ram_ptr(0x03f80000)); - if (image_size < 0) - image_size = load_image("u-boot.bin", qemu_get_ram_ptr(0x03f80000)); - if (image_size > 0) { - if (image_size & (512 -1)) /* round size to a NAND block size */ - image_size = (image_size + 512) & ~(512-1); - mini2440_printf("loaded override u-boot (size %x)/n", image_size); - s->cpu->env->regs[15] = S3C_RAM_BASE | 0x03f80000; /* start address, u-boot already - } - } - /* - * if a kernel was explicitly specified, we load it too - */ - if (s->kernel) { - image_size = load_image(s->kernel, qemu_get_ram_ptr(0x02000000)); : diff --git a/hw/mini2440.c b/hw/mini2440.c index 5decf4b..7a70aae 100644 --- a/hw/mini2440.c +++ b/hw/mini2440.c @@ -258,46 +258,15 @@ static void mini2440_reset(void *opaque) struct mini2440_board_s *s = (struct mini2440_board_s *) opaque; uint32_t image_size; - /* - * Normally we would load 4 KB of nand to SRAM and jump there, but - * it is not working perfectly as expected, so we cheat and load - * it from nand directly relocated to 0x33f80000 and jump there - */ - if (mini2440_load_from_nand(s->nand, 0, S3C_RAM_BASE | 0x03f80000, 256*1024)> 0) { - mini2440_printf("loaded default u-boot from NAND/n"); - s->cpu->env->regs[15] = S3C_RAM_BASE | 0x03f80000; /* start address, u-boot already relocated - } -#if 0 && defined(LATER) - if (mini2440_load_from_nand(s->nand, 0, S3C_SRAM_BASE_NANDBOOT, S3C_SRAM_SIZE) > 0) { - s->cpu->env->regs[15] = S3C_SRAM_BASE_NANDBOOT; /* start address, u-boot relocating code */ - mini2440_printf("4KB SteppingStone loaded from NAND/n"); - } -#endif - /* - * if a u--boot is available as a file, we always use it - */ - { - image_size = load_image("mini2440/u-boot.bin", qemu_get_ram_ptr(0x03f80000)); - if (image_size < 0) - image_size = load_image("u-boot.bin", qemu_get_ram_ptr(0x03f80000)); - if (image_size > 0) { - if (image_size & (512 -1)) /* round size to a NAND block size */ - image_size = (image_size + 512) & ~(512-1); - mini2440_printf("loaded override u-boot (size %x)/n", image_size); - s->cpu->env->regs[15] = S3C_RAM_BASE | 0x03f80000; /* start address, u-boot already reloc - } - } - /* - * if a kernel was explicitly specified, we load it too - */ - if (s->kernel) { - image_size = load_image(s->kernel, qemu_get_ram_ptr(0x02000000)); - if (image_size > 0) { - if (image_size & (512 -1)) /* round size to a NAND block size */ : diff --git a/hw/mini2440.c b/hw/mini2440.c index 5decf4b..7a70aae 100644 --- a/hw/mini2440.c +++ b/hw/mini2440.c @@ -258,46 +258,15 @@ static void mini2440_reset(void *opaque) struct mini2440_board_s *s = (struct mini2440_board_s *) opaque; uint32_t image_size; - /* - * Normally we would load 4 KB of nand to SRAM and jump there, but - * it is not working perfectly as expected, so we cheat and load - * it from nand directly relocated to 0x33f80000 and jump there - */ - if (mini2440_load_from_nand(s->nand, 0, S3C_RAM_BASE | 0x03f80000, 256*1024)> 0) { - mini2440_printf("loaded default u-boot from NAND/n"); - s->cpu->env->regs[15] = S3C_RAM_BASE | 0x03f80000; /* start address, u-boot already relocated * - } -#if 0 && defined(LATER) - if (mini2440_load_from_nand(s->nand, 0, S3C_SRAM_BASE_NANDBOOT, S3C_SRAM_SIZE) > 0) { - s->cpu->env->regs[15] = S3C_SRAM_BASE_NANDBOOT; /* start address, u-boot relocating code */ - mini2440_printf("4KB SteppingStone loaded from NAND/n"); - } -#endif - /* - * if a u--boot is available as a file, we always use it - */ - { - image_size = load_image("mini2440/u-boot.bin", qemu_get_ram_ptr(0x03f80000)); - if (image_size < 0) - image_size = load_image("u-boot.bin", qemu_get_ram_ptr(0x03f80000)); - if (image_size > 0) { - if (image_size & (512 -1)) /* round size to a NAND block size */ - image_size = (image_size + 512) & ~(512-1); - mini2440_printf("loaded override u-boot (size %x)/n", image_size); - s->cpu->env->regs[15] = S3C_RAM_BASE | 0x03f80000; /* start address, u-boot already reloca - } - } - /* - * if a kernel was explicitly specified, we load it too - */ - if (s->kernel) { - image_size = load_image(s->kernel, qemu_get_ram_ptr(0x02000000)); - if (image_size > 0) { - if (image_size & (512 -1)) /* round size to a NAND block size */ - image_size = (image_size + 512) & ~(512-1); : diff --git a/hw/mini2440.c b/hw/mini2440.c index 5decf4b..7a70aae 100644 --- a/hw/mini2440.c +++ b/hw/mini2440.c @@ -258,46 +258,15 @@ static void mini2440_reset(void *opaque) struct mini2440_board_s *s = (struct mini2440_board_s *) opaque; uint32_t image_size; - /* - * Normally we would load 4 KB of nand to SRAM and jump there, but - * it is not working perfectly as expected, so we cheat and load - * it from nand directly relocated to 0x33f80000 and jump there - */ - if (mini2440_load_from_nand(s->nand, 0, S3C_RAM_BASE | 0x03f80000, 256*1024)> 0) { - mini2440_printf("loaded default u-boot from NAND/n"); - s->cpu->env->regs[15] = S3C_RAM_BASE | 0x03f80000; /* start address, u-boot already relocated * - } -#if 0 && defined(LATER) - if (mini2440_load_from_nand(s->nand, 0, S3C_SRAM_BASE_NANDBOOT, S3C_SRAM_SIZE) > 0) { - s->cpu->env->regs[15] = S3C_SRAM_BASE_NANDBOOT; /* start address, u-boot relocating code */ - mini2440_printf("4KB SteppingStone loaded from NAND/n"); - } -#endif - /* - * if a u--boot is available as a file, we always use it - */ - { - image_size = load_image("mini2440/u-boot.bin", qemu_get_ram_ptr(0x03f80000)); - if (image_size < 0) - image_size = load_image("u-boot.bin", qemu_get_ram_ptr(0x03f80000)); - if (image_size > 0) { - if (image_size & (512 -1)) /* round size to a NAND block size */ - image_size = (image_size + 512) & ~(512-1); - mini2440_printf("loaded override u-boot (size %x)/n", image_size); - s->cpu->env->regs[15] = S3C_RAM_BASE | 0x03f80000; /* start address, u-boot already reloca - } - } - /* - * if a kernel was explicitly specified, we load it too - */ - if (s->kernel) { - image_size = load_image(s->kernel, qemu_get_ram_ptr(0x02000000)); - if (image_size > 0) { - if (image_size & (512 -1)) /* round size to a NAND block size */ - image_size = (image_size + 512) & ~(512-1); - mini2440_printf("loaded %s (size %x)/n", s->kernel, image_size); - } - } + if (s->kernel) { + image_size = load_image(s->kernel, qemu_get_ram_ptr(0)); + if (image_size > 0) { + if (image_size & (512 -1)) + image_size = (image_size + 512) & ~(512-1); + s->cpu->env->regs[15] = S3C_RAM_BASE ; + mini2440_printf("loaded kernel %s at %p/n", s->kernel, s->cpu->env->regs[15]); + } + } } /* Typical touchscreen calibration values */ @@ -353,6 +322,11 @@ static struct mini2440_board_s *mini2440_init_common(int ram_size, return s; } static void mini2440_init(ram_addr_t ram_size, const char *boot_device, @@ -371,9 +345,18 @@ static void mini2440_init(ram_addr_t ram_size, mini = mini2440_init_common(ram_size, kernel_filename, cpu_model, sd); mini->nand = nand_init(NAND_MFR_SAMSUNG, 0x76); mini->cpu->nand->reg(mini->cpu->nand, mini->nand); mini2440_reset(mini); }
编译qemu for mini2440./configure --target-list=arm-softmmu --disable-linux-user;make