Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - drbytes

Pages: [1] 2
2
See http://support.planetcom.co.uk/index.php/Linux_for_Cosmo#Linux_installation, there is a link there to download the custom installer (v2 at time of writing)

It's all in there.


3
These are the steps I took to compile a kernel for the Cosmo, if you'd like one, follow along.

I'll assume you have access to a linux machine, I'm using debian.
Install the following packages:

Code: [Select]
sudo apt install build-essential libncurses-dev bison flex libssl-dev libelf-dev bc git gcc-aarch64-linux-gnu pythonCreate some directories for use later :
Code: [Select]
mkdir cosmo_android
cd cosmo_android
mkdir KERNEL_OUT


Now get mkbootimg and edit the source :
Code: [Select]
git clone https://github.com/osm0sis/mkbootimg
cd mkbooting
nano mkbootimg.c
Find the following lines and change them to these offsets :
Code: [Select]
uint32_t kernel_offset  = 0xEC080100U;
uint32_t ramdisk_offset = 0x01000100U;
uint32_t second_offset  = 0xECF00100U;
save and run
Code: [Select]
make
cd out to cosmo_android root and create a directory called Packing.
Code: [Select]
cd ..
mkdir Packing && cd Packing
Get the PC v23 Custom installer and place the root-boot.img in this directory and unpack the image :
Code: [Select]
../mkbootimg/unpackbootimg -i root-boot.img -o .
We're specifically after the RAM disk root-boot.img-ramdisk.gz to pack a boot.img later on.
cd out and get the cosmo android kernel
Code: [Select]
cd ..
git clone https://github.com/deadman96385/android_kernel_planet_mt6771.git
cd into it and import the latest config
Code: [Select]
cd android_kernel_planet_mt6771
make O=../KERNEL_OUT ARCH=arm64 k71v1_64_bsp_defconfig

Edit the Makefile to get rid of some errors. If anyone knows how to get this compiling without editing this Makefile, let me know.
Code: [Select]
nano MakefileFind this line and add -w to it :
Code: [Select]
KBUILD_CFLAGS   := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \so it looks like
Code: [Select]
KBUILD_CFLAGS   := -w -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
Next we need to do some more editing to get the Bluetooth, Wifi, etc drivers to load.

To get these to load you need to edit module.c located in  android_kernel_planet_mt6771/kernel/module.c
Code: [Select]
nano kernel/module.c
Go to line ~3477 (CTRL+_), that should drop you in function load_module(...), it's there you need to add these two lines :

Code: [Select]
        flags |= MODULE_INIT_IGNORE_MODVERSIONS;
        flags |= MODULE_INIT_IGNORE_VERMAGIC;

