gtxaspec / wz_mini_hacks

wz camera mods... make your camera better.
1.31k stars 113 forks source link

Kernel compliation for overlayfs testing #124

Closed archandanime closed 2 years ago

archandanime commented 2 years ago

I'm ready to apply the overlayfs patch, I also complied T31 kernel from mnakada's repo after replacing mnakada's built-in init by your v3_init. Was that all I need to do to make the v3 cam boot successfully? I ask in case there are some missing steps. Thank you.

gtxaspec commented 2 years ago

yes, use the t31 kernel config from my repo, just put it in, since you need to modify the kernel command line (different from the one in atomcam_tools), then modify the init script in src/initramfs_skeleton/init and then make linux-rebuild to get the uImage

I have a sample init that I was testing if you want it too.

archandanime commented 2 years ago

yes, I also replaced the kernel.config, I forgot to tell, sorry about that. I would love to see your init file. Edit: Is the commandline same as the stock one?

gtxaspec commented 2 years ago
#!/bin/sh
# devtmpfs does not get automounted for initramfs

V2="true"

set -x

echo "welcome to initramfs"

mount -t devtmpfs devtmpfs /dev
mount -t proc proc /proc
mount -t sysfs sysfs /sys

echo 43 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio43/direction

mkdir /upper
mkdir /overlay
mkdir /rootfs
mkdir /sdcard

sleep 1

mount -t tmpfs -o size=1 tmpfs /upper
mount -t tmpfs -o size=1 tmpfs /overlay

mount -t squashfs /dev/mtdblock2 /rootfs

mount -t vfat /dev/mmcblk0p1 /sdcard -o rw,umask=0000,dmask=0000

mount -t overlayfs overlayfs -olowerdir=/rootfs,upperdir=/upper /overlay

mkdir /overlay/rootfs
mkdir /overlay/overlay
mkdir /overlay/upper

mount --move /sdcard /overlay/opt
mount --move /rootfs /overlay/rootfs
#mount --move /upper /overlay/overlay

if [[ $(cat /overlay/opt/wz_mini/run_mmc.sh | grep "INITRAMFS_DBG_ENABLED\=") == "INITRAMFS_DBG_ENABLED=\"true\"" ]]; then
    /bin/sh
else
#   umount /proc
#   umount /sys
#   umount /dev

    mount --move /dev /overlay/dev
    mount --move /sys /overlay/sys
    mount --move /proc /overlay/proc

    exec busybox switch_root /overlay /opt/wz_mini/etc/init.d/v3_init.sh
##fi

its old, so rename the scripts accordingly.

gtxaspec commented 2 years ago

no, the kernel command line is not the same as the stock. It specifies the initramfs.

archandanime commented 2 years ago

ummm do you have a file where you wrote down the commandline?

gtxaspec commented 2 years ago

its in the .config in the wz_mini repo under src edit: https://github.com/gtxaspec/wz_mini_hacks/blob/de38d8745813a15601f6e1d2ed42e5d8b02bbe34/src/kernel/kernel.config#L2188

archandanime commented 2 years ago

I get it now, it's already there :), replace the kernel.config and it's done

archandanime commented 2 years ago

@gtxaspec the factory_t31_ZMC6tiIDQN kernel is loaded by uboot instead of being written to the device so there's no risk bricking it, right? I just want to make sure, again

gtxaspec commented 2 years ago

right, the camera is impossible to brick, unless you mess with u-boot, /dev/mtd0

if any other partition gets damaged, just flash demo-wcv3.bin and everything is back to stock.

edit: u-boot is /dev/mtd0, not /dev/mtd1 ( that is the kernel)

archandanime commented 2 years ago

Procedure:

  1. Replace initramfs-skeleton/init by init_overlay(the one you sent above) and renamed
  2. Replace kernel.config
  3. run "sudo make" at atomcam_tools
    (atomcam_tools) $ ls target
    factory_t31_ZMC6tiIDQN  rootfs_hack.ext2
  4. scp the factory_t31_ZMC6tiIDQN to /media/mmc/ Result: The device fails to boot, I ssh'ed to router(it runs Openwrt), the camera is not connected to the router. I'm not at home to check if the status light is on or what's inside the SD card, but I'll be home in the next 5 hours to see
gtxaspec commented 2 years ago

did you change the script names in the init? they changed, its not v3_init anymore, wz_init.sh

archandanime commented 2 years ago

the built-in init? - Yes oh the line:

    exec busybox switch_root /overlay /opt/wz_mini/etc/init.d/v3_init.sh

I didn't change it to wz_init.sh I'll do it as soon as I get home

archandanime commented 2 years ago

@gtxaspec the camera still doesn't boot. I changed

