We present the design, fabrication, modeling and feedback control of an earthworm-inspired soft robot capable of bidirectional locomotion on both horizontal and inclined flat platforms. In this approach, the locomotion patterns are controlled by actively varying the coefficients of friction between the contacting surfaces of the robot and the supporting platform, thus emulating the limbless locomotion of earthworms at a conceptual level. Earthworms are characterized by segmented body structures, known as metameres, composed of longitudinal and circular muscles which during locomotion are contracted and relaxed periodically in order to generate a peristaltic wave that propagates backwards with respect to the worm's traveling direction; simultaneously, microscopic bristle-like structures (setae) on each metamere coordinately protrude or retract to provide varying traction with the ground, thus enabling the worm to burrow or crawl. The proposed soft robot replicates the muscle functionalities and setae mechanisms of earthworms employing pneumatically-driven actuators and 3D-printed casings. Using the notion of controllable subspace, we show that friction plays an indispensable role in the generation and control of locomotion in robots of this type. Based on this analysis, we introduce a simulation-based method for synthesizing and implementing feedback control schemes that enable the robot to generate forward and backward locomotion. From the set of feasible control strategies studied in simulation, we adopt a friction-modulation-based feedback control algorithm which is implementable in real time and compatible with the hardware limitations of the robotic system. Through experiments, the robot is demonstrated to be capable of bidirectional crawling on surfaces with different textures and inclinations.