gtxaspec / wz_flash-helper

Firmware flash tool for Wyze cameras
11 stars 1 forks source link

Not booting after trying to switch to OpenIPC #14

Closed yeahme49 closed 4 months ago

yeahme49 commented 9 months ago

I followed the guide on here to switch to OpenIPC. Booting to the card worked, I heard the audio prompts saying it was flashing then it said it was rebooting. After the camera rebooted it no longers boots. I checked the SD card and the log files are from the first boot, nothing from the second boot to run the script to set the env variables.

Wyze Cam V3 (t31x)

I used https://github.com/gtxaspec/u-boot-ingenic/releases/download/latest/u-boot-t31x.bin for U-Boot and https://github.com/OpenIPC/firmware/releases/download/latest/openipc.t31-nor-ultimate.tgz for the OpenIPC image.

Any thoughts?

yeahme49 commented 9 months ago

openipc.txt Log from TTL adapter

archandanime commented 9 months ago

Hi! Sorry for the very late reply.

As you have Serial connection to the camera, I assume that you can't see the U-boot log from your serial terminal and something is wrong the U-boot which makes the camera SoC unable to load U-boot. Would you mind trying Ingenic Cloner from this guide to recover it?

In case you can still see the U-boot log(which means U-boot is not corrupted), would you mind trying these steps:

  1. Rename the SD card kernel to factory_t31_ZMC6tiIDQN on your SD card and insert it to your camera.
  2. Power on your camera, it should drop you U-boot shell
  3. From U-boot shell, run:
    fatload mmc 0 0x80600000 factory_t31_ZMC6tiIDQN
    bootm 0x80600000

    then your camera should boot wz_flash-helper

archandanime commented 9 months ago

There is something quite strange happened, even the openipc.txt log file shows that OpenIPC was booted successfully:

Welcome to OpenIPC
openipc-t31 login:

But now the camera no longer boots.

Would you mind sharing the initramfs_serial.log and general.log files? In case you have still have them unmodified.

If you don't have these files, I really can't guess what happened.

yeahme49 commented 9 months ago

I will get more logs later today but when I initially posted I thought the camera wasn't booting. Once I was able to get a serial connection I discovered it is booting but it doesn't recognize any SD card when I insert one and wifi doesn't work. Any commands or logs I can pull to help diagnose why the SD card and wifi don't work?

yeahme49 commented 9 months ago

Restored to stock firmware, formatted my SD card and followed the guide again from scratch. Same issue. Flashes OpenIPC, reboots, can't read SD card so it never does the second step of setting up wifi.

Serial log, from flashing openipc to reboot initramfs.log initramfs_serial.log

Let me know if I can provide any other info or logs.

archandanime commented 9 months ago

I know what is going on now. It is due to a known OpenIPC firmware bug with Wi-Fi and SD card GPIO initialization. To be more details, this is the normal boot flow when you switch from stock firmware to OpenIPC:

  1. Stock U-boot is booted, then it boots wz_flash-helper SD card kernel. wz_flash-helper writes OpenIPC boot, kernel and rootfs partitions, then reboots.
  2. OpenIPC U-boot is booted, it writes env variables, then it boots wz_flash-helper SD card kernel. wz_flash-helper runs setup_openipc_variables.sh, then reboots.
  3. OpenIPC U-boot is booted, it boots OpenIPC kernel. The OpenIPC kernel starts OpenIPC system.

Details about how OpenIPC U-boot sets env variables is here.

Because there are different cameras with different GPIO configuration, U-boot has to set GPIO configuration for them differently to make Wi-Fi, SD card, LEDs, speaker, IR LEDs, etc. works. There are init scripts that read the GPIO configuration from the env partition to make those components work.

Currently, the init scripts for Wi-Fi and SD card initialization is missing from OpenIPC firmware(which means even you flash OpenIPC using official guide, the issue remains). There was a workaround with it using S09mmc init script but gtxaspec removed it from his openipc_firmware repo.