exec busybox switch_root /overlay /opt/wz_mini/etc/init.d/v3_init.sh

to

exec busybox switch_root /overlay /opt/wz_mini/etc/init.d/wz_init.sh

then complied the kernel but it didn't boot. I also tried using the old kernel-built-in init but it still doesn't boot

gtxaspec commented 2 years ago

how are you recompiling? did you docker exec into the docker instance?

archandanime commented 2 years ago

I ran sudo docker-compose exec builder bash then make linux-rebuild it gave me a uImage at output/images/ after that, I used it to replace factory_t31_ZMC6tiIDQN

gtxaspec commented 2 years ago

ok that works too. I use docker exec -it <id> /bin/bash Did put the wz_mini kernel config in /src/kernel.config ?

gtxaspec commented 2 years ago

this is the latest stock init:

#!/bin/sh

set -x

# devtmpfs does not get automounted for initramfs
mount -t devtmpfs devtmpfs /dev
mount -t proc proc /proc
mount -t sysfs sysfs /sys

#Required delay on T20/T31
sleep 1

echo "Check for T20 platform"

if [ -b /dev/mtdblock10 ]; then

    echo "Found T20"

    #T20: Need to export the sd card enable gpio manually
    echo 43 > /sys/class/gpio/export
    echo in > /sys/class/gpio/gpio43/direction

    #T20: Insert required delay for sd card init
    sleep 3

else
    echo "Not T20"
fi

mkdir -p /sdcard
mount -t vfat /dev/mmcblk0p1 /sdcard -o rw,umask=0000,dmask=0000

initram_init() {

mkdir /wz
mount -t squashfs /dev/mtdblock2 /wz

if [ ! -f /sdcard/wz_mini/etc/init.d/wz_init.sh ]; then

    echo "wz_mini not found, booting stock"

    mount --move /dev /wz/dev
    mount --move /sys /wz/sys
    mount --move /proc /wz/proc

    umount /sdcard

    exec busybox switch_root /wz /linuxrc

else

    echo "Loading wz_mini..."

    mkdir -p /wz/dev
    mkdir -p /wz/sys

    mount --move /dev /wz/dev
    mount --move /sys /wz/sys
    mount --move /proc /wz/proc

    #mkdir -p /wz/media/mmc
    mount --move /sdcard /wz/opt

    #exec busybox switch_root /wz /linuxrc
    exec busybox switch_root /wz /opt/wz_mini/etc/init.d/wz_init.sh

fi

}

if [ -f /sdcard/wz_mini/wz_mini.conf ]; then

    source /sdcard/wz_mini/wz_mini.conf

    if [[ "$DEBUG_INITRAMFS_ENABLED" == "true" ]]; then
        /bin/sh
        #exit 0
    else
        echo "initramfs debug disabled"
        initram_init
    fi
else
        initram_init
fi

try using that one just to make sure you can compile a working kernel

archandanime commented 2 years ago

yes, it has CONFIG_OVERLAYFS_FS=y and CONFIG_CMDLINE="console=ttyS1,115200n8 mem=99M@0x0 rmem=29M@0x6300000 rdinit=/init mtdparts=jz_sfc:256K(boot),1984K(kernel),3904K(rootfs),3904K(app),1984K(kback),3904K(aback),384K(cfg),64K(para)"

archandanime commented 2 years ago

I tried the code above to initramfs-skeleton/init, it still doesn't boot. there's only the LED red above the cam and the wz_mini directory was downloaded recently(30 minutes ago)

gtxaspec commented 2 years ago

hmm... tough to say without having serial access to the camera. make sure the kernel you are trying to boot is the latest one that has been compiled. i usually copy it from /openmiko/build/buildroot-2016.02/output/images/uImage.lzma

archandanime commented 2 years ago

I think I can make serial connection to the camera, I'll solder and give you the bootlog

archandanime commented 2 years ago

I got the log! these are last lines of the log

[    0.748035] ALSA device list:
[    0.751094]   #0: Loopback 1
^@[    0.755996] Freeing unused kernel memory: 484K (80507000 - 80580000)
[    0.762592] Failed to execute /init

Please press Enter to activate this console. [    0.963813] mmc0: new high speed SDHC card at address 5048
[    0.969696] mmcblk0: mmc0:5048 SD16G 14.4 GiB 
[    0.975660]  mmcblk0: p1

full log is here initramfs-skeleton/init: exec busybox switch_root /wz /opt/wz_mini/etc/init.d/wz_init.sh

archandanime commented 2 years ago

booting without SD card

