#!/bin/sh echo "*** GENERATE ROOTFS BEGIN ***" global SRC_ROOT := $[pwd] # Remember the glibc prepared folder. global GLIBC_PREPARED := "$[pwd]/work/glibc/glibc_prepared" # Remember the BysyBox install folder. global BUSYBOX_INSTALLED := "$[pwd]/work/busybox/busybox_installed" cd work echo "Preparing initramfs work area..." rm -rf rootfs # Copy all BusyBox generated stuff to the location of our 'initramfs' folder. cp -r $BUSYBOX_INSTALLED rootfs # Copy all rootfs resources to the location of our 'initramfs' folder. cp -r src/minimal_rootfs/* rootfs cd rootfs # Remove 'linuxrc' which is used when we boot in 'RAM disk' mode. rm -f linuxrc # Read the 'COPY_SOURCE_ROOTFS' property from '.config' global COPY_SOURCE_ROOTFS := $[grep -i ^COPY_SOURCE_ROOTFS $SRC_ROOT/.config | cut -f2 -d'=] if test $COPY_SOURCE_ROOTFS = "true" { # Copy all prepared source files and folders to '/src'. Note that the scripts # will not work there because you also need proper toolchain. cp -r ../src src echo "Source files and folders have been copied to '/src'." } else { echo "Source files and folders have been skipped." } # This is for the dynamic loader. Note that the name and the location are both # specific for 32-bit and 64-bit machines. First we check the BusyBox executable # and then we copy the dynamic loader to its appropriate location. global BUSYBOX_ARCH := $[file bin/busybox | cut -d' ' -f3] if test $BUSYBOX_ARCH = "64-bit" { mkdir lib64 cp $GLIBC_PREPARED/lib/ld-linux* lib64 echo "Dynamic loader is accessed via '/lib64'." } else { cp $GLIBC_PREPARED/lib/ld-linux* lib echo "Dynamic loader is accessed via '/lib'." } # Copy all necessary 'glibc' libraries to '/lib' BEGIN. # BusyBox has direct dependencies on these libraries. cp $GLIBC_PREPARED/lib/libm.so.6 lib cp $GLIBC_PREPARED/lib/libc.so.6 lib # These libraries are necessary for the DNS resolving. cp $GLIBC_PREPARED/lib/libresolv.so.2 lib cp $GLIBC_PREPARED/lib/libnss_dns.so.2 lib # Copy all necessary 'glibc' libraries to '/lib' END. strip -g \ $SRC_ROOT/work/rootfs/bin/* \ $SRC_ROOT/work/rootfs/sbin/* \ $SRC_ROOT/work/rootfs/lib/* \ !2 >/dev/null echo "Reduced the size of libraries and executables." echo "The initramfs area has been generated." cd $SRC_ROOT echo "*** GENERATE ROOTFS END ***" (CommandList children: [ (C {(echo)} {(DQ ("*** GENERATE ROOTFS BEGIN ***"))}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:SRC_ROOT) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [12 14] ) } spids: [11] ) ] spids: [11] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:GLIBC_PREPARED) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [21 23] ) (/work/glibc/glibc_prepared) } spids: [20] ) ] spids: [20] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:BUSYBOX_INSTALLED) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [31 33] ) (/work/busybox/busybox_installed) } spids: [30] ) ] spids: [30] ) (C {(cd)} {(work)}) (C {(echo)} {(DQ ("Preparing initramfs work area..."))}) (C {(rm)} {(-rf)} {(rootfs)}) (C {(cp)} {(-r)} {($ VSub_Name "$BUSYBOX_INSTALLED")} {(rootfs)}) (C {(cp)} {(-r)} {(src/minimal_rootfs/) (Lit_Other "*")} {(rootfs)}) (C {(cd)} {(rootfs)}) (C {(rm)} {(-f)} {(linuxrc)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:COPY_SOURCE_ROOTFS) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(grep)} {(-i)} {(Lit_Other "^") (COPY_SOURCE_ROOTFS)} {($ VSub_Name "$SRC_ROOT") (/.config)} ) (C {(cut)} {(-f2)} {(-d) (SQ <"=">)}) ] negated: False ) ] ) left_token: spids: [100 121] ) ) } spids: [98] ) ] spids: [98] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$COPY_SOURCE_ROOTFS"))} {(Lit_Other "=")} {(DQ (true))} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(cp)} {(-r)} {(../src)} {(src)}) (C {(echo)} {(DQ ("Source files and folders have been copied to '/src'."))}) ] spids: [-1 143] ) ] else_action: [(C {(echo)} {(DQ ("Source files and folders have been skipped."))})] spids: [169 178] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:BUSYBOX_ARCH) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [(C {(file)} {(bin/busybox)}) (C {(cut)} {(-d) (SQ <" ">)} {(-f3)})] negated: False ) ] ) left_token: spids: [191 206] ) } spids: [190] ) ] spids: [190] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$BUSYBOX_ARCH"))} {(Lit_Other "=")} {(DQ (64-bit))} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(mkdir)} {(lib64)}) (C {(cp)} {($ VSub_Name "$GLIBC_PREPARED") (/lib/ld-linux) (Lit_Other "*")} {(lib64)}) (C {(echo)} {(DQ ("Dynamic loader is accessed via '/lib64'."))}) ] spids: [-1 226] ) ] else_action: [ (C {(cp)} {($ VSub_Name "$GLIBC_PREPARED") (/lib/ld-linux) (Lit_Other "*")} {(lib)}) (C {(echo)} {(DQ ("Dynamic loader is accessed via '/lib'."))}) ] spids: [249 267] ) (C {(cp)} {($ VSub_Name "$GLIBC_PREPARED") (/lib/libm.so.6)} {(lib)}) (C {(cp)} {($ VSub_Name "$GLIBC_PREPARED") (/lib/libc.so.6)} {(lib)}) (C {(cp)} {($ VSub_Name "$GLIBC_PREPARED") (/lib/libresolv.so.2)} {(lib)}) (C {(cp)} {($ VSub_Name "$GLIBC_PREPARED") (/lib/libnss_dns.so.2)} {(lib)}) (SimpleCommand words: [ {(strip)} {(-g)} {($ VSub_Name "$SRC_ROOT") (/work/rootfs/bin/) (Lit_Other "*")} {($ VSub_Name "$SRC_ROOT") (/work/rootfs/sbin/) (Lit_Other "*")} {($ VSub_Name "$SRC_ROOT") (/work/rootfs/lib/) (Lit_Other "*")} ] redirects: [(Redir op_id:Redir_Great fd:2 arg_word:{(/dev/null)} spids:[338])] ) (C {(echo)} {(DQ ("Reduced the size of libraries and executables."))}) (C {(echo)} {(DQ ("The initramfs area has been generated."))}) (C {(cd)} {($ VSub_Name "$SRC_ROOT")}) (C {(echo)} {(DQ ("*** GENERATE ROOTFS END ***"))}) ] )