ricardojlrufino / anyka_v380ipcam_experiments

Scripts and hacks for Anyka V380 / AK3918 IP camera
47 stars 13 forks source link

Rootfs SD card - Failed to execute /init #6

Closed cocos-ascent closed 1 year ago

cocos-ascent commented 2 years ago

Hello! First off, thanks for all the work on this. I would have had no chance without your guides. I'm currently trying to get root on a Teckin TC100 that has a near identical board. I'm attempting to go the custom rootfs path. I've successfully ran the make_sd.sh. I've mimicked your partitions just to make it easier on myself while reading the steps, so the rootfs is on the 2nd partition.

After starting up the camera, changing the boot args, and then run boot_normal, the sd card is recognized but I can't get /init to execute.

U-Boot 2013.10.0-AK_V3.0.05 (Aug 10 2020 - 03:27:13)

DRAM:  64 MiB
8 MiB
Create flash partition table init OK!
ak_sdhsmmc_init:
ANYKA SDHC/MMC4.0: 0
Load Env CRC OK!
In:    serial
Out:   serial
Err:   serial
reset pin value: 1

Hit any key to stop autoboot:  1 
 0 
anyka$k
Unknown command 'k' - try 'help'

anyka$help
?       - alias for 'help'
base    - print or set address offset
bootm   - boot application image from memory
bootp   - boot image via network using BOOTP/TFTP protocol
chpart  - change active partition
cmp     - memory compare
cp      - memory copy
crc32   - checksum calculation
downcheck_patition_update- load usr.sqsh4 tftp
downimage- downimage   - download and write All-Image to FLASH device,partiton table from ENV partition.
downjffs2fs- load usr.jffs2 tftp
downkernel- load uImage tftp
downrootfs- load root.sqsh4 tftp
downsquashfs- load usr.sqsh4 tftp
downuboot- load uboot tftp
env     - environment handling commands
erase   - erase FLASH memory
exfatdownkernel- exfat load uImageTF
exfatdownrootfs- exfat loadroot.sqsh4TF
exfatdownsquashfs- exfat loadusr.sqsh4TF
exfatupdateimage- exfatupdateimage   - download and write All-Image to FLASH device
exfatwrite- exfatwrite   -write file to mmc
fatinfo - print information about filesystem
fatload - load binary file from a dos filesystem
fatls   - list files in a directory (default /)
fatwrite- write file into a dos filesystem
flinfo  - print FLASH memory information
format  - erase uboot env
go      - start application at address 'addr'
help    - print command description/usage
loop    - infinite loop on address range
md      - memory display
mm      - memory modify (auto-incrementing address)
mmc     - MMC sub system
mmcinfo - display MMC info
mtdparts- define flash/nand partitions
mw      - memory write (fill)
nm      - memory modify (constant address)
parts   - read out partitions table info.
parts_adjust- 
adjust parts info. Each part's size,offset etc.

ping    - send ICMP ECHO_REQUEST to network host
printenv- print environment variables
protect - enable or disable FLASH write protection
readcfg - read config from config.
reset   - Perform RESET of the CPU
run     - run commands in an environment variable
run_uvc - run uvc test program
saveenv - save environment variables to persistent storage
setenv  - set environment variables
setloadaddr- set loadaddr to  config infor .
sf      - spi flash sub-system:
tfdownjffs2fs- load usr.jffs2TF
tfdownkernel- load uImageTF
tfdownrootfs- load root.sqsh4TF
tfdownsquashfs- load usr.sqsh4TF
tfdownuboot- load u-boot.binTF
tftpboot- boot image via network using TFTP protocol
tfupdateimage- tfupdateimage   - download and write All-Image to FLASH device
updatecfg- update config from config infor table.
version - print monitor, compiler and linker version