[    0.447339] Creating 8 MTD partitions on "jz_sfc":
[    0.452287] 0x000000000000-0x000000040000 : "boot"
[    0.457627] 0x000000040000-0x000000230000 : "kernel"
[    0.463138] 0x000000230000-0x000000600000 : "rootfs"
[    0.468602] 0x000000600000-0x0000009d0000 : "app"
[    0.473856] 0x0000009d0000-0x000000bc0000 : "kback"
[    0.479238] 0x000000bc0000-0x000000f90000 : "aback"
[    0.484672] 0x000000f90000-0x000000ff0000 : "cfg"
[    0.489880] 0x000000ff0000-0x000001000000 : "para"
[    0.495218] SPI NOR MTD LOAD OK
[    0.498498] tun: Universal TUN/TAP device driver, 1.6
[    0.503732] tun: (C) 1999-2004 Max Krasnyansky <maxk@qualcomm.com>
[    0.510209] usbcore: registered new interface driver zd1201
[    0.516010] usbcore: registered new interface driver r8152
[    0.521710] usbcore: registered new interface driver asix
[    0.527370] usbcore: registered new interface driver usb-storage
[    0.533688] usbcore: registered new interface driver usbserial
[    0.539728] usbcore: registered new interface driver ch37x
[    0.545442] usbcore: registered new interface driver pl2303
[    0.551207] usbserial: USB Serial support registered for pl2303
[    0.557358] usbcore: registered new interface driver emi26 - firmware loader
[    0.564874] jzmmc_v1.2 jzmmc_v1.2.0: vmmc regulator missing
[    0.570905] jzmmc_v1.2 jzmmc_v1.2.0: register success!
[    0.576330] jzmmc_v1.2 jzmmc_v1.2.1: vmmc regulator missing
[    0.582262] jzmmc_v1.2 jzmmc_v1.2.1: register success!
[    0.587740] hidraw: raw HID events driver (C) Jiri Kosina
[    0.593493] usbcore: registered new interface driver usbhid
[    0.599235] usbhid: USB HID core driver
[    0.603853] usbcore: registered new interface driver snd-usb-audio
[    0.610409] TCP: cubic registered
[    0.613896] NET: Registered protocol family 17
[    0.619123] input: gpio-keys as /devices/platform/gpio-keys/input/input0
[    0.626222] drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
[    0.632792] ALSA device list:
[    0.635854]   #0: Virtual MIDI Card 1
^@[    0.643802] VFS: Mounted root (squashfs filesystem) readonly on device 31:2.
[    0.651420] Freeing unused kernel memory: 252K (80571000 - 805b0000)
mdev is ok......
 __________________________________
