├── 0001-dtsi_collector ├── README.md └── dtsi_collector.sh ├── 0002-build-gcc-4.9 ├── .gitignore ├── README.md ├── anykernel │ ├── anykernel.sh │ └── dtbtool.c └── build.sh ├── 0003-clean-dts ├── README.md └── cleandts.sh ├── 0004-dtb-dts-converter-reconverter ├── README.md ├── dtbtodts.sh └── dtstodtb.sh ├── 0005-dtb-appender ├── README.md └── catdtb.sh ├── 0006-arm-magisk-patch ├── README.md └── arm-magisk-patch.sh ├── 0007-touch-fw-dumper ├── .src ├── README.md ├── dump_touch_fw.sh └── touchfw_uploader.ipynb ├── 0008-git-patcheroo └── patch.sh └── 0009-fedora-module-rebuild ├── ec_sys-builder.sh └── uvc_driver.patch /0001-dtsi_collector/README.md: -------------------------------------------------------------------------------- 1 | ## 1. dtsi_collector.sh ## 2 | 3 | ### About: ### 4 | 5 | Grabs all the DTSIs used to build a device-specific dtb. 6 | 7 | This makes rebasing DTSI changes to caf way more easier. 8 | 9 | ### Usage: ### 10 | 11 | First compile the kernel source with a bootable defconfig. 12 | 13 | If you're just grabbing from a fresh caf tree, build it using the default CAF defconfig. 14 | 15 | Place this script inside the root directory of kernel source. 16 | 17 | Open a terminal in kernel rootdir. 18 | 19 | `./dtsi_collector.sh dtbname dtsfolder` 20 | 21 | dtsfolder is qcom by default if nothing is passed as the second argument but it may be vendor/qcom for 4.19 and above. pass it as needed. 22 | 23 | A folder with the format KERNEL-DIR-NAME_DTB-NAME would be created outside the kernel dir with all the dtsis used to build that specific dtb. 24 | 25 | If unsure about which is the proper name still, open arch/arm(64)/boot/dts/qcom/Makefile and search for parts of the name you found out earlier from DMESG. 26 | 27 | ### Example: ### 28 | 29 | For msm8953 sd625 mido, the master dts name is `msm8953-qrd-sku3`. 30 | 31 | This can be found out easily by grabbing a DMESG from a normal boot cycle and search for any line with `(DT)` or `MACHINE`. 32 | 33 | You should see a similar string. That is the name of the dtb that the kernel uses to identify the hardware layout and configurations of your device. 34 | 35 | So here, the usage would be: 36 | 37 | `./dtsi_collector.sh msm8953-qrd-sku3` 38 | 39 | ### Backstory: ### 40 | 41 | So my OEM didn't release kernel sources for oreo and there were quite a few differences between the nougat dts and oreo dts when i compared the extracted ones with meld. 42 | 43 | I wanted to create proper overlays by comparing to the DTSIs of best caf base and writing them that way but the dts/qcom folder had way too many DTSIs in there and it was getting difficult to navigate. 44 | 45 | I was poking around in the `out/arch/arm64/boot/dts` folder one day and found this file named `.msm8953-qrd-sku3.dtb.d.pre.tmp`. 46 | 47 | I opened it looking for any useful info and I was pleasantly surprised. It had the list of all the DTSIs which were parsed by DTC to build the final DTB in out/ so I got to work making a script which formats the aforementioned file and grabs the DTSIs and places them to a folder outside the kernel rootdir. 48 | 49 | I did the same with the best caf base for the nougat oem source which i first built with caf defconfig and ran the script with same master dts name as argument. Now I had two folders which had the DTSIs used to build the same dtb in both best caf base and oem base. 50 | 51 | I then opened up Meld and did folder diffing for both of them and was able to plan out the changes from there. 52 | 53 | You can find the process i adopted in this repo: https://github.com/Jebaitedneko/android_kernel_10or_G/commits/3.18-dtsi-new 54 | -------------------------------------------------------------------------------- /0001-dtsi_collector/dtsi_collector.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $1 == "" ]]; then 4 | echo -e "\nProvide DTB/DTBO Target Name" && exit 5 | fi 6 | 7 | if [[ $2 == "" ]]; then 8 | echo -e "\nSearching in arch/arm64/boot/dts/qcom by default." 9 | DTS_DIR="qcom" 10 | else 11 | DTS_DIR=$2 12 | fi 13 | 14 | if [[ ! -d "out/arch/arm64/boot/dts/$DTS_DIR" ]]; then 15 | echo "$DTS_DIR is invalid. try again." && exit 16 | fi 17 | 18 | file="" 19 | if [[ $(find out/arch/arm64/boot/dts/$DTS_DIR -type f -iname ".$1.dtbo.d.pre.tmp") ]]; then 20 | echo -e "\nDTBO Target Detected at $DTS_DIR\n" 21 | file=".$1.dtbo.d.pre.tmp" 22 | else 23 | if [[ $(find out/arch/arm64/boot/dts/$DTS_DIR -type f -iname ".$1.dtb.d.pre.tmp") ]]; then 24 | echo -e "\nDTB Target Detected at $DTS_DIR\n" 25 | file=".$1.dtb.d.pre.tmp" 26 | fi 27 | fi 28 | 29 | if [[ $file == "" ]]; then 30 | echo "$1 not found. try again." && exit 31 | fi 32 | 33 | folder=${PWD##*/}_${1} 34 | [ -d ../$folder ] && rm -rf ../$folder && mkdir -p ../$folder || mkdir -p ../$folder 35 | 36 | echo " 37 | $( 38 | cat out/arch/arm64/boot/dts/$DTS_DIR/"$file" | \ 39 | cut -f2 -d ':' | \ 40 | sed "s/ ..\///g;s/ \///g" | \ 41 | cut -f1 -d '\' | 42 | sort -u 43 | ) 44 | " | column -t | while read file; do echo -e "Copying $file"; cp --parents $file ../$folder; done 45 | 46 | ( cd ../$folder; git init; git add .; git commit -m "init" ) &> /dev/null 47 | 48 | echo -e "\nInitialized Git Repo Over At $(pwd)/../$folder" 49 | -------------------------------------------------------------------------------- /0002-build-gcc-4.9/.gitignore: -------------------------------------------------------------------------------- 1 | anykernel/anykernel3 2 | anykernel/anykernel3/Image 3 | anykernel/anykernel3/Image.gz 4 | anykernel/anykernel3/Image.gz-dtb 5 | anykernel/anykernel3/kernel 6 | anykernel/anykernel3/dt.img 7 | -------------------------------------------------------------------------------- /0002-build-gcc-4.9/README.md: -------------------------------------------------------------------------------- 1 | ## 2. build.sh ## 2 | 3 | ### About: ### 4 | 5 | Build script and zipping script using GCC-4.9 + CCACHE for legacy devices. 6 | 7 | ### Advantage: ### 8 | 9 | We all know GCC-4.9 is painfully slow to compile with. (well it's been well over 7 years since it's release but there are plenty of legacy devices that need to use it even today) 10 | With CCACHE on Arch i was able to get a consecutive build time of 33s. 11 | 12 | ### Usage: ### 13 | 14 | Edit L#18 in build.sh to point to your device defconfig. 15 | 16 | Change L#41 in build.sh to whatever you want the zip name to be. 17 | 18 | Change L#30 in build.sh to get Image, Image.gz, Image.gz-dtb or whichever one you want to use 19 | 20 | L#32 and L#33 uses DTBTOOL to compile dt.img from dts in out/ so you may or may not need it. Configure as needed. 21 | 22 | You can edit anykernel.sh in anykernel dir to change the message to be displayed while flashing (this will be later used instead of the sh in anykernel) 23 | 24 | Build will be timed so you can see the difference in consecutive build. 25 | 26 | Clone to kernel root (might need to merge the gitignore or ignore it and add the entries from here to the ignore in the kernel) 27 | 28 | Run build.sh 29 | 30 | Toolchains will be auto-downloaded to ~/android/TOOLS/GCC by default (you can edit this in build.sh XD) 31 | -------------------------------------------------------------------------------- /0002-build-gcc-4.9/anykernel/anykernel.sh: -------------------------------------------------------------------------------- 1 | # AnyKernel3 Ramdisk Mod Script 2 | # osm0sis @ xda-developers 3 | properties() { ' 4 | kernel.string=MOCHI 5 | do.devicecheck=0 6 | do.modules=0 7 | do.systemless=0 8 | do.cleanup=1 9 | do.cleanuponabort=0 10 | device.name1=test 11 | device.name2= 12 | device.name3= 13 | device.name4= 14 | device.name5= 15 | supported.versions= 16 | '; } 17 | 18 | block=/dev/block/bootdevice/by-name/boot; 19 | is_slot_device=0; 20 | ramdisk_compression=auto; 21 | 22 | . tools/ak3-core.sh; 23 | 24 | chmod -R 750 $ramdisk/*; 25 | chown -R root:root $ramdisk/*; 26 | 27 | dump_boot; 28 | 29 | ui_print "*******************************************" 30 | ui_print "Updating Kernel and Patching cmdline..." 31 | ui_print "*******************************************" 32 | 33 | 34 | ui_print "*******************************************" 35 | ui_print "Brought to you by MOCHI (TG: @mochi_wwww)" 36 | ui_print "*******************************************" 37 | 38 | patch_cmdline androidboot.selinux androidboot.selinux=permissive 39 | 40 | write_boot; 41 | -------------------------------------------------------------------------------- /0002-build-gcc-4.9/anykernel/dtbtool.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are 6 | * met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following 11 | disclaimer in the documentation and/or other materials provided 12 | with the distribution. 13 | * Neither the name of The Linux Foundation nor the names of its 14 | contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 24 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 26 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #define _GNU_SOURCE 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #define QCDT_MAGIC "QCDT" /* Master DTB magic */ 45 | #define QCDT_VERSION 3 /* QCDT version */ 46 | 47 | #define QCDT_DT_TAG "qcom,msm-id = <" 48 | #define QCDT_BOARD_TAG "qcom,board-id = <" 49 | #define QCDT_PMIC_TAG "qcom,pmic-id = <" 50 | 51 | 52 | #define PAGE_SIZE_DEF 2048 53 | #define PAGE_SIZE_MAX (1024*1024) 54 | 55 | #define log_err(x...) printf(x) 56 | #define log_info(x...) printf(x) 57 | #define log_dbg(x...) { if (verbose) printf(x); } 58 | 59 | #define COPY_BLK 1024 /* File copy block size */ 60 | 61 | #define RC_SUCCESS 0 62 | #define RC_ERROR -1 63 | 64 | struct chipInfo_t { 65 | uint32_t chipset; 66 | uint32_t platform; 67 | uint32_t subtype; 68 | uint32_t revNum; 69 | uint32_t pmic_model[4]; 70 | uint32_t oppoId; 71 | uint32_t dtb_size; 72 | char *dtb_file; 73 | struct chipInfo_t *prev; 74 | struct chipInfo_t *next; 75 | struct chipInfo_t *master; 76 | int wroteDtb; 77 | uint32_t master_offset; 78 | struct chipInfo_t *t_next; 79 | }; 80 | 81 | struct chipInfo_t *chip_list; 82 | 83 | struct chipId_t { 84 | uint32_t chipset; 85 | uint32_t revNum; 86 | struct chipId_t *next; 87 | struct chipId_t *t_next; 88 | }; 89 | 90 | struct chipSt_t { 91 | uint32_t platform; 92 | uint32_t subtype; 93 | uint32_t oppoId; 94 | struct chipSt_t *next; 95 | struct chipSt_t *t_next; 96 | }; 97 | 98 | struct chipPt_t { 99 | uint32_t pmic0; 100 | uint32_t pmic1; 101 | uint32_t pmic2; 102 | uint32_t pmic3; 103 | struct chipPt_t *next; 104 | struct chipPt_t *t_next; 105 | }; 106 | 107 | char *input_dir; 108 | char *output_file; 109 | char *dtc_path; 110 | char *dt_tag = QCDT_DT_TAG; 111 | int verbose; 112 | int page_size = PAGE_SIZE_DEF; 113 | int version_override = 0; 114 | 115 | void print_help() 116 | { 117 | log_info("dtbTool version %d (kinda :) )\n", QCDT_VERSION); 118 | log_info("dtbTool [options] -o \n"); 119 | log_info(" options:\n"); 120 | log_info(" --output-file/-o output file\n"); 121 | log_info(" --dtc-path/-p path to dtc\n"); 122 | log_info(" --page-size/-s page size in bytes\n"); 123 | log_info(" --dt-tag/-d alternate QCDT_DT_TAG\n"); 124 | log_info(" --verbose/-v verbose\n"); 125 | log_info(" --force-v2/-2 output dtb v2 format\n"); 126 | log_info(" --force-v3/-3 output dtb v3 format\n"); 127 | log_info(" --help/-h this help screen\n"); 128 | } 129 | 130 | int parse_commandline(int argc, char *const argv[]) 131 | { 132 | int c; 133 | 134 | struct option long_options[] = { 135 | {"output-file", 1, 0, 'o'}, 136 | {"dtc-path", 1, 0, 'p'}, 137 | {"page-size", 1, 0, 's'}, 138 | {"dt-tag", 1, 0, 'd'}, 139 | {"force-v2", 0, 0, '2'}, 140 | {"force-v3", 0, 0, '3'}, 141 | {"verbose", 0, 0, 'v'}, 142 | {"help", 0, 0, 'h'}, 143 | {0, 0, 0, 0} 144 | }; 145 | 146 | while ((c = getopt_long(argc, argv, "-o:p:s:d:23vh", long_options, NULL)) 147 | != -1) { 148 | switch (c) { 149 | case 1: 150 | if (!input_dir) 151 | input_dir = optarg; 152 | break; 153 | case 'o': 154 | output_file = optarg; 155 | break; 156 | case 'p': 157 | dtc_path = optarg; 158 | break; 159 | case 's': 160 | page_size = atoi(optarg); 161 | if ((page_size <= 0) || (page_size > (PAGE_SIZE_MAX))) { 162 | log_err("Invalid page size (> 0 and <=1MB\n"); 163 | return RC_ERROR; 164 | } 165 | break; 166 | case 'd': 167 | dt_tag = optarg; 168 | break; 169 | case '2': 170 | case '3': 171 | if (version_override != 0) { 172 | log_err("A version output argument may only be passed once\n"); 173 | return RC_ERROR; 174 | } 175 | version_override = c - '0'; 176 | break; 177 | case 'v': 178 | verbose = 1; 179 | break; 180 | case 'h': 181 | default: 182 | return RC_ERROR; 183 | } 184 | } 185 | 186 | if (!output_file) { 187 | log_err("Output file must be specified\n"); 188 | return RC_ERROR; 189 | } 190 | 191 | if (!input_dir) 192 | input_dir = "./"; 193 | 194 | if (!dtc_path) 195 | dtc_path = ""; 196 | 197 | return RC_SUCCESS; 198 | } 199 | 200 | /* Unique entry sorted list add (by chipset->platform->rev) */ 201 | int chip_add(struct chipInfo_t *c) 202 | { 203 | struct chipInfo_t *x = chip_list; 204 | 205 | if (!chip_list) { 206 | chip_list = c; 207 | c->next = NULL; 208 | c->prev = NULL; 209 | return RC_SUCCESS; 210 | } 211 | 212 | while (1) { 213 | if ((c->chipset < x->chipset) || 214 | ((c->chipset == x->chipset) && 215 | ((c->platform < x->platform) || 216 | ((c->platform == x->platform) && 217 | ((c->subtype < x->subtype) || 218 | ((c->subtype == x->subtype) && 219 | (c->revNum < x->revNum))))))) { 220 | if (!x->prev) { 221 | c->next = x; 222 | c->prev = NULL; 223 | x->prev = c; 224 | chip_list = c; 225 | break; 226 | } else { 227 | c->next = x; 228 | c->prev = x->prev; 229 | x->prev->next = c; 230 | x->prev = c; 231 | break; 232 | } 233 | } 234 | if ((c->chipset == x->chipset) && 235 | (c->platform == x->platform) && 236 | (c->subtype == x->subtype) && 237 | (c->revNum == x->revNum) && 238 | (c->pmic_model[0] == x->pmic_model[0]) && 239 | (c->pmic_model[1] == x->pmic_model[1]) && 240 | (c->pmic_model[2] == x->pmic_model[2]) && 241 | (c->pmic_model[3] == x->pmic_model[3]) && 242 | (c->oppoId == x->oppoId)) { 243 | return RC_ERROR; /* duplicate */ 244 | } 245 | if (!x->next) { 246 | c->prev = x; 247 | c->next = NULL; 248 | x->next = c; 249 | break; 250 | } 251 | x = x->next; 252 | } 253 | return RC_SUCCESS; 254 | } 255 | 256 | void chip_deleteall() 257 | { 258 | struct chipInfo_t *c = chip_list, *t; 259 | 260 | while (c) { 261 | t = c; 262 | c = c->next; 263 | if (t->dtb_file) 264 | free(t->dtb_file); 265 | free(t); 266 | } 267 | } 268 | 269 | /* 270 | For v1 Extract 'qcom,msm-id' parameter triplet from DTB 271 | qcom,msm-id = ; 272 | 273 | For v2 Extract 'qcom,msm-id', 'qcom,board-id' parameter double from DTB 274 | qcom,msm-id = i.e chipset, revision number; 275 | qcom,board-id = i.e platform and sub-type; 276 | */ 277 | 278 | struct chipInfo_t *getChipInfo(const char *filename, int *num, uint32_t msmversion) 279 | { 280 | 281 | const char str1[] = "dtc -I dtb -O dts \""; 282 | const char str2[] = "\" 2>&1"; 283 | char *buf, *pos; 284 | char *line = NULL; 285 | size_t line_size; 286 | FILE *pfile; 287 | int llen; 288 | struct chipInfo_t *chip = NULL, *tmp, *chip_t; 289 | uint32_t data[3] = {0, 0, 0}; 290 | uint32_t data_st[3] = {0, 0, 0}; 291 | uint32_t data_pt[4] = {0, 0, 0, 0}; 292 | char *tok, *sptr = NULL; 293 | int i, entryValid, entryEnded; 294 | int count = 0, count1 = 0, count2 = 0, count3 = 0; 295 | int entryValidST, entryEndedST, entryValidDT, entryEndedDT, entryValidPT, entryEndedPT; 296 | struct chipId_t *chipId = NULL, *cId = NULL, *tmp_id = NULL; 297 | struct chipSt_t *chipSt = NULL, *cSt = NULL, *tmp_st = NULL; 298 | struct chipPt_t *chipPt = NULL, *cPt = NULL, *tmp_pt = NULL; 299 | struct chipId_t *chipId_tmp = NULL; 300 | struct chipSt_t *chipSt_tmp = NULL; 301 | struct chipPt_t *chipPt_tmp = NULL; 302 | 303 | line_size = 1024; 304 | line = (char *)malloc(line_size); 305 | if (!line) { 306 | log_err("Out of memory\n"); 307 | return NULL; 308 | } 309 | 310 | llen = sizeof(char) * (strlen(dtc_path) + 311 | strlen(str1) + 312 | strlen(str2) + 313 | strlen(filename) + 1); 314 | buf = (char *)malloc(llen); 315 | if (!buf) { 316 | log_err("Out of memory\n"); 317 | free(line); 318 | return NULL; 319 | } 320 | 321 | strncpy(buf, dtc_path, llen); 322 | strncat(buf, str1, llen); 323 | strncat(buf, filename, llen); 324 | strncat(buf, str2, llen); 325 | 326 | pfile = popen(buf, "r"); 327 | free(buf); 328 | 329 | if (pfile == NULL) { 330 | log_err("... skip, fail to decompile dtb\n"); 331 | } else { 332 | /* Find "qcom,msm-id" */ 333 | while ((llen = getline(&line, &line_size, pfile)) != -1) { 334 | if (msmversion == 1) { 335 | if ((pos = strstr(line, dt_tag)) != NULL) { 336 | pos += strlen(dt_tag); 337 | 338 | entryEnded = 0; 339 | while (1) { 340 | entryValid = 1; 341 | for (i = 0; i < 3; i++) { 342 | tok = strtok_r(pos, " \t", &sptr); 343 | pos = NULL; 344 | if (tok != NULL) { 345 | if (*tok == '>') { 346 | entryEnded = 1; 347 | entryValid = 0; 348 | break; 349 | } 350 | data[i] = strtoul(tok, NULL, 0); 351 | } else { 352 | data[i] = 0; 353 | entryValid = 0; 354 | entryEnded = 1; 355 | } 356 | } 357 | if (entryEnded) { 358 | free(line); 359 | pclose(pfile); 360 | *num = count; 361 | return chip; 362 | } 363 | if (entryValid) { 364 | tmp = (struct chipInfo_t *) 365 | malloc(sizeof(struct chipInfo_t)); 366 | if (!tmp) { 367 | log_err("Out of memory\n"); 368 | break; 369 | } 370 | if (!chip) { 371 | chip = tmp; 372 | chip->t_next = NULL; 373 | } else { 374 | tmp->t_next = chip->t_next; 375 | chip->t_next = tmp; 376 | } 377 | tmp->chipset = data[0]; 378 | tmp->platform = data[1]; 379 | tmp->subtype = 0; 380 | tmp->revNum = data[2]; 381 | tmp->pmic_model[0] = 0; 382 | tmp->pmic_model[1] = 0; 383 | tmp->pmic_model[2] = 0; 384 | tmp->pmic_model[3] = 0; 385 | tmp->dtb_size = 0; 386 | tmp->dtb_file = NULL; 387 | tmp->master = chip; 388 | tmp->wroteDtb = 0; 389 | tmp->master_offset = 0; 390 | count++; 391 | } 392 | } 393 | 394 | log_err("... skip, incorrect '%s' format\n", dt_tag); 395 | break; 396 | } 397 | } else if (msmversion == 2 || msmversion == 3) { 398 | if ((pos = strstr(line, dt_tag)) != NULL) { 399 | pos += strlen(dt_tag); 400 | 401 | entryEndedDT = 0; 402 | for (;entryEndedDT < 1;) { 403 | entryValidDT = 1; 404 | for (i = 0; i < 2; i++) { 405 | tok = strtok_r(pos, " \t", &sptr); 406 | pos = NULL; 407 | if (tok != NULL) { 408 | if (*tok == '>') { 409 | entryEndedDT = 1; 410 | entryValidDT = 0; 411 | break; 412 | } 413 | data_st[i] = strtoul(tok, NULL, 0); 414 | } else { 415 | data_st[i] = 0; 416 | entryValidDT = 0; 417 | entryEndedDT = 1; 418 | } 419 | } 420 | 421 | if (entryValidDT) { 422 | tmp_id = (struct chipId_t *) 423 | malloc(sizeof(struct chipId_t)); 424 | if (!tmp_id) { 425 | log_err("Out of memory\n"); 426 | break; 427 | } 428 | if (!chipId) { 429 | chipId = tmp_id; 430 | cId = tmp_id; 431 | chipId->t_next = NULL; 432 | } else { 433 | tmp_id->t_next = chipId->t_next; 434 | chipId->t_next = tmp_id; 435 | } 436 | tmp_id->chipset = data_st[0]; 437 | tmp_id->revNum= data_st[1]; 438 | count1++; 439 | } 440 | } 441 | } 442 | 443 | if ((pos = strstr(line,QCDT_BOARD_TAG)) != NULL) { 444 | pos += strlen(QCDT_BOARD_TAG); 445 | entryEndedST = 0; 446 | for (;entryEndedST < 1;) { 447 | entryValidST = 1; 448 | for (i = 0; i < 3; i++) { 449 | tok = strtok_r(pos, " \t", &sptr); 450 | pos = NULL; 451 | if (tok != NULL) { 452 | if (*tok == '>') { 453 | entryEndedST = 1; 454 | entryValidST = 0; 455 | break; 456 | } 457 | data_st[i] = strtoul(tok, NULL, 0); 458 | } else { 459 | data_st[i] = 0; 460 | entryValidST = 0; 461 | entryEndedST = 1; 462 | } 463 | } 464 | if (entryValidST) { 465 | tmp_st = (struct chipSt_t *) 466 | malloc(sizeof(struct chipSt_t)); 467 | if (!tmp_st) { 468 | log_err("Out of memory\n"); 469 | break; 470 | } 471 | 472 | if (!chipSt) { 473 | chipSt = tmp_st; 474 | cSt = tmp_st; 475 | chipSt->t_next = NULL; 476 | } else { 477 | tmp_st->t_next = chipSt->t_next; 478 | chipSt->t_next = tmp_st; 479 | } 480 | 481 | tmp_st->platform = data_st[0]; 482 | tmp_st->subtype= data_st[1]; 483 | tmp_st->oppoId = data_st[2]; 484 | count2++; 485 | } 486 | } 487 | } 488 | 489 | if ((pos = strstr(line,QCDT_PMIC_TAG)) != NULL) { 490 | pos += strlen(QCDT_PMIC_TAG); 491 | entryEndedPT = 0; 492 | for (;entryEndedPT < 1;) { 493 | entryValidPT = 1; 494 | for (i = 0; i < 4; i++) { 495 | tok = strtok_r(pos, " \t", &sptr); 496 | pos = NULL; 497 | if (tok != NULL) { 498 | if (*tok == '>') { 499 | entryEndedPT = 1; 500 | entryValidPT = 0; 501 | break; 502 | } 503 | data_pt[i] = strtoul(tok, NULL, 0); 504 | } else { 505 | data_pt[i] = 0; 506 | entryValidPT = 0; 507 | entryEndedPT = 1; 508 | } 509 | } 510 | if (entryValidPT) { 511 | tmp_pt = (struct chipPt_t *) 512 | malloc(sizeof(struct chipPt_t)); 513 | if (!tmp_pt) { 514 | log_err("Out of memory\n"); 515 | break; 516 | } 517 | 518 | if (!chipPt) { 519 | chipPt = tmp_pt; 520 | cPt = tmp_pt; 521 | chipPt->t_next = NULL; 522 | } else { 523 | tmp_pt->t_next = chipPt->t_next; 524 | chipPt->t_next = tmp_pt; 525 | } 526 | 527 | tmp_pt->pmic0 = data_pt[0]; 528 | tmp_pt->pmic1 = data_pt[1]; 529 | tmp_pt->pmic2 = data_pt[2]; 530 | tmp_pt->pmic3 = data_pt[3]; 531 | count3++; 532 | } 533 | } 534 | } 535 | } 536 | } 537 | } 538 | 539 | if (line) 540 | free(line); 541 | 542 | if (count1 == 0) { 543 | log_err("... skip, incorrect '%s' format\n", dt_tag); 544 | return NULL; 545 | } 546 | if (count2 == 0) { 547 | log_err("... skip, incorrect '%s' format\n", QCDT_BOARD_TAG); 548 | return NULL; 549 | } 550 | if (count3 == 0 && msmversion == 3) { 551 | log_err("... skip, incorrect '%s' format\n", QCDT_PMIC_TAG); 552 | return NULL; 553 | } 554 | 555 | tmp_st = cSt; 556 | tmp_pt = cPt; 557 | while (cId != NULL) { 558 | while (cSt != NULL) { 559 | if (msmversion == 3) { 560 | while (cPt != NULL) { 561 | tmp = (struct chipInfo_t *) 562 | malloc(sizeof(struct chipInfo_t)); 563 | if (!tmp) { 564 | log_err("Out of memory\n"); 565 | break; 566 | } 567 | if (!chip) { 568 | chip = tmp; 569 | chip->t_next = NULL; 570 | } else { 571 | tmp->t_next = chip->t_next; 572 | chip->t_next = tmp; 573 | } 574 | 575 | tmp->chipset = cId->chipset; 576 | tmp->platform = cSt->platform; 577 | tmp->revNum = cId->revNum; 578 | tmp->subtype = cSt->subtype; 579 | tmp->pmic_model[0] = cPt->pmic0; 580 | tmp->pmic_model[1] = cPt->pmic1; 581 | tmp->pmic_model[2] = cPt->pmic2; 582 | tmp->pmic_model[3] = cPt->pmic3; 583 | tmp->oppoId = cSt->oppoId; 584 | tmp->dtb_size = 0; 585 | tmp->dtb_file = NULL; 586 | tmp->master = chip; 587 | tmp->wroteDtb = 0; 588 | tmp->master_offset = 0; 589 | cPt = cPt->t_next; 590 | } 591 | cPt = tmp_pt; 592 | } else { 593 | tmp = (struct chipInfo_t *) 594 | malloc(sizeof(struct chipInfo_t)); 595 | if (!tmp) { 596 | log_err("Out of memory\n"); 597 | break; 598 | } 599 | if (!chip) { 600 | chip = tmp; 601 | chip->t_next = NULL; 602 | } else { 603 | tmp->t_next = chip->t_next; 604 | chip->t_next = tmp; 605 | } 606 | tmp->chipset = cId->chipset; 607 | tmp->platform = cSt->platform; 608 | tmp->revNum = cId->revNum; 609 | tmp->subtype = cSt->subtype; 610 | tmp->pmic_model[0] = 0; 611 | tmp->pmic_model[1] = 0; 612 | tmp->pmic_model[2] = 0; 613 | tmp->pmic_model[3] = 0; 614 | tmp->oppoId = cSt->oppoId; 615 | tmp->dtb_size = 0; 616 | tmp->dtb_file = NULL; 617 | tmp->master = chip; 618 | tmp->wroteDtb = 0; 619 | tmp->master_offset = 0; 620 | } 621 | cSt = cSt->t_next; 622 | } 623 | cSt = tmp_st; 624 | cId = cId->t_next; 625 | } 626 | 627 | if (msmversion == 2) 628 | entryEndedPT = 1; 629 | 630 | /* clear memory*/ 631 | pclose(pfile); 632 | while (chipId) { 633 | chipId_tmp = chipId; 634 | chipId = chipId->t_next; 635 | free(chipId_tmp); 636 | } 637 | while (chipSt) { 638 | chipSt_tmp= chipSt; 639 | chipSt = chipSt->t_next; 640 | free(chipSt_tmp); 641 | } 642 | 643 | while (chipPt) { 644 | chipPt_tmp= chipPt; 645 | chipPt = chipPt->t_next; 646 | free(chipPt_tmp); 647 | } 648 | 649 | if (entryEndedST == 1 && entryEndedDT == 1 && entryEndedPT == 1) { 650 | *num = count1; 651 | return chip; 652 | } 653 | 654 | /* clear memory*/ 655 | while (chip) { 656 | chip_t = chip; 657 | chip = chip->next; 658 | if (chip_t->dtb_file) 659 | free(chip_t->dtb_file); 660 | free(chip_t); 661 | } 662 | return NULL; 663 | } 664 | 665 | /* Get the version-id based on dtb files */ 666 | uint32_t GetVersionInfo(const char *filename) 667 | { 668 | const char str1[] = "dtc -I dtb -O dts \""; 669 | const char str2[] = "\" 2>&1"; 670 | char *buf, *pos; 671 | char *line = NULL; 672 | size_t line_size; 673 | FILE *pfile; 674 | int llen; 675 | uint32_t v = 1; 676 | 677 | line_size = 1024; 678 | line = (char *)malloc(line_size); 679 | if (!line) { 680 | log_err("Out of memory\n"); 681 | return 0; 682 | } 683 | 684 | llen = sizeof(char) * (strlen(dtc_path) + 685 | strlen(str1) + 686 | strlen(str2) + 687 | strlen(filename) + 1); 688 | buf = (char *)malloc(llen); 689 | if (!buf) { 690 | log_err("Out of memory\n"); 691 | free(line); 692 | return 0; 693 | } 694 | 695 | strncpy(buf, dtc_path, llen); 696 | strncat(buf, str1, llen); 697 | strncat(buf, filename, llen); 698 | strncat(buf, str2, llen); 699 | 700 | pfile = popen(buf, "r"); 701 | free(buf); 702 | 703 | if (pfile == NULL) { 704 | log_err("... skip, fail to decompile dtb\n"); 705 | } else { 706 | /* Find the type of version */ 707 | while ((llen = getline(&line, &line_size, pfile)) != -1) { 708 | if ((pos = strstr(line,QCDT_BOARD_TAG)) != NULL) { 709 | v = 2; 710 | } 711 | if ((pos = strstr(line,QCDT_PMIC_TAG)) != NULL) { 712 | v = 3; 713 | break; 714 | } 715 | } 716 | } 717 | 718 | free(line); 719 | log_info("Version:%d\n", v); 720 | 721 | return v; 722 | } 723 | 724 | static int find_dtb(const char *path, uint32_t *version) 725 | { 726 | struct dirent *dp; 727 | int flen; 728 | char *filename; 729 | struct chipInfo_t *chip, *t_chip; 730 | struct stat st; 731 | int num; 732 | int rc = RC_SUCCESS; 733 | uint32_t msmversion = 0; 734 | int dtb_count = 0; 735 | 736 | DIR *dir = opendir(path); 737 | if (!dir) { 738 | log_err("Failed to open input directory '%s'\n", path); 739 | return RC_ERROR; 740 | } 741 | 742 | /* Open the .dtb files in the specified path, decompile and 743 | extract "qcom,msm-id" parameter 744 | */ 745 | while ((dp = readdir(dir)) != NULL) { 746 | if (dp->d_type == DT_UNKNOWN) { 747 | struct stat statbuf; 748 | char name[PATH_MAX]; 749 | snprintf(name, sizeof(name), "%s%s%s", 750 | path, 751 | (path[strlen(path) - 1] == '/' ? "" : "/"), 752 | dp->d_name); 753 | if (!stat(name, &statbuf)) { 754 | if (S_ISREG(statbuf.st_mode)) { 755 | dp->d_type = DT_REG; 756 | } else if (S_ISDIR(statbuf.st_mode)) { 757 | dp->d_type = DT_DIR; 758 | } 759 | } 760 | } 761 | 762 | if (dp->d_type == DT_DIR) { 763 | char name[PATH_MAX]; 764 | if (dp->d_name[0] == '.') { 765 | continue; 766 | } 767 | snprintf(name, sizeof(name), "%s%s%s%s", 768 | path, 769 | (path[strlen(path) - 1] == '/' ? "" : "/"), 770 | dp->d_name, 771 | "/"); 772 | log_info("Searching subdir: %s ... \n", name); 773 | dtb_count += find_dtb(name, version); 774 | } else if (dp->d_type == DT_REG) { 775 | flen = strlen(dp->d_name); 776 | if ((flen > 4) && 777 | (strncmp(&dp->d_name[flen-4], ".dtb", 4) == 0)) { 778 | log_info("Found file: %s ... \n", dp->d_name); 779 | 780 | flen = strlen(path) + strlen(dp->d_name) + 1; 781 | filename = (char *)malloc(flen); 782 | if (!filename) { 783 | log_err("Out of memory\n"); 784 | rc = RC_ERROR; 785 | break; 786 | } 787 | strncpy(filename, path, flen); 788 | strncat(filename, dp->d_name, flen); 789 | 790 | /* To identify the version number */ 791 | msmversion = GetVersionInfo(filename); 792 | if (*version < msmversion) { 793 | *version = msmversion; 794 | } 795 | 796 | num = 1; 797 | chip = getChipInfo(filename, &num, msmversion); 798 | 799 | if (msmversion == 1) { 800 | if (!chip) { 801 | log_err("skip, failed to scan for '%s' tag\n", dt_tag); 802 | free(filename); 803 | continue; 804 | } 805 | } 806 | if (msmversion == 2) { 807 | if (!chip) { 808 | log_err("skip, failed to scan for '%s' or '%s' tag\n", 809 | dt_tag, QCDT_BOARD_TAG); 810 | free(filename); 811 | continue; 812 | } 813 | } 814 | if (msmversion == 3) { 815 | if (!chip) { 816 | log_err("skip, failed to scan for '%s', '%s' or '%s' tag\n", 817 | dt_tag, QCDT_BOARD_TAG, QCDT_PMIC_TAG); 818 | free(filename); 819 | continue; 820 | } 821 | } 822 | 823 | if ((stat(filename, &st) != 0) || 824 | (st.st_size == 0)) { 825 | log_err("skip, failed to get DTB size\n"); 826 | free(filename); 827 | continue; 828 | } 829 | 830 | log_info("chipset: %u, rev: %u, platform: %u, subtype: %u, oppoId: %u, pmic0: %u, pmic1: %u, pmic2: %u, pmic3: %u\n", 831 | chip->chipset, chip->revNum, chip->platform, chip->subtype, chip->oppoId, 832 | chip->pmic_model[0], chip->pmic_model[1], chip->pmic_model[2], chip->pmic_model[3]); 833 | 834 | for (t_chip = chip->t_next; t_chip; t_chip = t_chip->t_next) { 835 | log_info("additional chipset: %u, rev: %u, platform: %u, subtype: %u, oppoId: %u pmic0: %u, pmic1: %u, pmic2: %u, pmic3: %u\n", 836 | t_chip->chipset, t_chip->revNum, t_chip->platform, t_chip->subtype, t_chip->oppoId, 837 | t_chip->pmic_model[0], t_chip->pmic_model[1], t_chip->pmic_model[2], t_chip->pmic_model[3]); 838 | } 839 | 840 | rc = chip_add(chip); 841 | if (rc != RC_SUCCESS) { 842 | log_err("... duplicate info, skipped\n"); 843 | free(filename); 844 | continue; 845 | } 846 | 847 | dtb_count++; 848 | 849 | chip->dtb_size = st.st_size + 850 | (page_size - (st.st_size % page_size)); 851 | chip->dtb_file = filename; 852 | 853 | for (t_chip = chip->t_next; t_chip; t_chip = t_chip->t_next) { 854 | rc = chip_add(t_chip); 855 | if (rc != RC_SUCCESS) { 856 | log_err("... duplicate info, skipped (chipset %u, rev: %u, platform: %u, subtype: %u, oppoId: %u\n", 857 | t_chip->chipset, t_chip->revNum, t_chip->platform, t_chip->subtype, t_chip->oppoId); 858 | continue; 859 | } 860 | dtb_count++; 861 | } 862 | } 863 | } 864 | } 865 | closedir(dir); 866 | return dtb_count; 867 | } 868 | 869 | /* Extract 'qcom,msm-id' 'qcom,board-id' parameter from DTB 870 | v1 format: 871 | qcom,msm-id = [, ...]; 872 | v2 format: 873 | qcom,msm-id = [, ...; 874 | qcom,board-id = [, ...; 875 | Fields: 876 | x = chipset 877 | y = platform 878 | y' = subtype 879 | z = soc rev 880 | */ 881 | int main(int argc, char **argv) 882 | { 883 | char buf[COPY_BLK]; 884 | struct chipInfo_t *chip; 885 | FILE *pInputFile; 886 | int padding; 887 | uint8_t *filler = NULL; 888 | int numBytesRead = 0; 889 | int totBytesRead = 0; 890 | int out_fd; 891 | int rc = RC_SUCCESS; 892 | int dtb_count = 0, dtb_offset = 0, entry_size; 893 | size_t wrote = 0, expected = 0; 894 | uint32_t dtb_size; 895 | uint32_t version = 0; 896 | char *filename; 897 | 898 | log_info("DTB combiner:\n"); 899 | 900 | if (parse_commandline(argc, argv) != RC_SUCCESS) { 901 | print_help(); 902 | return RC_ERROR; 903 | } 904 | 905 | log_info(" Input directory: '%s'\n", input_dir); 906 | log_info(" Output file: '%s'\n", output_file); 907 | 908 | 909 | filler = (uint8_t *)malloc(page_size); 910 | if (!filler) { 911 | log_err("Out of memory\n"); 912 | return RC_ERROR; 913 | } 914 | memset(filler, 0, page_size); 915 | 916 | dtb_count = find_dtb(input_dir, &version); 917 | 918 | log_info("=> Found %d unique DTB(s)\n", dtb_count); 919 | 920 | if (!dtb_count) 921 | goto cleanup; 922 | 923 | 924 | /* Generate the master DTB file: 925 | 926 | Simplify write error handling by just checking for actual vs 927 | expected bytes written at the end. 928 | */ 929 | 930 | log_info("\nGenerating master DTB... "); 931 | 932 | out_fd = open(output_file, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR); 933 | if (out_fd == -1) { 934 | log_err("Cannot create '%s'\n", output_file); 935 | rc = RC_ERROR; 936 | goto cleanup; 937 | } 938 | 939 | if (version_override != 0) { 940 | version = version_override; 941 | } 942 | 943 | if (version == 1) { 944 | entry_size = 20; 945 | } else if (version == 2) { 946 | entry_size = 28; 947 | } else { 948 | entry_size = 44; 949 | } 950 | 951 | /* Write header info */ 952 | wrote += write(out_fd, QCDT_MAGIC, sizeof(uint8_t) * 4); /* magic */ 953 | wrote += write(out_fd, &version, sizeof(uint32_t)); /* version */ 954 | wrote += write(out_fd, (uint32_t *)&dtb_count, sizeof(uint32_t)); 955 | /* #DTB */ 956 | 957 | /* Calculate offset of first DTB block */ 958 | dtb_offset = 12 + /* header */ 959 | (entry_size * dtb_count) + /* DTB table entries */ 960 | 4; /* end of table indicator */ 961 | 962 | /* Round up to page size */ 963 | padding = page_size - (dtb_offset % page_size); 964 | dtb_offset += padding; 965 | expected = dtb_offset; 966 | 967 | /* Write index table: 968 | chipset 969 | platform 970 | subtype (v2/v3 only) 971 | soc rev 972 | OPPO ID (v2/v3 only) 973 | pmic model0 (v3 only) 974 | pmic model1 (v3 only) 975 | pmic model2 (v3 only) 976 | pmic model3 (v3 only) 977 | dtb offset 978 | dtb size 979 | */ 980 | for (chip = chip_list; chip; chip = chip->next) { 981 | wrote += write(out_fd, &chip->chipset, sizeof(uint32_t)); 982 | wrote += write(out_fd, &chip->platform, sizeof(uint32_t)); 983 | if (version >= 2) { 984 | wrote += write(out_fd, &chip->subtype, sizeof(uint32_t)); 985 | } 986 | wrote += write(out_fd, &chip->revNum, sizeof(uint32_t)); 987 | if (version >= 2) { 988 | wrote += write(out_fd, &chip->oppoId, sizeof(uint32_t)); 989 | } 990 | if (version >= 3) { 991 | wrote += write(out_fd, &chip->pmic_model[0], sizeof(uint32_t)); 992 | wrote += write(out_fd, &chip->pmic_model[1], sizeof(uint32_t)); 993 | wrote += write(out_fd, &chip->pmic_model[2], sizeof(uint32_t)); 994 | wrote += write(out_fd, &chip->pmic_model[3], sizeof(uint32_t)); 995 | } 996 | if (chip->master->master_offset != 0) { 997 | wrote += write(out_fd, &chip->master->master_offset, sizeof(uint32_t)); 998 | } else { 999 | wrote += write(out_fd, &expected, sizeof(uint32_t)); 1000 | chip->master->master_offset = expected; 1001 | expected += chip->master->dtb_size; 1002 | } 1003 | wrote += write(out_fd, &chip->master->dtb_size, sizeof(uint32_t)); 1004 | } 1005 | 1006 | rc = RC_SUCCESS; 1007 | wrote += write(out_fd, &rc, sizeof(uint32_t)); /* end of table indicator */ 1008 | if (padding > 0) 1009 | wrote += write(out_fd, filler, padding); 1010 | 1011 | /* Write DTB's */ 1012 | for (chip = chip_list; chip; chip = chip->next) { 1013 | if (chip->master->wroteDtb) { 1014 | continue; 1015 | } 1016 | 1017 | chip->master->wroteDtb = 1; 1018 | filename = chip->master->dtb_file; 1019 | dtb_size = chip->master->dtb_size; 1020 | 1021 | log_dbg("\n (writing '%s' - %u bytes) ", filename, dtb_size); 1022 | pInputFile = fopen(filename, "r"); 1023 | if (pInputFile != NULL) { 1024 | totBytesRead = 0; 1025 | while ((numBytesRead = fread(buf, 1, COPY_BLK, pInputFile)) > 0) { 1026 | wrote += write(out_fd, buf, numBytesRead); 1027 | totBytesRead += numBytesRead; 1028 | } 1029 | fclose(pInputFile); 1030 | padding = page_size - (totBytesRead % page_size); 1031 | if ((uint32_t)(totBytesRead + padding) != dtb_size) { 1032 | log_err("DTB size mismatch, please re-run: expected %d vs actual %d (%s)\n", 1033 | dtb_size, totBytesRead + padding, 1034 | filename); 1035 | rc = RC_ERROR; 1036 | break; 1037 | } 1038 | if (padding > 0) 1039 | wrote += write(out_fd, filler, padding); 1040 | } else { 1041 | log_err("failed to open DTB '%s'\n", filename); 1042 | rc = RC_ERROR; 1043 | break; 1044 | } 1045 | } 1046 | close(out_fd); 1047 | 1048 | if (expected != wrote) { 1049 | log_err("error writing output file, please rerun: size mismatch %zu vs %zu\n", 1050 | expected, wrote); 1051 | rc = RC_ERROR; 1052 | } else 1053 | log_dbg("Total wrote %zu bytes\n", wrote); 1054 | 1055 | if (rc != RC_SUCCESS) 1056 | unlink(output_file); 1057 | else 1058 | log_info("completed\n"); 1059 | 1060 | cleanup: 1061 | free(filler); 1062 | chip_deleteall(); 1063 | return rc; 1064 | } 1065 | -------------------------------------------------------------------------------- /0002-build-gcc-4.9/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | BUILD_START=$(date +"%s") 3 | tcdir=${HOME}/android/TOOLS/GCC 4 | ak_dir=anykernel/anykernel3 5 | 6 | [ -d "out" ] && rm -rf out && mkdir -p out || mkdir -p out 7 | 8 | [ -d $tcdir ] && \ 9 | echo "ARM64 TC Present." || \ 10 | echo "ARM64 TC Not Present. Downloading..." | \ 11 | git clone --depth=1 https://github.com/LineageOS/android_prebuilts_gcc_linux-x86_aarch64_aarch64-linux-android-4.9 $tcdir/los-4.9-64 12 | 13 | [ -d $tcdir ] && \ 14 | echo "ARM32 TC Present." || \ 15 | echo "ARM32 TC Not Present. Downloading..." | \ 16 | git clone --depth=1 https://github.com/LineageOS/android_prebuilts_gcc_linux-x86_arm_arm-linux-androideabi-4.9 $tcdir/los-4.9-32 17 | 18 | make O=out ARCH=arm64 lineageos_a37f_defconfig 19 | 20 | PATH="$tcdir/los-4.9-64/bin:$tcdir/los-4.9-32/bin:${PATH}" \ 21 | make O=out \ 22 | ARCH=arm64 \ 23 | CC="ccache $tcdir/los-4.9-64/bin/aarch64-linux-android-gcc" \ 24 | CROSS_COMPILE=aarch64-linux-android- \ 25 | CROSS_COMPILE_ARM32=arm-linux-androideabi- \ 26 | CONFIG_NO_ERROR_ON_MISMATCH=y \ 27 | CONFIG_DEBUG_SECTION_MISMATCH=y \ 28 | -j$(nproc --all) || exit 29 | 30 | cp out/arch/arm64/boot/Image $ak_dir 31 | 32 | cc $ak_dir/../dtbtool.c -o out/arch/arm64/boot/dts/dtbtool 33 | ( cd out/arch/arm64/boot/dts; dtbtool -v -s 2048 -o dt.img ) 34 | 35 | [ -d $ak_dir ] && echo -e "\nAnykernel 3 Present.\n" \ 36 | || mkdir -p $ak_dir \ 37 | | git clone --depth=1 https://github.com/osm0sis/AnyKernel3 $ak_dir 38 | rm $ak_dir/anykernel.sh 39 | cp $ak_dir/../anykernel.sh $ak_dir 40 | 41 | ( cd $ak_dir; zip -r ../out/A37F_KERNEL_`date +%d\.%m\.%Y_%H\:%M\:%S`.zip . -x 'LICENSE' 'README.md' 'dtbtool.c' ) 42 | 43 | BUILD_END=$(date +"%s") 44 | DIFF=$(($BUILD_END - $BUILD_START)) 45 | echo -e "Build completed in $(($DIFF / 60)) minute(s) and $(($DIFF % 60)) seconds." 46 | -------------------------------------------------------------------------------- /0003-clean-dts/README.md: -------------------------------------------------------------------------------- 1 | ## 2. cleandts.sh ## 2 | 3 | ### About: ### 4 | 5 | Cleans decompiled dts files to make it easier to diff between two for getting major changes in devicetree. 6 | 7 | ### Issue addressed: ### 8 | 9 | There will be times when you only have two dtb files and just want to quickly check what's different between them. 10 | 11 | The only issue is that it's riddled with phandles and other addresses which get slightly shifted which completely messes up the diff detection in almost all diffing programs. 12 | 13 | My script just cleans said nuisances and tries to make both of the dts as consistent as possible. 14 | 15 | ### Usage: ### 16 | 17 | `./cleandts.sh your_decompiled_dts_01.dts` 18 | `./cleandts.sh your_decompiled_dts_01.dts` 19 | 20 | These will output 21 | 22 | your_decompiled_dts_01_diff.dts 23 | your_decompiled_dts_02_diff.dts 24 | 25 | Then you can use something like meld to compare the two and get only the relevant changes 26 | 27 | You can also put this in your bin folder and use it from anywhere 28 | -------------------------------------------------------------------------------- /0003-clean-dts/cleandts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | clean() { 3 | cp $1 ${1::-4}_diff.dts 4 | sed -i 's/linux\,phandle \= [<]0x[0-9 A-Z a-z]*[>][;]//g' ${1::-4}_diff.dts 5 | sed -i 's/phandle \= [<]0x[0-9 A-Z a-z]*[>][;]//g' ${1::-4}_diff.dts 6 | sed -i 's/0x00/0x0/g' ${1::-4}_diff.dts 7 | sed -i 's/okay/ok/g' ${1::-4}_diff.dts 8 | sed -i 's/fragment@\([0-9]*\)/fragment/g' ${1::-4}_diff.dts 9 | sed -i 's/[ \t]*$//' ${1::-4}_diff.dts 10 | awk 'BEGIN{RS="";ORS="\n\n"}1' ${1::-4}_diff.dts > ${1::-4}_diff_final.dts && rm ${1::-4}_diff.dts && mv ${1::-4}_diff_final.dts ${1::-4}_diff.dts 11 | sed -i 's/[ \t]*$//' ${1::-4}_diff.dts 12 | } 13 | 14 | clean $1 15 | -------------------------------------------------------------------------------- /0004-dtb-dts-converter-reconverter/README.md: -------------------------------------------------------------------------------- 1 | ## 4. dtstodtb.sh dtbtodts.sh ## 2 | 3 | ### About: ### 4 | 5 | Converts all .dtb in current dir to .dts and .dts in current dir to .dtb 6 | 7 | PS: non-recursive so dw about it going to places you don't want it to go to XD 8 | 9 | ### Usage: ### 10 | 11 | `cd dir_with_dtb_or_dts` 12 | `./dtbtodts.sh` 13 | `./dtstodtb.sh` 14 | 15 | These will output 16 | 17 | your_decompiled_dts_01_extracted.dts 18 | your_decompiled_dts_02_recompiled.dtb 19 | 20 | Respectively. 21 | 22 | Then you can use the 0003-clean-dts script to cleanup the extracted ones for diffing if you want to, 23 | 24 | You can also put this in your bin folder and use it from anywhere 25 | -------------------------------------------------------------------------------- /0004-dtb-dts-converter-reconverter/dtbtodts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | for f in $(find . -maxdepth 1 -iname "*.dtb"); do dtc -I dtb -O dts -o ${f/\.dtb/}_extracted.dts $f; done 3 | -------------------------------------------------------------------------------- /0004-dtb-dts-converter-reconverter/dtstodtb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | for f in $(find . -maxdepth 1 -iname "*.dts"); do dtc -I dts -O dtb -o ${f/\.dts/}_recompiled.dtb $f; done 3 | -------------------------------------------------------------------------------- /0005-dtb-appender/README.md: -------------------------------------------------------------------------------- 1 | ## 5. catdtb.sh ## 2 | 3 | ### About: ### 4 | 5 | Ever had a moment where you forgot to add some overlay change but your kernel build started already and you're too lazy to recompile just to add that one small change ? 6 | 7 | Well look no further lol you can just use this to lazily append the modified dtb to the compiled kernel image (Image.gz) 8 | 9 | ### Usage: ### 10 | 11 | Grab "Image.gz" from out/arch/arm64/boot. 12 | 13 | Redo the build with `make dtbs` command. 14 | 15 | This will only compile the final dtb using the modded overlay. 16 | 17 | Grab the new dtb from out/arch/arm64/boot/dts/qcom/whatever.dtb 18 | 19 | Copy it over to the same dir where you copied Image.gz from earlier. 20 | 21 | Run 22 | 23 | `./catdtb.sh` 24 | 25 | This will output 26 | 27 | Image.gz-dtb 28 | 29 | Aaand there you have it XD flash away and happy building :D 30 | -------------------------------------------------------------------------------- /0005-dtb-appender/catdtb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | for f in $(find . -maxdepth 1 -iname "*.dtb"); do cat $f >> $1; done 3 | mv $1 Image.gz-dtb 4 | -------------------------------------------------------------------------------- /0006-arm-magisk-patch/README.md: -------------------------------------------------------------------------------- 1 | ## 6. arm-magisk-patch.sh ## 2 | 3 | ### About: ### 4 | boot image magisk patcher for arm devices 5 | 6 | ### Usage: ### 7 | 8 | Assuming boot image name as boot.img 9 | 10 | 1. `curl -LSsO https://github.com/Jebaitedneko/scripts/raw/master/0006-arm-magisk-patch/arm-magisk-patch.sh` 11 | 2. `chmod +x arm-magisk-patch.sh` 12 | 3. `./arm-magisk-patch.sh boot.img` 13 | 14 | Repacked image will be boot_repacked.img 15 | -------------------------------------------------------------------------------- /0006-arm-magisk-patch/arm-magisk-patch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo -e "\ncarving out headers from ${1}..." 4 | dd if=$1 of=headers bs=1 skip=0 count=$(grep -obaP "\x1F\x8B\x08" $1 | cut -f1 -d ":" | head -n1) 5 | 6 | echo -e "\ncarving out Image.gz-dtb from ${1} ..." 7 | dd if=$1 of=Image.gz-dtb bs=1 skip=$(grep -obaP "\x1F\x8B\x08" $1 | cut -f1 -d ":" | head -n1) 8 | 9 | echo -e "\ncarving out dtbs from ${1} ..." 10 | dd if=$1 of=dtbs bs=1 skip=$(grep -obaP "\xD0\x0D\xFE\xED" Image.gz-dtb | cut -f1 -d ":" | head -n1) 11 | 12 | echo -e "\ngunzip Image.gz-dtb in progress ..." 13 | mv Image.gz-dtb Image.gz && 7z x Image.gz 14 | 15 | echo -e "\npatching for magisk (skip_initramfs -> want_initramfs) ..." 16 | sed -i "s|\x73\x6b\x69\x70\x5f\x69\x6e\x69\x74\x72\x61\x6d\x66\x73|\x77\x61\x6e\x74\x5f\x69\x6e\x69\x74\x72\x61\x6d\x66\x73|g" Image 17 | 18 | echo -e "\ngzip Image in progress ..." 19 | 7z a -mx9 Image.gz Image 20 | 21 | echo -e "\nAppending dtbs to the end of Image.gz ..." 22 | cat dtbs >> Image.gz && rm dtbs && mv Image.gz Image.gz-dtb 23 | 24 | echo -e "\nAppending Image.gz-dtb to the end of arm header ..." 25 | cat Image.gz-dtb >> headers && rm Image.gz-dtb 26 | 27 | echo -e "\nRenaming to ${1::-4}_repacked.img" 28 | mv headers ${1::-4}_repacked.img 29 | -------------------------------------------------------------------------------- /0007-touch-fw-dumper/.src: -------------------------------------------------------------------------------- 1 | https://bigota.d.miui.com/V12.0.1.0.RJUTWXM/miui_VAYUTWGlobal_V12.0.1.0.RJUTWXM_00aa3cfefa_11.0.zip 2 | https://bigota.d.miui.com/V12.0.2.0.RJUTRXM/miui_VAYUTRGlobal_V12.0.2.0.RJUTRXM_9a06cb8258_11.0.zip 3 | https://bigota.d.miui.com/V12.0.2.0.RJUTWXM/miui_VAYUTWGlobal_V12.0.2.0.RJUTWXM_217c95e9d4_11.0.zip 4 | https://bigota.d.miui.com/V12.0.3.0.RJUIDXM/miui_VAYUIDGlobal_V12.0.3.0.RJUIDXM_1511576317_11.0.zip 5 | https://bigota.d.miui.com/V12.0.3.0.RJURUXM/miui_VAYURUGlobal_V12.0.3.0.RJURUXM_f2c7080ff6_11.0.zip 6 | https://bigota.d.miui.com/V12.0.4.0.RJUEUXM/miui_VAYUEEAGlobal_V12.0.4.0.RJUEUXM_9d5ae2d814_11.0.zip 7 | https://bigota.d.miui.com/V12.0.4.0.RJUINXM/miui_VAYUINGlobal_V12.0.4.0.RJUINXM_e54da35521_11.0.zip 8 | https://bigota.d.miui.com/V12.0.4.0.RJUMIXM/miui_VAYUGlobal_V12.0.4.0.RJUMIXM_503a04bdd4_11.0.zip 9 | https://bigota.d.miui.com/V12.0.5.0.RJUEUXM/miui_VAYUEEAGlobal_V12.0.5.0.RJUEUXM_756afb9384_11.0.zip 10 | https://bigota.d.miui.com/V12.0.5.0.RJUINXM/miui_VAYUINGlobal_V12.0.5.0.RJUINXM_17d5ede63d_11.0.zip 11 | https://bigota.d.miui.com/V12.0.6.0.RJUMIXM/miui_VAYUGlobal_V12.0.6.0.RJUMIXM_eccd7da42b_11.0.zip 12 | https://bigota.d.miui.com/V12.0.6.0.RJURUXM/miui_VAYURUGlobal_V12.0.6.0.RJURUXM_55d1244f4a_11.0.zip 13 | https://bigota.d.miui.com/V12.5.1.0.RJUEUXM/miui_VAYUEEAGlobal_V12.5.1.0.RJUEUXM_8f1ef5258e_11.0.zip 14 | https://bigota.d.miui.com/V12.5.1.0.RJUIDXM/miui_VAYUIDGlobal_V12.5.1.0.RJUIDXM_28e1b99312_11.0.zip 15 | https://bigota.d.miui.com/V12.5.1.0.RJUMIXM/miui_VAYUGlobal_V12.5.1.0.RJUMIXM_502138f418_11.0.zip 16 | https://bigota.d.miui.com/V12.5.1.0.RJURUXM/miui_VAYURUGlobal_V12.5.1.0.RJURUXM_cfe292d16a_11.0.zip 17 | https://bigota.d.miui.com/V12.5.1.0.RJUTRXM/miui_VAYUTRGlobal_V12.5.1.0.RJUTRXM_c8e5e7739f_11.0.zip 18 | https://bigota.d.miui.com/V12.5.1.0.RJUTWXM/miui_VAYUTWGlobal_V12.5.1.0.RJUTWXM_1152276715_11.0.zip 19 | https://bigota.d.miui.com/V12.5.2.0.RJUEUXM/miui_VAYUEEAGlobal_V12.5.2.0.RJUEUXM_f042fd8556_11.0.zip 20 | https://bigota.d.miui.com/V12.5.2.0.RJUIDXM/miui_VAYUIDGlobal_V12.5.2.0.RJUIDXM_ccd5ae2bf8_11.0.zip 21 | https://bigota.d.miui.com/V12.5.2.0.RJUMIXM/miui_VAYUGlobal_V12.5.2.0.RJUMIXM_450711067e_11.0.zip 22 | https://bigota.d.miui.com/V12.5.2.0.RJUTRXM/miui_VAYUTRGlobal_V12.5.2.0.RJUTRXM_8b507ca133_11.0.zip 23 | https://bigota.d.miui.com/V12.5.2.0.RJUTWXM/miui_VAYUTWGlobal_V12.5.2.0.RJUTWXM_661e96fd4f_11.0.zip 24 | https://bigota.d.miui.com/V12.5.3.0.RJUEUXM/miui_VAYUEEAGlobal_V12.5.3.0.RJUEUXM_cd87d10d5f_11.0.zip 25 | https://bigota.d.miui.com/V12.5.3.0.RJUINXM/miui_VAYUINGlobal_V12.5.3.0.RJUINXM_eec8e9ea1a_11.0.zip 26 | https://bigota.d.miui.com/V12.5.3.0.RJUMIXM/miui_VAYUGlobal_V12.5.3.0.RJUMIXM_8c9f40a764_11.0.zip 27 | https://bigota.d.miui.com/V12.5.3.0.RJURUXM/miui_VAYURUGlobal_V12.5.3.0.RJURUXM_d2c495362f_11.0.zip 28 | https://bigota.d.miui.com/V12.5.3.0.RJUTRXM/miui_VAYUTRGlobal_V12.5.3.0.RJUTRXM_9ae0c1af71_11.0.zip 29 | https://bigota.d.miui.com/V12.5.3.0.RJUTWXM/miui_VAYUTWGlobal_V12.5.3.0.RJUTWXM_3340f2f777_11.0.zip 30 | https://bigota.d.miui.com/V12.5.4.0.RJUEUXM/miui_VAYUEEAGlobal_V12.5.4.0.RJUEUXM_c58b88dbee_11.0.zip 31 | https://bigota.d.miui.com/V12.5.4.0.RJUIDXM/miui_VAYUIDGlobal_V12.5.4.0.RJUIDXM_a0b73fd4eb_11.0.zip 32 | https://bigota.d.miui.com/V12.5.4.0.RJUINXM/miui_VAYUINGlobal_V12.5.4.0.RJUINXM_a0ae152bd5_11.0.zip 33 | https://bigota.d.miui.com/V12.5.4.0.RJUMIXM/miui_VAYUGlobal_V12.5.4.0.RJUMIXM_d43dee18b9_11.0.zip 34 | https://bigota.d.miui.com/V12.5.4.0.RJURUXM/miui_VAYURUGlobal_V12.5.4.0.RJURUXM_6bf1945100_11.0.zip 35 | https://bigota.d.miui.com/V12.5.4.0.RJUTRXM/miui_VAYUTRGlobal_V12.5.4.0.RJUTRXM_89cdd7fdee_11.0.zip 36 | https://bigota.d.miui.com/V12.5.5.0.RJUEUXM/miui_VAYUEEAGlobal_V12.5.5.0.RJUEUXM_65bf3713de_11.0.zip 37 | https://bigota.d.miui.com/V12.5.5.0.RJUIDXM/miui_VAYUIDGlobal_V12.5.5.0.RJUIDXM_b7bf22385b_11.0.zip 38 | https://bigota.d.miui.com/V12.5.5.0.RJUINXM/miui_VAYUINGlobal_V12.5.5.0.RJUINXM_7c5caa3f0c_11.0.zip 39 | https://bigota.d.miui.com/V12.5.5.0.RJUMIXM/miui_VAYUGlobal_V12.5.5.0.RJUMIXM_9217fed24b_11.0.zip 40 | https://bigota.d.miui.com/V12.5.5.0.RJURUXM/miui_VAYURUGlobal_V12.5.5.0.RJURUXM_eb9fa3c275_11.0.zip 41 | https://bigota.d.miui.com/V12.5.6.0.RJUIDXM/miui_VAYUIDGlobal_V12.5.6.0.RJUIDXM_03f03ad77b_11.0.zip 42 | https://bigota.d.miui.com/V12.5.6.0.RJUINXM/miui_VAYUINGlobal_V12.5.6.0.RJUINXM_448b9400c2_11.0.zip 43 | https://bigota.d.miui.com/V12.5.6.0.RJURUXM/miui_VAYURUGlobal_V12.5.6.0.RJURUXM_c32051259a_11.0.zip 44 | https://bigota.d.miui.com/V12.5.7.0.RJUMIXM/miui_VAYUGlobal_V12.5.7.0.RJUMIXM_9847c652ee_11.0.zip 45 | https://bigota.d.miui.com/V12.5.9.0.RJUMIXM/miui_VAYUGlobal_V12.5.9.0.RJUMIXM_bddf74b11e_11.0.zip 46 | https://bigota.d.miui.com/V13.0.1.0.SJUEUXM/miui_VAYUEEAGlobal_V13.0.1.0.SJUEUXM_7ef0764aa8_12.0.zip 47 | https://bigota.d.miui.com/V13.0.1.0.SJUIDXM/miui_VAYUIDGlobal_V13.0.1.0.SJUIDXM_f50700f4ac_12.0.zip 48 | https://bigota.d.miui.com/V13.0.1.0.SJUINXM/miui_VAYUINGlobal_V13.0.1.0.SJUINXM_b603785914_12.0.zip 49 | https://bigota.d.miui.com/V13.0.1.0.SJURUXM/miui_VAYURUGlobal_V13.0.1.0.SJURUXM_5e4fbb4a70_12.0.zip 50 | https://bigota.d.miui.com/V13.0.1.0.SJUTRXM/miui_VAYUTRGlobal_V13.0.1.0.SJUTRXM_9d7d4ec87e_12.0.zip 51 | https://bigota.d.miui.com/V13.0.1.0.SJUTWXM/miui_VAYUTWGlobal_V13.0.1.0.SJUTWXM_e792e25c9d_12.0.zip 52 | https://bigota.d.miui.com/V13.0.3.0.SJUMIXM/miui_VAYUGlobal_V13.0.3.0.SJUMIXM_7d71e31adb_12.0.zip -------------------------------------------------------------------------------- /0007-touch-fw-dumper/README.md: -------------------------------------------------------------------------------- 1 | ## 7. dump_touch_fw.sh ## 2 | 3 | ### About: ### 4 | dump touch fw for poco x3 pro from an input direct fastboot rom link 5 | 6 | ### Usage: ### 7 | 8 | 1. `curl -LSsO https://github.com/Jebaitedneko/scripts/raw/master/0007-touch-fw-dumper/dump_touch_fw.sh` 9 | 2. `chmod +x dump_touch_fw.sh` 10 | 3. `./dump_touch_fw.sh direct_rom_link_here` 11 | 12 | ### NOTE ### 13 | 14 | You can provide `u` as second argument to the script to upload each zipped fw 15 | 16 | You can provide `k` as the third argument to the script to keep fw.xxd and kernel image 17 | 18 | #### COLAB INSTANCE #### 19 | Launch In Colab 20 | 21 | 1. Run Cell 1 22 | 2. Open Files tab from left sidebar 23 | 3. Drop a file named `.src` with direct links for roms with boot.img, line by line 24 | 4. Run Cell 2 25 | 5. Wait a bit until the fw are zipped and links generated to `links.txt` file 26 | -------------------------------------------------------------------------------- /0007-touch-fw-dumper/dump_touch_fw.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ROM_LINK="$1" 4 | 5 | ROM_NAME=$(echo "$ROM_LINK" | sed 's/.*\///;s/.zip//g') 6 | ROM_NAME_MIN="$(echo "$ROM_NAME" | sed 's/miui_VAYU//g;s/Global//g;s/^_/GL_/g')" 7 | 8 | if [ ! -d "$ROM_NAME_MIN" ]; then 9 | mkdir -p "$ROM_NAME_MIN" 10 | fi 11 | 12 | if [ ! -f unpack_bootimg.py ]; then 13 | wget "https://android.googlesource.com/platform/system/tools/mkbootimg/+archive/refs/heads/master.tar.gz" &> /dev/null 14 | tar -xf master.tar.gz unpack_bootimg.py && chmod +x unpack_bootimg.py && rm master.tar.gz 15 | fi 16 | 17 | cd "$ROM_NAME_MIN" 18 | 19 | echo "$ROM_NAME" > info.txt 20 | 21 | if [ ! -f "${ROM_NAME}.zip" ]; then 22 | aria2c -j32 -x16 -c -s16 "$ROM_LINK" &> aria.txt 23 | fi 24 | 25 | unzip -p "${ROM_NAME}.zip" boot.img > boot 26 | 27 | python3 "../unpack_bootimg.py" --boot_img boot --out . &> /dev/null 28 | 29 | xxd -g 1 kernel | grep "40 71 02 00" -B1 -A8702 | grep -oE "[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ [0-9a-f]+ [0-9a-f]+ [0-9a-f]+ [0-9a-f]+ [0-9a-f]+ [0-9a-f]+ [0-9a-f]+ [0-9a-f]+ [0-9a-f]+ [0-9a-f]+ [0-9a-f]+ [0-9a-f]+ [0-9a-f]+" > firmware.xxd 30 | 31 | xxd -r -p <(sed -n '1,8704p' firmware.xxd | sed "s/ //g" | tr -d '\n') > j20s_novatek_ts_fw01.bin 32 | xxd -r -p <(sed -n '8705,17408p' firmware.xxd | sed "s/ //g" | tr -d '\n') > j20s_novatek_ts_mp01.bin 33 | xxd -r -p <(sed -n '17409,26112p' firmware.xxd | sed "s/ //g" | tr -d '\n') > j20s_novatek_ts_fw02.bin 34 | xxd -r -p <(sed -n '26113,34816p' firmware.xxd | sed "s/ //g" | tr -d '\n') > j20s_novatek_ts_mp02.bin 35 | 36 | dos2unix ./*.bin 37 | 38 | find . -type f -iname "*.bin" -exec avr-objcopy -I binary -O ihex {} {}.ihex \; 39 | 40 | dos2unix ./*.ihex 41 | 42 | md5sum ./*.bin ./*.ihex >> info.txt 43 | 44 | ZIPNAME="${ROM_NAME_MIN}_TOUCH_FW.zip" 45 | zip -r9 "$ZIPNAME" ./*.bin ./*.ihex info.txt &> /dev/null 46 | 47 | if [[ $3 != '' && $3 == 'k' ]]; then 48 | zip -ur "$ZIPNAME" firmware.xxd kernel 49 | fi 50 | 51 | rm ./*.bin ./*.ihex info.txt dtb ramdisk boot firmware.xxd kernel "${ROM_NAME}.zip" 52 | 53 | if [[ $2 != '' && $2 == 'u' ]]; then 54 | UPLOAD=$(curl -s -F f[]=@"$ZIPNAME" "https://oshi.at" | grep DL | sed 's/DL: //g') 55 | echo -e "$UPLOAD\n" >> ../links.txt 56 | fi 57 | 58 | mv "$ZIPNAME" ../ 59 | 60 | cd ../ 61 | 62 | rm -rf "$ROM_NAME_MIN" 63 | 64 | echo -e "JOB: $ROM_NAME_MIN DONE\n" 65 | -------------------------------------------------------------------------------- /0007-touch-fw-dumper/touchfw_uploader.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "touchfw_uploader.ipynb", 7 | "provenance": [], 8 | "collapsed_sections": [] 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | }, 14 | "language_info": { 15 | "name": "python" 16 | } 17 | }, 18 | "cells": [ 19 | { 20 | "cell_type": "code", 21 | "metadata": { 22 | "id": "E3RkbppjGSAj" 23 | }, 24 | "source": [ 25 | "!rm -rf $(pwd)/*" 26 | ], 27 | "execution_count": 18, 28 | "outputs": [] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "metadata": { 33 | "id": "_SHGC4TM1vAc" 34 | }, 35 | "source": [ 36 | "!apt install aria2 gcc-avr xxd dos2unix &> /dev/null\n", 37 | "!wget https://github.com/Jebaitedneko/scripts/raw/master/0007-touch-fw-dumper/dump_touch_fw.sh &> /dev/null\n", 38 | "!chmod +x dump_touch_fw.sh\n", 39 | "![ -f .src ] && cat .src | while read f; do bash -c \"nohup bash dump_touch_fw.sh \"$f\" u &\"; done\n", 40 | "![ -f links.txt ] && echo -e \"\\n\" && cat links.txt" 41 | ], 42 | "execution_count": null, 43 | "outputs": [] 44 | } 45 | ] 46 | } -------------------------------------------------------------------------------- /0008-git-patcheroo/patch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | EDITOR_CHOICE=xed 4 | 5 | function gitaliases() { 6 | alias gca='git commit --amend' 7 | alias gcp='git cherry-pick' 8 | alias grc='git rebase --continue' 9 | alias gpf='git push --force' 10 | alias grh='git reset --hard' 11 | alias clr='clear' 12 | } 13 | 14 | function crej() { 15 | find . -type f -iname "*.rej" -delete 16 | find . -type f -iname "*.orig" -delete 17 | } 18 | 19 | function orej() { 20 | find . -type f -iname "*.rej" | while read -r f; do sh -c "$EDITOR_CHOICE $f"; sh -c "$EDITOR_CHOICE ${f/.rej/}"; done 21 | } 22 | 23 | function scrape() { 24 | curl -s "$1/commits" | grep "Copy the full SHA" | grep -oE "[0-9a-f]{40}" &> ./req 25 | first=$(head -n1 < ./req) 26 | i=34; j=$2 27 | while [ $((j)) -gt 0 ]; do 28 | link="$1/commits/$3?after=$first+$i&branch=$3" 29 | echo -e "\n$link" 30 | curl -s "$link" | grep "Copy the full SHA" | grep -oE "[0-9a-f]{40}" 31 | i=$((i+35)); j=$((j-1)) 32 | done 33 | rm ./req 34 | } 35 | 36 | function gpatch() { 37 | 38 | # You can export REPO_LINK=https://github.com/torvalds/linux 39 | # for example and then just call gpatch with the commit SHA 40 | # instead of the whole link everytime 41 | 42 | link=$(echo "$1" | cut -f1 -d#) 43 | name=$(echo "$link" | sed "s/.*commit\///g") 44 | ftmp="./$name" 45 | plog="./patch_log" 46 | 47 | [[ $REPO_LINK != "" ]] && link="$REPO_LINK/commit/$1" 48 | curl -s "$link".patch > "$ftmp" 49 | cmtmsg=$(awk '/---/{stop=1} stop==0{print}' < ./"$ftmp" | tail -n+2 | sed "s/\[PATCH\]//g") 50 | newlineys_msg=$(echo "$cmtmsg" | pcregrep -M 'Subject.*\n .*\n') 51 | if [[ $(("${#newlineys_msg}")) -gt 0 ]]; then 52 | corrected_msg=$(echo "$newlineys_msg" | sed ':a;N;$!ba;s/\n//g') 53 | echo "Fixing commit msg newlines" 54 | cmtmsg=$(echo "$cmtmsg" | grep -v "$newlineys_msg") 55 | cmtmsg=$(echo "$cmtmsg" | sed "/Date:.*/a $corrected_msg") 56 | fi 57 | cmtmsg="$2$cmtmsg" 58 | author="${cmtmsg/From: /}" 59 | codate="${cmtmsg/Date: /}" 60 | subjct=$(echo "${cmtmsg/Subject: /}" | tail -n+3) 61 | subjct=$(echo "$2$subjct" | sed "s/^ //g") 62 | patch -Np1 < "$ftmp" > "$plog" 63 | 64 | echo -e "\n\n------------------------------------------------------PATCH DATA START------------------------------------------------------" 65 | echo -e "\n$(cat "$plog")\n" 66 | echo -e "------------------------------------------------------PATCH DATA END--------------------------------------------------------\n\n" 67 | 68 | result="$(( $(grep -oE "*.rej" "$plog" | wc -c) + $(grep -oE "File to patch:" "$plog" | wc -c) ))" 69 | if [[ $result -eq 0 ]]; then 70 | echo -e "\nPatching succeeded. Applying commit from original data. Please review the changes and amend it." 71 | crej; rm "$plog" "$ftmp" 72 | git ls-files -dmo | grep -vE "^out/" | while read -r f; do git add -f "$f"; done 73 | git commit -m "$subjct" --author="$author" -s # --date="$codate" 74 | echo -e "\n" && git log --oneline | head -n3 75 | else 76 | echo -e "\nPatching failed. Saving the original commit info to \$subjct, author data to \$author, date to \$codate." 77 | echo -e "\n\nPlease review the changes and commit it with" 78 | echo -e "\n\ngit commit -m \"\$(echo -e \"\$subjct\")\" --author=\"\$(echo -e \"\$author\")\" --date=\"\$(echo -e \"\$codate\")\"." 79 | echo -e "\n\nRecent commits:" 80 | git log --oneline | head -n3 81 | echo -e "\n" 82 | rm "$plog" "$ftmp" 83 | fi 84 | 85 | } 86 | -------------------------------------------------------------------------------- /0009-fedora-module-rebuild/ec_sys-builder.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -x && cd ~ 3 | rpmdev-setuptree 4 | [[ ! -f $(cat .kernel-rpm) ]] && yumdownloader --source kernel | grep -oE "kernel-.*.rpm" > .kernel-rpm 5 | sudo yum-builddep $(cat .kernel-rpm) 6 | rpm -Uvh $(cat .kernel-rpm) 7 | cd ~/rpmbuild/SPECS 8 | rpmbuild -bp --target=$(uname -m) kernel.spec > .kernel-rpm-build 9 | cd ~/rpmbuild/BUILD/$(cat .kernel-rpm-build | grep -oE "kernel-.*/linux-.*.x86_64" | tail -n1) 10 | 11 | kver=$(uname -a | cut -f3 -d' ' | cut -f1 -d'-') 12 | version=$(echo $kver | cut -f1 -d.) 13 | patchlevel=$(echo $kver | cut -f2 -d.) 14 | sublevel=$(echo $kver | cut -f3 -d.) 15 | extraver=$(uname -a | cut -f3 -d' ' | cut -f2 -d'-') 16 | sed -i "s/^VERSION =.*/VERSION = ${version}/g" Makefile 17 | sed -i "s/^PATCHLEVEL =.*/PATCHLEVEL = ${patchlevel}/g" Makefile 18 | sed -i "s/^SUBLEVEL =.*/SUBLEVEL = ${sublevel}/g" Makefile 19 | sed -i "s/^EXTRAVERSION =.*/EXTRAVERSION = -${extraver}/g" Makefile 20 | cp configs/kernel-${kver}-x86_64.config .config 21 | echo -e "\nCONFIG_ACPI_EC_DEBUGFS=m" >> .config 22 | make modules_prepare 23 | 24 | xzcat /boot/symvers-$(uname -r).xz | grep "drivers/acpi" > drivers/acpi/Module.symvers 25 | xzcat /boot/symvers-$(uname -r).xz > Module.symvers 26 | make M=drivers/acpi modules 27 | xz -z drivers/acpi/ec_sys.ko 28 | sudo cp drivers/acpi/ec_sys.ko.xz /usr/lib/modules/$(uname -r)/kernel/drivers/acpi 29 | 30 | xzcat /boot/symvers-$(uname -r).xz | grep "drivers/media/usb/uvc" > drivers/media/usb/uvc/Module.symvers 31 | ( cd drivers/media/usb/uvc && patch -Np1 < ~/uvc_driver.patch ) 32 | make M=drivers/media/usb/uvc modules 33 | xz -z drivers/media/usb/uvc/uvcvideo.ko 34 | sudo cp drivers/media/usb/uvc/uvcvideo.ko.xz /usr/lib/modules/$(uname -r)/kernel/drivers/media/usb/uvc 35 | 36 | sudo depmod 37 | # make binrpm-pkg 38 | cd ~ && set +x 39 | -------------------------------------------------------------------------------- /0009-fedora-module-rebuild/uvc_driver.patch: -------------------------------------------------------------------------------- 1 | From 1d6eef858e0c5ae4594136df7d6be60bacd442e8 Mon Sep 17 00:00:00 2001 2 | From: Jebaitedneko 3 | Date: Fri, 2 Jun 2023 02:24:03 +0530 4 | Subject: [PATCH] patch 5 | 6 | --- 7 | uvc_driver.c | 10 ++++++++++ 8 | 1 file changed, 10 insertions(+) 9 | 10 | diff --git a/uvc_driver.c b/uvc_driver.c 11 | index 7aefa76..723f303 100644 12 | --- a/uvc_driver.c 13 | +++ b/uvc_driver.c 14 | @@ -2402,6 +2402,16 @@ static const struct uvc_device_info uvc_quirk_force_y8 = { 15 | * though they are compliant. 16 | */ 17 | static const struct usb_device_id uvc_ids[] = { 18 | + /* Quanta ACER HD User Facing */ 19 | + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 20 | + | USB_DEVICE_ID_MATCH_INT_INFO, 21 | + .idVendor = 0x0408, 22 | + .idProduct = 0x4035, 23 | + .bInterfaceClass = USB_CLASS_VIDEO, 24 | + .bInterfaceSubClass = 1, 25 | + .bInterfaceProtocol = UVC_PC_PROTOCOL_15, 26 | + .driver_info = (kernel_ulong_t)&(const struct uvc_device_info){.uvc_version = 0x010a,} 27 | + }, 28 | /* Quanta USB2.0 HD UVC Webcam */ 29 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 30 | | USB_DEVICE_ID_MATCH_INT_INFO, 31 | -- 32 | 2.41.0.rc2 33 | 34 | --------------------------------------------------------------------------------