@gtxaspec do you have a workaround with Wi-Fi and SD card GPIO initialization for now?

While we are waiting, would you mind sharing the output of ifconfig and fw_printenv running from OpenIPC shell?

archandanime commented 9 months ago

Flashes OpenIPC, reboots, can't read SD card so it never does the second step of setting up wifi.

Do you remember that you enabled the re_run option on general.conf?

re_run="yes"

Checking the general.conf for the option value would be incorrect because wz_flash-helper changes the option value to no after switching to OpenIPC.

yeahme49 commented 9 months ago

Yes I did set re_run="yes" in general.conf

root@openipc-t31:~# ifconfig
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:48 errors:0 dropped:0 overruns:0 frame:0
          TX packets:48 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:3744 (3.6 KiB)  TX bytes:3744 (3.6 KiB)
root@openipc-t31:~# fw_printenv
baseaddr=0x80600000
baudrate=115200
bootargs=mem=${osmem} rmem=${rmem} console=${serialport},${baudrate}n8 panic=${panic_timeout} root=/dev/mtdblock3 rootfstype=squashfs init=/init mtdparts=jz_sfc:256k(boot),64k(env),${kern_size}(kernel),${rootfs_size}(rootfs),-(rootfs_data)${update}
bootcmd=sf probe;sq probe;setenv setargs setenv bootargs ${bootargs};run setargs;sf read ${baseaddr} 0x50000 ${kern_len};bootm ${baseaddr};
bootdelay=3
disable_eth=false
disable_sd=false
enable_updates=false
ethaddr=16:d7:89:20:4d:06
gatewayip=192.168.1.1
gpio_default=25ID 26IDU
gpio_ircut=52I 53I 49I 50I 57I 58I
ipaddr=192.168.1.10
loads_echo=1
netmask=255.255.255.0
osmem=99M@0x0
panic_timeout=10
restore=n
rmem=29M@0x6300000
serialport=ttyS1
serverip=192.168.1.254
soc=t31
sensor=gc2053
archandanime commented 9 months ago

About the GPIO bug, OpenIPC T31 kernel hard coded the GPIO 59 as "SD card detect pin", it has to be 62 actually. Once the kernel is loaded, the GPIO can't be changed. We can still override the GPIO using ingenic-gpio.

Would you mind creating /etc/init.d/09mmc with:

#!/bin/sh

MMC_VENDOR=$(ipcinfo -v)
MMC_SOC_FAMILY=$(ipcinfo -f)
MMC_SOC_SUBVAR=$(ipcinfo -c)

MMC_GPIO_CD=$(fw_printenv -n gpio_mmc_cd)

if [ -z "$MMC_GPIO_CD" ]; then
    MMC_GPIO_CD="59"
fi

check_return() {
    if [ $? -ne 0 ]; then
        echo "err: $1"
        exit
    fi
}

load_module() {
    case "$MMC_VENDOR" in
        "ingenic")
            MMC_MODULE="jzmmc_v12"
            # Default CD-PIN for Ingenic PB27 (GPIO59)
            MMC_PARAM="cd_gpio_pin=$MMC_GPIO_CD"

            # Check if MDIO directory exists
            if [ ! -d /proc/jz/mdio ]; then
                case "$MMC_SOC_FAMILY" in
                    "t20" | "t10" | "t21" | "t30" | "t40" | "t41")
                    echo "OK"
                    ;;
                    "t31")
                        # Check for specific SOC sub-variants
                        if [ "$MMC_SOC_SUBVAR" != "t31a" ] && [ "$MMC_SOC_SUBVAR" != "t31al" ]; then
                            ingenic-gpio pb08 func 1 drive 2
                            ingenic-gpio pb09 func 1 drive 1
                            ingenic-gpio pb10 func 1 drive 1
                            ingenic-gpio pb11 func 1 drive 1
                            ingenic-gpio pb13 func 1 drive 1
                            ingenic-gpio pb14 func 1 drive 1
                        else
                            echo "Skipping GPIO setup for $MMC_SOC_SUBVAR"
                            return 1
                        fi
                        ;;
                    "t23")
                        echo "Unsupported: T23"
                        ;;
                    # Add more cases for other SOC types as needed here
                    *)
                        echo "Unsupported SOC type: $MMC_SOC_FAMILY"
                        return 1
                        ;;
                esac
            fi
            ;;
        *)
            echo "MMC Host support disabled, unsupported vendor: $MMC_VENDOR"
            return 1
            ;;
    esac

    lsmod | grep "$MMC_MODULE" >/dev/null
    if [ $? -ne 0 ]; then
        modprobe $MMC_MODULE ${MMC_PARAM}
        check_return "modprobe $MMC_MODULE"
        echo "OK"
    fi
}