When you're done it should look like this :
Code: [Select]
static int load_module(struct load_info *info, const char __user *uargs,
                       int flags)
{
        struct module *mod;
        long err;
        char *after_dashes;

        flags |= MODULE_INIT_IGNORE_MODVERSIONS;
        flags |= MODULE_INIT_IGNORE_VERMAGIC;

        err = module_sig_check(info, flags);
        if (err)
                goto free_copy;
.... etc ....

We're not done yet, we need to configure the kernel so it force loads modules, you could do it via menuconfig but you can also edit the .config file in the KERNEL_OUT directory.
Code: [Select]
nano ../KERNEL_OUT/.configSearch (CTRL+W) for    
Code: [Select]
# CONFIG_MODULE_FORCE_LOAD is not setand change it so it reads:
Code: [Select]
CONFIG_MODULE_FORCE_LOAD=y
Save it and now build the kernel :

Code: [Select]
make O=../KERNEL_OUT ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
When that is finished we're going to take the resulting Image and pack it with the modified mkbootimg*.
Go to the packing directory and copy the result of the build into the directory :
Code: [Select]
cd ../Packing
cp ../KERNEL_OUT/arch/arm64/boot/Image.gz-dtb .

Now repack it, make sure to use the modified mkbootimg and the ramdisk that we unpacked earlier :

Code: [Select]
../mkbootimg/mkbootimg --kernel Image.gz-dtb --ramdisk root-boot.img-ramdisk.gz --base 0x53ffff00 --cmdline 'bootopt=64S3,32N2,64N2 buildvariant=user veritykeyid=id:7e4333f9bba00adfe0ede979e28ed1920492b40f' -o drbytes.img
You now have a drbytes.img which you can use to flash the kernel to one of the boot slots on the cosmo.
Here's how I flash it, I have the "cosmo-customos-installer" directory on my SD Card, so I added this line to the list_installers.sh :
Code: [Select]
echo "DrBytes Kernel,$MBF/Cosmo_Installer_DrBytes_Kernel.sh" >> $INSTALLER_FILE
I also have added another file called Cosmo_Installer_DrBytes_Kernel.sh, it's a copy paste of the Cosmo_Installer_Rooted_Android.sh by PC but adapted to take the drbytes.img :

Code: [Select]
#!/system/bin/sh
PARTED="/sbin/parted_static"
DD="/system/bin/dd"
MBF="/sdcard/cosmo-customos-installer"
BOOT_PARTITION="/dev/block/mmcblk0p"
LINUX_ROOTFS="/dev/block/mmcblk0p43"
OUTPUT="/tmp/output.txt"
ERROR="/tmp/error.txt"

echo "Installing DrBytes Kernel..." > $OUTPUT

log () {
echo -n "$1 " >> $OUTPUT
}

execute() {
log "Running \"$1\""
R=$($1 2> $ERROR)

if [ "$?" -eq "0" ]
then
log "OK\n"
else
log "ERROR: `cat /tmp/error`\n"
fi
}

# Installing boot image into user-selected boot partition
execute "$DD if=$MBF/drbytes.img of=$BOOT_PARTITION$1 bs=1m"

# Rename partition to specific OS
execute "$PARTED /dev/block/mmcblk0  name $1 DrBytes_Kernel"

Lastly, don't forget to copy the drbytes.img you created to the sdcard.
Reboot to the android recovery, the same procedure as if you were to install Linux or Rooted Android but select the new entry and flash it to the Rooted Android partition.
Reboot and test it out.

To undo it, reboot to android recovery as before and flash PC's Rooted android to the Rooted Android Partition.
When you followed all the steps you should be left with your own kernel booting and everything should work.

Note : You can patch drbytes.img with Magisk so that you have root available.

This is how I got an android kernel booting, I'm sure there are better ways and if you know how, please share.

*: Regarding the modified mkbootimg, we've changed the offsets of the kernel and the ramdisk. These values aren't just a guess, I've gotten these from a tool called unmkbootimg, hosted on XDA. This tool does the same thing as the mkbootimg project but it is able to summarize the results of the unpacking which can be used when we create a new boot image.


Took some asking around, the people over at GeminiPDA on telegram were very helpful; TheKit, Varti, Sean, etc.

Big thx to @Deadman96385 for pointing me to a commit that had the relevant lines of code to skip the module checking.
( https://github.com/LineageOS/android_kernel_asus_sm8150/commit/66976d9f1bbbaf58b81c8ddb1847ef9ca622de3e )

4
Cosmo Communicator - Hardware / Completely re flashing the Cosmo
« on: August 04, 2020, 08:04:36 am »
Say you do something stupid like flashing a boot.img for a samsung device using twrp to your boot partition and you now have a bootlooping cosmo that doesnt respond to anything, not even the recovery key sequence (ON+VOLUP) works and you are stuck at a blank and empty screen.

There is a way out. Connect your cosmo to your pc via the left port. If you are using windows you might hear something connect and disconnect. That is the mediatek flash interface.
Get SP Flash tool, find out what he most current is, I used SP_Flash_Tool_v5.2028_Win from https://spflashtools.com/windows/sp-flash-tool-v5-2028. You might also need the Mediatek Drivers, I used Mediatek_Driver_Auto_Installer_v1.1352 from https://androiddatahost.com/276a2.
Next you need to get the PC official firmware, I got mine from support.planetcom.co.uk/download/cosmo-android-v23.zip, extract this zip.

Last but not least, you need a scatter file so SP Flash knows where to write stuff to, I used MT6771_Android_scatter__cosmo_full_stock, shared on this forum by ZimbiX, I'm including it here but he's the one to credit for this.

Now run the SP Flash tool as administrator and connect your cosmo, go to Download, select the scatter-loading File by ZimbiX, make sure the dropdown says you are in "Download Only".
Next you need to match the files of the zip file with the info loaded by the scatter file, see the attached screenshot to get an idea how that looks.
Hit download and wait. When it's all done, disconnect the cosmo and press ON. You've lost everything but you're left with a functional device.


5
Cosmo Communicator - Linux / Re: Newly installed Debian: no Bluetooth
« on: August 03, 2020, 04:48:03 am »
There is a mediatek module but the kernel does not have the appropriate drivers compiled, either in-kernel or as a module. I tried last week but gave up due to time constraints (actual development work that needed to be done). Might try later this week, it's definitely possible, just need to get into it.

6
Cosmo Communicator - Android / Re: Camera on cosmo
« on: July 27, 2020, 06:47:22 am »
I understand but a dedicated QR scanner won't work when my banking app insist on using it's own built-in implementation. And this is a large bank that has to support many devices, it does that by relying on manufacturers to actually know what they're doing.

I keep coming back to it; PC would be better off chucking those damn data/agenda/whatever custom apps and focusing on core functionality. They're not a Samsung that can afford to create a custom calendar app. Samsung solved it's basic functionality. Those PC apps also tackle problems that have been solved already, far better even, by others.
There is no value there.

Are the android sources available for this device?

7
Cosmo Communicator - Android / Camera on cosmo
« on: July 27, 2020, 03:36:51 am »
I'm still undecided on using the cosmo as a daily driver. One thing that irks me is the camera. I have no idea how this passed quality control. I'm not talking about the hardware but about the implementation on Android. Try scanning a QR code or try taking a picture in telegram to send to a contact, it's all horribly deformed and lacks focus.

I installed OpenCamera and sure enough, the hardware seems fine, not great but definitely an improvement over the stock camera software.
I thought this kind of agro was a thing of the past, early 2010 problem but it's back in the Cosmo and it's disappointing.
Not being able to scan QR codes because the image is stretched and unfocussed is a deal breaker, I use it all the time to log into sites, make payments online, etc. It's 2020, it's ridiculous that this does not work correctly.

Is there a way to change the stock implementation ?

8
Cosmo Communicator - Linux / Re: FTDI_SIO
« on: July 27, 2020, 03:03:53 am »
@cam1965 : You are correct, there is no need for the android cross compiler when building the module. It was well past bedtime when I wrote that post :)
The directory structure should be correct.

@varti : I've placed the relevant info in another post, good suggestion as otherwise it might be buried.

9

This information was buried in another thread where I tried to get my Cosmo to talk to my Nodemcu devices via serial, for that to happen I had to compile the 4.4 kernel released 24 Juli 2020.
@Varti suggested to extract the relevant kernel building information and place it in a separate post.

Here are the steps I took if anybody wants to compile the kernel used on the Cosmo to add support for devices or just good old tinkering.

Get hold of a debian machine, either Install debian in a virtual machine or use an existing installation.
Install some dependencies and create a folder cosmo to keep everything organized.

Code: [Select]
sudo apt install build-essential libncurses-dev bison flex libssl-dev libelf-dev bc git gcc-aarch64-linux-gnu
mkdir cosmo
cd cosmo
mkdir KERNEL_OUT

Go ahead and get the cosmo kernel used in the 24/07 build and cd into the directory:
Code: [Select]
git clone https://github.com/gemian/cosmo-linux-kernel-4.4.git

You should have this directory structure now if you started in your home directory :
~/cosmo/
            |_ KERNEL_OUT/
            |_ cosmo-linux-kernel-4.4/

Edit the Makefile
Code: [Select]
cd cosmo-linux-kernel-4.4/
nano Makefile

--> Find "KBUILD_CFLAGS" and change the line
Code: [Select]
KBUILD_CFLAGS   := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ to
Code: [Select]
KBUILD_CFLAGS   := -w -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
Import the latest kernel config, it's the one that is in the 24/07 build
Code: [Select]
make O=../KERNEL_OUT ARCH=arm64 k71v1_64_bsp_defconfigConfigure your kernel and save to the default .config location
Code: [Select]
make O=../KERNEL_OUT ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfigbuild it
Code: [Select]
make O=../KERNEL_OUT ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
Your module should be in ../KERNEL_OUT/drivers, just scp it over to your cosmo, depmod and modprobe it.

Enjoy



10
Cosmo Communicator - Linux / Re: FTDI_SIO
« on: July 26, 2020, 06:03:07 pm »
Ah ha, thx for the tip, I hate that message.

So here's how I did it:

I'll post it here in case I need to do this in the future and I've forgotten it :)
Install debian in a virtual machine and execute these commands :