|                                  |
|                                  |
|                                  |
|                                  |
| _   _             _           _  |
|| | | |_   _  __ _| |     __ _(_) |
|| |_| | | | |/ _| | |  _ / _| | | |
||  _  | |_| | (_| | |_| | (_| | | |
||_| |_|\__,_|\__,_|_____|\__,_|_| |
|                                  |
|                                  |
|_____2020_WYZE_CAM_V3_@HUALAI_____|

WCV3 login: [    1.342281] @@@@ tx-isp-probe ok(version H20211130a), compiler date=Nov 30 2021 @@@@@
[    1.380877] exFAT: Version 1.2.9
[    1.411625] jz_codec_register: probe() successful!
[    1.822987] dma dma0chan24: Channel 24 have been requested.(phy id 7,type 0x06 desc a47b9000)
[    1.832083] dma dma0chan25: Channel 25 have been requested.(phy id 6,type 0x06 desc a48d0000)
[    1.841262] dma dma0chan26: Channel 26 have been requested.(phy id 5,type 0x04 desc a498f000)
[    1.863285] __init
[    1.869689] jz_pwm_probe[255] d_name = tcu_chn0
[    1.876311] The version of PWM driver is H20180309a
[    1.887840] request pwm channel 0 successfully
[    1.896087] pwm-jz pwm-jz: jz_pwm_probe register ok !
[    1.919792] mmc1: new SDIO card at address 0001
[    1.939714] usbcore: registered new interface driver usb_ch34x
[    1.947368] ch34x: USB to serial driver for USB to serial chip ch340, ch341, etc.
[    1.955158] ch34x: V1.16 On 2020.12.23
archandanime commented 2 years ago

I tried compiling the kernel so many times without success. always stuck at

[    0.748100] ALSA device list:
[    0.751160]   #0: Loopback 1
^@[    0.756052] Freeing unused kernel memory: 484K (80507000 - 80580000)
[    0.762647] Failed to execute /init

Please press Enter to activate this console. [    0.963819] mmc0: new high speed SDHC card at address 5048

how exactly did you compile your kernel, please? I think I'm not doing it the right way, what I do:

git clone https://github.com/mnakada/atomcam_tools.git
cd atomcam_tools
sudo systemctl start docker
sudo docker-compose exec builder bash
make linux-rebuild
cp output/images/uImage.lzma /src

then I copy the uImage.lzma to SD card and rename to factory_t31_ZMC6tiIDQN I don't know if I'm doing wrong :( maybe you want to try compiling it and send me so we can test it out

gtxaspec commented 2 years ago

In the kernel config, can you verify the path of the initramfs.cpio?

archandanime commented 2 years ago

it's at CONFIG_INITRAMFS_SOURCE="/openmiko/build/buildroot-2016.02/output/images/initramfs.cpio"

gtxaspec commented 2 years ago

can you verify the permissions of the init file? chmod +x init just in case

archandanime commented 2 years ago

it's 644, let's see if it work with 755

archandanime commented 2 years ago

it works!!!!!!!!

gtxaspec commented 2 years ago

=D

archandanime commented 2 years ago

wait, I think the init works but I have kernel panic here after the reboot, I mean here's the the log file

gtxaspec commented 2 years ago

in the kernel, disable netfilter and try again

archandanime commented 2 years ago

changed to CONFIG_NETFILTER=n, compiling again

gtxaspec commented 2 years ago

you can also use make linux-menuconfig to bring up the standard Linux menu config

archandanime commented 2 years ago

I encounter

  /atomtools/build/buildroot-2016.02/output/build/linux-custom/scripts/gen_initramfs_list.sh: Cannot open '/openmiko/build/buildroot-2016.02/output/images/initramfs.cpio'
/atomtools/build/buildroot-2016.02/output/build/linux-custom/usr/Makefile:67: recipe for target 'usr/initramfs_data.cpio.lzma' failed

this time I didn't see this error before so I clone the repo again, replaced kernel.config and init, chmod +x init, still same error

gtxaspec commented 2 years ago

there may be a typo in the .config file? or formatting error?

archandanime commented 2 years ago

I'm sure there's no typo in kernel.config, I Ctrl-Z and checked it again

gtxaspec commented 2 years ago

does /openmiko/build/buildroot-2016.02/output/images/initramfs.cpio exist?

archandanime commented 2 years ago

wait, is CONFIG_NETFILTER=n correct? or I should leave CONFIG_NETFILTER=? /openmiko/build/buildroot-2016.02/output/images/initramfs.cpio doesn't exist

gtxaspec commented 2 years ago

just comment the line out,don't set to n

archandanime commented 2 years ago
mkdir -p /openmiko/build/buildroot-2016.02/output/images/
touch /openmiko/build/buildroot-2016.02/output/images/initramfs.cpio

it's compiling

archandanime commented 2 years ago
[    0.307334] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.313868] dwc2 dwc2: ID PIN CHANGED!
[    0.328174] Kernel panic - not syncing: junk in compressed archive
[    0.334374] Rebooting in 3 seconds..Restarting after 4 ms

that trick didn't help

gtxaspec commented 2 years ago

if you leave netfilter, do you get that error still?

archandanime commented 2 years ago

yes, my the issue on my computer I'm removing files in output/images and run make again, I don't know why it checked for /openmiko/build/buildroot-2016.02/output/images/initramfs.cpio but now it doesn't because it's compiling smoothly still kernel panic after running make

gtxaspec commented 2 years ago

hmm... ok try disabling the new wifi drivers in wz_mini.conf

gtxaspec commented 2 years ago

i updated https://github.com/gtxaspec/wz_mini_hacks/blob/master/src/kernel/t31-config.conf

if you use that config, add the overlay, and it should work with the new wifi drivers (i think)

archandanime commented 2 years ago

it's my computer acting weird. I'll try it as soon as the compiler works again

archandanime commented 2 years ago

and thank you!

gtxaspec commented 2 years ago

no worries! knowledge for all! =D

archandanime commented 2 years ago

@gtxaspec with t3-config.conf as kernel.config

[    1.773712] FAT-fs (mmcblk0p1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
mount: mounting /sdcard/rootfs_hack.ext2 on /newroot failed: No such file or directory
mount: mounting /proc on /newroot/proc failed: No such file or directory
BusyBox v1.24.1 (2020-08-26 19:40:44 UTC) multi-call binary.

Usage: switch_root [-c /dev/console] NEW_ROOT NEW_INIT [ARGS]

Free initramfs and switch to another root fs:
chroot to NEW_ROOT, delete all in /, move NEW_ROOT to /,
execute NEW_INIT. PID must be 1. NEW_ROOT must be a mountpoint.

    -c DEV  Reopen stdio to DEV after switch
[    1.843866] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000100
[    1.843866] 
[    1.853306] Rebooting in 3 seconds..Restarting after 4 ms