case "$1" in
    start)
        if [ "$MMC_VENDOR" == "ingenic" ]; then
            printf "Starting MMC: "
            load_module
        fi
        ;;
esac

exit 0

reboot your camera, the run ifconfig, df and dmesg and share the output please?

I currently don't have a camera to see what have been changed with OpenIPC since the last time I tested it.

gtxaspec commented 8 months ago

we're working on a fix, stay tuned

yeahme49 commented 8 months ago

Added /etc/init.d/S09mmc and chmod +x /etc/init.d/S09mmc

root@openipc-t31:~# ifconfig
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:64 errors:0 dropped:0 overruns:0 frame:0
          TX packets:64 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:4992 (4.8 KiB)  TX bytes:4992 (4.8 KiB)

root@openipc-t31:~# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/root                 7040      7040         0 100% /rom
devtmpfs                 47024         0     47024   0% /dev
/dev/mtdblock4            6016       248      5768   4% /overlay
overlayfs                 6016       248      5768   4% /
tmpfs                    47124         8     47116   0% /dev/shm
tmpfs                    47124        12     47112   0% /tmp
tmpfs                    47124        40     47084   0% /run
root@openipc-t31:~# dmesg
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Initializing cgroup subsys cpuacct
[    0.000000] Linux version 3.10.14__isvp_swan_1.0__ (runner@fv-az654-436) (buildroot-gcc-12.3.0) #2 PREEMPT Wed Feb 7 19:51:29 UTC 2024
[    0.000000] bootconsole [early0] enabled
[    0.000000] CPU0 RESET ERROR PC:801BE680
[    0.000000] [<801be680>] __delay+0x0/0x10
[    0.000000] CPU0 revision is: 00d00100 (Ingenic Xburst)
[    0.000000] FPU revision is: 00b70000
[    0.000000] cgu_get_rate, parent = 1392000000, rate = 0, m = 129, n = 255, reg val = 0x081000ff
[    0.000000] cgu_get_rate, parent = 1392000000, rate = 0, m = 129, n = 255, reg val = 0x081000ff
[    0.000000] CCLK:1392MHz L2CLK:696Mhz H0CLK:200MHz H2CLK:200Mhz PCLK:100Mhz
[    0.000000] Determined physical RAM map:
[    0.000000]  memory: 0055e000 @ 00010000 (usable)
[    0.000000]  memory: 00032000 @ 0056e000 (usable after init)
[    0.000000] User-defined physical RAM map:
[    0.000000]  memory: 06300000 @ 00000000 (usable)
[    0.000000] Initrd not found or empty - disabling initrd
[    0.000000] Zone ranges:
[    0.000000]   Normal   [mem 0x00000000-0x062fffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x00000000-0x062fffff]
[    0.000000] On node 0 totalpages: 25344
[    0.000000] free_area_init_node: node 0, pgdat 80568130, node_mem_map 81000000
[    0.000000]   Normal zone: 198 pages used for memmap
[    0.000000]   Normal zone: 0 pages reserved
[    0.000000]   Normal zone: 25344 pages, LIFO batch:7
[    0.000000] Primary instruction cache 32kB, 8-way, VIPT, linesize 32 bytes.
[    0.000000] Primary data cache 32kB, 8-way, VIPT, no aliases, linesize 32 bytes
[    0.000000] pls check processor_id[0x00d00100],sc_jz not support!
[    0.000000] MIPS secondary cache 128kB, 8-way, linesize 32 bytes.
[    0.000000] pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
[    0.000000] pcpu-alloc: [0] 0
[    0.000000] Built 1 zonelists in Zone order, mobility grouping off.  Total pages: 25146
[    0.000000] Kernel command line: mem=99M@0x0 rmem=29M@0x6300000 console=ttyS1,115200n8 panic=10 root=/dev/mtdblock3 rootfstype=squashfs init=/init mtdparts=jz_sfc:256k(boot),64k(env),3072k(kernel),6976k(rootfs),-(rootfs_data)
[    0.000000] PID hash table entries: 512 (order: -1, 2048 bytes)
[    0.000000] Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
[    0.000000] Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
[    0.000000] Memory: 94048k/101376k available (4076k kernel code, 7328k reserved, 1417k data, 200k init, 0k highmem)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] Preemptible hierarchical RCU implementation.
[    0.000000] NR_IRQS:358
[    0.000000] clockevents_config_and_register success.
[    0.000014] Calibrating delay loop... 1391.00 BogoMIPS (lpj=6955008)
[    0.087831] pid_max: default: 32768 minimum: 301
[    0.092688] Mount-cache hash table entries: 512
[    0.097592] Initializing cgroup subsys debug
[    0.101850] Initializing cgroup subsys freezer
[    0.107857] devtmpfs: initialized
[    0.112596] regulator-dummy: no parameters
[    0.116962] NET: Registered protocol family 16
[    0.124559] Skipping MSC1_PB GPIO setup
[    0.128437] Skipping WYZE GPIO setup
[    0.131986] Skipping WYZE GPIO setup
[    0.136184] set gpio strength: 32-2
[    0.136193] set gpio strength: 33-2set gpio strength: 34-2
[    0.136204] set gpio strength: 35-2set gpio strength: 36-2
[    0.136212] set gpio strength: 37-2set gpio pull: 59-90
[    0.154428] bio: create slab <bio-0> at 0
[    0.164359] jz-dma jz-dma: JZ SoC DMA initialized
[    0.170688] usbcore: registered new interface driver usbfs
[    0.176712] usbcore: registered new interface driver hub
[    0.182216] usbcore: registered new device driver usb
[    0.187757]  (null): set:249  hold:250 dev=100000000 h=500 l=500
[    0.195582] Switching to clocksource jz_clocksource
[    0.202804] dwc2 otg probe start
[    0.202832] jz-dwc2 jz-dwc2: cgu clk gate get error
[    0.207808] DWC IN OTG MODE
[    0.211515] dwc2 dwc2: Keep PHY ON
[    0.214884] dwc2 dwc2: Using Buffer DMA mode
[    0.219212] dwc2 dwc2: Core Release: 3.00a
[    0.223497] dwc2 dwc2: DesignWare USB2.0 High-Speed Host Controller
[    0.229790] dwc2 dwc2: new USB bus registered, assigned bus number 1
[    0.237232] hub 1-0:1.0: USB hub found
[    0.241050] hub 1-0:1.0: 1 port detected
[    0.245052] dwc2 dwc2: DWC2 Host Initialized
[    0.249338] dwc2 otg probe success
[    0.249580] NET: Registered protocol family 2
[    0.254439] TCP established hash table entries: 1024 (order: 1, 8192 bytes)
[    0.261548] TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
[    0.267926] TCP: Hash tables configured (established 1024 bind 1024)
[    0.274469] TCP: reno registered
[    0.277662] UDP hash table entries: 256 (order: 0, 4096 bytes)
[    0.283630] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
[    0.290118] NET: Registered protocol family 1
[    0.294713] RPC: Registered named UNIX socket transport module.
[    0.300688] RPC: Registered udp transport module.
[    0.305408] RPC: Registered tcp transport module.
[    0.310175] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.317295] freq_udelay_jiffys[0].max_num = 10
[    0.321784] cpufreq  udelay  loops_per_jiffy
[    0.326142] dwc2 dwc2: ID PIN CHANGED!
[    0.329969] 12000     59956   59956
[    0.333222] 24000     119913  119913
[    0.336641] 60000     299784  299784
[    0.340084] 120000    599569  599569
[    0.343697] 200000    999282  999282
[    0.347148] 300000    1498924         1498924
[    0.350956] 600000    2997848         2997848
[    0.354584] 792000    3957159         3957159
[    0.358292] 1008000   5036385         5036385
[    0.362122] 1200000   5995696         5995696
[    0.375674] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.382792] jffs2: version 2.2. © 2001-2006 Red Hat, Inc.
[    0.388850] msgmni has been set to 183
[    0.393895] io scheduler noop registered
[    0.397816] io scheduler cfq registered (default)
[    0.409497] jz-uart.1: ttyS1 at MMIO 0x10031000 (irq = 58) is a uart1
[    0.417116] console [ttyS1] enabled, bootconsole disabled
[    0.436890] brd: module loaded
[    0.444478] loop: module loaded
[    0.447938] logger: created 256K log 'log_main'
[    0.454819] jz TCU driver register completed
[    0.460160] the id code = 1c7018, the flash name is EN25QH128A
[    0.466432] JZ SFC Controller for SFC channel 0 driver register
[    0.472692] 5 cmdlinepart partitions found on MTD device jz_sfc
[    0.478796] Creating 5 MTD partitions on "jz_sfc":
[    0.483784] 0x000000000000-0x000000040000 : "boot"
[    0.489740] 0x000000040000-0x000000050000 : "env"
[    0.495742] 0x000000050000-0x000000350000 : "kernel"
[    0.502019] 0x000000350000-0x000000a20000 : "rootfs"
[    0.508162] 0x000000a20000-0x000001000000 : "rootfs_data"
[    0.514841] SPI NOR MTD LOAD OK
[    0.518296] Bus Mode Reg after reset: 0x00020101, cnt=0
[    0.524772] Bus Mode Reg after reset: 0x00020101, cnt=1
[    0.531306] Bus Mode Reg after reset: 0x00020101, cnt=2
[    0.537689] Bus Mode Reg after reset: 0x00020101, cnt=3
[    0.544099] Bus Mode Reg after reset: 0x00020101, cnt=4
[    0.550520] Bus Mode Reg after reset: 0x00020101, cnt=5
[    0.556912] Bus Mode Reg after reset: 0x00020101, cnt=6
[    0.563311] Bus Mode Reg after reset: 0x00020101, cnt=7
[    0.569694] Bus Mode Reg after reset: 0x00020101, cnt=8
[    0.576091] Bus Mode Reg after reset: 0x00020101, cnt=9
[    0.582486] func:jz_mii_bus_probe, synopGMAC_reset failed
[    0.588062] jz_mii_bus: probe of jz_mii_bus.0 failed with error -1
[    0.594625] =======>gmacdev = 0x84090380<================
[    0.600191] =========>gmacdev->MacBase = 0xb34b0000 DmaBase = 0xb34b1000
[    0.607170] Bus Mode Reg after reset: 0x00020101, cnt=0
[    0.613582] Bus Mode Reg after reset: 0x00020101, cnt=1
[    0.619963] Bus Mode Reg after reset: 0x00020101, cnt=2
[    0.626373] Bus Mode Reg after reset: 0x00020101, cnt=3
[    0.632782] Bus Mode Reg after reset: 0x00020101, cnt=4
[    0.639165] Bus Mode Reg after reset: 0x00020101, cnt=5
[    0.645566] Bus Mode Reg after reset: 0x00020101, cnt=6
[    0.651971] Bus Mode Reg after reset: 0x00020101, cnt=7
[    0.658353] Bus Mode Reg after reset: 0x00020101, cnt=8
[    0.664762] Bus Mode Reg after reset: 0x00020101, cnt=9
[    0.671154] func:jz_mac_probe, synopGMAC_reset failed
[    0.676363] jz_mac: probe of jz_mac.0 failed with error -1
[    0.682158] STA : @@@@@@ rtusb init rt2870 --->
[    0.687005] usbcore: registered new interface driver rt2870
[    0.692955] usbcore: registered new interface driver asix
[    0.698539] i2c /dev entries driver
[    0.703386] jzmmc_v1.2 jzmmc_v1.2.0: vmmc regulator missing
[    0.709479] jzmmc_v1.2 jzmmc_v1.2.0: register success!
[    0.714883] jzmmc_v1.2 jzmmc_v1.2.1: vmmc regulator missing
[    0.721020] jzmmc_v1.2 jzmmc_v1.2.1: register success!
[    0.726784] ipip: IPv4 over IPv4 tunneling driver
[    0.732287] TCP: cubic registered
[    0.736764] NET: Registered protocol family 10
[    0.742143] NET: Registered protocol family 17
[    0.747943] input: gpio-keys as /devices/platform/gpio-keys/input/input0
[    0.755454] drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
[    0.766407] VFS: Mounted root (squashfs filesystem) readonly on device 31:3.
[    0.777780] devtmpfs: mounted
[    0.781213] Freeing unused kernel memory: 200K (8056e000 - 805a0000)
[    1.200499] jzmmc_v1.2 jzmmc_v1.2.0: card inserted, state=0
[    1.231459] jffs2: notice: (449) jffs2_build_xattr_subsystem: complete building xattr subsystem, 0 of xdatum (0 unchecked, 0 orphan) and 0 of xref (0 dead, 0 orphan) found.
[    1.712254] [resetd] GPIO undefined in /usr/sbin/resetd
[    2.374837] @@@@ avpu driver ok(version H20220825a) @@@@@
[    2.589365] @@@@ tx-isp-probe ok(version H20221206a), compiler date=Dec  6 2022 @@@@@
[    2.635946] jz_codec_register: probe() successful!
[    2.636035] cgu_set_rate, parent = 1392000000, rate = 2048000, n = 10875, reg val = 0x01002a7b
[    2.636043] cgu_enable,cgu_i2s_spk reg val = 0x21002a7b
[    2.636061] cgu_set_rate, parent = 1392000000, rate = 2048000, n = 10875, reg val = 0x01002a7b
[    2.636067] cgu_enable,cgu_i2s_mic reg val = 0x21002a7b
[    3.040687] dma dma0chan24: Channel 24 have been requested.(phy id 7,type 0x06 desc a4aa4000)
[    3.040966] dma dma0chan25: Channel 25 have been requested.(phy id 6,type 0x06 desc a483a000)
[    3.041279] dma dma0chan26: Channel 26 have been requested.(phy id 5,type 0x04 desc a497c000)
[    3.068592] GPIO claim module (c) OpenIPC.org
[    4.104408] wait stable.[289][cgu_cim]
[    4.104426] probe ok ------->gc2053
[    4.180970] -----gc2053_detect: 1282 ret = 0, v = 0x20
[    4.181462] -----gc2053_detect: 1288 ret = 0, v = 0x53
[    4.181470] gc2053 chip found @ 0x37 (i2c0) version H20230726a
[    4.381470] gc2053 stream on
archandanime commented 8 months ago

Currently official OpenIPC upstream code still have the issues with the GPIOs. Here is the repo that have these issues fixed, the development on this repo has been quick though it is not yet finished. If you want to try, here is the firmware: openipc_t31x.zip.

Once the firmware is ready, you will see the Release page from the above repo.

archandanime commented 4 months ago

Closing as thingino now sets devices-specific env variables automatically with S03environment script to enable SD card GPIO pins.