anyka$mmcinfo
cdh:MMC device available:curr_device=0
find MMC device available
cdh:use ak mmc cd!
cdh:ak getcd=0
mmc_getcd, cd=0
MMC: detect card present
MMC: no init, start init!
mmc/sd share pin!
want set asic clk = 100000000, wanted sdmmc clk = 400000
asic clk = 100000000, real sdmmc clk = 400000
MMC: ak mmc driver init OK!
want set asic clk = 100000000, wanted sdmmc clk = 400000
asic clk = 100000000, real sdmmc clk = 400000
MMC: default init bus width=1, clock=400khz, OK!
MMC: ak mmc drmmc_go_idle OK!
MMC: ak mmc mmc_send_if_cond OK!
cdh:sd_send_op_cond, mmc->high_capacity=1
MMC: ak mmc sd_send_op_cond OK!
mmc_start_init: init OK!
cdh:MMC_CMD_ALL_SEND_CID OK!
cdh:mmc cid[0]=771832760
cdh:mmc cid[1]=536871007
cdh:mmc cid[2]=1144010823
cdh:mmc cid[3]=-16777133
cdh:sd mmc->rca=0x1
want set asic clk = 100000000, wanted sdmmc clk = 1000000
asic clk = 100000000, real sdmmc clk = 1000000
want set asic clk = 100000000, wanted sdmmc clk = 2000000
asic clk = 100000000, real sdmmc clk = 2000000
cdh:MMC_CMD_SEND_CSD OK!
cmd csdlong response[0]:0xa40008a!
cmd csdlong response[1]:0x3c1f7f80!
cmd csdlong response[2]:0x5b590000!
cmd csdlong response[3]:0x400e0032!
cdh:mmc->tran_speed:0x32!
cdh:sd card, mmc->write_bl_len:512!
cdh:yes mmc->high_capacity!
cdh:sd card, mmc->capacity_user:0x1e1000000 blocks!
cdh:sd card, mmc->write_bl_len2:512!
cdh:MMC_CMD_SELECT_CARD OK!
cdh:MMC_CMD_SET_BLOCKLEN OK!
cdh:mmc->capacity:0x1e1000000 !
cdh:part_num:0, mmc_set_capacity OK!
cdh:mmc->scr[0]=0x2b58000, mmc->scr[1]=0x0
cdh:mmc->version=0x20300
cdh:SD_DATA_4BIT, mmc->card_caps=0x100
cdh:SD_SWITCH_CHECK ready
cdh:MMC Controller mmc->host_caps:0x811, yes support high-speed!
cdh:SD_SWITCH_SWITCH OK!
cdh:mmc->card_caps:0x101, MODE HS OK!
cdh:mmc->tran_speed=50000000
want set asic clk = 100000000, wanted sdmmc clk = 25000000
asic clk = 100000000, real sdmmc clk = 25000000
cdh:test_part_dos read ok!
cdh:test_part_dos DOS_PART_MAGIC_OFFSET ok!
cdh:test_part_dos DOS_MBR ok!
Device: ANYKA SDHC/MMC4.0
Manufacturer ID: 2e
OEM: 13b
Name: � Tran Speed: 25000000
Rd Block Len: 512
SD version 3.0
High Capacity: Yes
Capacity: 7.5 GiB
Bus Width: 1-bit

anyka$setenv bootargs console=ttySAK0,115200n8 root=/dev/mmcblk0p2 rw rootwait rootfstype=squashfs init=/init mem=64M memsize=64M


anyka$env print
backuppage=ffffffff
baudrate=115200
boot_normal=readcfg; run read_kernel; bootm ${loadaddr}
bootargs=console=ttySAK0,115200n8 root=/dev/mmcblk0p2 rw rootwait rootfstype=squashfs init=/init mem=64M memsize=64M
bootcmd=run boot_normal
bootdelay=1
console=ttySAK0,115200n8
erase_env=sf probe 0:0 ${sf_hz} 0; sf erase 0x20000 0x2000
ethaddr=00:55:7b:b5:7d:f7
fs_addr=0x230000
fw_version=V1.1.41
init=/sbin/init
ipaddr=192.168.1.99
kernel_addr=39000
kernel_size=15aca0
loadaddr=81b08000
memsize=64M
mtd_root=/dev/mtdblock4 
netmask=255.255.255.0
poweroff_flag=0
read_kernel=sf probe 0:0 ${sf_hz} 0; sf read ${loadaddr} ${kernel_addr} ${kernel_size}
rootfstype=squashfs
serverip=192.168.1.1
setcmd=setenv bootargs console=${console} root=${mtd_root} rootfstype=${rootfstype} init=${init} mem=${memsize}
sf_hz=20000000
stderr=serial
stdin=serial
stdout=serial
update_flag=0
ver=U-Boot 2013.10.0-AK_V3.0.05 (Aug 10 2020 - 03:27:13)
vram=12M

Environment size: 996/4088 bytes

anyka$run boot_normal

SF: 1420448 bytes @ 0x39000 Read: OK
## Booting kernel from Legacy Image at 81b08000 ...
   Image Name:   Linux-3.4.35
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    1420384 Bytes = 1.4 MiB
   Load Address: 81b08000
   Entry Point:  81b08040
   Verifying Checksum ... OK
   XIP Kernel Image ... OK