Code: [Select]
sudo apt install build-essential libncurses-dev bison flex libssl-dev libelf-dev bc git
mkdir cosmo
cd cosmo
mkdir KERNEL_OUT
git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9 -b nougat-release --depth 1
This is the cosmo kernel used in the 24/07 build
Code: [Select]
git clone https://github.com/gemian/cosmo-linux-kernel-4.4.git
cd cosmo-linux-kernel-4.4/

Edit the Makefile
Code: [Select]
nano Makefile --> Find "KBUILD_CFLAGS" and change the line
Code: [Select]
KBUILD_CFLAGS   := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ to
Code: [Select]
KBUILD_CFLAGS   := -w -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
Import the latest kernel config, it's the one that is in the 24/07 build
Code: [Select]
make O=../KERNEL_OUT ARCH=arm64 k71v1_64_bsp_defconfigConfigure your kernel and save to the default .config location
Code: [Select]
make O=../KERNEL_OUT ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfigbuild it
Code: [Select]
make O=../KERNEL_OUT ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
Your module should be in ../KERNEL_OUT/drivers, just scp it over to your cosmo, depmod and modprobe it.

Enjoy



11
Cosmo Communicator - Linux / Re: FTDI_SIO
« on: July 26, 2020, 05:06:08 pm »
Success !!!