Starting kernel ...

Uncompressing Linux... done, booting the kernel.
Anyka Linux Kernel Version: 1.1.12
Booting Linux on physical CPU 0
Linux version 3.4.35 (caibin@apemans_server) (gcc version 4.8.5 (anyka (gcc-4.8.5 + binutils-2.24 + ulcibc-0.9.33.2)(20170223)) ) #1 Wed Aug 19 06:47:45 UTC 2020
CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00053177
CPU: VIVT data cache, VIVT instruction cache
Machine: CLOUD39EV3_AK3918EV300_MNBD
Memory policy: ECC disabled, Data cache writeback
ANYKA CPU AK3918 (ID 0x20160100)
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 9398
Kernel command line: console=ttySAK0,115200n8 root=/dev/mmcblk0p2 rw rootwait rootfstype=squashfs init=/init mem=64M memsize=64M
PID hash table entries: 256 (order: -2, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 37MB = 37MB total
Memory: 33276k/33276k available, 4612k reserved, 0K highmem
Virtual kernel memory layout:
    vector  : 0xffff0000 - 0xffff1000   (   4 kB)
    fixmap  : 0xfff00000 - 0xfffe0000   ( 896 kB)
    vmalloc : 0xc2800000 - 0xff000000   ( 968 MB)
    lowmem  : 0xc0000000 - 0xc2500000   (  37 MB)
    modules : 0xbf000000 - 0xc0000000   (  16 MB)
      .text : 0xc0008000 - 0xc03a8000   (3712 kB)
      .init : 0xc03a8000 - 0xc03c3000   ( 108 kB)
      .data : 0xc03c4000 - 0xc03e9f38   ( 152 kB)
       .bss : 0xc03e9f5c - 0xc040aec8   ( 132 kB)
SLUB: Genslabs=13, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
NR_IRQS:117
sched_clock: 32 bits at 12MHz, resolution 83ns, wraps every 357913ms
AK39 console driver initial
console [ttySAK0] enabled
Calibrating delay loop... 199.06 BogoMIPS (lpj=995328)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
Setting up static identity map for 0x81ddbf60 - 0x81ddbfb8
devtmpfs: initialized
NET: Registered protocol family 16
On-chip L2 memory initialized
AK39 clocks: CPU 400MHz, MEM 400MHz, ASIC 120MHz
Anyka platform share gpio locks initialize.
bio: create slab <bio-0> at 0
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
i2c-ak39 i2c-ak39: Unable to achieve desired frequency 300KHz. Lowest achievable 312KHz
i2c-ak39 i2c-ak39: i2c-0: AK39 I2C adapter
Linux video capture interface: v2.00
cfg80211: Calling CRDA to update world regulatory domain
Switching to clocksource ak_timer5 cs
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP: reno registered
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
squashfs: version 4.0 (2009/01/31) Phillip Lougher
exFAT: Version 1.2.9
jffs2: version 2.2. © 2001-2006 Red Hat, Inc.
msgmni has been set to 64
io scheduler noop registered
io scheduler cfq registered (default)
AK39xx uart driver init, (c) 2013 ANYKA
ak39-uart.0: ttySAK0 at MMIO 0x20130000 (irq = 10) is a AK39
ion: failed to create debug files.
brd: module loaded
loop: module loaded
@@@ [akpcm_init]: enter @@@
@@@ [akpcm_probe]: enter @@@
akpcmL0->ak39_codec_probe enter...
akpcm probe: mic on
akpcm_probe: OK

akisp_init
Start to init Anyka SPI Flash...
Start to init Anyka partition table...
AK SPI Driver, (c) 2012 ANYKA
akpi regs: SPICON:00000152, SPISTA:00000015, SPIINT:00000000.
ak-spi ak-spi: master is unqueued, this is deprecated
ak_spi setup the master.
pre-scaler=2 (wanted 20Mhz, got 20Mhz)
ak spiflash probe enter.
pre-scaler=2 (wanted 20Mhz, got 20Mhz)
ak_spi_setupxfer,con:00000252.
akspi flash ID: 0x00207017
ak-spiflash spi0.0: xm25qh64a (8192 Kbytes)
FHA:partition lib version: V1.1.06
FHA:spiflash init
FHA:boot block num offset:427
FHA:Sflash_Get_Partition_Startpage g_boot_len:880
mtd_part[0]:
name = KERNEL
size = 0x200000
offset = 0x39000
mask_flags = 0x1

mtd_part[1]:
name = MAC
size = 0x1000
offset = 0x239000
mask_flags = 0x1

mtd_part[2]:
name = ENV
size = 0x1000
offset = 0x23a000
mask_flags = 0x1

mtd_part[3]:
name = A
size = 0x180000
offset = 0x23b000
mask_flags = 0x1

mtd_part[4]:
name = B
size = 0x7d000
offset = 0x3bb000
mask_flags = 0x1

mtd_part[5]:
name = C
size = 0x3b6000
offset = 0x438000
mask_flags = 0x1

Creating 6 MTD partitions on "spi0.0":
0x000000039000-0x000000239000 : "KERNEL"
0x000000239000-0x00000023a000 : "MAC"
0x00000023a000-0x00000023b000 : "ENV"
0x00000023b000-0x0000003bb000 : "A"
0x0000003bb000-0x000000438000 : "B"
0x000000438000-0x0000007ee000 : "C"
Init AK SPI Flash finish.
akspi master initialize success, use for DMA mode.
input: akgpio-keys as /devices/platform/akgpio-keys/input/input0
We're Using Internal RC OSC.
AK RTC, (c) 2010 ANYKA 
i2c /dev entries driver
AK MCI Driver (c) 2010 ANYKA
akmci_probe : MCI
## MMC Power: GPIO-1 Setup
akmci ak_mci.0: Mci Interface driver.mmc0. using l2dma, sw IRQ. detect mode:GPIO detect.
akmci_probe : SDIO
## MMC Power: GPIO-1 Setup
mmc0: host does not support reading read-only switch. assuming write-enable.
mmc0: new SDHC card at address 0001
mmcblk0: mmc0:0001 SD08G 7.51 GiB 
 mmcblk0: p1 p2
akmci ak_sdio.1: Mci Interface driver.mmc1. using l2dma, hw IRQ. detect mode:plugin alway.
TCP: cubic registered
NET: Registered protocol family 17
lib80211: common routines for IEEE802.11 drivers
/home/caibin/cam_sdk/nooie_ipc_code_base/kernel/drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
VFS: Mounted root (squashfs filesystem) readonly on device 179:2.
devtmpfs: mounted
Freeing init memory: 108K
Failed to execute /init.  Attempting defaults...
Kernel panic - not syncing: No init found.  Try passing init= option to kernel. See Linux Documentation/init.txt for guidance.

I recognize it's a different camera, so perhaps it isn't compatible, but I'm thankful for any advice or direction if you have some. Thanks for your time!

ricardojlrufino commented 2 years ago

Can you upload photos from your camera?

Do you have root access to the camera? already tried to follow: https://blog.caller.xyz/v380-ipcam-firmware-patching/

bolt1502 commented 2 years ago

I also have such a problem, did you solve it?

ohdavid2018 commented 1 year ago

I got the same error when following the blog. The procedure in general however works, I used the factory firmware dumped from IPCAM, converted it to squashfs, then dd to sdcard, boot from sdcard works. But when using the kernel (mtd4, root.sqsh) from this github, got the error. After comparing factory kernel with this github, the init is the only changed file, plus two extra files from root folder, so the issue may be caused by some bugs in the init file. It's a very useful method to be able to boot kernel from sdcard, thanks Ricardo! However we like to see how your 'Clean kernel' works, please update the git so we can move forward, and we are waiting for you to finish your blogs, many thanks!

ricardojlrufino commented 1 year ago

Were you able to accomplish the first part of the tutorial, which is to make telnet work? https://ricardojlrufino.wordpress.com/2022/02/14/hack-ipcam-anyka-teardown-and-root-access/

This is the first part of the hack that enables you to load custom scripts

ohdavid2018 commented 1 year ago

Yes, the first part of the blog works great. Got the telnet access and be able to backup the firmware.

ricardojlrufino commented 1 year ago

on rootfs_v1basic/rootfs/ image

init, is a symbol to busybox

try re-recreate

ohdavid2018 commented 1 year ago

Found my issue, use: chmod 777 rootfs then follow the blog, and everything went smooth and I got log into root!

ricardojlrufino commented 1 year ago

I had prepared a new rootfs using Build root, so it's much easier to make customization. watch this: https://github.com/ricardojlrufino/anyka_v380ipcam_experiments/issues/9