Code: [Select]
drbytes@cosmopda:~$ ls /dev/ttyU*
/dev/ttyUSB0
drbytes@cosmopda:~$

Code: [Select]
Jul 26 23:03:04 cosmopda kernel: [ 1445.533536]  (1)[9259:kworker/1:1]usb 1-1: cp210x converter now attached to ttyUSB0

And it shows my serial console:

Code: [Select]
drbytes@cosmopda:~$ sudo picocom -b 9600 /dev/ttyUSB0
sudo: unable to resolve host cosmopda: Name or service not known
picocom v3.1

port is        : /dev/ttyUSB0
flowcontrol    : none
baudrate is    : 9600
parity is      : none
databits are   : 8
stopbits are   : 1
escape is      : C-a
local echo is  : no
noinit is      : no
noreset is     : no
hangup is      : no
nolock is      : no
send_cmd is    : sz -vv
receive_cmd is : rz -vv -E
imap is        :
omap is        :
emap is        : crcrlf,delbs,
logfile is     : none
initstring     : none
exit_after is  : not set
exit is        : no

Type [C-a] [C-h] to see available commands
Terminal ready
Hi. I'm a nodemcu running the Garage Door code
Current state: Closed. MQTT: GarageESP/Door/Status
MQTT: Publish to GarageESP/Door/Status -> OK
Message will repeat in 5000.
Hi. I'm a nodemcu running the Garage Door code
Current state: Closed. MQTT: GarageESP/Door/Status
MQTT: Publish to GarageESP/Door/Status -> OK
Message will repeat in 5000.


I'll document how I did it tomorrow, but it's all just cross compiling with another debian machine and some guess work.
It's still wonky, though, it takes a couple of tries before it will show up.





12
Cosmo Communicator - Linux / Re: FTDI_SIO
« on: July 26, 2020, 04:16:54 pm »
It is a bit fiddly, I agree.

However ...

Code: [Select]
root@cosmopda:~# cat /var/log/messages | grep ftdi
Jul 26 22:05:29 cosmopda kernel: [ 4011.761624]  (1)[18323:modprobe]usbcore: registered new interface driver ftdi_sio

So I have been able to build it as a module (cross compiled), copied it over, depmodded it and finally modprobed it.
Still no ttyUSB0 tho, so I'm missing something.

I thnk it is VCP UART drivers.
<M>   USB CP210x family of UART Bridge Controllers
Code: [Select]
build trng...
  LD      drivers/misc/mediatek/built-in.o
  LD      drivers/misc/built-in.o
  CC [M]  drivers/usb/serial/cp210x.o
  LD      drivers/built-in.o
  LINK    vmlinux
  LD      vmlinux.o

13
Cosmo Communicator - Linux / Re: FTDI_SIO
« on: July 26, 2020, 02:05:29 pm »
So these are the steps I followed to get it to compile on the cosmo it self, no modifications to the config by using the current kernel config on the device:


Code: [Select]
sudo apt-get install build-essential libncurses-dev bison flex libssl-dev libelf-dev git bc
mkdir cosmo
cd cosmo/
git clone https://github.com/gemian/cosmo-linux-kernel-4.4.git
mkdir KERNEL_OUT
cat /proc/config.gz | gunzip > KERNEL_OUT/.config
make O=../KERNEL_OUT -C cosmo-linux-kernel-4.4 menuconfig -j8
make O=../KERNEL_OUT -C cosmo-linux-kernel-4.4 -j8

That starts to compile the kernel but I run into issues :

Code: [Select]
  CC      arch/arm64/kvm/guest.o
/home/drbytes/cosmo/cosmo-linux-kernel-4.4/fs/exec.c: In function 'get_task_comm':
/home/drbytes/cosmo/cosmo-linux-kernel-4.4/fs/exec.c:1086:32: error: argument to 'sizeof' in 'strncpy' call is the same expression as the source; did you mean to use the size of the destination? [-Werror=sizeof-pointer-memaccess]
  strncpy(buf, tsk->comm, sizeof(tsk->comm));

and further down :

Code: [Select]
In file included from /home/drbytes/cosmo/cosmo-linux-kernel-4.4/include/linux/sctp.h:57,
                 from /home/drbytes/cosmo/cosmo-linux-kernel-4.4/security/lsm_audit.c:31:
/home/drbytes/cosmo/cosmo-linux-kernel-4.4/include/uapi/linux/sctp.h:306:1: error: alignment 4 of 'struct sctp_paddr_change' is less than 8 [-Werror=packed-not-aligned]
 } __attribute__((packed, aligned(4)));
 ^
/home/drbytes/cosmo/cosmo-linux-kernel-4.4/include/uapi/linux/sctp.h:580:1: error: alignment 4 of 'struct sctp_setpeerprim' is less than 8 [-Werror=packed-not-aligned]
 } __attribute__((packed, aligned(4)));
 ^
/home/drbytes/cosmo/cosmo-linux-kernel-4.4/include/uapi/linux/sctp.h:579:26: error: 'sspp_addr' offset 4 in 'struct sctp_setpeerprim' isn't aligned to 8 [-Werror=packed-not-aligned]
  struct sockaddr_storage sspp_addr;
                          ^~~~~~~~~
/home/drbytes/cosmo/cosmo-linux-kernel-4.4/include/uapi/linux/sctp.h:593:1: error: alignment 4 of 'struct sctp_prim' is less than 8 [-Werror=packed-not-aligned]
 } __attribute__((packed, aligned(4)));
 ^
/home/drbytes/cosmo/cosmo-linux-kernel-4.4/include/uapi/linux/sctp.h:592:26: error: 'ssp_addr' offset 4 in 'struct sctp_prim' isn't aligned to 8 [-Werror=packed-not-aligned]
  struct sockaddr_storage ssp_addr;
                          ^~~~~~~~
/home/drbytes/cosmo/cosmo-linux-kernel-4.4/include/uapi/linux/sctp.h:640:1: error: alignment 4 of 'struct sctp_paddrparams' is less than 8 [-Werror=packed-not-aligned]
 } __attribute__((packed, aligned(4)));
 ^
/home/drbytes/cosmo/cosmo-linux-kernel-4.4/include/uapi/linux/sctp.h:634:26: error: 'spp_address' offset 4 in 'struct sctp_paddrparams' isn't aligned to 8 [-Werror=packed-not-aligned]
  struct sockaddr_storage spp_address;
                          ^~~~~~~~~~~
/home/drbytes/cosmo/cosmo-linux-kernel-4.4/include/uapi/linux/sctp.h:747:1: error: alignment 4 of 'struct sctp_paddrinfo' is less than 8 [-Werror=packed-not-aligned]
 } __attribute__((packed, aligned(4)));
 ^
/home/drbytes/cosmo/cosmo-linux-kernel-4.4/include/uapi/linux/sctp.h:741:26: error: 'spinfo_address' offset 4 in 'struct sctp_paddrinfo' isn't aligned to 8 [-Werror=packed-not-aligned]
  struct sockaddr_storage spinfo_address;
                          ^~~~~~~~~~~~~~
  CC      security/selinux/nlmsgtab.o
  CC      security/selinux/netif.o
cc1: all warnings being treated as errors

Too bad that a fresh git can't get off the ground.

14
Cosmo Communicator - Linux / Re: FTDI_SIO
« on: July 26, 2020, 09:43:17 am »
Super info.

I also received this link with a ton of useful info: https://github.com/gemian/gemian/wiki/KernelCompilation


15
Cosmo Communicator - Linux / Re: FTDI_SIO
« on: July 26, 2020, 08:36:36 am »
Thx for the reply.

Interestingly adding support for my rtl-sdr is something I planned to tackle next week, seeing your posts you've already made some headway.
Have you shared your kernel work online somewhere? Or perhaps you can point me to some documentation/repo's?

thx

Pages: [1] 2